Browse Source
ADDED: Properties panel for schematic editor
ADDED: Properties panel for schematic editor
Initial infrastructure work; follow-ons will add more properties for schematic items. Fixes https://gitlab.com/kicad/code/kicad/-/issues/6351 Fixes https://gitlab.com/kicad/code/kicad/-/issues/14105newinvert
49 changed files with 896 additions and 63 deletions
-
2common/CMakeLists.txt
-
15common/eda_draw_frame.cpp
-
78common/properties/color4d_variant.cpp
-
77common/properties/pg_properties.cpp
-
10common/properties/property_mgr.cpp
-
5common/tool/actions.cpp
-
7common/tool/properties_tool.cpp
-
3common/widgets/properties_panel.cpp
-
1eeschema/CMakeLists.txt
-
9eeschema/eeschema_settings.cpp
-
3eeschema/eeschema_settings.h
-
1eeschema/menubar.cpp
-
11eeschema/sch_bitmap.cpp
-
15eeschema/sch_bus_entry.cpp
-
24eeschema/sch_edit_frame.cpp
-
2eeschema/sch_edit_frame.h
-
27eeschema/sch_field.cpp
-
34eeschema/sch_item.cpp
-
4eeschema/sch_item.h
-
10eeschema/sch_junction.cpp
-
35eeschema/sch_label.cpp
-
10eeschema/sch_line.cpp
-
11eeschema/sch_pin.cpp
-
28eeschema/sch_shape.cpp
-
23eeschema/sch_sheet.cpp
-
11eeschema/sch_symbol.cpp
-
17eeschema/sch_text.cpp
-
22eeschema/sch_textbox.cpp
-
27eeschema/toolbars_sch_editor.cpp
-
8eeschema/tools/sch_editor_control.cpp
-
1eeschema/tools/sch_editor_control.h
-
190eeschema/widgets/sch_properties_panel.cpp
-
64eeschema/widgets/sch_properties_panel.h
-
10include/eda_draw_frame.h
-
55include/properties/color4d_variant.h
-
16include/properties/pg_properties.h
-
6include/properties/property.h
-
10include/properties/property_mgr.h
-
1include/tool/actions.h
-
8include/tool/properties_tool.h
-
1pcbnew/CMakeLists.txt
-
11pcbnew/footprint_edit_frame.cpp
-
2pcbnew/menubar_pcb_editor.cpp
-
23pcbnew/pcb_base_edit_frame.cpp
-
9pcbnew/pcb_base_edit_frame.h
-
14pcbnew/pcb_edit_frame.cpp
-
2pcbnew/tools/board_editor_control.cpp
-
5pcbnew/tools/pcb_actions.cpp
-
1pcbnew/tools/pcb_actions.h
@ -0,0 +1,78 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#include <properties/color4d_variant.h>
|
|||
|
|||
COLOR4D_VARIANT_DATA::COLOR4D_VARIANT_DATA() : |
|||
wxVariantData() |
|||
{} |
|||
|
|||
|
|||
COLOR4D_VARIANT_DATA::COLOR4D_VARIANT_DATA( const wxString& aColorStr ) : |
|||
wxVariantData(), |
|||
m_color( aColorStr ) |
|||
{} |
|||
|
|||
|
|||
COLOR4D_VARIANT_DATA::COLOR4D_VARIANT_DATA( const KIGFX::COLOR4D& aColor ) : |
|||
wxVariantData(), |
|||
m_color( aColor ) |
|||
{} |
|||
|
|||
|
|||
bool COLOR4D_VARIANT_DATA::Eq( wxVariantData& aOther ) const |
|||
{ |
|||
try |
|||
{ |
|||
COLOR4D_VARIANT_DATA& evd = dynamic_cast<COLOR4D_VARIANT_DATA&>( aOther ); |
|||
|
|||
return evd.m_color == m_color; |
|||
} |
|||
catch( std::bad_cast& ) |
|||
{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
|
|||
bool COLOR4D_VARIANT_DATA::Read( wxString& aString ) |
|||
{ |
|||
m_color = KIGFX::COLOR4D( aString ); |
|||
return true; |
|||
} |
|||
|
|||
|
|||
bool COLOR4D_VARIANT_DATA::Write( wxString& aString ) const |
|||
{ |
|||
aString = m_color.ToCSSString(); |
|||
return true; |
|||
} |
|||
|
|||
|
|||
bool COLOR4D_VARIANT_DATA::GetAsAny( wxAny* aAny ) const |
|||
{ |
|||
*aAny = m_color; |
|||
return true; |
|||
} |
|||
|
|||
|
|||
wxVariantData* COLOR4D_VARIANT_DATA::VariantDataFactory( const wxAny& aAny ) |
|||
{ |
|||
return new COLOR4D_VARIANT_DATA( aAny.As<KIGFX::COLOR4D>() ); |
|||
} |
|||
@ -0,0 +1,190 @@ |
|||
/*
|
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2020 CERN |
|||
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* @author Maciej Suminski <maciej.suminski@cern.ch> |
|||
* |
|||
* 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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#include "sch_properties_panel.h"
|
|||
|
|||
#include <connection_graph.h>
|
|||
#include <properties/pg_editors.h>
|
|||
#include <properties/pg_properties.h>
|
|||
#include <properties/property_mgr.h>
|
|||
#include <sch_commit.h>
|
|||
#include <sch_edit_frame.h>
|
|||
#include <schematic.h>
|
|||
#include <settings/color_settings.h>
|
|||
#include <string_utils.h>
|
|||
#include <tool/tool_manager.h>
|
|||
#include <tools/ee_selection_tool.h>
|
|||
|
|||
|
|||
SCH_PROPERTIES_PANEL::SCH_PROPERTIES_PANEL( wxWindow* aParent, SCH_BASE_FRAME* aFrame ) : |
|||
PROPERTIES_PANEL( aParent, aFrame ), |
|||
m_frame( aFrame ), |
|||
m_propMgr( PROPERTY_MANAGER::Instance() ) |
|||
{ |
|||
m_propMgr.Rebuild(); |
|||
bool found = false; |
|||
|
|||
wxASSERT( wxPGGlobalVars ); |
|||
|
|||
wxString editorKey = PG_UNIT_EDITOR::BuildEditorName( m_frame ); |
|||
|
|||
auto it = wxPGGlobalVars->m_mapEditorClasses.find( editorKey ); |
|||
|
|||
if( it != wxPGGlobalVars->m_mapEditorClasses.end() ) |
|||
{ |
|||
m_unitEditorInstance = static_cast<PG_UNIT_EDITOR*>( it->second ); |
|||
m_unitEditorInstance->UpdateFrame( m_frame ); |
|||
found = true; |
|||
} |
|||
|
|||
if( !found ) |
|||
{ |
|||
PG_UNIT_EDITOR* new_editor = new PG_UNIT_EDITOR( m_frame ); |
|||
m_unitEditorInstance = static_cast<PG_UNIT_EDITOR*>( wxPropertyGrid::RegisterEditorClass( new_editor ) ); |
|||
} |
|||
|
|||
it = wxPGGlobalVars->m_mapEditorClasses.find( PG_CHECKBOX_EDITOR::EDITOR_NAME ); |
|||
|
|||
if( it == wxPGGlobalVars->m_mapEditorClasses.end() ) |
|||
{ |
|||
PG_CHECKBOX_EDITOR* cbEditor = new PG_CHECKBOX_EDITOR(); |
|||
m_checkboxEditorInstance = static_cast<PG_CHECKBOX_EDITOR*>( wxPropertyGrid::RegisterEditorClass( cbEditor ) ); |
|||
} |
|||
else |
|||
{ |
|||
m_checkboxEditorInstance = static_cast<PG_CHECKBOX_EDITOR*>( it->second ); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
SCH_PROPERTIES_PANEL::~SCH_PROPERTIES_PANEL() |
|||
{ |
|||
m_unitEditorInstance->UpdateFrame( nullptr ); |
|||
} |
|||
|
|||
|
|||
void SCH_PROPERTIES_PANEL::UpdateData() |
|||
{ |
|||
EE_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<EE_SELECTION_TOOL>(); |
|||
const SELECTION& selection = selectionTool->GetSelection(); |
|||
|
|||
// TODO perhaps it could be called less often? use PROPERTIES_TOOL and catch MODEL_RELOAD?
|
|||
if( SCH_EDIT_FRAME* schFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) ) |
|||
updateLists( schFrame->Schematic() ); |
|||
|
|||
// Will actually just be updatePropertyValues() if selection hasn't changed
|
|||
rebuildProperties( selection ); |
|||
} |
|||
|
|||
|
|||
void SCH_PROPERTIES_PANEL::AfterCommit() |
|||
{ |
|||
EE_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<EE_SELECTION_TOOL>(); |
|||
const SELECTION& selection = selectionTool->GetSelection(); |
|||
|
|||
rebuildProperties( selection ); |
|||
|
|||
CallAfter( [&]() |
|||
{ |
|||
m_frame->GetCanvas()->SetFocus(); |
|||
} ); |
|||
} |
|||
|
|||
|
|||
wxPGProperty* SCH_PROPERTIES_PANEL::createPGProperty( const PROPERTY_BASE* aProperty ) const |
|||
{ |
|||
return PGPropertyFactory( aProperty, m_frame ); |
|||
} |
|||
|
|||
|
|||
PROPERTY_BASE* SCH_PROPERTIES_PANEL::getPropertyFromEvent( const wxPropertyGridEvent& aEvent ) const |
|||
{ |
|||
EE_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<EE_SELECTION_TOOL>(); |
|||
const SELECTION& selection = selectionTool->GetSelection(); |
|||
SCH_ITEM* firstItem = static_cast<SCH_ITEM*>( selection.Front() ); |
|||
|
|||
wxCHECK_MSG( firstItem, nullptr, |
|||
wxT( "getPropertyFromEvent for a property with nothing selected!") ); |
|||
|
|||
PROPERTY_BASE* property = m_propMgr.GetProperty( TYPE_HASH( *firstItem ), |
|||
aEvent.GetPropertyName() ); |
|||
wxCHECK_MSG( property, nullptr, |
|||
wxT( "getPropertyFromEvent for a property not found on the selected item!" ) ); |
|||
|
|||
return property; |
|||
} |
|||
|
|||
|
|||
void SCH_PROPERTIES_PANEL::valueChanging( wxPropertyGridEvent& aEvent ) |
|||
{ |
|||
EE_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<EE_SELECTION_TOOL>(); |
|||
const SELECTION& selection = selectionTool->GetSelection(); |
|||
EDA_ITEM* item = selection.Front(); |
|||
|
|||
PROPERTY_BASE* property = getPropertyFromEvent( aEvent ); |
|||
wxCHECK( property, /* void */ ); |
|||
wxCHECK( item, /* void */ ); |
|||
|
|||
wxVariant newValue = aEvent.GetPropertyValue(); |
|||
|
|||
if( VALIDATOR_RESULT validationFailure = property->Validate( newValue.GetAny(), item ) ) |
|||
{ |
|||
wxString errorMsg = wxString::Format( wxS( "%s: %s" ), wxGetTranslation( property->Name() ), |
|||
validationFailure->get()->Format( m_frame ) ); |
|||
m_frame->ShowInfoBarError( errorMsg ); |
|||
aEvent.Veto(); |
|||
return; |
|||
} |
|||
} |
|||
|
|||
|
|||
void SCH_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent ) |
|||
{ |
|||
EE_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<EE_SELECTION_TOOL>(); |
|||
const SELECTION& selection = selectionTool->GetSelection(); |
|||
|
|||
PROPERTY_BASE* property = getPropertyFromEvent( aEvent ); |
|||
wxCHECK( property, /* void */ ); |
|||
|
|||
wxVariant newValue = aEvent.GetPropertyValue(); |
|||
SCH_COMMIT changes( m_frame ); |
|||
SCH_SCREEN* screen = m_frame->GetScreen(); |
|||
|
|||
for( EDA_ITEM* edaItem : selection ) |
|||
{ |
|||
SCH_ITEM* item = static_cast<SCH_ITEM*>( edaItem ); |
|||
changes.Modify( item, screen ); |
|||
item->Set( property, newValue ); |
|||
} |
|||
|
|||
changes.Push( _( "Change property" ) ); |
|||
m_frame->Refresh(); |
|||
|
|||
// Perform grid updates as necessary based on value change
|
|||
AfterCommit(); |
|||
} |
|||
|
|||
|
|||
void SCH_PROPERTIES_PANEL::updateLists( const SCHEMATIC& aSchematic ) |
|||
{ |
|||
// No lists yet
|
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
/* |
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* @author Maciej Suminski <maciej.suminski@cern.ch> |
|||
* |
|||
* 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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef SCH_PROPERTIES_PANEL_H |
|||
#define SCH_PROPERTIES_PANEL_H |
|||
|
|||
#include <widgets/properties_panel.h> |
|||
|
|||
class SELECTION; |
|||
class SCHEMATIC; |
|||
class SCH_BASE_FRAME; |
|||
class PROPERTY_MANAGER; |
|||
class PG_UNIT_EDITOR; |
|||
class PG_CHECKBOX_EDITOR; |
|||
|
|||
class SCH_PROPERTIES_PANEL : public PROPERTIES_PANEL |
|||
{ |
|||
public: |
|||
SCH_PROPERTIES_PANEL( wxWindow* aParent, SCH_BASE_FRAME* aFrame ); |
|||
|
|||
virtual ~SCH_PROPERTIES_PANEL(); |
|||
|
|||
void UpdateData() override; |
|||
|
|||
void AfterCommit() override; |
|||
|
|||
protected: |
|||
wxPGProperty* createPGProperty( const PROPERTY_BASE* aProperty ) const override; |
|||
|
|||
PROPERTY_BASE* getPropertyFromEvent( const wxPropertyGridEvent& aEvent ) const; |
|||
|
|||
void valueChanging( wxPropertyGridEvent& aEvent ) override; |
|||
void valueChanged( wxPropertyGridEvent& aEvent ) override; |
|||
|
|||
///< Regenerates caches of list properties |
|||
void updateLists( const SCHEMATIC& aSchematic ); |
|||
|
|||
SCH_BASE_FRAME* m_frame; |
|||
PROPERTY_MANAGER& m_propMgr; |
|||
PG_UNIT_EDITOR* m_unitEditorInstance; |
|||
PG_CHECKBOX_EDITOR* m_checkboxEditorInstance; |
|||
|
|||
wxPGChoices m_nets; |
|||
}; |
|||
|
|||
#endif /* PCB_PROPERTIES_PANEL_H */ |
|||
@ -0,0 +1,55 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef KICAD_COLOR4D_VARIANT_H |
|||
#define KICAD_COLOR4D_VARIANT_H |
|||
|
|||
#include <gal/color4d.h> |
|||
#include <wx/variant.h> |
|||
|
|||
class COLOR4D_VARIANT_DATA : public wxVariantData |
|||
{ |
|||
public: |
|||
COLOR4D_VARIANT_DATA(); |
|||
|
|||
COLOR4D_VARIANT_DATA( const wxString& aColorStr ); |
|||
|
|||
COLOR4D_VARIANT_DATA( const KIGFX::COLOR4D& aColor ); |
|||
|
|||
bool Eq( wxVariantData& aOther ) const override; |
|||
|
|||
wxString GetType() const override { return wxT( "COLOR4D" ); } |
|||
|
|||
bool Read( wxString& aString ) override; |
|||
|
|||
bool Write( wxString& aString ) const override; |
|||
|
|||
bool GetAsAny( wxAny* aAny ) const override; |
|||
|
|||
static wxVariantData* VariantDataFactory( const wxAny& aAny ); |
|||
|
|||
const KIGFX::COLOR4D& Color() { return m_color; } |
|||
|
|||
void SetColor( const KIGFX::COLOR4D& aColor ) { m_color = aColor; } |
|||
|
|||
protected: |
|||
KIGFX::COLOR4D m_color; |
|||
}; |
|||
|
|||
#endif //KICAD_COLOR4D_VARIANT_H |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue