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
ae5fa232
Commit
ae5fa232
authored
Feb 11, 2014
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added DIMENSION drawing tool.
parent
46db6ac1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
152 additions
and
0 deletions
+152
-0
common_actions.cpp
pcbnew/tools/common_actions.cpp
+4
-0
common_actions.h
pcbnew/tools/common_actions.h
+3
-0
drawing_tool.cpp
pcbnew/tools/drawing_tool.cpp
+142
-0
drawing_tool.h
pcbnew/tools/drawing_tool.h
+2
-0
pcb_tools.cpp
pcbnew/tools/pcb_tools.cpp
+1
-0
No files found.
pcbnew/tools/common_actions.cpp
View file @
ae5fa232
...
@@ -72,3 +72,7 @@ TOOL_ACTION COMMON_ACTIONS::drawArc( "pcbnew.InteractiveDrawing.arc",
...
@@ -72,3 +72,7 @@ TOOL_ACTION COMMON_ACTIONS::drawArc( "pcbnew.InteractiveDrawing.arc",
TOOL_ACTION
COMMON_ACTIONS
::
drawText
(
"pcbnew.InteractiveDrawing.text"
,
TOOL_ACTION
COMMON_ACTIONS
::
drawText
(
"pcbnew.InteractiveDrawing.text"
,
AS_GLOBAL
,
'T'
,
AS_GLOBAL
,
'T'
,
"Add a text"
,
"Add a text"
);
"Add a text"
,
"Add a text"
);
TOOL_ACTION
COMMON_ACTIONS
::
drawDimension
(
"pcbnew.InteractiveDrawing.dimension"
,
AS_GLOBAL
,
'X'
,
"Add a dimension"
,
"Add a dimension"
);
pcbnew/tools/common_actions.h
View file @
ae5fa232
...
@@ -68,4 +68,7 @@ public:
...
@@ -68,4 +68,7 @@ public:
/// Activation of the drawing tool (text)
/// Activation of the drawing tool (text)
static
TOOL_ACTION
drawText
;
static
TOOL_ACTION
drawText
;
/// Activation of the drawing tool (dimension)
static
TOOL_ACTION
drawDimension
;
};
};
pcbnew/tools/drawing_tool.cpp
View file @
ae5fa232
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include <class_board.h>
#include <class_board.h>
#include <class_drawsegment.h>
#include <class_drawsegment.h>
#include <class_pcb_text.h>
#include <class_pcb_text.h>
#include <class_dimension.h>
#include <gal/graphics_abstraction_layer.h>
#include <gal/graphics_abstraction_layer.h>
#include <tool/tool_manager.h>
#include <tool/tool_manager.h>
#include <confirm.h>
#include <confirm.h>
...
@@ -350,6 +351,11 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
...
@@ -350,6 +351,11 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
// Init the new item attributes
// Init the new item attributes
TEXTE_PCB
*
newText
=
getEditFrame
<
PCB_EDIT_FRAME
>
()
->
CreateTextePcb
(
NULL
);
TEXTE_PCB
*
newText
=
getEditFrame
<
PCB_EDIT_FRAME
>
()
->
CreateTextePcb
(
NULL
);
if
(
newText
==
NULL
)
{
setTransitions
();
return
0
;
}
// Add a VIEW_GROUP that serves as a preview for the new item
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX
::
VIEW_GROUP
preview
(
view
);
KIGFX
::
VIEW_GROUP
preview
(
view
);
...
@@ -417,10 +423,146 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
...
@@ -417,10 +423,146 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
}
}
int
DRAWING_TOOL
::
DrawDimension
(
TOOL_EVENT
&
aEvent
)
{
m_continous
=
false
;
int
step
=
0
;
KIGFX
::
VIEW
*
view
=
getView
();
KIGFX
::
VIEW_CONTROLS
*
controls
=
getViewControls
();
BOARD
*
board
=
getModel
<
BOARD
>
(
PCB_T
);
DIMENSION
*
dimension
=
new
DIMENSION
(
board
);
// Init the new item attributes
dimension
->
Text
().
SetSize
(
board
->
GetDesignSettings
().
m_PcbTextSize
);
int
width
=
board
->
GetDesignSettings
().
m_PcbTextWidth
;
int
maxthickness
=
Clamp_Text_PenSize
(
width
,
dimension
->
Text
().
GetSize
()
);
if
(
width
>
maxthickness
)
width
=
maxthickness
;
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
KIGFX
::
VIEW_GROUP
preview
(
view
);
view
->
Add
(
&
preview
);
controls
->
ShowCursor
(
true
);
controls
->
SetSnapping
(
true
);
Activate
();
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
VECTOR2D
cursorPos
=
view
->
ToWorld
(
controls
->
GetCursorPosition
()
);
if
(
evt
->
IsCancel
()
)
{
delete
dimension
;
break
;
}
else
if
(
evt
->
IsKeyUp
()
)
{
int
width
=
dimension
->
GetWidth
();
// Modify the new item width
if
(
evt
->
KeyCode
()
==
'-'
&&
width
>
WIDTH_STEP
)
dimension
->
SetWidth
(
width
-
WIDTH_STEP
);
else
if
(
evt
->
KeyCode
()
==
'='
)
dimension
->
SetWidth
(
width
+
WIDTH_STEP
);
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
else
if
(
evt
->
IsClick
(
BUT_LEFT
)
)
{
switch
(
step
)
{
case
0
:
{
LAYER_NUM
layer
=
getEditFrame
<
PCB_EDIT_FRAME
>
()
->
GetScreen
()
->
m_Active_Layer
;
if
(
IsCopperLayer
(
layer
)
)
{
DisplayInfoMessage
(
NULL
,
_
(
"Graphic not allowed on Copper layers"
)
);
--
step
;
}
else
{
controls
->
SetAutoPan
(
true
);
dimension
->
SetLayer
(
layer
);
dimension
->
SetOrigin
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
preview
.
Add
(
dimension
);
}
}
break
;
case
2
:
{
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
dimension
->
GetPosition
()
)
{
view
->
Add
(
dimension
);
board
->
Add
(
dimension
);
dimension
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
}
break
;
}
if
(
++
step
==
3
)
break
;
}
else
if
(
evt
->
IsMotion
()
)
{
switch
(
step
)
{
case
1
:
dimension
->
SetEnd
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
break
;
case
2
:
{
/* Calculating the direction of travel perpendicular to the selected axis. */
double
angle
=
dimension
->
GetAngle
()
+
(
M_PI
/
2
);
wxPoint
pos
(
cursorPos
.
x
,
cursorPos
.
y
);
wxPoint
delta
(
pos
-
dimension
->
m_featureLineDO
);
double
height
=
(
delta
.
x
*
cos
(
angle
)
)
+
(
delta
.
y
*
sin
(
angle
)
);
dimension
->
SetHeight
(
height
);
}
break
;
}
// Show a preview of the item
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
}
controls
->
ShowCursor
(
false
);
controls
->
SetSnapping
(
false
);
controls
->
SetAutoPan
(
false
);
view
->
Remove
(
&
preview
);
setTransitions
();
return
0
;
}
void
DRAWING_TOOL
::
setTransitions
()
void
DRAWING_TOOL
::
setTransitions
()
{
{
Go
(
&
DRAWING_TOOL
::
DrawLine
,
COMMON_ACTIONS
::
drawLine
.
MakeEvent
()
);
Go
(
&
DRAWING_TOOL
::
DrawLine
,
COMMON_ACTIONS
::
drawLine
.
MakeEvent
()
);
Go
(
&
DRAWING_TOOL
::
DrawCircle
,
COMMON_ACTIONS
::
drawCircle
.
MakeEvent
()
);
Go
(
&
DRAWING_TOOL
::
DrawCircle
,
COMMON_ACTIONS
::
drawCircle
.
MakeEvent
()
);
Go
(
&
DRAWING_TOOL
::
DrawArc
,
COMMON_ACTIONS
::
drawArc
.
MakeEvent
()
);
Go
(
&
DRAWING_TOOL
::
DrawArc
,
COMMON_ACTIONS
::
drawArc
.
MakeEvent
()
);
Go
(
&
DRAWING_TOOL
::
DrawText
,
COMMON_ACTIONS
::
drawText
.
MakeEvent
()
);
Go
(
&
DRAWING_TOOL
::
DrawText
,
COMMON_ACTIONS
::
drawText
.
MakeEvent
()
);
Go
(
&
DRAWING_TOOL
::
DrawDimension
,
COMMON_ACTIONS
::
drawDimension
.
MakeEvent
()
);
}
}
pcbnew/tools/drawing_tool.h
View file @
ae5fa232
...
@@ -57,6 +57,8 @@ public:
...
@@ -57,6 +57,8 @@ public:
int
DrawText
(
TOOL_EVENT
&
aEvent
);
int
DrawText
(
TOOL_EVENT
&
aEvent
);
int
DrawDimension
(
TOOL_EVENT
&
aEvent
);
private
:
private
:
///> Starts drawing a selected shape.
///> Starts drawing a selected shape.
int
draw
(
STROKE_T
aShape
);
int
draw
(
STROKE_T
aShape
);
...
...
pcbnew/tools/pcb_tools.cpp
View file @
ae5fa232
...
@@ -59,6 +59,7 @@ void PCB_EDIT_FRAME::setupTools()
...
@@ -59,6 +59,7 @@ void PCB_EDIT_FRAME::setupTools()
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
drawCircle
);
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
drawCircle
);
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
drawArc
);
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
drawArc
);
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
drawText
);
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
drawText
);
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
drawDimension
);
// Register tools
// Register tools
m_toolManager
->
RegisterTool
(
new
SELECTION_TOOL
);
m_toolManager
->
RegisterTool
(
new
SELECTION_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