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
c1c8f54e
Commit
c1c8f54e
authored
Feb 14, 2014
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a few asserts. Made some steps idiotproof.
parent
9d3f7230
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
44 deletions
+72
-44
drawing_tool.cpp
pcbnew/tools/drawing_tool.cpp
+72
-44
No files found.
pcbnew/tools/drawing_tool.cpp
View file @
c1c8f54e
...
@@ -83,11 +83,11 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
...
@@ -83,11 +83,11 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
VECTOR2I
cursorPos
=
m_controls
->
GetCursorPosition
();
VECTOR2I
cursorPos
=
m_controls
->
GetCursorPosition
();
// Init the new item attributes
// Init the new item attributes
DRAWSEGMENT
*
graphi
c
=
new
DRAWSEGMENT
(
m_board
);
DRAWSEGMENT
*
ar
c
=
new
DRAWSEGMENT
(
m_board
);
graphi
c
->
SetShape
(
S_ARC
);
ar
c
->
SetShape
(
S_ARC
);
graphi
c
->
SetAngle
(
0.0
);
ar
c
->
SetAngle
(
0.0
);
graphi
c
->
SetWidth
(
m_board
->
GetDesignSettings
().
m_DrawSegmentWidth
);
ar
c
->
SetWidth
(
m_board
->
GetDesignSettings
().
m_DrawSegmentWidth
);
graphi
c
->
SetCenter
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
ar
c
->
SetCenter
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
DRAWSEGMENT
helperLine
;
DRAWSEGMENT
helperLine
;
helperLine
.
SetShape
(
S_SEGMENT
);
helperLine
.
SetShape
(
S_SEGMENT
);
...
@@ -100,7 +100,6 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
...
@@ -100,7 +100,6 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
m_controls
->
ShowCursor
(
true
);
m_controls
->
ShowCursor
(
true
);
m_controls
->
SetSnapping
(
true
);
m_controls
->
SetSnapping
(
true
);
m_controls
->
SetAutoPan
(
true
);
Activate
();
Activate
();
...
@@ -120,25 +119,25 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
...
@@ -120,25 +119,25 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
if
(
evt
->
IsCancel
()
)
if
(
evt
->
IsCancel
()
)
{
{
delete
graphi
c
;
delete
ar
c
;
break
;
break
;
}
}
else
if
(
evt
->
IsKeyUp
()
)
else
if
(
evt
->
IsKeyUp
()
)
{
{
int
width
=
graphi
c
->
GetWidth
();
int
width
=
ar
c
->
GetWidth
();
// Modify the new item width
// Modify the new item width
if
(
evt
->
KeyCode
()
==
'-'
&&
width
>
WIDTH_STEP
)
if
(
evt
->
KeyCode
()
==
'-'
&&
width
>
WIDTH_STEP
)
graphi
c
->
SetWidth
(
width
-
WIDTH_STEP
);
ar
c
->
SetWidth
(
width
-
WIDTH_STEP
);
else
if
(
evt
->
KeyCode
()
==
'='
)
else
if
(
evt
->
KeyCode
()
==
'='
)
graphi
c
->
SetWidth
(
width
+
WIDTH_STEP
);
ar
c
->
SetWidth
(
width
+
WIDTH_STEP
);
else
if
(
evt
->
KeyCode
()
==
'/'
)
else
if
(
evt
->
KeyCode
()
==
'/'
)
{
{
if
(
clockwise
)
if
(
clockwise
)
graphic
->
SetAngle
(
graphi
c
->
GetAngle
()
-
3600.0
);
arc
->
SetAngle
(
ar
c
->
GetAngle
()
-
3600.0
);
else
else
graphic
->
SetAngle
(
graphi
c
->
GetAngle
()
+
3600.0
);
arc
->
SetAngle
(
ar
c
->
GetAngle
()
+
3600.0
);
clockwise
=
!
clockwise
;
clockwise
=
!
clockwise
;
}
}
...
@@ -161,34 +160,45 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
...
@@ -161,34 +160,45 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
}
}
else
else
{
{
helperLine
.
SetStart
(
graphic
->
GetCenter
()
);
helperLine
.
SetStart
(
arc
->
GetCenter
()
);
graphic
->
SetLayer
(
layer
);
arc
->
SetCenter
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
preview
.
Add
(
graphic
);
arc
->
SetLayer
(
layer
);
preview
.
Add
(
arc
);
preview
.
Add
(
&
helperLine
);
preview
.
Add
(
&
helperLine
);
m_controls
->
SetAutoPan
(
true
);
}
}
}
}
break
;
break
;
case
SET_END
:
case
SET_END
:
{
{
VECTOR2D
startLine
(
graphic
->
GetArcStart
()
-
graphic
->
GetCenter
()
);
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
arc
->
GetCenter
()
)
startAngle
=
startLine
.
Angle
();
{
VECTOR2D
startLine
(
arc
->
GetArcStart
()
-
arc
->
GetCenter
()
);
startAngle
=
startLine
.
Angle
();
arc
->
SetArcStart
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
}
else
--
step
;
// one another chance to draw a proper arc
}
}
break
;
break
;
case
SET_ANGLE
:
case
SET_ANGLE
:
{
{
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
graphic
->
GetCenter
()
)
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
arc
->
GetArcStart
()
)
{
{
m_view
->
Add
(
graphic
);
assert
(
arc
->
GetAngle
()
>
0
);
m_board
->
Add
(
graphic
);
assert
(
arc
->
GetArcStart
()
!=
arc
->
GetArcEnd
()
);
graphic
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
assert
(
arc
->
GetWidth
()
>
0
);
m_view
->
Add
(
arc
);
m_board
->
Add
(
arc
);
arc
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
}
else
else
{
--
step
;
// one another chance to draw a proper arc
// Let's give the user another chance of drawing a proper arc (i.e. angle > 0)
--
step
;
}
}
}
break
;
break
;
}
}
...
@@ -202,18 +212,18 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
...
@@ -202,18 +212,18 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
switch
(
step
)
switch
(
step
)
{
{
case
SET_ORIGIN
:
case
SET_ORIGIN
:
graphi
c
->
SetCenter
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
ar
c
->
SetCenter
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
break
;
break
;
case
SET_END
:
case
SET_END
:
helperLine
.
SetEnd
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
helperLine
.
SetEnd
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
graphi
c
->
SetArcStart
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
ar
c
->
SetArcStart
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
break
;
break
;
case
SET_ANGLE
:
case
SET_ANGLE
:
{
{
// Compute the current angle
// Compute the current angle
VECTOR2D
endLine
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
-
graphi
c
->
GetCenter
()
);
VECTOR2D
endLine
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
-
ar
c
->
GetCenter
()
);
double
newAngle
=
RAD2DECIDEG
(
endLine
.
Angle
()
-
startAngle
);
double
newAngle
=
RAD2DECIDEG
(
endLine
.
Angle
()
-
startAngle
);
if
(
clockwise
&&
newAngle
<
0.0
)
if
(
clockwise
&&
newAngle
<
0.0
)
...
@@ -221,7 +231,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
...
@@ -221,7 +231,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
else
if
(
!
clockwise
&&
newAngle
>
0.0
)
else
if
(
!
clockwise
&&
newAngle
>
0.0
)
newAngle
-=
3600.0
;
newAngle
-=
3600.0
;
graphi
c
->
SetAngle
(
newAngle
);
ar
c
->
SetAngle
(
newAngle
);
}
}
break
;
break
;
}
}
...
@@ -245,8 +255,8 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
...
@@ -245,8 +255,8 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
int
DRAWING_TOOL
::
DrawText
(
TOOL_EVENT
&
aEvent
)
int
DRAWING_TOOL
::
DrawText
(
TOOL_EVENT
&
aEvent
)
{
{
// Init the new item attributes
// Init the new item attributes
TEXTE_PCB
*
newT
ext
=
m_frame
->
CreateTextePcb
(
NULL
);
TEXTE_PCB
*
t
ext
=
m_frame
->
CreateTextePcb
(
NULL
);
if
(
newT
ext
==
NULL
)
if
(
t
ext
==
NULL
)
{
{
setTransitions
();
setTransitions
();
return
0
;
return
0
;
...
@@ -254,7 +264,7 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
...
@@ -254,7 +264,7 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
// 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
(
m_view
);
KIGFX
::
VIEW_GROUP
preview
(
m_view
);
preview
.
Add
(
newT
ext
);
preview
.
Add
(
t
ext
);
m_view
->
Add
(
&
preview
);
m_view
->
Add
(
&
preview
);
m_controls
->
ShowCursor
(
true
);
m_controls
->
ShowCursor
(
true
);
...
@@ -271,7 +281,7 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
...
@@ -271,7 +281,7 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
if
(
evt
->
IsCancel
()
)
if
(
evt
->
IsCancel
()
)
{
{
// it was already added by CreateTextPcb()
// it was already added by CreateTextPcb()
m_board
->
Delete
(
newT
ext
);
m_board
->
Delete
(
t
ext
);
break
;
break
;
}
}
...
@@ -279,28 +289,31 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
...
@@ -279,28 +289,31 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
{
{
if
(
evt
->
IsAction
(
&
COMMON_ACTIONS
::
rotate
)
)
if
(
evt
->
IsAction
(
&
COMMON_ACTIONS
::
rotate
)
)
{
{
newText
->
Rotate
(
newT
ext
->
GetPosition
(),
m_frame
->
GetRotationAngle
()
);
text
->
Rotate
(
t
ext
->
GetPosition
(),
m_frame
->
GetRotationAngle
()
);
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
}
else
if
(
evt
->
IsAction
(
&
COMMON_ACTIONS
::
flip
)
)
else
if
(
evt
->
IsAction
(
&
COMMON_ACTIONS
::
flip
)
)
{
{
newText
->
Flip
(
newT
ext
->
GetPosition
()
);
text
->
Flip
(
t
ext
->
GetPosition
()
);
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
}
}
}
else
if
(
evt
->
IsClick
(
BUT_LEFT
)
)
else
if
(
evt
->
IsClick
(
BUT_LEFT
)
)
{
{
newText
->
ClearFlags
();
assert
(
text
->
GetText
().
Length
()
>
0
);
m_view
->
Add
(
newText
);
assert
(
text
->
GetSize
().
x
>
0
&&
text
->
GetSize
().
y
>
0
);
// m_board->Add( newText ); // it is already added by CreateTextePcb()
newText
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
text
->
ClearFlags
();
m_view
->
Add
(
text
);
// m_board->Add( text ); // it is already added by CreateTextePcb()
text
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
break
;
break
;
}
}
else
if
(
evt
->
IsMotion
()
)
else
if
(
evt
->
IsMotion
()
)
{
{
newT
ext
->
SetTextPosition
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
t
ext
->
SetTextPosition
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
// Show a preview of the item
// Show a preview of the item
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
...
@@ -411,6 +424,9 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
...
@@ -411,6 +424,9 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
{
{
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
dimension
->
GetPosition
()
)
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
dimension
->
GetPosition
()
)
{
{
assert
(
dimension
->
GetOrigin
()
!=
dimension
->
GetEnd
()
);
assert
(
dimension
->
GetWidth
()
>
0
);
m_view
->
Add
(
dimension
);
m_view
->
Add
(
dimension
);
m_board
->
Add
(
dimension
);
m_board
->
Add
(
dimension
);
dimension
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
dimension
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
...
@@ -519,6 +535,9 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
...
@@ -519,6 +535,9 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
else
if
(
evt
->
IsClick
(
BUT_LEFT
)
)
else
if
(
evt
->
IsClick
(
BUT_LEFT
)
)
{
{
assert
(
target
->
GetSize
()
>
0
);
assert
(
target
->
GetWidth
()
>
0
);
m_view
->
Add
(
target
);
m_view
->
Add
(
target
);
m_board
->
Add
(
target
);
m_board
->
Add
(
target
);
target
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
target
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
...
@@ -638,6 +657,7 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
...
@@ -638,6 +657,7 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
Activate
();
Activate
();
bool
started
=
false
;
bool
started
=
false
;
int
addedSegments
=
0
;
// Main loop: keep receiving events
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
{
...
@@ -648,7 +668,7 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
...
@@ -648,7 +668,7 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
if
(
evt
->
IsCancel
()
)
if
(
evt
->
IsCancel
()
)
{
{
preview
.
FreeItems
();
preview
.
FreeItems
();
if
(
!
started
)
if
(
!
started
)
// TODO check it
delete
graphic
;
delete
graphic
;
break
;
break
;
}
}
...
@@ -691,10 +711,14 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
...
@@ -691,10 +711,14 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
{
{
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
graphic
->
GetStart
()
)
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
graphic
->
GetStart
()
)
{
{
assert
(
graphic
->
GetLength
()
>
0
);
assert
(
graphic
->
GetWidth
()
>
0
);
m_view
->
Add
(
graphic
);
m_view
->
Add
(
graphic
);
m_board
->
Add
(
graphic
);
m_board
->
Add
(
graphic
);
graphic
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
graphic
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
preview
.
Remove
(
graphic
);
preview
.
Remove
(
graphic
);
++
addedSegments
;
if
(
aContinous
)
if
(
aContinous
)
{
{
...
@@ -704,10 +728,12 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
...
@@ -704,10 +728,12 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
preview
.
Add
(
graphic
);
preview
.
Add
(
graphic
);
}
}
else
else
{
break
;
break
;
}
}
}
else
else
if
(
addedSegments
>
0
)
// User has clicked twice in the same spot
{
// User has clicked twice in the same spot
{
delete
graphic
;
// seems like a clear sign that the drawing is finished
delete
graphic
;
// seems like a clear sign that the drawing is finished
break
;
// and we should remove the latest DRAWSEGMENT we have created
break
;
// and we should remove the latest DRAWSEGMENT we have created
}
}
...
@@ -808,6 +834,8 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
...
@@ -808,6 +834,8 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
{
{
if
(
numPoints
>
2
)
if
(
numPoints
>
2
)
{
{
assert
(
zone
->
GetNumCorners
()
>
2
);
// Finish the zone
// Finish the zone
zone
->
Outline
()
->
CloseLastContour
();
zone
->
Outline
()
->
CloseLastContour
();
zone
->
Outline
()
->
RemoveNullSegments
();
zone
->
Outline
()
->
RemoveNullSegments
();
...
...
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