Commit a1ac84e5 authored by Mikhail Karpenko's avatar Mikhail Karpenko

Add teardrops to circular pads

The idea of removing teardrops from selected tracks proved to be
difficult to implement. The concept of teardrop implementation should be
reconsidered.
parent a8113135
......@@ -62,7 +62,7 @@ bool TEARDROP::SetVector(TRACK &aTrack, const VIA & aVia, VECTOR2I &startPoint,
endPoint = aTrack.GetEnd();
}
else {
// The via is too far from any ends or the track is too short
// The via is too far from any end or the track is too short
return false;
}
......@@ -80,7 +80,7 @@ bool TEARDROP::CurvedSegments(TRACK &aTrack, const VIA &aVia, std::vector<VECTOR
// Check that the track is not too short
double segOutsideVia = aTrack.GetLength() - (aVia.GetWidth() / 2);
double minLength = (90 * aVia.GetWidth()) / 100;
double minLength = (90 * aVia.GetWidth() / 2) / 100;
if (segOutsideVia < minLength) {
return false;
}
......@@ -188,7 +188,6 @@ BOARD_CONNECTED_ITEM* TEARDROP::GetObjectOnEnd(TRACK &aTrack, ENDPOINT_T endPoin
bool hitTest = (*iter)->HitTest(trackPoint);
if (shape == PAD_CIRCLE && hitTest == true) {
item = *iter;
printf("found circle pad\n");
}
}
}
......
......@@ -44,9 +44,12 @@ void DIALOG_TEARDROPS::InitDialogSettings()
void DIALOG_TEARDROPS::OnModeAdd(wxCommandEvent &event)
{
event.Skip();
if (m_settings != NULL) {
m_settings->m_mode = TEARDROPS_MODE_ADD;
LockOptionsControls(false);
LockTracksControls(false);
LockScopeControls(false);
}
}
......@@ -56,11 +59,14 @@ void DIALOG_TEARDROPS::OnModeRemove(wxCommandEvent &event)
if (m_settings != NULL) {
m_settings->m_mode = TEARDROPS_MODE_REMOVE;
LockOptionsControls(true);
LockTracksControls(true);
LockScopeControls(true);
}
}
void DIALOG_TEARDROPS::OnTracksAll(wxCommandEvent &event)
{
event.Skip();
if (m_settings != NULL) {
m_settings->m_track = TEARDROPS_TRACKS_ALL;
}
......@@ -69,6 +75,7 @@ void DIALOG_TEARDROPS::OnTracksAll(wxCommandEvent &event)
void DIALOG_TEARDROPS::OnTracksSelected(wxCommandEvent &event)
{
event.Skip();
if (m_settings != NULL) {
m_settings->m_track = TEARDROPS_TRACKS_SELECTED;
}
......@@ -77,6 +84,7 @@ void DIALOG_TEARDROPS::OnTracksSelected(wxCommandEvent &event)
void DIALOG_TEARDROPS::OnScopeVias(wxCommandEvent &event)
{
event.Skip();
if (m_settings != NULL) {
if (m_scopeVias->IsChecked()) {
m_settings->m_scope = static_cast<TEARDROPS_SCOPE>(m_settings->m_scope | TEARDROPS_SCOPE_VIAS);
......@@ -87,19 +95,24 @@ void DIALOG_TEARDROPS::OnScopeVias(wxCommandEvent &event)
}
}
void DIALOG_TEARDROPS::OnScopePads(wxCommandEvent &event)
{
event.Skip();
if (m_settings != NULL) {
if (m_scopePads->IsChecked()) {
m_settings->m_scope = static_cast<TEARDROPS_SCOPE>(m_settings->m_scope | TEARDROPS_SCOPE_PADS);
}
else {
m_settings->m_scope = static_cast<TEARDROPS_SCOPE>(m_settings->m_scope & (~TEARDROPS_SCOPE_PADS));
}
}
}
void DIALOG_TEARDROPS::OnStyleChanged(wxCommandEvent &event)
{
event.Skip();
if (m_settings != NULL) {
m_settings->m_type = static_cast<TEARDROPS_TYPE>(m_choiceStyle->GetSelection());
// if (selection == TEARDROPS_TYPE_STRAIGHT) {
// m_settings->m_type= TEARDROPS_TYPE_STRAIGHT;
// }
// else if (selection == TEARDROPS_TYPE_CURVED) {
// m_settings->m_type = TEARDROPS_TYPE_CURVED;
// }
// else {
// m_settings->m_type = TEARDROPS_TYPE_NONE;
// }
}
}
......@@ -137,3 +150,27 @@ void DIALOG_TEARDROPS::LockOptionsControls(bool state)
m_choiceStyle->Enable(true);
}
}
void DIALOG_TEARDROPS::LockTracksControls(bool state)
{
if (state == true) {
m_tracksAll->Enable(false);
m_tracksSelected->Enable(false);
}
else {
m_tracksAll->Enable(true);
m_tracksSelected->Enable(true);
}
}
void DIALOG_TEARDROPS::LockScopeControls(bool state)
{
if (state == true) {
m_scopePads->Enable(false);
m_scopeVias->Enable(false);
}
else {
m_scopePads->Enable(true);
m_scopeVias->Enable(true);
}
}
......@@ -45,6 +45,7 @@ public:
void OnClearSelection(wxCommandEvent &event);
void OnIgnoreDrc(wxCommandEvent &event);
void OnScopeVias(wxCommandEvent &event);
void OnScopePads(wxCommandEvent &event);
private:
PCB_EDIT_FRAME *m_parent;
......@@ -52,6 +53,8 @@ private:
void InitDialogSettings();
void LockOptionsControls(bool state);
void LockTracksControls(bool state);
void LockScopeControls(bool state);
};
#endif // DIALOG_TEARDROPS_H
......@@ -86,19 +86,17 @@ DIALOG_TEARDROPS_BASE::DIALOG_TEARDROPS_BASE( wxWindow* parent, wxWindowID id, c
m_scopeVias = new wxCheckBox( this, wxID_ANY, wxT("Vias"), wxDefaultPosition, wxDefaultSize, 0 );
m_scopeVias->SetValue(true);
sbSizer16->Add( m_scopeVias, 0, wxALL, 5 );
sbSizer16->Add( m_scopeVias, 0, 0, 5 );
m_scopePads = new wxCheckBox( this, wxID_ANY, wxT("Pads"), wxDefaultPosition, wxDefaultSize, 0 );
m_scopePads->Enable( false );
m_scopePads->Hide();
sbSizer16->Add( m_scopePads, 0, wxALL, 5 );
m_scopePads->SetValue(true);
sbSizer16->Add( m_scopePads, 0, 0, 5 );
m_scopeTracks = new wxCheckBox( this, wxID_ANY, wxT("Tracks"), wxDefaultPosition, wxDefaultSize, 0 );
m_scopeTracks->Enable( false );
m_scopeTracks->Hide();
sbSizer16->Add( m_scopeTracks, 0, wxALL, 5 );
sbSizer16->Add( m_scopeTracks, 0, 0, 5 );
m_scopeSizer->Add( sbSizer16, 1, wxEXPAND, 5 );
......@@ -131,6 +129,7 @@ DIALOG_TEARDROPS_BASE::DIALOG_TEARDROPS_BASE( wxWindow* parent, wxWindowID id, c
m_checkClear->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnClearSelection ), NULL, this );
m_choiceStyle->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnStyleChanged ), NULL, this );
m_scopeVias->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnScopeVias ), NULL, this );
m_scopePads->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnScopePads ), NULL, this );
}
DIALOG_TEARDROPS_BASE::~DIALOG_TEARDROPS_BASE()
......@@ -144,4 +143,5 @@ DIALOG_TEARDROPS_BASE::~DIALOG_TEARDROPS_BASE()
m_checkClear->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnClearSelection ), NULL, this );
m_choiceStyle->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnStyleChanged ), NULL, this );
m_scopeVias->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnScopeVias ), NULL, this );
m_scopePads->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnScopePads ), NULL, this );
}
......@@ -682,12 +682,12 @@
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="bg"></property>
<property name="checked">0</property>
<property name="checked">1</property>
<property name="context_help"></property>
<property name="enabled">0</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">1</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Pads</property>
<property name="maximum_size"></property>
......@@ -707,7 +707,7 @@
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnCheckBox"></event>
<event name="OnCheckBox">OnScopePads</event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
......
......@@ -62,6 +62,7 @@ class DIALOG_TEARDROPS_BASE : public DIALOG_SHIM
virtual void OnClearSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnStyleChanged( wxCommandEvent& event ) { event.Skip(); }
virtual void OnScopeVias( wxCommandEvent& event ) { event.Skip(); }
virtual void OnScopePads( wxCommandEvent& event ) { event.Skip(); }
public:
......
......@@ -3,6 +3,7 @@
#include "class_module.h"
#include "ratsnest_data.h"
#include "view/view.h"
#include "router/pns_utils.h"
TEARDROPS_EDITOR::TEARDROPS_EDITOR(PCB_EDIT_FRAME *frame, KIGFX::VIEW *view)
{
......@@ -43,12 +44,7 @@ bool TEARDROPS_EDITOR::EditTeardrops(SELECTION &selection, const DIALOG_TEARDROP
}
}
else if (settings.m_mode == DIALOG_TEARDROPS::TEARDROPS_MODE_REMOVE) {
if (settings.m_track == DIALOG_TEARDROPS::TEARDROPS_TRACKS_SELECTED) {
RemoveSelected(selection);
}
else if (settings.m_track == DIALOG_TEARDROPS::TEARDROPS_TRACKS_ALL) {
RemoveAll();
}
RemoveAll();
retVal = true;
}
return retVal;
......@@ -56,25 +52,14 @@ bool TEARDROPS_EDITOR::EditTeardrops(SELECTION &selection, const DIALOG_TEARDROP
bool TEARDROPS_EDITOR::AddToAll(const DIALOG_TEARDROPS::TEARDROPS_SETTINGS &settings)
{
bool retVal = false;
bool added = false;
// Iterate through all vias and add teardrops to connected tracks
if ((settings.m_scope & DIALOG_TEARDROPS::TEARDROPS_SCOPE_VIAS) == DIALOG_TEARDROPS::TEARDROPS_SCOPE_VIAS) {
for (VIA *via = GetFirstVia(m_frame->GetBoard()->m_Track); via != NULL;
via = GetFirstVia(via->Next())) {
for (size_t i = 0; i < via->m_TracksConnected.size(); i++) {
TRACK *track = via->m_TracksConnected[i];
STATUS_FLAGS viaPosition = track->IsPointOnEnds(via->GetPosition());
if (viaPosition == STARTPOINT || viaPosition == ENDPOINT) {
ENDPOINT_T endpoint = viaPosition == STARTPOINT ? ENDPOINT_START : ENDPOINT_END;
TEARDROP teardrop;
retVal = teardrop.Create(*track, endpoint, m_type);
if (retVal == true) {
DrawSegments(teardrop, *track);
added = true;
}
}
if (IterateTracks(via) == true) {
added = true;
}
}
}
......@@ -82,12 +67,19 @@ bool TEARDROPS_EDITOR::AddToAll(const DIALOG_TEARDROPS::TEARDROPS_SETTINGS &sett
// Iterate through all modules and add teardrops to tracks connected to their pads
if ((settings.m_scope & DIALOG_TEARDROPS::TEARDROPS_SCOPE_PADS) == DIALOG_TEARDROPS::TEARDROPS_SCOPE_PADS) {
for (MODULE *module = m_frame->GetBoard()->m_Modules.GetFirst(); module != NULL; module = module->Next()) {
D_PAD *pad = module->Pads();
while (pad != NULL) {
if ((pad->GetShape() == PAD_CIRCLE) && IterateTracks(pad) == true) {
added = true;
}
pad = pad->Next();
}
}
}
if (added == true) {
m_frame->SaveCopyInUndoList(m_undoListPicker, UR_NEW);
m_undoListPicker.ClearItemsList();
}
return added;
}
......@@ -118,57 +110,56 @@ bool TEARDROPS_EDITOR::AddToSelected(SELECTION &selection, const DIALOG_TEARDROP
if (added == true) {
m_frame->SaveCopyInUndoList(m_undoListPicker, UR_NEW);
m_undoListPicker.ClearItemsList();
}
return added;
}
bool TEARDROPS_EDITOR::IterateTracks(const BOARD_CONNECTED_ITEM *aObject)
{
assert(aObject);
bool retVal = false;
bool added = false;
for (size_t i = 0; i < aObject->m_TracksConnected.size(); i++) {
TRACK *track = aObject->m_TracksConnected[i];
STATUS_FLAGS objPosition = track->IsPointOnEnds(aObject->GetPosition());
if (objPosition == STARTPOINT || objPosition == ENDPOINT) {
ENDPOINT_T endpoint = (objPosition == STARTPOINT ? ENDPOINT_START : ENDPOINT_END);
TEARDROP teardrop;
retVal = teardrop.Create(*track, endpoint, m_type);
if (retVal == true) {
DrawSegments(teardrop, *track);
added = true;
}
}
}
return added;
}
void TEARDROPS_EDITOR::RemoveAll()
{
ITEM_PICKER picker(NULL, UR_DELETED);
TRACK *nextTrack = NULL;
bool removed = false;
for (TRACK *track = m_frame->GetBoard()->m_Track.begin(); track != NULL; ) {
nextTrack = track->Next();
if (track->GetState(FLAG1) == FLAG1) {
picker.SetItem(track);
m_undoListPicker.PushItem(picker);
removed = true;
m_view->Remove(track);
m_frame->GetBoard()->Remove(track);
}
track = nextTrack;
}
m_frame->GetBoard()->GetRatsnest()->Recalculate();
}
void TEARDROPS_EDITOR::RemoveSelected(SELECTION &selection)
{
EDA_ITEM *selectedItem = NULL;
for (size_t i = 0; i < selection.items.GetCount(); i++) {
selectedItem = selection.items.GetPickedItem(i);
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> result;
EDA_RECT rect = selectedItem->GetBoundingBox();
VECTOR2I vect = VECTOR2I(rect.GetX(), rect.GetY());
VECTOR2I sz = VECTOR2I(rect.GetWidth(), rect.GetHeight());
BOX2I bbox = BOX2I(vect, sz);
printf("Bounding box origin: %d, %d\n", bbox.GetX(), bbox.GetY());
printf("bounding box dimentions: %d, %d\n", bbox.GetWidth(), bbox.GetHeight());
m_view->Query(bbox, result);
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR>::iterator iter;
BOX2I container;
for (iter = result.begin(); iter != result.end(); ++iter) {
BOARD_ITEM *item = static_cast<BOARD_ITEM *>(iter->first);
if (item->GetState(FLAG1) == FLAG1) {
rect = item->GetBoundingBox();
vect = VECTOR2I(rect.GetX(), rect.GetY());
sz = VECTOR2I(rect.GetWidth(), rect.GetHeight());
BOX2I nearBBox = BOX2I(vect, sz);
container.Merge(nearBox);
// m_view->Remove(item);
// m_frame->GetBoard()->Remove(item);
}
}
if (removed == true) {
m_frame->SaveCopyInUndoList(m_undoListPicker, UR_DELETED);
m_undoListPicker.ClearItemsList();
}
m_frame->GetBoard()->GetRatsnest()->Recalculate();
}
void TEARDROPS_EDITOR::DrawSegments(TEARDROP &teardrop, TRACK &aTrack)
......@@ -182,7 +173,6 @@ void TEARDROPS_EDITOR::DrawSegments(TEARDROP &teardrop, TRACK &aTrack)
wxPoint prevPoint(coordinates[0].x, coordinates[0].y);
for (size_t i = 1; i < coordinates.size(); i++) {
TRACK *track = new TRACK(aTrack);
// TRACK *track = static_cast<TRACK *>(aTrack.Clone());
track->SetWidth(aTrack.GetWidth());
track->SetLayer(aTrack.GetLayer());
track->SetNetCode(aTrack.GetNetCode());
......
......@@ -18,7 +18,19 @@ private:
TEARDROP::TEARDROP_TYPE m_type;
PICKED_ITEMS_LIST m_undoListPicker;
/**
* @brief FilterSelection filters selected objects and removes all objects except tracks.
* @param selection contains the list of currently selected objects
*/
void FilterSelection(SELECTION &selection);
/**
* @brief IterateTracks creates teardrop for all tracks connected to \a aObject
* @param aObject is a board object a which teardrops should be created. Currently such an object can
* be via or circular pad.
* @return \a true if at least one teardrop was successfully added and \a false otherwise
*/
bool IterateTracks(const BOARD_CONNECTED_ITEM *aObject);
bool AddToAll(const DIALOG_TEARDROPS::TEARDROPS_SETTINGS &settings);
bool AddToSelected(SELECTION &selection, const DIALOG_TEARDROPS::TEARDROPS_SETTINGS &settings);
......@@ -27,11 +39,6 @@ private:
*/
void RemoveAll();
/**
* @brief RemoveSelected removes teardrops from selected tracks
* @param selection contains a list of track to work on
*/
void RemoveSelected(SELECTION &selection);
void DrawSegments(TEARDROP &teardrop, TRACK &track);
};
......
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