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
e6a7ff3c
Commit
e6a7ff3c
authored
Mar 18, 2014
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Isolated EDIT_CONSTRAINTs to different .cpp/.h files.
parent
6a1d3445
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
420 additions
and
358 deletions
+420
-358
CMakeLists.txt
pcbnew/CMakeLists.txt
+1
-0
edit_constraints.cpp
pcbnew/tools/edit_constraints.cpp
+175
-0
edit_constraints.h
pcbnew/tools/edit_constraints.h
+242
-0
edit_points.cpp
pcbnew/tools/edit_points.cpp
+1
-134
edit_points.h
pcbnew/tools/edit_points.h
+1
-224
No files found.
pcbnew/CMakeLists.txt
View file @
e6a7ff3c
...
...
@@ -256,6 +256,7 @@ set( PCBNEW_CLASS_SRCS
tools/selection_area.cpp
tools/bright_box.cpp
tools/edit_points.cpp
tools/edit_constraints.cpp
tools/point_editor.cpp
tools/drawing_tool.cpp
tools/edit_tool.cpp
...
...
pcbnew/tools/edit_constraints.cpp
0 → 100644
View file @
e6a7ff3c
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2014 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "edit_constraints.h"
#include "edit_points.h"
#include <geometry/seg.h>
void
EC_VERTICAL
::
Apply
(
EDIT_POINT
&
aHandle
)
{
VECTOR2I
point
=
aHandle
.
GetPosition
();
point
.
x
=
m_constrainer
.
GetPosition
().
x
;
aHandle
.
SetPosition
(
point
);
}
void
EC_HORIZONTAL
::
Apply
(
EDIT_POINT
&
aHandle
)
{
VECTOR2I
point
=
aHandle
.
GetPosition
();
point
.
y
=
m_constrainer
.
GetPosition
().
y
;
aHandle
.
SetPosition
(
point
);
}
void
EC_45DEGREE
::
Apply
(
EDIT_POINT
&
aHandle
)
{
// Current line vector
VECTOR2I
lineVector
(
aHandle
.
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
);
aHandle
.
SetPosition
(
m_constrainer
.
GetPosition
()
+
newLineVector
);
}
EC_LINE
::
EC_LINE
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aConstrainer
)
:
EDIT_CONSTRAINT
<
EDIT_POINT
>
(
aConstrained
),
m_constrainer
(
aConstrainer
)
{
m_line
=
m_constrained
.
GetPosition
()
-
m_constrainer
.
GetPosition
();
}
void
EC_LINE
::
Apply
(
EDIT_POINT
&
aHandle
)
{
SEG
main
(
m_constrainer
.
GetPosition
(),
m_constrainer
.
GetPosition
()
+
m_line
);
SEG
projection
(
aHandle
.
GetPosition
(),
aHandle
.
GetPosition
()
+
m_line
.
Perpendicular
()
);
if
(
OPT_VECTOR2I
intersect
=
projection
.
IntersectLines
(
main
)
)
aHandle
.
SetPosition
(
*
intersect
);
}
void
EC_CIRCLE
::
Apply
(
EDIT_POINT
&
aHandle
)
{
VECTOR2I
centerToEnd
=
m_end
.
GetPosition
()
-
m_center
.
GetPosition
();
VECTOR2I
centerToPoint
=
aHandle
.
GetPosition
()
-
m_center
.
GetPosition
();
int
radius
=
centerToEnd
.
EuclideanNorm
();
double
angle
=
centerToPoint
.
Angle
();
VECTOR2I
newLine
(
radius
,
0
);
newLine
=
newLine
.
Rotate
(
angle
);
aHandle
.
SetPosition
(
m_center
.
GetPosition
()
+
newLine
);
}
EC_CONVERGING
::
EC_CONVERGING
(
EDIT_LINE
&
aLine
,
EDIT_POINTS
&
aPoints
)
:
EDIT_CONSTRAINT
<
EDIT_POINT
>
(
aLine
.
GetOrigin
()
),
m_colinearConstraint
(
NULL
),
m_line
(
aLine
),
m_editPoints
(
aPoints
)
{
// Dragged segment endings
EDIT_POINT
&
origin
=
aLine
.
GetOrigin
();
EDIT_POINT
&
end
=
aLine
.
GetEnd
();
// Previous and next points, to make constraining lines (adjacent to the dragged line)
EDIT_POINT
&
prevOrigin
=
*
aPoints
.
Previous
(
origin
);
EDIT_POINT
&
nextEnd
=
*
aPoints
.
Next
(
end
);
// Constraints for segments adjacent to the dragged one
m_originSideConstraint
=
new
EC_LINE
(
origin
,
prevOrigin
);
m_endSideConstraint
=
new
EC_LINE
(
end
,
nextEnd
);
// Store the current vector of the line
m_draggedVector
=
end
.
GetPosition
()
-
origin
.
GetPosition
();
// Check for colinearity
SEG
originSide
(
origin
.
GetPosition
(),
prevOrigin
.
GetPosition
()
);
SEG
endSide
(
end
.
GetPosition
(),
nextEnd
.
GetPosition
()
);
SEG
dragged
(
origin
.
GetPosition
(),
end
.
GetPosition
()
);
if
(
dragged
.
Collinear
(
originSide
)
)
m_colinearConstraint
=
m_originSideConstraint
;
else
if
(
dragged
.
Collinear
(
endSide
)
)
m_colinearConstraint
=
m_endSideConstraint
;
}
EC_CONVERGING
::~
EC_CONVERGING
()
{
delete
m_originSideConstraint
;
delete
m_endSideConstraint
;
// m_colinearConstraint should not be freed, it is a pointer to one of the above
}
void
EC_CONVERGING
::
Apply
(
EDIT_POINT
&
aHandle
)
{
// The dragged segment endpoints
EDIT_POINT
&
origin
=
m_line
.
GetOrigin
();
EDIT_POINT
&
end
=
m_line
.
GetEnd
();
if
(
m_colinearConstraint
)
{
m_colinearConstraint
->
Apply
(
origin
);
m_colinearConstraint
->
Apply
(
end
);
}
// The dragged segment
SEG
dragged
(
origin
.
GetPosition
(),
origin
.
GetPosition
()
+
m_draggedVector
);
// Do not allow points on the adjacent segments move freely
m_originSideConstraint
->
Apply
();
m_endSideConstraint
->
Apply
();
EDIT_POINT
&
prevOrigin
=
*
m_editPoints
.
Previous
(
origin
);
EDIT_POINT
&
nextEnd
=
*
m_editPoints
.
Next
(
end
);
// Two segments adjacent to the dragged segment
SEG
originSide
=
SEG
(
origin
.
GetPosition
(),
prevOrigin
.
GetPosition
()
);
SEG
endSide
=
SEG
(
end
.
GetPosition
(),
nextEnd
.
GetPosition
()
);
// First intersection point (dragged segment against origin side)
if
(
OPT_VECTOR2I
originIntersect
=
dragged
.
IntersectLines
(
originSide
)
)
origin
.
SetPosition
(
*
originIntersect
);
// Second intersection point (dragged segment against end side)
if
(
OPT_VECTOR2I
endIntersect
=
dragged
.
IntersectLines
(
endSide
)
)
end
.
SetPosition
(
*
endIntersect
);
// Check if adjacent segments intersect (did we dragged the line to the point that it may
// create a selfintersecting polygon?)
originSide
=
SEG
(
origin
.
GetPosition
(),
prevOrigin
.
GetPosition
()
);
endSide
=
SEG
(
end
.
GetPosition
(),
nextEnd
.
GetPosition
()
);
if
(
OPT_VECTOR2I
originEndIntersect
=
endSide
.
Intersect
(
originSide
)
)
{
origin
.
SetPosition
(
*
originEndIntersect
);
end
.
SetPosition
(
*
originEndIntersect
);
}
}
pcbnew/tools/edit_constraints.h
0 → 100644
View file @
e6a7ff3c
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2014 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef EDIT_CONSTRAINTS_H_
#define EDIT_CONSTRAINTS_H_
#include <math/vector2d.h>
class
EDIT_POINT
;
class
EDIT_LINE
;
class
EDIT_POINTS
;
/**
* Class EDIT_CONSTRAINT
*
* Allows to describe constraints between two edit handles. After the constrained handle is changed,
* Apply() has to be called to fix its coordinates according to the implemented constraint.
*/
template
<
class
EDIT_TYPE
>
class
EDIT_CONSTRAINT
{
public
:
/**
* Constructor
*
* @param aConstrained is EDIT_POINT to which the constraint is applied.
*/
EDIT_CONSTRAINT
(
EDIT_TYPE
&
aConstrained
)
:
m_constrained
(
aConstrained
)
{};
virtual
~
EDIT_CONSTRAINT
()
{};
/**
* Function Apply()
*
* Corrects coordinates of the constrained edit handle.
*/
virtual
void
Apply
(
EDIT_TYPE
&
aHandle
)
=
0
;
/**
* Function Apply()
*
* Corrects coordinates of the constrained edit handle.
*/
void
Apply
()
{
Apply
(
m_constrained
);
}
protected
:
EDIT_TYPE
&
m_constrained
;
///< Point that is constrained by rules implemented by Apply()
};
/**
* Class EC_VERTICAL.
*
* EDIT_CONSTRAINT that imposes a constraint that two points have to have the same X coordinate.
*/
class
EC_VERTICAL
:
public
EDIT_CONSTRAINT
<
EDIT_POINT
>
{
public
:
/**
* Constructor.
*
* @param aConstrained is the point that is put under constrain.
* @param aConstrainer is the point that is the source of the constrain.
*/
EC_VERTICAL
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aConstrainer
)
:
EDIT_CONSTRAINT
<
EDIT_POINT
>
(
aConstrained
),
m_constrainer
(
aConstrainer
)
{}
///> @copydoc EDIT_CONSTRAINT::Apply()
virtual
void
Apply
(
EDIT_POINT
&
aHandle
);
private
:
const
EDIT_POINT
&
m_constrainer
;
///< Point that imposes the constraint.
};
/**
* Class EC_HORIZONTAL.
*
* EDIT_CONSTRAINT that imposes a constraint that two points have to have the same Y coordinate.
*/
class
EC_HORIZONTAL
:
public
EDIT_CONSTRAINT
<
EDIT_POINT
>
{
public
:
/**
* Constructor.
*
* @param aConstrained is the point that is put under constrain.
* @param aConstrainer is the point that is the source of the constrain.
*/
EC_HORIZONTAL
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aConstrainer
)
:
EDIT_CONSTRAINT
<
EDIT_POINT
>
(
aConstrained
),
m_constrainer
(
aConstrainer
)
{}
///> @copydoc EDIT_CONSTRAINT::Apply()
virtual
void
Apply
(
EDIT_POINT
&
aHandle
);
private
:
const
EDIT_POINT
&
m_constrainer
;
///< Point that imposes the constraint.
};
/**
* Class EC_45DEGREE
*
* EDIT_CONSTRAINT that imposes a constraint that two to be located at angle of 45 degree
* multiplicity.
*/
class
EC_45DEGREE
:
public
EDIT_CONSTRAINT
<
EDIT_POINT
>
{
public
:
/**
* Constructor.
*
* @param aConstrained is the point that is put under constrain.
* @param aConstrainer is the point that is the source of the constrain.
*/
EC_45DEGREE
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aConstrainer
)
:
EDIT_CONSTRAINT
<
EDIT_POINT
>
(
aConstrained
),
m_constrainer
(
aConstrainer
)
{}
///> @copydoc EDIT_CONSTRAINT::Apply()
virtual
void
Apply
(
EDIT_POINT
&
aHandle
);
private
:
const
EDIT_POINT
&
m_constrainer
;
///< Point that imposes the constraint.
};
/**
* Class EC_LINE
*
* EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a line (determined
* by 2 points).
*/
class
EC_LINE
:
public
EDIT_CONSTRAINT
<
EDIT_POINT
>
{
public
:
EC_LINE
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aConstrainer
);
///> @copydoc EDIT_CONSTRAINT::Apply()
virtual
void
Apply
(
EDIT_POINT
&
aHandle
);
private
:
const
EDIT_POINT
&
m_constrainer
;
///< Point that imposes the constraint.
VECTOR2I
m_line
;
///< Vector representing the constraining line.
};
/**
* Class EC_CIRCLE.
*
* EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a circle.
*/
class
EC_CIRCLE
:
public
EDIT_CONSTRAINT
<
EDIT_POINT
>
{
public
:
/**
* Constructor.
*
* @param aConstrained is the point that is put under constrain.
* @parama aCenter is the point that is the center of the circle.
* @parama aEnd is the point that decides on the radius of the circle.
*/
EC_CIRCLE
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aCenter
,
const
EDIT_POINT
&
aEnd
)
:
EDIT_CONSTRAINT
<
EDIT_POINT
>
(
aConstrained
),
m_center
(
aCenter
),
m_end
(
aEnd
)
{}
///> @copydoc EDIT_CONSTRAINT::Apply()
virtual
void
Apply
(
EDIT_POINT
&
aHandle
);
private
:
///> Point that imposes the constraint (center of the circle).
const
EDIT_POINT
&
m_center
;
///> Point that imposes the constraint (decides on the radius of the circle).
const
EDIT_POINT
&
m_end
;
};
/**
* Class EC_CONVERGING
*
* EDIT_CONSTRAINT for 3 segment: dragged and two adjacent ones, enforcing to keep their slopes
* and allows only to change ending points. Applied to zones.
*/
class
EC_CONVERGING
:
public
EDIT_CONSTRAINT
<
EDIT_POINT
>
{
public
:
EC_CONVERGING
(
EDIT_LINE
&
aLine
,
EDIT_POINTS
&
aPoints
);
virtual
~
EC_CONVERGING
();
///> @copydoc EDIT_CONSTRAINT::Apply()
virtual
void
Apply
(
EDIT_POINT
&
aHandle
);
private
:
///> Constraint for origin side segment.
EDIT_CONSTRAINT
<
EDIT_POINT
>*
m_originSideConstraint
;
///> Constraint for end side segment.
EDIT_CONSTRAINT
<
EDIT_POINT
>*
m_endSideConstraint
;
///> Additional constriant, applied when at least two points are collinear. It is a pointer to
///> m_[origin/end]SideConstraint, so it should not be freed.
EDIT_CONSTRAINT
<
EDIT_POINT
>*
m_colinearConstraint
;
///> Dragged segment.
EDIT_LINE
&
m_line
;
///> EDIT_POINTS instance that stores currently modified lines.
EDIT_POINTS
&
m_editPoints
;
///> Vector that represents the initial direction of the dragged segment.
VECTOR2I
m_draggedVector
;
};
#endif
/* EDIT_CONSTRAINTS_H_ */
pcbnew/tools/edit_points.cpp
View file @
e6a7ff3c
...
...
@@ -24,9 +24,8 @@
#include <boost/foreach.hpp>
#include "edit_points.h"
#include <gal/graphics_abstraction_layer.h>
#include
<geometry/seg.h>
#include
"edit_points.h"
bool
EDIT_POINT
::
WithinPoint
(
const
VECTOR2I
&
aPoint
,
unsigned
int
aSize
)
const
{
...
...
@@ -145,135 +144,3 @@ void EDIT_POINTS::ViewDraw( int aLayer, KIGFX::GAL* aGal ) const
aGal
->
PopDepth
();
}
void
EC_45DEGREE
::
Apply
(
EDIT_POINT
&
aHandle
)
{
// Current line vector
VECTOR2I
lineVector
(
aHandle
.
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
);
aHandle
.
SetPosition
(
m_constrainer
.
GetPosition
()
+
newLineVector
);
}
EC_LINE
::
EC_LINE
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aConstrainer
)
:
EDIT_CONSTRAINT
<
EDIT_POINT
>
(
aConstrained
),
m_constrainer
(
aConstrainer
)
{
m_line
=
m_constrained
.
GetPosition
()
-
m_constrainer
.
GetPosition
();
}
void
EC_LINE
::
Apply
(
EDIT_POINT
&
aHandle
)
{
SEG
main
(
m_constrainer
.
GetPosition
(),
m_constrainer
.
GetPosition
()
+
m_line
);
SEG
projection
(
aHandle
.
GetPosition
(),
aHandle
.
GetPosition
()
+
m_line
.
Perpendicular
()
);
if
(
OPT_VECTOR2I
intersect
=
projection
.
IntersectLines
(
main
)
)
aHandle
.
SetPosition
(
*
intersect
);
}
void
EC_CIRCLE
::
Apply
(
EDIT_POINT
&
aHandle
)
{
VECTOR2I
centerToEnd
=
m_end
.
GetPosition
()
-
m_center
.
GetPosition
();
VECTOR2I
centerToPoint
=
aHandle
.
GetPosition
()
-
m_center
.
GetPosition
();
int
radius
=
centerToEnd
.
EuclideanNorm
();
double
angle
=
centerToPoint
.
Angle
();
VECTOR2I
newLine
(
radius
,
0
);
newLine
=
newLine
.
Rotate
(
angle
);
aHandle
.
SetPosition
(
m_center
.
GetPosition
()
+
newLine
);
}
EC_CONVERGING
::
EC_CONVERGING
(
EDIT_LINE
&
aLine
,
EDIT_POINTS
&
aPoints
)
:
EDIT_CONSTRAINT
<
EDIT_POINT
>
(
aLine
.
GetOrigin
()
),
m_colinearConstraint
(
NULL
),
m_line
(
aLine
),
m_editPoints
(
aPoints
)
{
// Dragged segment endings
EDIT_POINT
&
origin
=
aLine
.
GetOrigin
();
EDIT_POINT
&
end
=
aLine
.
GetEnd
();
// Previous and next points, to make constraining lines (adjacent to the dragged line)
EDIT_POINT
&
prevOrigin
=
*
aPoints
.
Previous
(
origin
);
EDIT_POINT
&
nextEnd
=
*
aPoints
.
Next
(
end
);
// Constraints for segments adjacent to the dragged one
m_originSideConstraint
=
new
EC_LINE
(
origin
,
prevOrigin
);
m_endSideConstraint
=
new
EC_LINE
(
end
,
nextEnd
);
// Store the current vector of the line
m_draggedVector
=
end
.
GetPosition
()
-
origin
.
GetPosition
();
// Check for colinearity
SEG
originSide
(
origin
.
GetPosition
(),
prevOrigin
.
GetPosition
()
);
SEG
endSide
(
end
.
GetPosition
(),
nextEnd
.
GetPosition
()
);
SEG
dragged
(
origin
.
GetPosition
(),
end
.
GetPosition
()
);
if
(
dragged
.
Collinear
(
originSide
)
)
m_colinearConstraint
=
m_originSideConstraint
;
else
if
(
dragged
.
Collinear
(
endSide
)
)
m_colinearConstraint
=
m_endSideConstraint
;
}
EC_CONVERGING
::~
EC_CONVERGING
()
{
delete
m_originSideConstraint
;
delete
m_endSideConstraint
;
// m_colinearConstraint should not be freed, it is a pointer to one of the above
}
void
EC_CONVERGING
::
Apply
(
EDIT_POINT
&
aHandle
)
{
// The dragged segment endpoints
EDIT_POINT
&
origin
=
m_line
.
GetOrigin
();
EDIT_POINT
&
end
=
m_line
.
GetEnd
();
if
(
m_colinearConstraint
)
{
m_colinearConstraint
->
Apply
(
origin
);
m_colinearConstraint
->
Apply
(
end
);
}
// The dragged segment
SEG
dragged
(
origin
.
GetPosition
(),
origin
.
GetPosition
()
+
m_draggedVector
);
// Do not allow points on the adjacent segments move freely
m_originSideConstraint
->
Apply
();
m_endSideConstraint
->
Apply
();
EDIT_POINT
&
prevOrigin
=
*
m_editPoints
.
Previous
(
origin
);
EDIT_POINT
&
nextEnd
=
*
m_editPoints
.
Next
(
end
);
// Two segments adjacent to the dragged segment
SEG
originSide
=
SEG
(
origin
.
GetPosition
(),
prevOrigin
.
GetPosition
()
);
SEG
endSide
=
SEG
(
end
.
GetPosition
(),
nextEnd
.
GetPosition
()
);
// First intersection point (dragged segment against origin side)
if
(
OPT_VECTOR2I
originIntersect
=
dragged
.
IntersectLines
(
originSide
)
)
origin
.
SetPosition
(
*
originIntersect
);
// Second intersection point (dragged segment against end side)
if
(
OPT_VECTOR2I
endIntersect
=
dragged
.
IntersectLines
(
endSide
)
)
end
.
SetPosition
(
*
endIntersect
);
// Check if adjacent segments intersect (did we dragged the line to the point that it may
// create a selfintersecting polygon?)
originSide
=
SEG
(
origin
.
GetPosition
(),
prevOrigin
.
GetPosition
()
);
endSide
=
SEG
(
end
.
GetPosition
(),
nextEnd
.
GetPosition
()
);
if
(
OPT_VECTOR2I
originEndIntersect
=
endSide
.
Intersect
(
originSide
)
)
{
origin
.
SetPosition
(
*
originEndIntersect
);
end
.
SetPosition
(
*
originEndIntersect
);
}
}
pcbnew/tools/edit_points.h
View file @
e6a7ff3c
...
...
@@ -25,57 +25,12 @@
#ifndef EDIT_POINTS_H_
#define EDIT_POINTS_H_
#include <vector>
#include <list>
#include <boost/shared_ptr.hpp>
#include <math/box2.h>
#include <base_struct.h>
#include <layers_id_colors_and_visibility.h>
class
EDIT_POINT
;
/**
* Class EDIT_CONSTRAINT
*
* Allows to describe constraints between two edit handles. After the constrained handle is changed,
* Apply() has to be called to fix its coordinates according to the implemented constraint.
*/
template
<
class
EDIT_TYPE
>
class
EDIT_CONSTRAINT
{
public
:
/**
* Constructor
*
* @param aConstrained is EDIT_POINT to which the constraint is applied.
*/
EDIT_CONSTRAINT
(
EDIT_TYPE
&
aConstrained
)
:
m_constrained
(
aConstrained
)
{};
virtual
~
EDIT_CONSTRAINT
()
{};
/**
* Function Apply()
*
* Corrects coordinates of the constrained edit handle.
*/
virtual
void
Apply
(
EDIT_TYPE
&
aHandle
)
=
0
;
/**
* Function Apply()
*
* Corrects coordinates of the constrained edit handle.
*/
void
Apply
()
{
Apply
(
m_constrained
);
}
protected
:
EDIT_TYPE
&
m_constrained
;
///< Point that is constrained by rules implemented by Apply()
};
#include "edit_constraints.h"
/**
* Class EDIT_POINT
...
...
@@ -458,182 +413,4 @@ private:
std
::
deque
<
EDIT_LINE
>
m_lines
;
///< EDIT_LINEs for modifying m_parent
};
/**
* Class EC_VERTICAL.
*
* EDIT_CONSTRAINT that imposes a constraint that two points have to have the same X coordinate.
*/
class
EC_VERTICAL
:
public
EDIT_CONSTRAINT
<
EDIT_POINT
>
{
public
:
/**
* Constructor.
*
* @param aConstrained is the point that is put under constrain.
* @param aConstrainer is the point that is the source of the constrain.
*/
EC_VERTICAL
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aConstrainer
)
:
EDIT_CONSTRAINT
<
EDIT_POINT
>
(
aConstrained
),
m_constrainer
(
aConstrainer
)
{}
///> @copydoc EDIT_CONSTRAINT::Apply()
virtual
void
Apply
(
EDIT_POINT
&
aHandle
)
{
VECTOR2I
point
=
aHandle
.
GetPosition
();
point
.
x
=
m_constrainer
.
GetPosition
().
x
;
aHandle
.
SetPosition
(
point
);
}
private
:
const
EDIT_POINT
&
m_constrainer
;
///< Point that imposes the constraint.
};
/**
* Class EC_HORIZONTAL.
*
* EDIT_CONSTRAINT that imposes a constraint that two points have to have the same Y coordinate.
*/
class
EC_HORIZONTAL
:
public
EDIT_CONSTRAINT
<
EDIT_POINT
>
{
public
:
/**
* Constructor.
*
* @param aConstrained is the point that is put under constrain.
* @param aConstrainer is the point that is the source of the constrain.
*/
EC_HORIZONTAL
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aConstrainer
)
:
EDIT_CONSTRAINT
<
EDIT_POINT
>
(
aConstrained
),
m_constrainer
(
aConstrainer
)
{}
///> @copydoc EDIT_CONSTRAINT::Apply()
virtual
void
Apply
(
EDIT_POINT
&
aHandle
)
{
VECTOR2I
point
=
aHandle
.
GetPosition
();
point
.
y
=
m_constrainer
.
GetPosition
().
y
;
aHandle
.
SetPosition
(
point
);
}
private
:
const
EDIT_POINT
&
m_constrainer
;
///< Point that imposes the constraint.
};
/**
* Class EC_45DEGREE
*
* EDIT_CONSTRAINT that imposes a constraint that two to be located at angle of 45 degree
* multiplicity.
*/
class
EC_45DEGREE
:
public
EDIT_CONSTRAINT
<
EDIT_POINT
>
{
public
:
/**
* Constructor.
*
* @param aConstrained is the point that is put under constrain.
* @param aConstrainer is the point that is the source of the constrain.
*/
EC_45DEGREE
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aConstrainer
)
:
EDIT_CONSTRAINT
<
EDIT_POINT
>
(
aConstrained
),
m_constrainer
(
aConstrainer
)
{}
///> @copydoc EDIT_CONSTRAINT::Apply()
virtual
void
Apply
(
EDIT_POINT
&
aHandle
);
private
:
const
EDIT_POINT
&
m_constrainer
;
///< Point that imposes the constraint.
};
/**
* Class EC_LINE
*
* EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a line (determined
* by 2 points).
*/
class
EC_LINE
:
public
EDIT_CONSTRAINT
<
EDIT_POINT
>
{
public
:
EC_LINE
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aConstrainer
);
///> @copydoc EDIT_CONSTRAINT::Apply()
virtual
void
Apply
(
EDIT_POINT
&
aHandle
);
private
:
EDIT_POINT
m_constrainer
;
///< Point that imposes the constraint.
VECTOR2I
m_line
;
///< Vector representing the constraining line.
};
/**
* Class EC_CIRCLE.
*
* EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a circle.
*/
class
EC_CIRCLE
:
public
EDIT_CONSTRAINT
<
EDIT_POINT
>
{
public
:
/**
* Constructor.
*
* @param aConstrained is the point that is put under constrain.
* @parama aCenter is the point that is the center of the circle.
* @parama aEnd is the point that decides on the radius of the circle.
*/
EC_CIRCLE
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aCenter
,
const
EDIT_POINT
&
aEnd
)
:
EDIT_CONSTRAINT
<
EDIT_POINT
>
(
aConstrained
),
m_center
(
aCenter
),
m_end
(
aEnd
)
{}
///> @copydoc EDIT_CONSTRAINT::Apply()
virtual
void
Apply
(
EDIT_POINT
&
aHandle
);
private
:
///> Point that imposes the constraint (center of the circle).
const
EDIT_POINT
&
m_center
;
///> Point that imposes the constraint (decides on the radius of the circle).
const
EDIT_POINT
&
m_end
;
};
/**
* Class EC_CONVERGING
*
* EDIT_CONSTRAINT for 3 segment: dragged and two adjacent ones, enforcing to keep their slopes
* and allows only to change ending points. Applied to zones.
*/
class
EC_CONVERGING
:
public
EDIT_CONSTRAINT
<
EDIT_POINT
>
{
public
:
EC_CONVERGING
(
EDIT_LINE
&
aLine
,
EDIT_POINTS
&
aPoints
);
virtual
~
EC_CONVERGING
();
///> @copydoc EDIT_CONSTRAINT::Apply()
virtual
void
Apply
(
EDIT_POINT
&
aHandle
);
private
:
///> Constraint for origin side segment.
EDIT_CONSTRAINT
<
EDIT_POINT
>*
m_originSideConstraint
;
///> Constraint for end side segment.
EDIT_CONSTRAINT
<
EDIT_POINT
>*
m_endSideConstraint
;
///> Additional constriant, applied when at least two points are collinear. It is a pointer to
///> m_[origin/end]SideConstraint, so it should not be freed.
EDIT_CONSTRAINT
<
EDIT_POINT
>*
m_colinearConstraint
;
///> Dragged segment.
EDIT_LINE
&
m_line
;
///> EDIT_POINTS instance that stores currently modified lines.
EDIT_POINTS
&
m_editPoints
;
///> Vector that represents the initial direction of the dragged segment.
VECTOR2I
m_draggedVector
;
};
#endif
/* EDIT_POINTS_H_ */
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