Collapse ARRAY_CREATOR into single class now that legacy instance is gone.

Also removes AllowLegacyCanvas ADVANCED_CONFIG option.
This commit is contained in:
Jeff Young 2019-06-01 12:11:05 +01:00
parent c1298570cb
commit f67df4bf11
9 changed files with 40 additions and 206 deletions

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -65,13 +65,6 @@ static const wxChar EnableSvgImport[] = wxT( "EnableSvgImport" );
*/ */
static const wxChar RealtimeConnectivity[] = wxT( "RealtimeConnectivity" ); static const wxChar RealtimeConnectivity[] = wxT( "RealtimeConnectivity" );
/**
* Allow legacy canvas to be shown in GTK3. Legacy canvas is generally pretty
* broken, but this avoids code in an ifdef where it could become broken
* on other platforms
*/
static const wxChar AllowLegacyCanvasInGtk3[] = wxT( "AllowLegacyCanvasInGtk3" );
} // namespace KEYS } // namespace KEYS
@ -150,7 +143,6 @@ ADVANCED_CFG::ADVANCED_CFG()
// Init defaults - this is done in case the config doesn't exist, // Init defaults - this is done in case the config doesn't exist,
// then the values will remain as set here. // then the values will remain as set here.
m_enableSvgImport = false; m_enableSvgImport = false;
m_allowLegacyCanvasInGtk3 = false;
m_realTimeConnectivity = true; m_realTimeConnectivity = true;
loadFromConfigFile(); loadFromConfigFile();
@ -188,9 +180,6 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
configParams.push_back( configParams.push_back(
new PARAM_CFG_BOOL( true, AC_KEYS::EnableSvgImport, &m_enableSvgImport, false ) ); new PARAM_CFG_BOOL( true, AC_KEYS::EnableSvgImport, &m_enableSvgImport, false ) );
configParams.push_back( new PARAM_CFG_BOOL(
true, AC_KEYS::AllowLegacyCanvasInGtk3, &m_allowLegacyCanvasInGtk3, false ) );
configParams.push_back( configParams.push_back(
new PARAM_CFG_BOOL( true, AC_KEYS::RealtimeConnectivity, &m_realTimeConnectivity, false ) ); new PARAM_CFG_BOOL( true, AC_KEYS::RealtimeConnectivity, &m_realTimeConnectivity, false ) );
@ -200,15 +189,3 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
} }
bool ADVANCED_CFG::AllowLegacyCanvas() const
{
// default is to allow
bool allow = true;
// on GTK3, check the config
#ifdef __WXGTK3__
allow = m_allowLegacyCanvasInGtk3;
#endif
return allow;
}

View File

@ -59,8 +59,8 @@ const BOX2I ORIGIN_VIEWITEM::ViewBBox() const
void ORIGIN_VIEWITEM::ViewDraw( int, VIEW* aView ) const void ORIGIN_VIEWITEM::ViewDraw( int, VIEW* aView ) const
{ {
auto gal = aView->GetGAL(); auto gal = aView->GetGAL();
// Nothing to do if the target shouldn't be drawn at 0,0 and that's where the target is. This
// mimics the Legacy canvas that doesn't display most targets at 0,0 // Nothing to do if the target shouldn't be drawn at 0,0 and that's where the target is.
if( !m_drawAtZero && ( m_position.x == 0 ) && ( m_position.y == 0 ) ) if( !m_drawAtZero && ( m_position.x == 0 ) && ( m_position.y == 0 ) )
return; return;

View File

@ -62,9 +62,6 @@ private:
///> Grid origin marker. ///> Grid origin marker.
std::unique_ptr<KIGFX::ORIGIN_VIEWITEM> m_gridOrigin; std::unique_ptr<KIGFX::ORIGIN_VIEWITEM> m_gridOrigin;
///> Applies the legacy canvas grid settings for GAL.
void updateGrid();
KIGFX::VIEW* view() KIGFX::VIEW* view()
{ {
return m_frame->GetGalCanvas()->GetView(); return m_frame->GetGalCanvas()->GetView();

View File

@ -452,7 +452,4 @@ static void addHoleToPolygon( SHAPE_POLY_SET* aPolygon,
} }
aPolygon->BooleanSubtract( holeBuffer, SHAPE_POLY_SET::PM_FAST ); aPolygon->BooleanSubtract( holeBuffer, SHAPE_POLY_SET::PM_FAST );
// Needed for legacy canvas only
aPolygon->Fracture( SHAPE_POLY_SET::PM_FAST );
} }

View File

@ -78,21 +78,6 @@ public:
*/ */
bool m_realTimeConnectivity; bool m_realTimeConnectivity;
/**
* Helper to determine if legacy canvas is allowed (according to platform
* and config)
* @return true if legacy canvas should be shown
*/
bool AllowLegacyCanvas() const;
private:
/*
* These settings are private, as there is extra logic provide by helper
* functions above.
*/
bool m_allowLegacyCanvasInGtk3;
private: private:
ADVANCED_CFG(); ADVANCED_CFG();

View File

@ -42,8 +42,8 @@ class PLOTTER;
* (using wxDC functions) in plot functions only for texts. * (using wxDC functions) in plot functions only for texts.
* It is used also to calculate the text bounding boxes * It is used also to calculate the text bounding boxes
* *
* The main purpose is to avoid duplicate code to do the same thing in GAL canvas * The main purpose is to avoid duplicate code to do the same thing in GAL canvas,
* legacy canvas, plotter canvas and DRC. * print & plotter canvasses and DRC.
* *
* It will be certainly removed when a full GAL canvas using wxDC is implemented * It will be certainly removed when a full GAL canvas using wxDC is implemented
* (or at least restricted to plotter and DRC "canvas") * (or at least restricted to plotter and DRC "canvas")

View File

@ -22,10 +22,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/**
* @file array_creator.cpp
*/
#include "array_creator.h" #include "array_creator.h"
#include <array_pad_name_provider.h> #include <array_pad_name_provider.h>
@ -52,17 +48,14 @@ static void TransformItem( const ARRAY_OPTIONS& aArrOpts, int aIndex, BOARD_ITEM
void ARRAY_CREATOR::Invoke() void ARRAY_CREATOR::Invoke()
{ {
const int numItems = getNumberOfItemsToArray();
// bail out if no items // bail out if no items
if( numItems == 0 ) if( m_selection.Size() == 0 )
return; return;
MODULE* const module = getModule(); MODULE* const module = m_editModules ? m_parent.GetBoard()->m_Modules.GetFirst() : nullptr;
const bool isModuleEditor = module != NULL;
const bool enableArrayNumbering = isModuleEditor; const bool enableArrayNumbering = m_editModules;
const wxPoint rotPoint = getRotationCentre(); const wxPoint rotPoint = (wxPoint) m_selection.GetCenter();
std::unique_ptr<ARRAY_OPTIONS> array_opts; std::unique_ptr<ARRAY_OPTIONS> array_opts;
@ -77,11 +70,11 @@ void ARRAY_CREATOR::Invoke()
ARRAY_PAD_NAME_PROVIDER pad_name_provider( module, *array_opts ); ARRAY_PAD_NAME_PROVIDER pad_name_provider( module, *array_opts );
for ( int i = 0; i < numItems; ++i ) for ( int i = 0; i < m_selection.Size(); ++i )
{ {
BOARD_ITEM* item = getNthItemToArray( i ); BOARD_ITEM* item = static_cast<BOARD_ITEM*>( m_selection[ i ] );
if( item->Type() == PCB_PAD_T && !isModuleEditor ) if( item->Type() == PCB_PAD_T && !m_editModules )
{ {
// If it is not the module editor, then duplicate the parent module instead // If it is not the module editor, then duplicate the parent module instead
item = static_cast<MODULE*>( item )->GetParent(); item = static_cast<MODULE*>( item )->GetParent();
@ -103,7 +96,7 @@ void ARRAY_CREATOR::Invoke()
// Need to create a new item // Need to create a new item
std::unique_ptr<BOARD_ITEM> new_item; std::unique_ptr<BOARD_ITEM> new_item;
if( isModuleEditor ) if( m_editModules )
{ {
// Don't bother incrementing pads: the module won't update // Don't bother incrementing pads: the module won't update
// until commit, so we can only do this once // until commit, so we can only do this once
@ -111,7 +104,7 @@ void ARRAY_CREATOR::Invoke()
} }
else else
{ {
new_item.reset( getBoard()->Duplicate( item ) ); new_item.reset( m_parent.GetBoard()->Duplicate( item ) );
// PCB items keep the same numbering // PCB items keep the same numbering
@ -129,9 +122,19 @@ void ARRAY_CREATOR::Invoke()
if( new_item ) if( new_item )
{ {
prePushAction( this_item ); // Because aItem is/can be created from a selected item, and inherits from
// it this state, reset the selected stated of aItem:
this_item->ClearSelected();
if( this_item->Type() == PCB_MODULE_T )
{
static_cast<MODULE*>( this_item )->RunOnChildren( [&] ( BOARD_ITEM* item )
{
item->ClearSelected();
});
}
commit.Add( new_item.release() ); commit.Add( new_item.release() );
postPushAction( this_item );
} }
} }
@ -163,5 +166,4 @@ void ARRAY_CREATOR::Invoke()
} }
commit.Push( _( "Create an array" ) ); commit.Push( _( "Create an array" ) );
finalise();
} }

View File

@ -22,93 +22,40 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/** #ifndef ARRAY_CREATOR_H_
* @file array_creator.h #define ARRAY_CREATOR_H_
*/
#ifndef PCBNEW_ARRAY_CREATOR_H_
#define PCBNEW_ARRAY_CREATOR_H_
#include <dialogs/dialog_create_array.h> #include <dialogs/dialog_create_array.h>
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
#include <class_board_item.h> #include <class_board_item.h>
#include <tool/selection.h>
/*! /*!
* Class that performs array creation by producing a dialog to gather * Class that performs array creation by producing a dialog to gather
* parameters and then creating and laying out the items. * parameters and then creating and laying out the items.
*
* This is a template class which needs to be implemented by the relevant
* edit tooling, since the details of how the document is manipulated
* varies between edit modes (e.g. legacy or GAL)
*/ */
class ARRAY_CREATOR class ARRAY_CREATOR
{ {
public: public:
ARRAY_CREATOR(PCB_BASE_FRAME& parent): ARRAY_CREATOR( PCB_BASE_FRAME& aParent, bool editModules, const SELECTION& aSelection ) :
m_parent( parent ) m_parent( aParent ),
m_editModules( editModules ),
m_selection( aSelection )
{} {}
virtual ~ARRAY_CREATOR() {}
/*! /*!
* Open the dialog, gather parameters and create the array * Open the dialog, gather parameters and create the array
*/ */
void Invoke(); void Invoke();
protected:
virtual ~ARRAY_CREATOR() {}
PCB_BASE_FRAME& m_parent;
private: private:
PCB_BASE_FRAME& m_parent;
/*! bool m_editModules;
* Get the BOARD that is currently being edited. const SELECTION& m_selection;
*/
virtual BOARD* getBoard() const = 0;
/*!
* If editing a footprint, returns the relevant MODULE, else NULL
*/
virtual MODULE* getModule() const = 0;
/*!
* @return number of original items to put into an array (eg size of the
* selection)
*/
virtual int getNumberOfItemsToArray() const = 0;
/*!
* @return the n'th original item to be arrayed
*/
virtual BOARD_ITEM* getNthItemToArray( int n ) const = 0;
/*!
* @return the rotation centre of all the items to be arrayed, when taken
* together
*/
virtual wxPoint getRotationCentre() const = 0;
/*!
* Perform any relevant action before pushing a newly created array item
* to the BOARD
*/
virtual void prePushAction( BOARD_ITEM* new_item )
{}
/*!
* Perform any actions needed after pushing an item to the BOARD
*/
virtual void postPushAction( BOARD_ITEM* new_item )
{}
/*!
* Actions to perform after the array process is complete
*/
virtual void finalise() = 0;
}; };
#endif /* ARRAY_CREATOR_H_ */
#endif /* PCBNEW_ARRAY_CREATOR_H_ */

View File

@ -1131,77 +1131,6 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
} }
class GAL_ARRAY_CREATOR: public ARRAY_CREATOR
{
public:
GAL_ARRAY_CREATOR( PCB_BASE_FRAME& editFrame, bool editModules,
const SELECTION& selection ):
ARRAY_CREATOR( editFrame ),
m_editModules( editModules ),
m_selection( selection )
{}
private:
int getNumberOfItemsToArray() const override
{
// only handle single items
return m_selection.Size();
}
BOARD_ITEM* getNthItemToArray( int n ) const override
{
return static_cast<BOARD_ITEM*>( m_selection[n] );
}
BOARD* getBoard() const override
{
return m_parent.GetBoard();
}
MODULE* getModule() const override
{
// Remember this is valid and used only in the module editor.
// in board editor, the parent of items is usually the board.
return m_editModules ? m_parent.GetBoard()->m_Modules.GetFirst() : NULL;
}
wxPoint getRotationCentre() const override
{
const VECTOR2I rp = m_selection.GetCenter();
return wxPoint( rp.x, rp.y );
}
void prePushAction( BOARD_ITEM* aItem ) override
{
// Because aItem is/can be created from a selected item, and inherits from
// it this state, reset the selected stated of aItem:
aItem->ClearSelected();
if( aItem->Type() == PCB_MODULE_T )
{
static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
{
item->ClearSelected();
}
);
}
}
void postPushAction( BOARD_ITEM* new_item ) override
{
}
void finalise() override
{
}
bool m_editModules;
const SELECTION& m_selection;
};
int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent )
{ {
const auto& selection = m_selectionTool->RequestSelection( const auto& selection = m_selectionTool->RequestSelection(
@ -1213,7 +1142,7 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent )
// we have a selection to work on now, so start the tool process // we have a selection to work on now, so start the tool process
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>(); PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
GAL_ARRAY_CREATOR array_creator( *editFrame, m_editModules, selection ); ARRAY_CREATOR array_creator( *editFrame, m_editModules, selection );
array_creator.Invoke(); array_creator.Invoke();
return 0; return 0;