Commit aac3de4a authored by Mikhail Karpenko's avatar Mikhail Karpenko

Add teardrops to all vias, add undo/redo

parent 4e114e1a
......@@ -36,7 +36,7 @@ void TEARDROP::GetCoordinates(std::vector<VECTOR2I> &points)
bool TEARDROP::SetVector(TRACK &aTrack, const VIA & aVia, VECTOR2I &startPoint, VECTOR2I &endPoint)
{
// Decide which end of the track is inside via and set this point as end of vector
STATUS_FLAGS status = aTrack.IsPointOnEnds(wxPoint(aVia.GetPosition().x, aVia.GetPosition().y), aVia.GetWidth() / 2);
STATUS_FLAGS status = aTrack.IsPointOnEnds(aVia.GetPosition(), aVia.GetWidth() / 2);
if (status == STARTPOINT) {
startPoint = aTrack.GetEnd();
endPoint = aTrack.GetStart();
......@@ -105,7 +105,7 @@ bool TEARDROP::StraightSegments(TRACK &aTrack, const VIA &aVia, std::vector<VECT
// Check that the track is not too short
double segOutsideVia = aTrack.GetLength() - (aVia.GetWidth() / 2);
double minLength = (distance * aVia.GetWidth()) / 100;
double minLength = (distance * aVia.GetWidth() / 2) / 100;
if (segOutsideVia < minLength) {
return false;
}
......
......@@ -38,12 +38,8 @@ void DIALOG_TEARDROPS::InitDialogSettings()
if (m_scopeTracks->IsChecked() == true) {
m_settings->m_scope = static_cast<TEARDROPS_SCOPE>(m_settings->m_scope | TEARDROPS_SCOPE_TRACKS);
}
if (m_checkClear->IsChecked() == true) {
m_settings->m_clearSelection = true;
}
else {
m_settings->m_clearSelection = false;
}
m_settings->m_clearSelection = m_checkClear->IsChecked();
m_settings->m_ignoreDrc = m_checkIgnore->IsChecked();
}
void DIALOG_TEARDROPS::OnModeAdd(wxCommandEvent &event)
......@@ -56,7 +52,7 @@ void DIALOG_TEARDROPS::OnModeAdd(wxCommandEvent &event)
void DIALOG_TEARDROPS::OnModeRemove(wxCommandEvent &event)
{
if (m_settings != NULL) {
m_settings->m_mode = TEARDROPS_MODE_REMOVE;
m_settings->m_mode = TEARDROPS_MODE_REMOVE;
}
}
......@@ -106,10 +102,16 @@ void DIALOG_TEARDROPS::OnStyleChanged(wxCommandEvent &event)
void DIALOG_TEARDROPS::OnClearSelection(wxCommandEvent &event)
{
if (m_checkClear->IsChecked() == true) {
m_settings->m_clearSelection = true;
event.Skip();
if (m_settings != NULL) {
m_settings->m_clearSelection = m_checkClear->IsChecked();
}
else {
m_settings->m_clearSelection = false;
}
void DIALOG_TEARDROPS::OnIgnoreDrc(wxCommandEvent &event)
{
event.Skip();
if (m_settings != NULL) {
m_settings->m_ignoreDrc = m_checkIgnore->IsChecked();
}
}
......@@ -33,6 +33,7 @@ public:
TEARDROPS_SCOPE m_scope;
TEARDROPS_TYPE m_type;
bool m_clearSelection;
bool m_ignoreDrc;
} TEARDROPS_SETTINGS;
DIALOG_TEARDROPS(PCB_EDIT_FRAME *aParent, TEARDROPS_SETTINGS *settings);
......@@ -42,6 +43,7 @@ public:
void OnTracksSelected(wxCommandEvent &event);
void OnStyleChanged(wxCommandEvent &event);
void OnClearSelection(wxCommandEvent &event);
void OnIgnoreDrc(wxCommandEvent &event);
void OnScopeVias(wxCommandEvent &event);
private:
......
......@@ -49,7 +49,7 @@ DIALOG_TEARDROPS_BASE::DIALOG_TEARDROPS_BASE( wxWindow* parent, wxWindowID id, c
m_checkIgnore = new wxCheckBox( this, wxID_ANY, wxT("Ignore DRC"), wxDefaultPosition, wxDefaultSize, 0 );
m_checkIgnore->SetValue(true);
m_checkIgnore->Hide();
m_checkIgnore->Enable( false );
m_optionsSizer->Add( m_checkIgnore, 0, 0, 5 );
......@@ -127,6 +127,7 @@ DIALOG_TEARDROPS_BASE::DIALOG_TEARDROPS_BASE( wxWindow* parent, wxWindowID id, c
m_modeRemove->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnModeRemove ), NULL, this );
m_tracksAll->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnTracksAll ), NULL, this );
m_tracksSelected->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnTracksSelected ), NULL, this );
m_checkIgnore->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnIgnoreDrc ), NULL, this );
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 );
......@@ -139,6 +140,7 @@ DIALOG_TEARDROPS_BASE::~DIALOG_TEARDROPS_BASE()
m_modeRemove->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnModeRemove ), NULL, this );
m_tracksAll->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnTracksAll ), NULL, this );
m_tracksSelected->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnTracksSelected ), NULL, this );
m_checkIgnore->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_TEARDROPS_BASE::OnIgnoreDrc ), NULL, this );
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 );
......
......@@ -370,10 +370,10 @@
<property name="bg"></property>
<property name="checked">1</property>
<property name="context_help"></property>
<property name="enabled">1</property>
<property name="enabled">0</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">Ignore DRC</property>
<property name="maximum_size"></property>
......@@ -393,7 +393,7 @@
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnCheckBox"></event>
<event name="OnCheckBox">OnIgnoreDrc</event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
......
......@@ -58,6 +58,7 @@ class DIALOG_TEARDROPS_BASE : public DIALOG_SHIM
virtual void OnModeRemove( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTracksAll( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTracksSelected( wxCommandEvent& event ) { event.Skip(); }
virtual void OnIgnoreDrc( wxCommandEvent& event ) { event.Skip(); }
virtual void OnClearSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnStyleChanged( wxCommandEvent& event ) { event.Skip(); }
virtual void OnScopeVias( wxCommandEvent& event ) { event.Skip(); }
......
......@@ -48,13 +48,37 @@ 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;
return retVal;
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 (added == true) {
m_frame->SaveCopyInUndoList(m_undoListPicker, UR_NEW);
}
return added;
}
bool TEARDROPS_EDITOR::AddToSelected(SELECTION &selection, const DIALOG_TEARDROPS::TEARDROPS_SETTINGS &settings)
{
bool retVal = false;
bool added = false;
for (size_t i = 0; i < selection.items.GetCount(); i++) {
TRACK *track = static_cast<TRACK *>(selection.items.GetPickedItem(i));
......@@ -62,22 +86,30 @@ bool TEARDROPS_EDITOR::AddToSelected(SELECTION &selection, const DIALOG_TEARDROP
retVal = teardropEnd.Create(*track, ENDPOINT_END, m_type);
if (retVal == true) {
DrawSegments(teardropEnd, *track);
added = true;
}
TEARDROP teardropStart;
retVal = teardropStart.Create(*track, ENDPOINT_START, m_type);
if (retVal == true) {
DrawSegments(teardropStart, *track);
added = true;
}
if (settings.m_clearSelection == true) {
track->ClearSelected();
}
}
return retVal;
if (added == true) {
m_frame->SaveCopyInUndoList(m_undoListPicker, UR_NEW);
}
return added;
}
void TEARDROPS_EDITOR::DrawSegments(TEARDROP &teardrop, TRACK &aTrack)
{
PICKED_ITEMS_LIST undoListPicker;
ITEM_PICKER picker(NULL, UR_NEW);
std::vector<VECTOR2I> coordinates;
teardrop.GetCoordinates(coordinates);
BOARD *board = aTrack.GetBoard();
......@@ -96,5 +128,7 @@ void TEARDROPS_EDITOR::DrawSegments(TEARDROP &teardrop, TRACK &aTrack)
board->Add(track);
m_view->Add(track);
prevPoint = currentPoint;
picker.SetItem(track);
m_undoListPicker.PushItem(picker);
}
}
......@@ -16,6 +16,7 @@ private:
PCB_EDIT_FRAME *m_frame;
KIGFX::VIEW *m_view;
TEARDROP::TEARDROP_TYPE m_type;
PICKED_ITEMS_LIST m_undoListPicker;
void FilterSelection(SELECTION &selection);
bool AddToAll(const DIALOG_TEARDROPS::TEARDROPS_SETTINGS &settings);
......
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