diff --git a/common/plotters/plotter.cpp b/common/plotters/plotter.cpp index 629cded16e..c4f687be7b 100644 --- a/common/plotters/plotter.cpp +++ b/common/plotters/plotter.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.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 @@ -594,3 +594,23 @@ void PLOTTER::PlotPoly( const SHAPE_LINE_CHAIN& aCornerList, FILL_T aFill, PlotPoly( cornerList, aFill, aWidth, aData ); } + + +wxPenStyle GetwxPenStyle( PLOT_DASH_TYPE aType ) +{ + switch( aType ) + { + case PLOT_DASH_TYPE::DEFAULT: + case PLOT_DASH_TYPE::SOLID: + return wxPENSTYLE_SOLID; + case PLOT_DASH_TYPE::DASH: + return wxPENSTYLE_SHORT_DASH; + case PLOT_DASH_TYPE::DOT: + return wxPENSTYLE_DOT; + case PLOT_DASH_TYPE::DASHDOT: + return wxPENSTYLE_DOT_DASH; + default: + wxFAIL_MSG( "Unhandled PlotDashType" ); + return wxPENSTYLE_SOLID; + } +} diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 113b0a9efa..1393c81f53 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -60,6 +60,8 @@ set( EESCHEMA_DLGS dialogs/dialog_global_sym_lib_table_config.cpp dialogs/dialog_global_edit_text_and_graphics.cpp dialogs/dialog_global_edit_text_and_graphics_base.cpp + dialogs/dialog_junction_props.cpp + dialogs/dialog_junction_props_base.cpp dialogs/dialog_lib_edit_draw_item.cpp dialogs/dialog_lib_edit_draw_item_base.cpp dialogs/dialog_lib_edit_pin.cpp diff --git a/eeschema/dialogs/dialog_junction_props.cpp b/eeschema/dialogs/dialog_junction_props.cpp new file mode 100644 index 0000000000..1bdc6b2483 --- /dev/null +++ b/eeschema/dialogs/dialog_junction_props.cpp @@ -0,0 +1,192 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Wayne Stambaugh + * Copyright (C) 2020 KiCad Developers, see AUTHORS.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 3 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, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +const int BUTT_COLOR_MINSIZE_X = 32; +const int BUTT_COLOR_MINSIZE_Y = 20; + + +static COLOR4D GetIndeterminateColor() +{ + COLOR4D indeterminateColor; + + indeterminateColor.r = indeterminateColor.b = indeterminateColor.g = + indeterminateColor.a = -1.0; + + return indeterminateColor; +} + + +DIALOG_JUNCTION_PROPS::DIALOG_JUNCTION_PROPS( SCH_EDIT_FRAME* aParent, + std::deque& aJunctions ) : + DIALOG_JUNCTION_PROPS_BASE( aParent ), + m_frame( aParent ), + m_junctions( aJunctions ), + m_diameter( aParent, m_staticTextDiameter, m_textCtrlDiameter, + m_staticTextDiameterUnits, true ) +{ + m_sdbSizerApply->SetLabel( _( "Default" ) ); + + SetInitialFocus( m_textCtrlDiameter ); + + m_sdbSizerOK->SetDefault(); + + // Now all widgets have the size fixed, call FinishDialogSettings + FinishDialogSettings(); +} + + +bool DIALOG_JUNCTION_PROPS::TransferDataToWindow() +{ + auto firstJunction = m_junctions.front(); + + if( std::all_of( m_junctions.begin() + 1, m_junctions.end(), + [&]( const SCH_JUNCTION* r ) + { + return r->GetDiameter() == firstJunction->GetDiameter(); + } ) ) + { + m_diameter.SetValue( firstJunction->GetDiameter() ); + } + else + { + m_diameter.SetValue( INDETERMINATE_ACTION ); + } + + if( std::all_of( m_junctions.begin() + 1, m_junctions.end(), + [&]( const SCH_JUNCTION* r ) + { + return r->GetColor() == firstJunction->GetColor(); + } ) ) + { + setColor( firstJunction->GetColor() ); + } + else + { + setColor( GetIndeterminateColor() ); + } + + return true; +} + + +void DIALOG_JUNCTION_PROPS::onColorButtonClicked( wxCommandEvent& event ) +{ + COLOR4D newColor = COLOR4D::UNSPECIFIED; + DIALOG_COLOR_PICKER dialog( this, m_selectedColor, false ); + + if( dialog.ShowModal() == wxID_OK ) + newColor = dialog.GetColor(); + + if( m_selectedColor == newColor ) + return; + + setColor( newColor ); +} + + +void DIALOG_JUNCTION_PROPS::updateColorButton( COLOR4D& aColor ) +{ + wxMemoryDC iconDC; + + if( aColor == COLOR4D::UNSPECIFIED || aColor == GetIndeterminateColor() ) + { + m_buttonColor->SetBitmap( KiBitmap( question_mark_xpm ) ); + } + else + { + wxBitmap bitmap( std::max( m_buttonColor->GetSize().x, BUTT_COLOR_MINSIZE_X ), + std::max( m_buttonColor->GetSize().y, BUTT_COLOR_MINSIZE_Y ) ); + + iconDC.SelectObject( bitmap ); + iconDC.SetPen( *wxBLACK_PEN ); + + wxBrush brush( aColor.ToColour() ); + iconDC.SetBrush( brush ); + + // Paint the full bitmap in aColor: + iconDC.SetBackground( brush ); + iconDC.Clear(); + + m_buttonColor->SetBitmap( bitmap ); + } + + m_buttonColor->Refresh(); + + Refresh( false ); +} + + +void DIALOG_JUNCTION_PROPS::resetDefaults( wxCommandEvent& event ) +{ + m_diameter.SetValue( 0 ); + setColor( COLOR4D::UNSPECIFIED ); + + Refresh(); +} + + +void DIALOG_JUNCTION_PROPS::setColor( const COLOR4D& aColor ) +{ + m_selectedColor = aColor; + + if( aColor == COLOR4D::UNSPECIFIED ) + { + COLOR4D defaultColor = Pgm().GetSettingsManager().GetColorSettings()->GetColor( + m_junctions.front()->GetLayer() ); + updateColorButton( defaultColor ); + } + else + { + updateColorButton( m_selectedColor ); + } +} + + +bool DIALOG_JUNCTION_PROPS::TransferDataFromWindow() +{ + PICKED_ITEMS_LIST pickedItems; + + for( auto& junction : m_junctions ) + pickedItems.PushItem( ITEM_PICKER( junction, UR_CHANGED ) ); + + m_frame->SaveCopyInUndoList( pickedItems, UR_CHANGED ); + + for( auto& junction : m_junctions ) + { + if( !m_diameter.IsIndeterminate() ) + junction->SetDiameter( m_diameter.GetValue() ); + + if( m_selectedColor != GetIndeterminateColor() ) + junction->SetColor( m_selectedColor ); + } + + m_frame->GetCanvas()->Refresh(); + m_frame->OnModify(); + + return true; +} diff --git a/eeschema/dialogs/dialog_junction_props.h b/eeschema/dialogs/dialog_junction_props.h new file mode 100644 index 0000000000..127e9ca4f0 --- /dev/null +++ b/eeschema/dialogs/dialog_junction_props.h @@ -0,0 +1,55 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Wayne Stambaugh + * Copyright (C) 2020 KiCad Developers, see AUTHORS.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 3 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, see . + */ + +#ifndef __dialog_junction_props__ +#define __dialog_junction_props__ + +#include +#include +#include + + +class SCH_EDIT_FRAME; +class SCH_JUNCTION; + + +class DIALOG_JUNCTION_PROPS : public DIALOG_JUNCTION_PROPS_BASE +{ +public: + DIALOG_JUNCTION_PROPS( SCH_EDIT_FRAME* aParent, std::deque& aJunctions ); + + bool TransferDataToWindow() override; + bool TransferDataFromWindow() override; + +private: + SCH_EDIT_FRAME* m_frame; + std::deque m_junctions; + + UNIT_BINDER m_diameter; + COLOR4D m_selectedColor; + + void resetDefaults( wxCommandEvent& event ) override; + void onColorButtonClicked( wxCommandEvent& aEvent ) override; + + void setColor( const COLOR4D& aColor ); + void updateColorButton( COLOR4D& aColor ); +}; + +#endif // __dialog_junction_props__ diff --git a/eeschema/dialogs/dialog_junction_props_base.cpp b/eeschema/dialogs/dialog_junction_props_base.cpp new file mode 100644 index 0000000000..90efb61fcb --- /dev/null +++ b/eeschema/dialogs/dialog_junction_props_base.cpp @@ -0,0 +1,81 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.9.0 Jun 18 2020) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_junction_props_base.h" + +/////////////////////////////////////////////////////////////////////////// + +DIALOG_JUNCTION_PROPS_BASE::DIALOG_JUNCTION_PROPS_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* bSizer2; + bSizer2 = new wxBoxSizer( wxVERTICAL ); + + wxFlexGridSizer* fgSizer2; + fgSizer2 = new wxFlexGridSizer( 0, 3, 5, 0 ); + fgSizer2->AddGrowableCol( 1 ); + fgSizer2->SetFlexibleDirection( wxBOTH ); + fgSizer2->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + + m_staticTextDiameter = new wxStaticText( this, wxID_ANY, _("Diameter:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextDiameter->Wrap( -1 ); + fgSizer2->Add( m_staticTextDiameter, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + + m_textCtrlDiameter = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer2->Add( m_textCtrlDiameter, 0, wxALIGN_CENTER_HORIZONTAL|wxEXPAND|wxLEFT, 5 ); + + m_staticTextDiameterUnits = new wxStaticText( this, wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextDiameterUnits->Wrap( -1 ); + fgSizer2->Add( m_staticTextDiameterUnits, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 ); + + m_staticTextColor = new wxStaticText( this, wxID_ANY, _("Color:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextColor->Wrap( -1 ); + fgSizer2->Add( m_staticTextColor, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + + m_buttonColor = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); + fgSizer2->Add( m_buttonColor, 0, wxEXPAND|wxLEFT, 5 ); + + + fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 ); + + + bSizer2->Add( fgSizer2, 1, wxALL|wxEXPAND, 5 ); + + m_staticline2 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); + bSizer2->Add( m_staticline2, 0, wxEXPAND | wxALL, 5 ); + + m_sdbSizer = new wxStdDialogButtonSizer(); + m_sdbSizerOK = new wxButton( this, wxID_OK ); + m_sdbSizer->AddButton( m_sdbSizerOK ); + m_sdbSizerApply = new wxButton( this, wxID_APPLY ); + m_sdbSizer->AddButton( m_sdbSizerApply ); + m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); + m_sdbSizer->AddButton( m_sdbSizerCancel ); + m_sdbSizer->Realize(); + + bSizer2->Add( m_sdbSizer, 0, wxBOTTOM|wxEXPAND, 5 ); + + + this->SetSizer( bSizer2 ); + this->Layout(); + bSizer2->Fit( this ); + + this->Centre( wxBOTH ); + + // Connect Events + m_buttonColor->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_JUNCTION_PROPS_BASE::onColorButtonClicked ), NULL, this ); + m_sdbSizerApply->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_JUNCTION_PROPS_BASE::resetDefaults ), NULL, this ); +} + +DIALOG_JUNCTION_PROPS_BASE::~DIALOG_JUNCTION_PROPS_BASE() +{ + // Disconnect Events + m_buttonColor->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_JUNCTION_PROPS_BASE::onColorButtonClicked ), NULL, this ); + m_sdbSizerApply->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_JUNCTION_PROPS_BASE::resetDefaults ), NULL, this ); + +} diff --git a/eeschema/dialogs/dialog_junction_props_base.fbp b/eeschema/dialogs/dialog_junction_props_base.fbp new file mode 100644 index 0000000000..b71e6c89fa --- /dev/null +++ b/eeschema/dialogs/dialog_junction_props_base.fbp @@ -0,0 +1,492 @@ + + + + + ; + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + dialog_junction_props_base + 1000 + none + + + 1 + dialog_junction_props_base + + . + + 1 + 1 + 1 + 1 + UI + 0 + 1 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + DIALOG_JUNCTION_PROPS_BASE + + + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + DIALOG_SHIM; dialog_shim.h; forward_declare + Junction Properties + + + + + + + bSizer2 + wxVERTICAL + none + + 5 + wxALL|wxEXPAND + 1 + + 3 + wxBOTH + 1 + + 0 + + fgSizer2 + wxFLEX_GROWMODE_SPECIFIED + none + 0 + 5 + + 5 + wxALIGN_CENTER_VERTICAL|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Diameter: + 0 + + 0 + + + 0 + + 1 + m_staticTextDiameter + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALIGN_CENTER_HORIZONTAL|wxEXPAND|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + m_textCtrlDiameter + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + 5 + wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + mils + 0 + + 0 + + + 0 + + 1 + m_staticTextDiameterUnits + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALIGN_CENTER_VERTICAL|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Color: + 0 + + 0 + + + 0 + + 1 + m_staticTextColor + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxEXPAND|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + MyButton + + 0 + + 0 + + + 0 + + 1 + m_buttonColor + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + onColorButtonClicked + + + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + + + + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_staticline2 + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + ; ; forward_declare + 0 + + + + + + + + 5 + wxBOTTOM|wxEXPAND + 0 + + 1 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + + m_sdbSizer + protected + resetDefaults + + + + + + diff --git a/eeschema/dialogs/dialog_junction_props_base.h b/eeschema/dialogs/dialog_junction_props_base.h new file mode 100644 index 0000000000..4f16907747 --- /dev/null +++ b/eeschema/dialogs/dialog_junction_props_base.h @@ -0,0 +1,62 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.9.0 Jun 18 2020) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_JUNCTION_PROPS_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_JUNCTION_PROPS_BASE : public DIALOG_SHIM +{ + private: + + protected: + wxStaticText* m_staticTextDiameter; + wxTextCtrl* m_textCtrlDiameter; + wxStaticText* m_staticTextDiameterUnits; + wxStaticText* m_staticTextColor; + wxBitmapButton* m_buttonColor; + wxStaticLine* m_staticline2; + wxStdDialogButtonSizer* m_sdbSizer; + wxButton* m_sdbSizerOK; + wxButton* m_sdbSizerApply; + wxButton* m_sdbSizerCancel; + + // Virtual event handlers, overide them in your derived class + virtual void onColorButtonClicked( wxCommandEvent& event ) { event.Skip(); } + virtual void resetDefaults( wxCommandEvent& event ) { event.Skip(); } + + + public: + + DIALOG_JUNCTION_PROPS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Junction Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~DIALOG_JUNCTION_PROPS_BASE(); + +}; + diff --git a/eeschema/ee_collectors.cpp b/eeschema/ee_collectors.cpp index eb4ce94c9e..9e6b84f0a3 100644 --- a/eeschema/ee_collectors.cpp +++ b/eeschema/ee_collectors.cpp @@ -54,6 +54,7 @@ const KICAD_T EE_COLLECTOR::EditableItems[] = { SCH_BITMAP_T, SCH_LINE_T, SCH_BUS_WIRE_ENTRY_T, + SCH_JUNCTION_T, EOT }; diff --git a/eeschema/sch_bus_entry.cpp b/eeschema/sch_bus_entry.cpp index 1a6dccfd3d..fe59583a11 100644 --- a/eeschema/sch_bus_entry.cpp +++ b/eeschema/sch_bus_entry.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.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 @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -131,13 +132,19 @@ const EDA_RECT SCH_BUS_ENTRY_BASE::GetBoundingBox() const int SCH_BUS_WIRE_ENTRY::GetPenWidth() const { + if( m_stroke.GetWidth() == 0 && Schematic() ) + return std::max( Schematic()->Settings().m_DefaultWireThickness, 1 ); + return ( m_stroke.GetWidth() == 0 ) ? 1 : m_stroke.GetWidth(); } int SCH_BUS_BUS_ENTRY::GetPenWidth() const { - return 1; + if( m_stroke.GetWidth() == 0 && Schematic() ) + return std::max( Schematic()->Settings().m_DefaultBusThickness, 1 ); + + return ( m_stroke.GetWidth() == 0 ) ? 1 : m_stroke.GetWidth(); } @@ -164,11 +171,13 @@ void SCH_BUS_BUS_ENTRY::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemLis void SCH_BUS_ENTRY_BASE::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) { wxDC* DC = aSettings->GetPrintDC(); - COLOR4D color = aSettings->GetLayerColor( m_Layer ); - int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() ); + COLOR4D color = ( GetStrokeColor() == COLOR4D::UNSPECIFIED ) ? + aSettings->GetLayerColor( m_Layer ) : GetStrokeColor(); + int penWidth = ( GetPenWidth() == 0 ) ? aSettings->GetDefaultPenWidth() : GetPenWidth(); GRLine( nullptr, DC, m_pos.x + aOffset.x, m_pos.y + aOffset.y, m_End().x + aOffset.x, - m_End().y + aOffset.y, penWidth, color ); + m_End().y + aOffset.y, penWidth, color, + GetwxPenStyle( (PLOT_DASH_TYPE) GetStrokeStyle() ) ); } @@ -356,10 +365,15 @@ bool SCH_BUS_ENTRY_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aA void SCH_BUS_ENTRY_BASE::Plot( PLOTTER* aPlotter ) { - int penWidth = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() ); + auto* settings = static_cast( aPlotter->RenderSettings() ); + + COLOR4D color = ( GetStrokeColor() == COLOR4D::UNSPECIFIED ) ? + settings->GetLayerColor( m_Layer ) : GetStrokeColor(); + int penWidth = ( GetPenWidth() == 0 ) ? settings->GetDefaultPenWidth() : GetPenWidth(); aPlotter->SetCurrentLineWidth( penWidth ); - aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( GetLayer() ) ); + aPlotter->SetColor( color ); + aPlotter->SetDash( GetStrokeStyle() ); aPlotter->MoveTo( m_pos ); aPlotter->FinishTo( m_End() ); } diff --git a/eeschema/sch_junction.cpp b/eeschema/sch_junction.cpp index 1f075d478c..9c07042a0b 100644 --- a/eeschema/sch_junction.cpp +++ b/eeschema/sch_junction.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.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 @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -42,10 +43,12 @@ #include -SCH_JUNCTION::SCH_JUNCTION( const wxPoint& pos, SCH_LAYER_ID aLayer ) : +SCH_JUNCTION::SCH_JUNCTION( const wxPoint& aPosition, int aDiameter, SCH_LAYER_ID aLayer ) : SCH_ITEM( NULL, SCH_JUNCTION_T ) { - m_pos = pos; + m_pos = aPosition; + m_color = COLOR4D::UNSPECIFIED; + m_diameter = aDiameter; m_Layer = aLayer; } @@ -63,6 +66,8 @@ void SCH_JUNCTION::SwapData( SCH_ITEM* aItem ) SCH_JUNCTION* item = (SCH_JUNCTION*) aItem; std::swap( m_pos, item->m_pos ); + std::swap( m_diameter, item->m_diameter ); + std::swap( m_color, item->m_color ); } @@ -81,6 +86,9 @@ const EDA_RECT SCH_JUNCTION::GetBoundingBox() const int size = Schematic() ? Schematic()->Settings().m_JunctionSize : Mils2iu( DEFAULT_JUNCTION_DIAM ); + if( m_diameter != 0 ) + size = m_diameter; + rect.SetOrigin( m_pos ); rect.Inflate( ( GetPenWidth() + size ) / 2 ); @@ -91,10 +99,16 @@ const EDA_RECT SCH_JUNCTION::GetBoundingBox() const void SCH_JUNCTION::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) { wxDC* DC = aSettings->GetPrintDC(); - COLOR4D color = aSettings->GetLayerColor( GetLayer() ); + COLOR4D color = ( m_color == COLOR4D::UNSPECIFIED ) ? aSettings->GetLayerColor( GetLayer() ) : + m_color ; + int diameter = + Schematic() ? Schematic()->Settings().m_JunctionSize : Mils2iu( DEFAULT_JUNCTION_DIAM ); + + if( m_diameter != 0 ) + diameter = m_diameter; GRFilledCircle( nullptr, DC, m_pos.x + aOffset.x, m_pos.y + aOffset.y, - Schematic()->Settings().m_JunctionSize / 2, 0, color, color ); + diameter / 2, 0, color, color ); } @@ -150,7 +164,8 @@ void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const // XML output: wxString s = GetClass(); - NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << "/>\n"; + NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << ", " << m_diameter + << "/>\n"; } #endif @@ -189,8 +204,18 @@ bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const void SCH_JUNCTION::Plot( PLOTTER* aPlotter ) { - aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( GetLayer() ) ); - aPlotter->Circle( m_pos, Schematic()->Settings().m_JunctionSize, FILLED_SHAPE ); + auto* settings = static_cast( aPlotter->RenderSettings() ); + + COLOR4D color = ( m_color == COLOR4D::UNSPECIFIED ) ? settings->GetLayerColor( GetLayer() ) : + m_color; + int diameter = + Schematic() ? Schematic()->Settings().m_JunctionSize : Mils2iu( DEFAULT_JUNCTION_DIAM ); + + if( m_diameter != 0 ) + diameter = m_diameter; + + aPlotter->SetColor( color ); + aPlotter->Circle( m_pos, diameter, FILLED_SHAPE ); } @@ -213,7 +238,12 @@ bool SCH_JUNCTION::operator <( const SCH_ITEM& aItem ) const if( GetPosition().x != junction->GetPosition().x ) return GetPosition().x < junction->GetPosition().x; - return GetPosition().y < junction->GetPosition().y; + if( GetPosition().y != junction->GetPosition().y ) + return GetPosition().y < junction->GetPosition().y; + + if( GetDiameter() != junction->GetDiameter() ) + return GetDiameter() < junction->GetDiameter(); + return GetColor() < junction->GetColor(); } diff --git a/eeschema/sch_junction.h b/eeschema/sch_junction.h index 3be6ebf9ca..f94094d006 100644 --- a/eeschema/sch_junction.h +++ b/eeschema/sch_junction.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.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 @@ -27,14 +27,19 @@ #include +#include + class NETLIST_OBJECT_LIST; class SCH_JUNCTION : public SCH_ITEM { - wxPoint m_pos; // Position of the junction. + wxPoint m_pos; // Position of the junction. + int m_diameter; // Diameter of the junction. Zero is user default. + COLOR4D m_color; // Color of the junction. #COLOR4D::UNSPECIFIED is user default. public: - SCH_JUNCTION( const wxPoint& pos = wxPoint( 0, 0 ), SCH_LAYER_ID aLayer = LAYER_JUNCTION ); + SCH_JUNCTION( const wxPoint& aPosition = wxPoint( 0, 0 ), int aDiameter = 0, + SCH_LAYER_ID aLayer = LAYER_JUNCTION ); // Do not create a copy constructor. The one generated by the compiler is adequate. @@ -92,6 +97,12 @@ public: const wxPoint GetPosition() const override { return m_pos; } void SetPosition( const wxPoint& aPosition ) override { m_pos = aPosition; } + int GetDiameter() const { return m_diameter; } + void SetDiameter( int aDiameter ) { m_diameter = aDiameter; } + + COLOR4D GetColor() const { return m_color; } + void SetColor( const COLOR4D& aColor ) { m_color = aColor; } + bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override; bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override; diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index f12567b234..7540e4d1b0 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -44,26 +44,6 @@ #include -static wxPenStyle getwxPenStyle( PLOT_DASH_TYPE aType ) -{ - switch( aType ) - { - case PLOT_DASH_TYPE::DEFAULT: - case PLOT_DASH_TYPE::SOLID: - return wxPENSTYLE_SOLID; - case PLOT_DASH_TYPE::DASH: - return wxPENSTYLE_SHORT_DASH; - case PLOT_DASH_TYPE::DOT: - return wxPENSTYLE_DOT; - case PLOT_DASH_TYPE::DASHDOT: - return wxPENSTYLE_DOT_DASH; - default: - wxFAIL_MSG( "Unhandled PlotDashType" ); - return wxPENSTYLE_SOLID; - } -} - - SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) : SCH_ITEM( NULL, SCH_LINE_T ) { @@ -310,7 +290,7 @@ void SCH_LINE::Print( RENDER_SETTINGS* aSettings, const wxPoint& offset ) color = aSettings->GetLayerColor( m_Layer ); GRLine( nullptr, DC, start.x, start.y, end.x, end.y, penWidth, color, - getwxPenStyle( (PLOT_DASH_TYPE) GetLineStyle() ) ); + GetwxPenStyle( GetLineStyle() ) ); } @@ -750,7 +730,7 @@ void SCH_LINE::Plot( PLOTTER* aPlotter ) if( m_stroke.GetColor() != COLOR4D::UNSPECIFIED ) aPlotter->SetColor( m_stroke.GetColor() ); else - aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( GetLayer() ) ); + aPlotter->SetColor( settings->GetLayerColor( GetLayer() ) ); switch( m_Layer ) { @@ -761,6 +741,9 @@ void SCH_LINE::Plot( PLOTTER* aPlotter ) penWidth = std::max( penWidth, aPlotter->RenderSettings()->GetDefaultPenWidth() ); + if( m_stroke.GetWidth() != 0 ) + penWidth = m_stroke.GetWidth(); + aPlotter->SetCurrentLineWidth( penWidth ); aPlotter->SetDash( GetLineStyle() ); @@ -784,12 +767,14 @@ void SCH_LINE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList ) switch( GetLayer() ) { - case LAYER_WIRE: msg = _( "Net Wire" ); break; - case LAYER_BUS: msg = _( "Bus Wire" ); break; - default: msg = _( "Graphical" ); return; + case LAYER_WIRE: msg = _( "Wire" ); break; + case LAYER_BUS: msg = _( "Bus" ); break; + default: msg = _( "Graphical" ); break; } aList.push_back( MSG_PANEL_ITEM( _( "Line Type" ), msg, DARKCYAN ) ); + msg = GetLineStyleName( GetLineStyle() ); + aList.push_back( MSG_PANEL_ITEM( _( "Line Style" ), msg, DARKCYAN ) ); SCH_EDIT_FRAME* frame = dynamic_cast( aFrame ); diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 26557f2d0b..30d0375afa 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -261,6 +261,20 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDr if( lineColor != COLOR4D::UNSPECIFIED ) color = lineColor; } + else if( aItem->Type() == SCH_BUS_WIRE_ENTRY_T ) + { + COLOR4D busEntryColor = static_cast( aItem )->GetStrokeColor(); + + if( busEntryColor != COLOR4D::UNSPECIFIED ) + color = busEntryColor; + } + else if( aItem->Type() == SCH_JUNCTION_T ) + { + COLOR4D junctionColor = static_cast( aItem )->GetColor(); + + if( junctionColor != COLOR4D::UNSPECIFIED ) + color = junctionColor; + } else if( aItem->Type() == SCH_SHEET_T ) { SCH_SHEET* sheet = (SCH_SHEET*) aItem; @@ -1189,12 +1203,17 @@ void SCH_PAINTER::draw( SCH_JUNCTION *aJct, int aLayer ) COLOR4D color = getRenderColor( aJct, aJct->GetLayer(), drawingShadows ); + int junctionSize = m_schSettings.m_JunctionSize / 2.0; + + if( aJct->GetDiameter() != 0 ) + junctionSize = aJct->GetDiameter() / 2; + m_gal->SetIsStroke( drawingShadows ); m_gal->SetLineWidth( getLineWidth( aJct, drawingShadows ) ); m_gal->SetStrokeColor( color ); m_gal->SetIsFill( !drawingShadows ); m_gal->SetFillColor( color ); - m_gal->DrawCircle( aJct->GetPosition(), m_schSettings.m_JunctionSize / 2.0 ); + m_gal->DrawCircle( aJct->GetPosition(), junctionSize ); } diff --git a/eeschema/sch_sexpr_parser.cpp b/eeschema/sch_sexpr_parser.cpp index 525eca97f7..9bc8a94548 100644 --- a/eeschema/sch_sexpr_parser.cpp +++ b/eeschema/sch_sexpr_parser.cpp @@ -2394,6 +2394,25 @@ SCH_JUNCTION* SCH_SEXPR_PARSER::parseJunction() NeedRIGHT(); break; + case T_diameter: + junction->SetDiameter( parseInternalUnits( "junction diameter" ) ); + NeedRIGHT(); + break; + + case T_color: + { + COLOR4D color; + + color.r = parseInt( "red" ) / 255.0; + color.g = parseInt( "green" ) / 255.0; + color.b = parseInt( "blue" ) / 255.0; + color.a = Clamp( parseDouble( "alpha" ), 0.0, 1.0 ); + + junction->SetColor( color ); + NeedRIGHT(); + break; + } + default: Expecting( "at" ); } diff --git a/eeschema/sch_sexpr_plugin.cpp b/eeschema/sch_sexpr_plugin.cpp index 652b218289..023e8cada7 100644 --- a/eeschema/sch_sexpr_plugin.cpp +++ b/eeschema/sch_sexpr_plugin.cpp @@ -1106,9 +1106,14 @@ void SCH_SEXPR_PLUGIN::saveJunction( SCH_JUNCTION* aJunction, int aNestLevel ) { wxCHECK_RET( aJunction != nullptr && m_out != nullptr, "" ); - m_out->Print( aNestLevel, "(junction (at %s %s))\n", + m_out->Print( aNestLevel, "(junction (at %s %s) (diameter %s) (color %d %d %d %s))\n", FormatInternalUnits( aJunction->GetPosition().x ).c_str(), - FormatInternalUnits( aJunction->GetPosition().y ).c_str() ); + FormatInternalUnits( aJunction->GetPosition().y ).c_str(), + FormatInternalUnits( aJunction->GetDiameter() ).c_str(), + KiROUND( aJunction->GetColor().r * 255.0 ), + KiROUND( aJunction->GetColor().g * 255.0 ), + KiROUND( aJunction->GetColor().b * 255.0 ), + Double2Str( aJunction->GetColor().a ).c_str() ); } @@ -1136,15 +1141,16 @@ void SCH_SEXPR_PLUGIN::saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry, int aNestLev } else { - m_out->Print( aNestLevel, "(bus_entry (at %s %s) (size %s %s) ", + m_out->Print( aNestLevel, "(bus_entry (at %s %s) (size %s %s)\n", FormatInternalUnits( aBusEntry->GetPosition().x ).c_str(), FormatInternalUnits( aBusEntry->GetPosition().y ).c_str(), FormatInternalUnits( aBusEntry->GetSize().GetWidth() ).c_str(), FormatInternalUnits( aBusEntry->GetSize().GetHeight() ).c_str() ); - formatStroke( m_out, 0, aBusEntry->GetStroke() ); + formatStroke( m_out, aNestLevel + 1, aBusEntry->GetStroke() ); - m_out->Print( 0, ")\n" ); + m_out->Print( 0, "\n" ); + m_out->Print( aNestLevel, ")\n" ); } } diff --git a/eeschema/schematic.keywords b/eeschema/schematic.keywords index 73e4dd9947..98fec3ee84 100644 --- a/eeschema/schematic.keywords +++ b/eeschema/schematic.keywords @@ -25,6 +25,7 @@ dash dash_dot data date +diameter dot edge_clock_high effects diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index d8161cdd99..31859909c4 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,7 @@ #include #include #include +#include #include "sch_drawing_tools.h" #include // for KiROUND #include @@ -208,6 +210,12 @@ bool SCH_EDIT_TOOL::Init() && eeSelection->AllItemsHaveLineStroke() ) ) return false; + if( aSel.GetSize() != 1 + && !( aSel.GetSize() >= 1 + && ( firstItem->Type() == SCH_JUNCTION_T ) + && eeSelection->AreAllItemsIdentical() ) ) + return false; + switch( firstItem->Type() ) { case SCH_COMPONENT_T: @@ -233,6 +241,9 @@ bool SCH_EDIT_TOOL::Init() return true; + case SCH_JUNCTION_T: + return true; + default: return false; } @@ -1278,6 +1289,12 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) break; + case SCH_JUNCTION_T: + if( !selection.AreAllItemsIdentical() ) + return 0; + + break; + default: if( selection.Size() > 1 ) return 0; @@ -1420,8 +1437,29 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) } break; - case SCH_MARKER_T: // These items have no properties to edit case SCH_JUNCTION_T: + { + std::deque junctions; + + for( auto selItem : selection.Items() ) + { + SCH_JUNCTION* junction = dynamic_cast( selItem ); + + wxCHECK( junction, 0 ); + + junctions.push_back( junction ); + } + + DIALOG_JUNCTION_PROPS dlg( m_frame, junctions ); + + if( dlg.ShowModal() == wxID_OK ) + { + m_toolMgr->PostEvent( EVENTS::SelectedItemsModified ); + m_frame->OnModify(); + } + } + + case SCH_MARKER_T: // These items have no properties to edit case SCH_NO_CONNECT_T: break; diff --git a/include/plotter.h b/include/plotter.h index 8b45452500..bfb800f0a7 100644 --- a/include/plotter.h +++ b/include/plotter.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.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 @@ -95,6 +95,16 @@ enum class PLOT_DASH_TYPE LAST_TYPE = DASHDOT }; +/** + * Convert KiCad line plot styles to wxWidgets device context styles. + * + * @param aType The KiCad line plot style to convert. + * + * @return The equivalent wxPenStyle of \a aType. + */ +wxPenStyle GetwxPenStyle( PLOT_DASH_TYPE aType ); + + /** * Base plotter engine class. General rule: all the interface with the caller * is done in IU, the IU size is specified with SetViewport. Internal and