Browse Source
Enhancements in Create array tool (bad parameters detection and disable parms when not applicable)
pull/12/head
Enhancements in Create array tool (bad parameters detection and disable parms when not applicable)
pull/12/head
committed by
jean-pierre charras
10 changed files with 639 additions and 280 deletions
-
1pcbnew/CMakeLists.txt
-
131pcbnew/array_creator.cpp
-
114pcbnew/array_creator.h
-
266pcbnew/dialogs/dialog_create_array.cpp
-
87pcbnew/dialogs/dialog_create_array.h
-
40pcbnew/dialogs/dialog_create_array_base.cpp
-
9pcbnew/dialogs/dialog_create_array_base.fbp
-
4pcbnew/dialogs/dialog_create_array_base.h
-
105pcbnew/edit.cpp
-
162pcbnew/tools/edit_tool.cpp
@ -0,0 +1,131 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Created on: 11 Mar 2016, author John Beard |
|||
* Copyright (C) 1992-2016 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 2 |
|||
* 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, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
/**
|
|||
* @file array_creator.cpp |
|||
*/ |
|||
|
|||
#include "array_creator.h"
|
|||
|
|||
#include <class_undoredo_container.h>
|
|||
|
|||
#include <dialogs/dialog_create_array.h>
|
|||
|
|||
|
|||
void ARRAY_CREATOR::Invoke() |
|||
{ |
|||
const int numItems = getNumberOfItemsToArray(); |
|||
|
|||
// bail out if no items
|
|||
if( numItems == 0 ) |
|||
return; |
|||
|
|||
MODULE* const module = getModule(); |
|||
const bool isModuleEditor = module != NULL; |
|||
|
|||
const bool enableArrayNumbering = isModuleEditor; |
|||
const wxPoint rotPoint = getRotationCentre(); |
|||
|
|||
DIALOG_CREATE_ARRAY dialog( &m_parent, enableArrayNumbering, rotPoint ); |
|||
int ret = dialog.ShowModal(); |
|||
|
|||
DIALOG_CREATE_ARRAY::ARRAY_OPTIONS* const array_opts = dialog.GetArrayOptions(); |
|||
|
|||
if( ret == wxID_OK && array_opts != NULL ) |
|||
{ |
|||
PICKED_ITEMS_LIST newItemsList; |
|||
|
|||
if( isModuleEditor ) |
|||
{ |
|||
// modedit saves everything upfront
|
|||
m_parent.SaveCopyInUndoList( getBoard()->m_Modules, UR_MODEDIT ); |
|||
} |
|||
|
|||
for ( int i = 0; i < numItems; ++i ) |
|||
{ |
|||
BOARD_ITEM* item = getNthItemToArray( i ); |
|||
|
|||
if( item->Type() == PCB_PAD_T && !isModuleEditor ) |
|||
{ |
|||
// If it is not the module editor, then duplicate the parent module instead
|
|||
item = static_cast<MODULE*>( item )->GetParent(); |
|||
} |
|||
|
|||
// The first item in list is the original item. We do not modify it
|
|||
for( int ptN = 1; ptN < array_opts->GetArraySize(); ptN++ ) |
|||
{ |
|||
BOARD_ITEM* new_item; |
|||
|
|||
if( isModuleEditor ) |
|||
{ |
|||
// increment pad numbers if do any renumbering
|
|||
// (we will number again later according to the numbering scheme if set)
|
|||
new_item = module->DuplicateAndAddItem( |
|||
item, array_opts->ShouldNumberItems() ); |
|||
} |
|||
else |
|||
{ |
|||
// PCB items keep the same numbering
|
|||
new_item = getBoard()->DuplicateAndAddItem( item, false ); |
|||
|
|||
// @TODO: we should merge zones. This is a bit tricky, because
|
|||
// the undo command needs saving old area, if it is merged.
|
|||
} |
|||
|
|||
if( new_item ) |
|||
{ |
|||
array_opts->TransformItem( ptN, new_item, rotPoint ); |
|||
|
|||
prePushAction( new_item ); |
|||
|
|||
newItemsList.PushItem( new_item ); // For undo list
|
|||
|
|||
postPushAction( new_item ); |
|||
} |
|||
|
|||
// attempt to renumber items if the array parameters define
|
|||
// a complete numbering scheme to number by (as opposed to
|
|||
// implicit numbering by incrementing the items during creation
|
|||
if( new_item && array_opts->NumberingStartIsSpecified() ) |
|||
{ |
|||
// Renumber pads. Only new pad number renumbering has meaning,
|
|||
// in the footprint editor.
|
|||
if( new_item->Type() == PCB_PAD_T ) |
|||
{ |
|||
const wxString padName = array_opts->GetItemNumber( ptN ); |
|||
static_cast<D_PAD*>( new_item )->SetPadName( padName ); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
if( !isModuleEditor ) |
|||
{ |
|||
// Add all items as a single undo point for PCB editors
|
|||
m_parent.SaveCopyInUndoList( newItemsList, UR_NEW ); |
|||
} |
|||
|
|||
finalise(); |
|||
} |
|||
} |
|||
@ -0,0 +1,114 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Created on: 11 Mar 2016, author John Beard |
|||
* Copyright (C) 1992-2016 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 2 |
|||
* 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, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
/** |
|||
* @file array_creator.h |
|||
*/ |
|||
|
|||
#ifndef PCBNEW_ARRAY_CREATOR_H_ |
|||
#define PCBNEW_ARRAY_CREATOR_H_ |
|||
|
|||
#include <dialogs/dialog_create_array.h> |
|||
|
|||
#include <class_board.h> |
|||
#include <class_module.h> |
|||
#include <class_board_item.h> |
|||
|
|||
/*! |
|||
* Class that performs array creation by producing a dialog to gather |
|||
* 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 |
|||
{ |
|||
public: |
|||
ARRAY_CREATOR(PCB_BASE_FRAME& parent): |
|||
m_parent( parent ) |
|||
{} |
|||
|
|||
/*! |
|||
* Open the dialog, gather parameters and create the array |
|||
*/ |
|||
void Invoke(); |
|||
|
|||
protected: |
|||
virtual ~ARRAY_CREATOR() {} |
|||
|
|||
PCB_BASE_FRAME& m_parent; |
|||
|
|||
private: |
|||
|
|||
/*! |
|||
* Get the BOARD that is currently being edited. |
|||
*/ |
|||
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 /* PCBNEW_ARRAY_CREATOR_H_ */ |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue