Browse Source

Fix incorrect refresh of User Interface after running an action plugin, and add comments

pull/7/merge
jean-pierre charras 8 years ago
parent
commit
a557838c61
  1. 2
      demos/python_scripts_examples/action_menu_text_by_date.py
  2. 6
      include/wxPcbStruct.h
  3. 29
      pcbnew/pcbframe.cpp
  4. 1
      pcbnew/swig/pcbnew_action_plugins.cpp
  5. 32
      pcbnew/swig/pcbnew_scripting_helpers.cpp
  6. 19
      pcbnew/swig/pcbnew_scripting_helpers.h

2
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() )

6
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
*

29
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 )

1
pcbnew/swig/pcbnew_action_plugins.cpp

@ -368,6 +368,7 @@ void PCB_EDIT_FRAME::OnActionPlugin( wxCommandEvent& aEvent )
}
else
{
UpdateUserInterface();
GetScreen()->SetModify();
Refresh();
}

32
pcbnew/swig/pcbnew_scripting_helpers.cpp

@ -40,20 +40,20 @@
#include <macros.h>
#include <stdlib.h>
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();
}

19
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
Loading…
Cancel
Save