diff --git a/common/gr_basic.cpp b/common/gr_basic.cpp index 0ca4edccb1..d2cbae4e36 100644 --- a/common/gr_basic.cpp +++ b/common/gr_basic.cpp @@ -208,6 +208,7 @@ void GRResetPenAndBrush( wxDC* DC ) */ void GRSetColorPen( wxDC* DC, COLOR4D Color, int width, wxPenStyle style ) { + wxDash dots[2] = { 1, 3 }; // Under OSX and while printing when wxPen is set to 0, renderer follows the request drawing // nothing & in the bitmap world the minimum is enough to light a pixel, in vectorial one not if( width <= 1 ) @@ -224,6 +225,11 @@ void GRSetColorPen( wxDC* DC, COLOR4D Color, int width, wxPenStyle style ) { wxPen pen; pen.SetColour( Color.ToColour() ); + if( style == wxPENSTYLE_DOT ) + { + style = wxPENSTYLE_USER_DASH; + pen.SetDashes( 2, dots ); + } pen.SetWidth( width ); pen.SetStyle( style ); DC->SetPen( pen ); @@ -356,18 +362,19 @@ void GRLine( EDA_RECT* ClipBox, int x2, int y2, int width, - COLOR4D Color ) + COLOR4D Color, + wxPenStyle aStyle) { - GRSetColorPen( DC, Color, width ); + GRSetColorPen( DC, Color, width, aStyle ); WinClipAndDrawLine( ClipBox, DC, x1, y1, x2, y2, width ); GRLastMoveToX = x2; GRLastMoveToY = y2; } -void GRLine( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, int aWidth, COLOR4D aColor ) +void GRLine( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, int aWidth, COLOR4D aColor, wxPenStyle aStyle ) { - GRLine( aClipBox, aDC, aStart.x, aStart.y, aEnd.x, aEnd.y, aWidth, aColor ); + GRLine( aClipBox, aDC, aStart.x, aStart.y, aEnd.x, aEnd.y, aWidth, aColor, aStyle ); } @@ -375,13 +382,15 @@ void GRDashedLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color ) { - GRLastMoveToX = x2; - GRLastMoveToY = y2; - s_DC_lastcolor = COLOR4D::UNSPECIFIED; - GRSetColorPen( DC, Color, width, wxPENSTYLE_SHORT_DASH ); - WinClipAndDrawLine( ClipBox, DC, x1, y1, x2, y2, width ); - s_DC_lastcolor = COLOR4D::UNSPECIFIED; - GRSetColorPen( DC, Color, width ); + GRLine( ClipBox, DC, x1, y1, x2, y2, width, Color, wxPENSTYLE_SHORT_DASH ); +} + + +void GRDottedLine( EDA_RECT* ClipBox, wxDC* DC, + int x1, int y1, int x2, int y2, + int width, COLOR4D Color ) +{ + GRLine( ClipBox, DC, x1, y1, x2, y2, width, Color, wxPENSTYLE_DOT ); } @@ -407,9 +416,7 @@ void GRLineTo( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int width, COLOR4D Col void GRMixedLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color ) { - GRSetColorPen( DC, Color, width, wxPENSTYLE_DOT_DASH ); - GRLine( ClipBox, DC, x1, y1, x2, y2, width, Color ); - GRSetColorPen( DC, Color, width ); + GRLine( ClipBox, DC, x1, y1, x2, y2, width, Color, wxPENSTYLE_DOT_DASH ); } diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 8cb429e8a7..8bfcd78345 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -39,6 +39,8 @@ set( EESCHEMA_DLGS dialogs/dialog_edit_label_base.cpp dialogs/dialog_edit_libentry_fields_in_lib.cpp dialogs/dialog_edit_libentry_fields_in_lib_base.cpp + dialogs/dialog_edit_line_style.cpp + dialogs/dialog_edit_line_style_base.cpp dialogs/dialog_edit_one_field.cpp dialogs/dialog_eeschema_options_base.cpp dialogs/dialog_eeschema_options.cpp diff --git a/eeschema/dialogs/dialog_edit_line_style.cpp b/eeschema/dialogs/dialog_edit_line_style.cpp new file mode 100644 index 0000000000..d72b68867a --- /dev/null +++ b/eeschema/dialogs/dialog_edit_line_style.cpp @@ -0,0 +1,95 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 Seth Hillbrand + * Copyright (C) 2015 KiCad Developers, see CHANGELOG.TXT for contributors. + * + * 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 + + +DIALOG_EDIT_LINE_STYLE::DIALOG_EDIT_LINE_STYLE( wxWindow* parent ) : + DIALOG_EDIT_LINE_STYLE_BASE( parent ) +{ + m_sdbSizer1Apply->SetLabel( _( "Default" ) ); + m_lineStyle->SetSelection( 0 ); + + m_lineWidth->SetFocus(); + defaultStyle = 0; + defaultWidth = ""; + m_sdbSizer1OK->SetDefault(); + + // Now all widgets have the size fixed, call FinishDialogSettings + FinishDialogSettings(); + + // On some windows manager (Unity, XFCE), this dialog is + // not always raised, depending on this dialog is run. + // Force it to be raised + Raise(); +} + + +void DIALOG_EDIT_LINE_STYLE::resetDefaults( wxCommandEvent& event ) +{ + SetStyle( defaultStyle ); + SetWidth( defaultWidth ); + SetColor( defaultColor ); + Refresh(); +} + + +void DIALOG_EDIT_LINE_STYLE::SetColor( const COLOR4D& aColor ) +{ + m_colorPicker->SetColour( aColor.ToColour() ); +} + + +void DIALOG_EDIT_LINE_STYLE::SetStyle( const int aStyle ) +{ + switch( aStyle ) + { + case wxPENSTYLE_SHORT_DASH: + m_lineStyle->SetSelection( 1 ); + break; + case wxPENSTYLE_DOT: + m_lineStyle->SetSelection( 2 ); + break; + case wxPENSTYLE_DOT_DASH: + m_lineStyle->SetSelection( 3 ); + break; + default: + m_lineStyle->SetSelection( 0 ); + break; + } +} + + +int DIALOG_EDIT_LINE_STYLE::GetStyle() +{ + const int retval[4] = + { + wxPENSTYLE_SOLID, + wxPENSTYLE_SHORT_DASH, + wxPENSTYLE_DOT, + wxPENSTYLE_DOT_DASH, + }; + + return retval[ m_lineStyle->GetSelection() ]; +} diff --git a/eeschema/dialogs/dialog_edit_line_style.h b/eeschema/dialogs/dialog_edit_line_style.h new file mode 100644 index 0000000000..522dba98e0 --- /dev/null +++ b/eeschema/dialogs/dialog_edit_line_style.h @@ -0,0 +1,67 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 Seth Hillbrand + * Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors. + * + * 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 __dialog_edit_line_style__ +#define __dialog_edit_line_style__ + + +/** + * @file + * Subclass of DIALOG_EDIT_LINE_STYLE_BASE, which is generated by wxFormBuilder. + */ + +#include +#include + + +class DIALOG_EDIT_LINE_STYLE : public DIALOG_EDIT_LINE_STYLE_BASE +{ +public: + DIALOG_EDIT_LINE_STYLE( wxWindow* parent ); + + void SetWidth( const wxString& aWidth ) { m_lineWidth->SetValue( aWidth ); } + void SetDefaultWidth( const wxString& aWidth ) { defaultWidth = aWidth; } + wxString GetWidth() const { return m_lineWidth->GetValue(); } + + COLOR4D GetColor() const { return COLOR4D( m_colorPicker->GetColour() ); } + void SetColor( const COLOR4D& aColor ); + void SetDefaultColor( const COLOR4D& aColor ) { defaultColor = aColor; } + + void SetStyle( const int aStyle ); + void SetDefaultStyle( const int aStyle ) { defaultStyle = aStyle; } + int GetStyle(); + + void SetLineWidthUnits(const wxString& aUnits) + { + m_staticWidthUnits->SetLabel( aUnits ); + } +private: + int defaultStyle; + wxString defaultWidth; + COLOR4D defaultColor; + + void resetDefaults( wxCommandEvent& event ) override; +}; + +#endif // __dialog_edit_line_style__ diff --git a/eeschema/dialogs/dialog_edit_line_style_base.cpp b/eeschema/dialogs/dialog_edit_line_style_base.cpp new file mode 100644 index 0000000000..f66282924b --- /dev/null +++ b/eeschema/dialogs/dialog_edit_line_style_base.cpp @@ -0,0 +1,111 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Nov 9 2017) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_edit_line_style_base.h" + +/////////////////////////////////////////////////////////////////////////// + +BEGIN_EVENT_TABLE( DIALOG_EDIT_LINE_STYLE_BASE, DIALOG_SHIM ) + EVT_BUTTON( wxID_APPLY, DIALOG_EDIT_LINE_STYLE_BASE::_wxFB_resetDefaults ) +END_EVENT_TABLE() + +DIALOG_EDIT_LINE_STYLE_BASE::DIALOG_EDIT_LINE_STYLE_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* mainSizer; + mainSizer = new wxBoxSizer( wxHORIZONTAL ); + + wxBoxSizer* dlgBorderSizer; + dlgBorderSizer = new wxBoxSizer( wxVERTICAL ); + + wxBoxSizer* bSizer7; + bSizer7 = new wxBoxSizer( wxHORIZONTAL ); + + wxStaticBoxSizer* sbSizer1; + sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("General") ), wxVERTICAL ); + + wxBoxSizer* bSizer31; + bSizer31 = new wxBoxSizer( wxHORIZONTAL ); + + m_staticWidth1 = new wxStaticText( sbSizer1->GetStaticBox(), wxID_ANY, _("&Width:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticWidth1->Wrap( -1 ); + bSizer31->Add( m_staticWidth1, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 ); + + m_lineWidth = new wxTextCtrl( sbSizer1->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + #ifdef __WXGTK__ + if ( !m_lineWidth->HasFlag( wxTE_MULTILINE ) ) + { + m_lineWidth->SetMaxLength( 6 ); + } + #else + m_lineWidth->SetMaxLength( 6 ); + #endif + bSizer31->Add( m_lineWidth, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 ); + + m_staticWidthUnits = new wxStaticText( sbSizer1->GetStaticBox(), wxID_ANY, _("millimeter"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticWidthUnits->Wrap( -1 ); + bSizer31->Add( m_staticWidthUnits, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 ); + + + sbSizer1->Add( bSizer31, 0, wxALL|wxEXPAND, 1 ); + + wxBoxSizer* bSizer5; + bSizer5 = new wxBoxSizer( wxHORIZONTAL ); + + m_staticText5 = new wxStaticText( sbSizer1->GetStaticBox(), wxID_ANY, _("C&olor:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText5->Wrap( -1 ); + bSizer5->Add( m_staticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + m_colorPicker = new wxColourPickerCtrl( sbSizer1->GetStaticBox(), wxID_ANY, wxColour( 0, 0, 0 ), wxDefaultPosition, wxDefaultSize, wxCLRP_DEFAULT_STYLE ); + bSizer5->Add( m_colorPicker, 0, wxALL, 5 ); + + + bSizer5->Add( 0, 0, 1, wxEXPAND, 5 ); + + + sbSizer1->Add( bSizer5, 0, wxEXPAND|wxALL, 1 ); + + + bSizer7->Add( sbSizer1, 3, wxALL|wxEXPAND, 5 ); + + wxString m_lineStyleChoices[] = { _("Solid"), _("Dashed"), _("Dotted"), _("Dash-Dot") }; + int m_lineStyleNChoices = sizeof( m_lineStyleChoices ) / sizeof( wxString ); + m_lineStyle = new wxRadioBox( this, wxID_ANY, _("&Pen Style"), wxDefaultPosition, wxDefaultSize, m_lineStyleNChoices, m_lineStyleChoices, 4, wxRA_SPECIFY_ROWS ); + m_lineStyle->SetSelection( 1 ); + bSizer7->Add( m_lineStyle, 2, wxALL|wxEXPAND, 5 ); + + + dlgBorderSizer->Add( bSizer7, 1, wxEXPAND, 5 ); + + + dlgBorderSizer->Add( 0, 0, 0, wxALL|wxEXPAND, 1 ); + + m_sdbSizer1 = new wxStdDialogButtonSizer(); + m_sdbSizer1OK = new wxButton( this, wxID_OK ); + m_sdbSizer1->AddButton( m_sdbSizer1OK ); + m_sdbSizer1Apply = new wxButton( this, wxID_APPLY ); + m_sdbSizer1->AddButton( m_sdbSizer1Apply ); + m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL ); + m_sdbSizer1->AddButton( m_sdbSizer1Cancel ); + m_sdbSizer1->Realize(); + + dlgBorderSizer->Add( m_sdbSizer1, 0, wxALL|wxEXPAND, 5 ); + + + mainSizer->Add( dlgBorderSizer, 1, wxALL|wxEXPAND, 12 ); + + + this->SetSizer( mainSizer ); + this->Layout(); + + this->Centre( wxBOTH ); +} + +DIALOG_EDIT_LINE_STYLE_BASE::~DIALOG_EDIT_LINE_STYLE_BASE() +{ +} diff --git a/eeschema/dialogs/dialog_edit_line_style_base.fbp b/eeschema/dialogs/dialog_edit_line_style_base.fbp new file mode 100644 index 0000000000..c05e92de62 --- /dev/null +++ b/eeschema/dialogs/dialog_edit_line_style_base.fbp @@ -0,0 +1,721 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + table + dialog_edit_line_style_base + 1000 + none + 1 + dialog_edit_line_style + + . + + 1 + 1 + 1 + 1 + UI + 1 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + DIALOG_EDIT_LINE_STYLE_BASE + + 399,230 + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + DIALOG_SHIM; dialog_shim.h + Line Style + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + mainSizer + wxHORIZONTAL + none + + 12 + wxALL|wxEXPAND + 1 + + + dlgBorderSizer + wxVERTICAL + none + + 5 + wxEXPAND + 1 + + + bSizer7 + wxHORIZONTAL + none + + 5 + wxALL|wxEXPAND + 3 + + wxID_ANY + General + + sbSizer1 + wxVERTICAL + 1 + none + + + 1 + wxALL|wxEXPAND + 0 + + + bSizer31 + wxHORIZONTAL + none + + 3 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + &Width: + + 0 + + + 0 + + 1 + m_staticWidth1 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 3 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 6 + + 0 + + 1 + m_lineWidth + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + bool + wxFILTER_NUMERIC + wxDefaultValidator + m_isValid + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 3 + wxALIGN_CENTER_VERTICAL|wxALL + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + millimeter + + 0 + + + 0 + + 1 + m_staticWidthUnits + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + wxEXPAND|wxALL + 0 + + + bSizer5 + wxHORIZONTAL + none + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + C&olor: + + 0 + + + 0 + + 1 + m_staticText5 + 1 + + + protected + 1 + + Resizable + 1 + + + ; forward_declare + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + 0,0,0 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_colorPicker + 1 + + + protected + 1 + + Resizable + 1 + + wxCLRP_DEFAULT_STYLE + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + + + + + + + 5 + wxALL|wxEXPAND + 2 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + "Solid" "Dashed" "Dotted" "Dash-Dot" + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + &Pen Style + 4 + + 0 + + + 0 + + 1 + m_lineStyle + 1 + + + protected + 1 + + Resizable + 1 + 1 + + wxRA_SPECIFY_ROWS + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + wxALL|wxEXPAND + 0 + + 0 + protected + 0 + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + + m_sdbSizer1 + protected + resetDefaults + + + + + + + + + + + + + + + diff --git a/eeschema/dialogs/dialog_edit_line_style_base.h b/eeschema/dialogs/dialog_edit_line_style_base.h new file mode 100644 index 0000000000..4cd6d7066e --- /dev/null +++ b/eeschema/dialogs/dialog_edit_line_style_base.h @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Nov 9 2017) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __DIALOG_EDIT_LINE_STYLE_BASE_H__ +#define __DIALOG_EDIT_LINE_STYLE_BASE_H__ + +#include +#include +#include +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_EDIT_LINE_STYLE_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_EDIT_LINE_STYLE_BASE : public DIALOG_SHIM +{ + DECLARE_EVENT_TABLE() + private: + + // Private event handlers + void _wxFB_resetDefaults( wxCommandEvent& event ){ resetDefaults( event ); } + + + protected: + wxStaticText* m_staticWidth1; + wxTextCtrl* m_lineWidth; + wxStaticText* m_staticWidthUnits; + wxStaticText* m_staticText5; + wxColourPickerCtrl* m_colorPicker; + wxRadioBox* m_lineStyle; + wxStdDialogButtonSizer* m_sdbSizer1; + wxButton* m_sdbSizer1OK; + wxButton* m_sdbSizer1Apply; + wxButton* m_sdbSizer1Cancel; + + // Virtual event handlers, overide them in your derived class + virtual void resetDefaults( wxCommandEvent& event ) { event.Skip(); } + + + public: + bool m_isValid; + + DIALOG_EDIT_LINE_STYLE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Line Style"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 399,230 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~DIALOG_EDIT_LINE_STYLE_BASE(); + +}; + +#endif //__DIALOG_EDIT_LINE_STYLE_BASE_H__ diff --git a/eeschema/sch_collectors.cpp b/eeschema/sch_collectors.cpp index 671c611a27..915d9616e1 100644 --- a/eeschema/sch_collectors.cpp +++ b/eeschema/sch_collectors.cpp @@ -87,6 +87,7 @@ const KICAD_T SCH_COLLECTOR::EditableItems[] = { SCH_SHEET_PIN_T, SCH_SHEET_T, SCH_BITMAP_T, + SCH_LINE_T, EOT }; diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index 9680695766..4b0b86763f 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -1147,6 +1147,27 @@ SCH_LINE* SCH_LEGACY_PLUGIN::loadWire( FILE_LINE_READER& aReader ) end.x = parseInt( aReader, line, &line ); end.y = parseInt( aReader, line, &line ); + if( !is_eol( *line ) ) + { + int size = parseInt( aReader, line, &line ); + wire->SetLineWidth( size ); + } + + if( !is_eol( *line ) ) + { + int style = parseInt( aReader, line, &line ); + wire->SetLineStyle( style ); + } + + if( !is_eol( *line ) ) + { + double color[ 4 ] = { 0. }; + for( int i = 0; i < 4 && !is_eol( *line ); i++ ) + color[i] = parseDouble( aReader, line, &line ); + + wire->SetLineColor( color[0], color[1], color[2], color[3] ); + } + wire->SetStartPoint( begin ); wire->SetEndPoint( end ); @@ -1958,6 +1979,9 @@ void SCH_LEGACY_PLUGIN::saveLine( SCH_LINE* aLine ) const char* layer = "Notes"; const char* width = "Line"; + bool styled = aLine->GetPenSize() != aLine->GetDefaultWidth() + || aLine->GetLineStyle() != aLine->GetDefaultStyle() + || aLine->GetLineColor() != aLine->GetDefaultColor(); if( aLine->GetLayer() == LAYER_WIRE ) layer = "Wire"; @@ -1965,8 +1989,15 @@ void SCH_LEGACY_PLUGIN::saveLine( SCH_LINE* aLine ) layer = "Bus"; m_out->Print( 0, "Wire %s %s\n", layer, width ); - m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n", aLine->GetStartPoint().x, aLine->GetStartPoint().y, + m_out->Print( 0, "\t%-4d %-4d %-4d %-4d", aLine->GetStartPoint().x, aLine->GetStartPoint().y, aLine->GetEndPoint().x, aLine->GetEndPoint().y ); + if( styled ) + m_out->Print( 0, " %-4d %-4d %-.4f %-.4f %-.4f %-.4f", + aLine->GetLineSize(), aLine->GetLineStyle(), + aLine->GetLineColor().r, aLine->GetLineColor().g, + aLine->GetLineColor().b, aLine->GetLineColor().a ); + + m_out->Print( 0, "\n"); } diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index 21b6fe8fd3..7a23f8bcad 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -37,8 +37,10 @@ #include #include #include +#include #include +#include SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) : SCH_ITEM( NULL, SCH_LINE_T ) @@ -46,6 +48,9 @@ SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) : m_start = pos; m_end = pos; m_startIsDangling = m_endIsDangling = false; + m_size = 0; + m_style = 0; + m_color = COLOR4D::UNSPECIFIED; switch( layer ) { @@ -69,6 +74,9 @@ SCH_LINE::SCH_LINE( const SCH_LINE& aLine ) : { m_start = aLine.m_start; m_end = aLine.m_end; + m_size = aLine.m_size; + m_style = aLine.m_style; + m_color = aLine.m_color; m_startIsDangling = m_endIsDangling = false; } @@ -201,8 +209,93 @@ bool SCH_LINE::Load( LINE_READER& aLine, wxString& aErrorMsg ) } +COLOR4D SCH_LINE::GetDefaultColor() const +{ + return GetLayerColor( m_Layer ); +} + + +void SCH_LINE::SetLineColor( const COLOR4D aColor ) +{ + if( aColor == GetDefaultColor() ) + m_color = COLOR4D::UNSPECIFIED; + else + m_color = aColor; +} + + +void SCH_LINE::SetLineColor( const double r, const double g, const double b, const double a ) +{ + COLOR4D newColor(r, g, b, a); + + if( newColor == GetDefaultColor() ) + m_color = COLOR4D::UNSPECIFIED; + else + m_color = newColor; +} + + +COLOR4D SCH_LINE::GetLineColor() const +{ + if( m_color == COLOR4D::UNSPECIFIED ) + return GetLayerColor( m_Layer ); + + return m_color; +} + + +enum wxPenStyle SCH_LINE::GetDefaultStyle() const +{ + if( m_Layer == LAYER_NOTES ) + return wxPENSTYLE_SHORT_DASH; + + return wxPENSTYLE_SOLID; +} + + +void SCH_LINE::SetLineStyle( const int aStyle ) +{ + if( aStyle == GetDefaultStyle() ) + m_style = 0; + else + m_style = aStyle; +} + + +enum wxPenStyle SCH_LINE::GetLineStyle() const +{ + if( m_style > 0 ) + return (enum wxPenStyle) m_style; + + if( m_Layer == LAYER_NOTES ) + return wxPENSTYLE_SHORT_DASH; + + return wxPENSTYLE_SOLID; +} + + +int SCH_LINE::GetDefaultWidth() const +{ + if( m_Layer == LAYER_BUS ) + return GetDefaultBusThickness(); + + return GetDefaultLineThickness(); +} + + +void SCH_LINE::SetLineWidth( const int aSize ) +{ + if( aSize == GetDefaultWidth() ) + m_size = 0; + else + m_size = aSize; +} + + int SCH_LINE::GetPenSize() const { + if( m_size > 0 ) + return m_size; if( m_Layer == LAYER_BUS ) return GetDefaultBusThickness(); @@ -219,6 +312,8 @@ void SCH_LINE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset, if( Color != COLOR4D::UNSPECIFIED ) color = Color; + else if( m_color != COLOR4D::UNSPECIFIED ) + color = m_color; else color = GetLayerColor( GetState( BRIGHTENED ) ? LAYER_BRIGHTENED : m_Layer ); @@ -233,10 +328,7 @@ void SCH_LINE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset, if( ( m_Flags & ENDPOINT ) == 0 ) end += offset; - if( m_Layer == LAYER_NOTES ) - GRDashedLine( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y, width, color ); - else - GRLine( panel->GetClipBox(), DC, start, end, width, color ); + GRLine( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y, width, color, GetLineStyle() ); if( m_startIsDangling ) DrawDanglingSymbol( panel, DC, start, color ); @@ -567,6 +659,20 @@ bool SCH_LINE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) return rect.Intersects( m_start, m_end ); } +void SCH_LINE::SwapData( SCH_ITEM* aItem ) +{ + SCH_LINE* item = (SCH_LINE*) aItem; + + std::swap( m_Layer, item->m_Layer ); + + std::swap( m_start, item->m_start ); + std::swap( m_end, item->m_end ); + std::swap( m_startIsDangling, item->m_startIsDangling ); + std::swap( m_endIsDangling, item->m_endIsDangling ); + std::swap( m_style, item->m_style ); + std::swap( m_size, item->m_size ); + std::swap( m_color, item->m_color ); +} bool SCH_LINE::doIsConnected( const wxPoint& aPosition ) const { @@ -604,3 +710,53 @@ wxPoint SCH_LINE::MidPoint() { return wxPoint( ( m_start.x + m_end.x ) / 2, ( m_start.y + m_end.y ) / 2 ); } + + +int SCH_EDIT_FRAME::EditLine( SCH_LINE* aLine, bool aRedraw ) +{ + if( aLine == NULL ) + return wxID_CANCEL; + + // We purposely disallow editing everything except graphic lines + if( aLine->GetLayer() != LAYER_NOTES ) + return wxID_CANCEL; + + DIALOG_EDIT_LINE_STYLE dlg( this ); + wxString units = GetUnitsLabel( g_UserUnit ); + int old_style = aLine->GetLineStyle(); + int old_width = aLine->GetPenSize(); + COLOR4D old_color = aLine->GetLineColor(); + + dlg.SetDefaultStyle( aLine->GetDefaultStyle() ); + dlg.SetDefaultWidth( StringFromValue( g_UserUnit, aLine->GetDefaultWidth(), false ) ); + dlg.SetDefaultColor( aLine->GetDefaultColor() ); + + dlg.SetWidth( StringFromValue( g_UserUnit, old_width, false ) ); + dlg.SetStyle( old_style ); + dlg.SetLineWidthUnits( units ); + dlg.SetColor( old_color ); + + dlg.Layout(); + dlg.Fit(); + dlg.SetMinSize( dlg.GetSize() ); + if( dlg.ShowModal() == wxID_CANCEL ) + return wxID_CANCEL; + + int new_width = std::max( 1, ValueFromString( dlg.GetWidth() ) ); + int new_style = dlg.GetStyle(); + COLOR4D new_color = dlg.GetColor(); + + if( new_width != old_width || new_style != old_style || new_color != old_color ) + { + SaveCopyInUndoList( (SCH_ITEM*) aLine, UR_CHANGED ); + aLine->SetLineWidth( new_width ); + aLine->SetLineStyle( new_style ); + aLine->SetLineColor( new_color ); + + OnModify(); + if( aRedraw ) + m_canvas->Refresh(); + } + + return wxID_OK; +} diff --git a/eeschema/sch_line.h b/eeschema/sch_line.h index 7b8cf5d1bc..db5ab18733 100644 --- a/eeschema/sch_line.h +++ b/eeschema/sch_line.h @@ -45,6 +45,9 @@ class SCH_LINE : public SCH_ITEM bool m_endIsDangling; ///< True if end point is not connected. wxPoint m_start; ///< Line start point wxPoint m_end; ///< Line end point + int m_size; ///< Line pensize + int m_style; ///< Line style + COLOR4D m_color; ///< Line color public: SCH_LINE( const wxPoint& pos = wxPoint( 0, 0 ), int layer = LAYER_NOTES ); @@ -76,6 +79,26 @@ public: void SetEndPoint( const wxPoint& aPosition ) { m_end = aPosition; } + enum wxPenStyle GetDefaultStyle() const; + + void SetLineStyle( const int aStyle ); + + enum wxPenStyle GetLineStyle() const; + + void SetLineColor( const COLOR4D aColor ); + + void SetLineColor( const double r, const double g, const double b, const double a ); + + COLOR4D GetLineColor() const; + + COLOR4D GetDefaultColor() const; + + int GetDefaultWidth() const; + + void SetLineWidth( const int aSize ); + + int GetLineSize() const { return m_size; } + const EDA_RECT GetBoundingBox() const override; /** @@ -147,6 +170,8 @@ public: EDA_ITEM* Clone() const override; + void SwapData( SCH_ITEM* aItem ) override; + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override; #endif diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index b350c5634f..e33743b325 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -1064,6 +1064,8 @@ void SCH_EDIT_FRAME::OnEditItem( wxCommandEvent& aEvent ) break; case SCH_LINE_T: // These items have no param to edit + EditLine( (SCH_LINE*) item, true ); + break; case SCH_MARKER_T: case SCH_JUNCTION_T: case SCH_NO_CONNECT_T: diff --git a/eeschema/schframe.h b/eeschema/schframe.h index 2a8322bf04..d1f702cb02 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -1039,6 +1039,16 @@ private: /// Loads the cache library associated to the aFileName bool LoadCacheLibrary( const wxString& aFileName ); +private: + /** + * Function EditLine + * displays the dialog for editing the parameters of \a aLine. + * @param aLine The Line/Wire/Bus to edit. + * @param aRedraw = true to refresh the screen + * @return The user response from the edit dialog. + */ + int EditLine( SCH_LINE* aLine, bool aRedraw ); + public: /** * Function EditSheet diff --git a/include/gr_basic.h b/include/gr_basic.h index 1e4d513d64..008d1cf0ca 100644 --- a/include/gr_basic.h +++ b/include/gr_basic.h @@ -112,13 +112,15 @@ void GRForceBlackPen( bool flagforce ); bool GetGRForceBlackPenState( void ); void GRLine( EDA_RECT* aClipBox, wxDC* aDC, - wxPoint aStart, wxPoint aEnd, int aWidth, COLOR4D aColor ); + wxPoint aStart, wxPoint aEnd, int aWidth, COLOR4D aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID ); void GRLine( EDA_RECT* ClipBox, wxDC* DC, - int x1, int y1, int x2, int y2, int width, COLOR4D Color ); + int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle = wxPENSTYLE_SOLID ); void GRMixedLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color ); void GRDashedLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color ); +void GRDottedLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, + int width, COLOR4D Color ); void GRMoveTo( int x, int y ); void GRLineTo( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int width, COLOR4D Color );