Commit cfe611c4 authored by Mikhail Karpenko's avatar Mikhail Karpenko

Add TEARDROP class functions to KiCAD source

Now you can select a PCB segment and pick a menu to create a teardrop
for the segment. This is just a mock up and this function works for segment-to-via joits only.
parent 02b1319c
......@@ -278,6 +278,7 @@ set( PCB_COMMON_SRCS
../pcbnew/class_track.cpp
../pcbnew/class_zone.cpp
../pcbnew/class_zone_settings.cpp
../pcbnew/class_teardrop.cpp
../pcbnew/classpcb.cpp
../pcbnew/ratsnest_data.cpp
../pcbnew/ratsnest_viewitem.cpp
......
......@@ -636,6 +636,8 @@ public:
*/
void ShowDesignRulesEditor( wxCommandEvent& event );
void ShowTeardropsWnd( wxCommandEvent& event );
/* toolbars update UI functions: */
void PrepareLayerIndicator();
......
#include "class_teardrop.h"
#include "class_board.h"
#include "class_board_item.h"
TEARDROP::TEARDROP(BOARD_ITEM *aParent) :
TRACK(aParent, PCB_TRACE_T)
......@@ -6,9 +8,28 @@ TEARDROP::TEARDROP(BOARD_ITEM *aParent) :
m_type = TEARDROP_NONE;
}
bool TEARDROP::Create(TRACK &aTrack)
bool TEARDROP::Create(TRACK &aTrack, ENDPOINT_T endPoint, TEARDROP_TYPE type = TEARDROP_STRAIGHT)
{
std::vector<VECTOR2I> upperSegment;
std::vector<VECTOR2I> lowerSegment;
bool result = false;
VIA *aVia = GetViaOnEnd(aTrack, endPoint);
if (aVia == NULL) {
return false;
}
if (type == TEARDROP_STRAIGHT) {
result = StraightSegments(aTrack, *aVia, upperSegment, lowerSegment, 100);
}
else if (type == TEARDROP_CURVED) {
result = CurvedSegments(aTrack, *aVia, upperSegment, lowerSegment);
}
if (result == true) {
result = BuildTracks(aTrack, upperSegment, lowerSegment);
}
return result;
}
bool TEARDROP::SetVector(TRACK &aTrack, const VIA & aVia, VECTOR2I &startPoint, VECTOR2I &endPoint)
......@@ -106,3 +127,63 @@ bool TEARDROP::StraightSegments(TRACK &aTrack, const VIA &aVia, std::vector<VECT
return true;
}
// TODO: m_TracksConnected member is considered a temporary storage. Find another way to get an object
VIA *TEARDROP::GetViaOnEnd(TRACK &aTrack, ENDPOINT_T endPoint)
{
wxPoint trackPoint;
std::vector<TRACK *>::const_iterator iter;
if (endPoint == ENDPOINT_START) {
trackPoint = aTrack.GetStart();
}
else {
trackPoint = aTrack.GetEnd();
}
for (iter = aTrack.m_TracksConnected.begin(); iter != aTrack.m_TracksConnected.end(); ++iter) {
KICAD_T type = (*iter)->Type();
bool hitTest = (*iter)->HitTest(trackPoint);
if (type == PCB_VIA_T && hitTest == true) {
return static_cast<VIA *>(*iter);
}
}
return NULL;
}
bool TEARDROP::BuildTracks(TRACK &aTrack, std::vector<VECTOR2I> upperSegments, std::vector<VECTOR2I> lowerSegments)
{
BOARD *board = aTrack.GetBoard();
wxPoint currentPoint(0, 0);
wxPoint prevPoint(upperSegments[0].x, upperSegments[0].y);
for (size_t i = 0; i < upperSegments.size(); i++) {
TRACK *track = new TRACK(board);
track->SetWidth(aTrack.GetWidth());
track->SetLayer(aTrack.GetLayer());
track->SetNetCode(aTrack.GetNetCode());
currentPoint.x = upperSegments[i].x;
currentPoint.y = upperSegments[i].y;
track->SetStart(prevPoint);
track->SetEnd(currentPoint);
board->Add(track);
m_upperSegment.push_back(track);
prevPoint = currentPoint;
}
currentPoint = wxPoint(0, 0);
prevPoint = wxPoint(lowerSegments[0].x, lowerSegments[0].y);
for (size_t i = 0; i < lowerSegments.size(); i++) {
TRACK *track = new TRACK(board);
track->SetWidth(aTrack.GetWidth());
track->SetLayer(aTrack.GetLayer());
track->SetNetCode(aTrack.GetNetCode());
currentPoint.x = lowerSegments[i].x;
currentPoint.y = lowerSegments[i].y;
track->SetStart(prevPoint);
track->SetEnd(currentPoint);
board->Add(track);
m_lowerSegment.push_back(track);
prevPoint = currentPoint;
}
return true;
}
......@@ -36,9 +36,9 @@ public:
* @brief Defines the type of a teardrop.
*/
typedef enum {
TEARDROP_NONE, /// The type is undefined
TEARDROP_STRAIGHT, /// The teardrop is created by two straight segments
TEARDROP_CURVED /// The teardrop is created by several segments approximating deltoid
TEARDROP_NONE, ///< The type is undefined
TEARDROP_STRAIGHT, ///< The teardrop is created by two straight segments
TEARDROP_CURVED ///< The teardrop is created by several segments approximating deltoid
} TEARDROP_TYPE;
/**
......@@ -52,14 +52,14 @@ public:
* @param aTrack
* @return \a true in case the teardrops were successfully built and \a false otherwise
*/
bool Create(TRACK &aTrack);
bool Create(TRACK &aTrack, ENDPOINT_T endPoint, TEARDROP_TYPE type);
private:
///> Contains the type of teardrop
TEARDROP_TYPE m_type;
///> \a m_upperSegment and \a m_lowerSegment contain actual segments composing a teardrop
std::vector<TRACK> m_upperSegment;
std::vector<TRACK> m_lowerSegment;
///> \a m_upperSegment and \a m_lowerSegment contain pointers to actual segments composing a teardrop
std::vector<TRACK *> m_upperSegment;
std::vector<TRACK *> m_lowerSegment;
/**
* @brief Function \a CurvedSegments computes several points on deltoid curve and moves
......@@ -96,6 +96,9 @@ private:
* @return \a true in case the vector is created successfully and \a false otherwise
*/
bool SetVector(TRACK &aTrack, const VIA &aVia, VECTOR2I &startPoint, VECTOR2I &endPoint);
VIA* GetViaOnEnd(TRACK &aTrack, ENDPOINT_T endPoint);
bool BuildTracks(TRACK &aTrack, std::vector<VECTOR2I> upperSegments, std::vector<VECTOR2I> lowerSegments);
};
#endif // CLASS_TEARDROP_H
......@@ -615,6 +615,10 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
_( "Fast access to the Web Based FreeROUTE advanced router" ),
KiBitmap( web_support_xpm ) );
AddMenuItem( toolsMenu, ID_TEARDROPS_WINDOW,
_( "Teardrops" ),
_("Add teardrops"), KiBitmap( new_pcb_xpm ) );
#if defined(KICAD_SCRIPTING_WXPYTHON)
AddMenuItem( toolsMenu, ID_TOOLBARH_PCB_SCRIPTING_CONSOLE,
_( "&Scripting Console" ),
......
......@@ -62,6 +62,7 @@
#include <class_track.h>
#include <class_board.h>
#include <class_module.h>
#include <class_teardrop.h>
#include <worksheet_viewitem.h>
#include <ratsnest_data.h>
#include <ratsnest_viewitem.h>
......@@ -206,6 +207,8 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
EVT_TOOL( ID_TOOLBARH_PCB_MODE_MODULE, PCB_EDIT_FRAME::OnSelectAutoPlaceMode )
EVT_TOOL( ID_TOOLBARH_PCB_MODE_TRACKS, PCB_EDIT_FRAME::OnSelectAutoPlaceMode )
EVT_TOOL( ID_TOOLBARH_PCB_FREEROUTE_ACCESS, PCB_EDIT_FRAME::Access_to_External_Tool )
EVT_TOOL( ID_TEARDROPS_WINDOW, PCB_EDIT_FRAME::ShowTeardropsWnd )
// has meaning only with KICAD_SCRIPTING_WXPYTHON enabled
EVT_TOOL( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, PCB_EDIT_FRAME::ScriptingConsoleEnableDisable )
......@@ -719,7 +722,17 @@ void PCB_EDIT_FRAME::ShowDesignRulesEditor( wxCommandEvent& event )
OnModify();
}
}
void PCB_EDIT_FRAME::ShowTeardropsWnd( wxCommandEvent& event )
{
BOARD_ITEM *item = GetScreen()->GetCurItem();
if ((item != NULL) && (item->Type() == PCB_TRACE_T)) {
TEARDROP *td = new TEARDROP(item);
TRACK *track = static_cast<TRACK *>(item);
td->Create(*track, ENDPOINT_START, TEARDROP::TEARDROP_CURVED);
td->Create(*track, ENDPOINT_END, TEARDROP::TEARDROP_CURVED);
}
m_canvas->Refresh();
}
void PCB_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg )
{
......
......@@ -327,6 +327,7 @@ enum pcbnew_ids
ID_POPUP_PCB_DELETE_TRACKSEG,
ID_TOOLBARH_PCB_SELECT_LAYER,
ID_PCB_DISPLAY_OPTIONS_SETUP,
ID_TEARDROPS_WINDOW,
// Module editor right vertical tool bar commands.
ID_MODEDIT_PAD_TOOL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment