From ab3ff61faa72b0998ebcc3ee88c206cab658afa3 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 20 Nov 2018 15:11:22 +0100 Subject: [PATCH] Eeschema: adjust the working/drawing area size on the page size. This makes using Scrollbars more easy to use, especially for "small" page sizes like A or B. Note also the working/drawing area size is bigger than the page size (3 times) --- common/dialogs/dialog_page_settings.cpp | 3 +++ eeschema/libedit/lib_edit_frame.cpp | 9 +++++++++ eeschema/sch_base_frame.cpp | 4 ---- eeschema/sch_draw_panel.cpp | 3 +++ eeschema/sch_edit_frame.cpp | 7 +++++++ eeschema/sch_edit_frame.h | 7 +++++++ eeschema/sch_view.cpp | 26 ++++++++++++++++++++----- eeschema/sch_view.h | 3 +++ eeschema/viewlib_frame.cpp | 9 +++++++++ include/draw_frame.h | 7 +++++++ 10 files changed, 69 insertions(+), 9 deletions(-) diff --git a/common/dialogs/dialog_page_settings.cpp b/common/dialogs/dialog_page_settings.cpp index 1534d77e38..45b15b7cda 100644 --- a/common/dialogs/dialog_page_settings.cpp +++ b/common/dialogs/dialog_page_settings.cpp @@ -240,6 +240,9 @@ void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event ) if( LocalPrjConfigChanged() ) m_parent->SaveProjectSettings( false ); + + // Call the post processing (if any) after changes + m_parent->OnPageSettingsChange(); } event.Skip(); diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index ea81a3e9b9..57cb83c94e 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -284,6 +284,15 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : GetGalCanvas()->GetView()->UseDrawPriority( true ); GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); GetGalCanvas()->GetGAL()->SetAxesEnabled( true ); + + // Set the working/draw area size to display a symbol to a reasonable value: + // A 600mm x 600mm with a origin at the area center looks like a large working area + double max_size_x = Millimeter2iu( 600 ); + double max_size_y = Millimeter2iu( 600 ); + BOX2D bbox; + bbox.SetOrigin( -max_size_x /2, -max_size_y/2 ); + bbox.SetSize( max_size_x, max_size_y ); + GetCanvas()->GetView()->SetBoundary( bbox ); } diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index ce0663b77f..4c2afa86ac 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -659,10 +659,6 @@ void SCH_BASE_FRAME::SyncView() auto gal = GetGalCanvas()->GetGAL(); auto gs = screen->GetGridSize(); - gal->SetGridSize( VECTOR2D( gs.x, gs.y )); - - DBG(printf("SyncView: grid %d %d\n", (int)gs.x, (int)gs.y );) - GetGalCanvas()->GetView()->UpdateAllItems( KIGFX::ALL ); } diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index 360592d60c..976937e62a 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -150,12 +150,14 @@ void SCH_DRAW_PANEL::DisplayComponent( const LIB_PART* aComponent ) } + void SCH_DRAW_PANEL::DisplaySheet( const SCH_SHEET* aSheet ) { view()->Clear(); view()->DisplaySheet( const_cast(aSheet) ); } + void SCH_DRAW_PANEL::DisplaySheet( const SCH_SCREEN *aScreen ) { view()->Clear(); @@ -164,6 +166,7 @@ void SCH_DRAW_PANEL::DisplaySheet( const SCH_SCREEN *aScreen ) view()->DisplaySheet( const_cast( aScreen ) ); } + void SCH_DRAW_PANEL::OnShow() { //m_view->RecacheAllItems(); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index dd7304fa89..1fdd5da909 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1514,6 +1514,13 @@ void SCH_EDIT_FRAME::CommonSettingsChanged() } +void SCH_EDIT_FRAME::OnPageSettingsChange() +{ + // Rebuild the sheet view (draw area and any other items): + DisplayCurrentSheet(); +} + + void SCH_EDIT_FRAME::ShowChangedLanguage() { // call my base class diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 3670ef599d..57728a2705 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -636,6 +636,13 @@ public: */ void DisplayCurrentSheet(); + /** + * Called when modifying the page settings. + * In derived classes it can be used to modify parameters like draw area size, + * and any other local parameter related to the page settings. + */ + void OnPageSettingsChange() override; + /** * Set or reset the BRIGHTENED of connected objects inside the current sheet, * according to the highlighted net name. diff --git a/eeschema/sch_view.cpp b/eeschema/sch_view.cpp index 02d2d6fc1d..e36d78d31c 100644 --- a/eeschema/sch_view.cpp +++ b/eeschema/sch_view.cpp @@ -47,11 +47,14 @@ SCH_VIEW::SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ) : { m_frame = aFrame; // Set m_boundary to define the max working area size. The default value - // is acceptable for Pcbnew and Gerbview, but too large for Eeschema. + // is acceptable for Pcbnew and Gerbview, but too large for Eeschema due to + // very different internal units. // So we have to use a smaller value. - // A better size could be a size depending on the worksheet size. - m_boundary.SetOrigin( -Millimeter2iu( 3200.0 ), -Millimeter2iu( 2000.0 ) ); - m_boundary.SetSize( Millimeter2iu( 6400.0 ), Millimeter2iu( 4000.0 ) ); + // A full size = 3 * MAX_PAGE_SIZE_EDITORS_MILS size allows a wide margin + // around the worksheet. + double max_size = MAX_PAGE_SIZE_EDITORS_MILS * IU_PER_MILS * 3.0; + m_boundary.SetOrigin( -max_size/4, -max_size/4 ); + m_boundary.SetSize( max_size, max_size ); } @@ -60,9 +63,20 @@ SCH_VIEW::~SCH_VIEW() } +void SCH_VIEW::ResizeSheetWorkingArea( SCH_SCREEN *aScreen ) +{ + const PAGE_INFO& page_info = aScreen->GetPageSettings(); + // A full size = 3 * page size allows a wide margin around the worksheet. + // This is useful to have a large working area. + double max_size_x = page_info.GetWidthMils() * IU_PER_MILS * 2.0; + double max_size_y = page_info.GetHeightMils() * IU_PER_MILS * 2.0; + m_boundary.SetOrigin( -max_size_x /4, -max_size_y/4 ); + m_boundary.SetSize( max_size_x, max_size_y ); +} + + void SCH_VIEW::DisplaySheet( SCH_SCREEN *aScreen ) { - for( auto item = aScreen->GetDrawItems(); item; item = item->Next() ) Add( item ); @@ -77,6 +91,8 @@ void SCH_VIEW::DisplaySheet( SCH_SCREEN *aScreen ) else m_worksheet->SetSheetName( "" ); + ResizeSheetWorkingArea( aScreen ); + m_selectionArea.reset( new KIGFX::PREVIEW::SELECTION_AREA( ) ); m_preview.reset( new KIGFX::VIEW_GROUP () ); diff --git a/eeschema/sch_view.h b/eeschema/sch_view.h index f73d0cede2..2a2154bd5b 100644 --- a/eeschema/sch_view.h +++ b/eeschema/sch_view.h @@ -78,6 +78,9 @@ public: void DisplaySheet( SCH_SCREEN *aScreen ); void DisplayComponent( LIB_PART *aPart ); + // Call it to set new draw area limits (max working and draw area size) + void ResizeSheetWorkingArea( SCH_SCREEN *aScreen ); + KIGFX::PREVIEW::SELECTION_AREA* GetSelectionArea() const { return m_selectionArea.get(); } KIGFX::VIEW_GROUP* GetPreview() const { return m_preview.get(); } diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index 3399e39a34..2d2d00b114 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -206,6 +206,15 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame GetGalCanvas()->GetViewControls()->SetSnapping( true ); GetGalCanvas()->GetGAL()->SetAxesEnabled( true ); GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); + + // Set the working/draw area size to display a symbol to a reasonable value: + // A 450mm x 450mm with a origin at the area center looks like a large working area + double max_size_x = Millimeter2iu( 450 ); + double max_size_y = Millimeter2iu( 450 ); + BOX2D bbox; + bbox.SetOrigin( -max_size_x /2, -max_size_y/2 ); + bbox.SetSize( max_size_x, max_size_y ); + GetCanvas()->GetView()->SetBoundary( bbox ); } diff --git a/include/draw_frame.h b/include/draw_frame.h index 7fc14861bf..83f12ebae0 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -749,6 +749,13 @@ public: virtual void ToolOnRightClick( wxCommandEvent& event ); void AdjustScrollBars( const wxPoint& aCenterPosition ); + /** + * Called when modifying the page settings. + * In derived classes it can be used to modify parameters like draw area size, + * and any other local parameter related to the page settings. + */ + virtual void OnPageSettingsChange() {}; + /** * Called when activating the frame. *