diff --git a/demos/python_scripts_examples/action_menu_text_by_date.py b/demos/python_scripts_examples/action_menu_text_by_date.py index 6e96530211..cc9630d682 100644 --- a/demos/python_scripts_examples/action_menu_text_by_date.py +++ b/demos/python_scripts_examples/action_menu_text_by_date.py @@ -48,7 +48,7 @@ class text_by_date( pcbnew.ActionPlugin ): def Run( self ): pcb = pcbnew.GetBoard() - for draw in pcb.m_Drawings: + for draw in pcb.GetDrawings(): if draw.GetClass() == 'PTEXT': txt = re.sub( "\$date\$ [0-9]{4}-[0-9]{2}-[0-9]{2}", "$date$", draw.GetText() ) diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index d1e23193ee..84788ef517 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -269,6 +269,12 @@ public: */ void PythonPluginsReload(); + /** + * Update the layer manager and other widgets from the board setup + * (layer and items visibility, colors ...) + */ + void UpdateUserInterface(); + /** * Function GetAutoSaveFilePrefix * diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 8572b02a31..6463a76cd6 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -724,8 +724,7 @@ void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable ) } // Re-create the layer manager to allow arbitrary colors when GAL is enabled - ReFillLayerWidget(); - m_Layers->ReFillRender(); + UpdateUserInterface(); } @@ -1048,6 +1047,32 @@ void PCB_EDIT_FRAME::UpdateTitle() } +void PCB_EDIT_FRAME::UpdateUserInterface() +{ + // Update the layer manager and other widgets from the board setup + // (layer and items visibility, colors ...) + + // Rebuild list of nets (full ratsnest rebuild) + Compile_Ratsnest( NULL, true ); + GetBoard()->BuildConnectivity(); + + // Update info shown by the horizontal toolbars + ReCreateLayerBox(); + + // Update the layer manager + m_Layers->Freeze(); + ReFillLayerWidget(); + m_Layers->ReFillRender(); + + // upate the layer widget to match board visibility states, both layers and render columns. + syncLayerVisibilities(); + syncLayerWidgetLayer(); + syncRenderStates(); + + m_Layers->Thaw(); +} + + #if defined( KICAD_SCRIPTING_WXPYTHON ) void PCB_EDIT_FRAME::ScriptingConsoleEnableDisable( wxCommandEvent& aEvent ) diff --git a/pcbnew/swig/pcbnew_action_plugins.cpp b/pcbnew/swig/pcbnew_action_plugins.cpp index 6a854b658a..ef18cde09e 100644 --- a/pcbnew/swig/pcbnew_action_plugins.cpp +++ b/pcbnew/swig/pcbnew_action_plugins.cpp @@ -368,6 +368,7 @@ void PCB_EDIT_FRAME::OnActionPlugin( wxCommandEvent& aEvent ) } else { + UpdateUserInterface(); GetScreen()->SetModify(); Refresh(); } diff --git a/pcbnew/swig/pcbnew_scripting_helpers.cpp b/pcbnew/swig/pcbnew_scripting_helpers.cpp index 0447c4c993..b1dc10267a 100644 --- a/pcbnew/swig/pcbnew_scripting_helpers.cpp +++ b/pcbnew/swig/pcbnew_scripting_helpers.cpp @@ -40,20 +40,20 @@ #include #include -static PCB_EDIT_FRAME* PcbEditFrame = NULL; +static PCB_EDIT_FRAME* s_PcbEditFrame = NULL; BOARD* GetBoard() { - if( PcbEditFrame ) - return PcbEditFrame->GetBoard(); + if( s_PcbEditFrame ) + return s_PcbEditFrame->GetBoard(); else return NULL; } -void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME* aPCBEdaFrame ) +void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME* aPcbEditFrame ) { - PcbEditFrame = aPCBEdaFrame; + s_PcbEditFrame = aPcbEditFrame; } @@ -101,13 +101,29 @@ bool SaveBoard( wxString& aFileName, BOARD* aBoard ) void Refresh() { - // first argument is erase background, second is a wxRect - PcbEditFrame->GetCanvas()->Refresh( true, NULL ); + if( s_PcbEditFrame ) + { + if( s_PcbEditFrame->IsGalCanvasActive() ) + s_PcbEditFrame->GetGalCanvas()->Refresh(); + else + // first argument is erase background, second is a wxRect that + // defines a reftresh area (all canvas if null) + s_PcbEditFrame->GetCanvas()->Refresh( true, NULL ); + } } void WindowZoom( int xl, int yl, int width, int height ) { EDA_RECT Rect( wxPoint( xl, yl ), wxSize( width, height )) ; - PcbEditFrame->Window_Zoom( Rect ); + + if( s_PcbEditFrame ) + s_PcbEditFrame->Window_Zoom( Rect ); +} + + +void UpdateUserInterface() +{ + if( s_PcbEditFrame ) + s_PcbEditFrame->UpdateUserInterface(); } diff --git a/pcbnew/swig/pcbnew_scripting_helpers.h b/pcbnew/swig/pcbnew_scripting_helpers.h index 8b3570bc35..f200f4e6c6 100644 --- a/pcbnew/swig/pcbnew_scripting_helpers.h +++ b/pcbnew/swig/pcbnew_scripting_helpers.h @@ -49,7 +49,24 @@ BOARD* LoadBoard( wxString& aFileName ); // so no option to choose the file format. bool SaveBoard( wxString& aFileName, BOARD* aBoard ); +/** + * Update the board display after modifying it bu a python script + * (note: it is automatically called by action plugins, after running the plugin, + * so call this function is usually not needed inside action plugins + * + * Could be deprecated because modifying a board (especially deleting items) outside + * a action plugin can crash Pcbnew. + */ void Refresh(); + void WindowZoom( int xl, int yl, int width, int height ); -#endif +/** + * Update the layer manager and other widgets from the board setup + * (layer and items visibility, colors ...) + * (note: it is automatically called by action plugins, after running the plugin, + * so call this function is usually not needed inside action plugins + */ +void UpdateUserInterface(); + +#endif // __PCBNEW_SCRIPTING_HELPERS_H