2011-11-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-02-28 16:56:09 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2018-09-19 19:32:51 +00:00
|
|
|
* Copyright (C) 2009 Wayne Stambaugh <stambaughw@gmail.com>
|
|
|
|
* Copyright (C) 2004-2018 KiCad Developers, see change_log.txt for contributors.
|
2011-11-10 15:55:05 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file eeschema/block.cpp
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <pgm_base.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gr_basic.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <lib_pin.h>
|
2017-11-13 17:38:51 +00:00
|
|
|
#include <list_operations.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_bus_entry.h>
|
|
|
|
#include <sch_marker.h>
|
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_no_connect.h>
|
|
|
|
#include <sch_text.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_sheet.h>
|
2015-06-07 20:31:55 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2017-11-13 15:11:54 +00:00
|
|
|
#include <list_operations.h>
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <preview_items/selection_area.h>
|
|
|
|
#include <sch_view.h>
|
|
|
|
#include <view/view_group.h>
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aPosition, bool aErase );
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2016-01-20 12:11:17 +00:00
|
|
|
int SCH_EDIT_FRAME::BlockCommand( EDA_KEY key )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2012-05-20 19:18:06 +00:00
|
|
|
int cmd = BLOCK_IDLE;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
switch( key )
|
|
|
|
{
|
|
|
|
default:
|
2019-10-10 08:07:15 +00:00
|
|
|
cmd = key & 0xFFFF;
|
|
|
|
|
|
|
|
if( cmd == 0 ) // All not handled values are seen as block move
|
|
|
|
cmd = BLOCK_MOVE;
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2019-10-10 08:07:15 +00:00
|
|
|
case GR_KB_ALT: // Should be BLOCK_ROTATE. Not suported: fall into move
|
2007-08-20 01:20:48 +00:00
|
|
|
case 0:
|
|
|
|
cmd = BLOCK_MOVE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_KB_SHIFT:
|
2017-07-04 08:08:33 +00:00
|
|
|
cmd = BLOCK_DUPLICATE;
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_KB_CTRL:
|
|
|
|
cmd = BLOCK_DRAG;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_KB_SHIFTCTRL:
|
|
|
|
cmd = BLOCK_DELETE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOUSE_MIDDLE:
|
|
|
|
cmd = BLOCK_ZOOM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::InitBlockPasteInfos()
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
block->GetItems().CopyList( m_blockItems.GetItems() );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetMouseCaptureCallback( DrawMovingBlockOutlines );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-09-19 19:32:51 +00:00
|
|
|
wxCHECK_RET( m_canvas->IsMouseCaptured(), "No block mouse capture callback is set" );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() == 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2010-11-03 14:13:15 +00:00
|
|
|
msg.Printf( wxT( "HandleBlockPLace() error : no items to place (cmd %d, state %d)" ),
|
2012-03-26 23:47:08 +00:00
|
|
|
block->GetCommand(), block->GetState() );
|
2018-09-05 22:55:11 +00:00
|
|
|
wxFAIL_MSG( msg );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
block->SetState( STATE_BLOCK_STOP );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
switch( block->GetCommand() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2014-07-29 16:38:27 +00:00
|
|
|
case BLOCK_DRAG: // Drag from mouse
|
|
|
|
case BLOCK_DRAG_ITEM: // Drag from a component selection and drag command
|
|
|
|
case BLOCK_MOVE:
|
2018-09-06 21:42:51 +00:00
|
|
|
case BLOCK_DUPLICATE: /* Duplicate */
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-01-23 20:29:15 +00:00
|
|
|
// If the block wasn't changed, don't update the schematic
|
2018-10-30 10:48:23 +00:00
|
|
|
if( block->GetMoveVector() == wxPoint( 0, 0 ) && !block->AppendUndo() )
|
2018-01-23 20:29:15 +00:00
|
|
|
{
|
|
|
|
// This calls the block-abort command routine on cleanup
|
2018-08-27 13:28:21 +00:00
|
|
|
m_canvas->EndMouseCapture( GetToolId(), GetGalCanvas()->GetCurrentCursor() );
|
2018-01-23 20:29:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-06 21:42:51 +00:00
|
|
|
if( block->GetCommand() != BLOCK_DUPLICATE )
|
|
|
|
SaveCopyInUndoList( block->GetItems(), UR_CHANGED, block->AppendUndo(), block->GetMoveVector() );
|
|
|
|
|
2018-09-07 21:35:04 +00:00
|
|
|
for( unsigned ii = 0; ii < block->GetItems().GetCount(); ii++ )
|
|
|
|
{
|
2018-11-11 07:28:58 +00:00
|
|
|
SCH_ITEM* item = static_cast<SCH_ITEM*>( block->GetItems().GetPickedItem( ii ) );
|
2018-09-07 21:35:04 +00:00
|
|
|
item->Move( block->GetMoveVector() );
|
2018-10-13 00:07:52 +00:00
|
|
|
item->SetFlags( IS_MOVED );
|
2018-09-07 21:35:04 +00:00
|
|
|
GetCanvas()->GetView()->Update( item, KIGFX::GEOMETRY );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_PRESELECT_MOVE: /* Move with preselection list*/
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
DuplicateItemsInList( GetScreen(), block->GetItems(), block->GetMoveVector() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-09-06 21:42:51 +00:00
|
|
|
SaveCopyInUndoList( block->GetItems(), UR_CHANGED, block->AppendUndo() );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case BLOCK_PASTE:
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
PasteListOfItems( DC );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2012-05-20 19:18:06 +00:00
|
|
|
default: // others are handled by HandleBlockEnd()
|
|
|
|
break;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2017-12-29 20:01:56 +00:00
|
|
|
CheckListConnections( block->GetItems(), true );
|
2017-11-27 19:27:24 +00:00
|
|
|
block->ClearItemsList();
|
|
|
|
SchematicCleanUp( true );
|
2018-10-16 13:11:33 +00:00
|
|
|
TestDanglingEnds();
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-03-24 14:25:30 +00:00
|
|
|
// clear dome flags and pointers
|
2010-11-03 14:13:15 +00:00
|
|
|
GetScreen()->ClearDrawingState();
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->ClearBlockCommand();
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetCurItem( NULL );
|
|
|
|
|
2018-08-27 13:28:21 +00:00
|
|
|
m_canvas->EndMouseCapture( GetToolId(), GetGalCanvas()->GetCurrentCursor(), wxEmptyString, false );
|
2018-08-03 12:18:26 +00:00
|
|
|
|
|
|
|
GetCanvas()->GetView()->ClearPreview();
|
|
|
|
GetCanvas()->GetView()->ClearHiddenFlags();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 16:18:30 +00:00
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* aDC )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2010-11-13 11:02:24 +00:00
|
|
|
bool nextcmd = false;
|
2018-02-12 16:23:30 +00:00
|
|
|
bool append = false;
|
2009-07-25 04:53:39 +00:00
|
|
|
BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
|
2012-11-20 11:35:09 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
auto panel =static_cast<SCH_DRAW_PANEL*>(m_canvas);
|
|
|
|
auto view = panel->GetView();
|
|
|
|
|
|
|
|
view->ShowSelectionArea( false );
|
|
|
|
view->ClearHiddenFlags();
|
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-03-26 23:47:08 +00:00
|
|
|
BLOCK_STATE_T state = block->GetState();
|
|
|
|
BLOCK_COMMAND_T command = block->GetCommand();
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2013-10-15 16:18:30 +00:00
|
|
|
m_canvas->CallEndMouseCapture( aDC );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
block->SetState( state );
|
|
|
|
block->SetCommand( command );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( DrawAndSizingBlockOutlines, AbortBlockCurrentCommand );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2018-11-14 21:54:53 +00:00
|
|
|
if( block->GetCommand() != BLOCK_ABORT
|
|
|
|
&& block->GetCommand() != BLOCK_DUPLICATE
|
|
|
|
&& block->GetCommand() != BLOCK_COPY
|
|
|
|
&& block->GetCommand() != BLOCK_CUT
|
|
|
|
&& block->GetCommand() != BLOCK_DELETE )
|
|
|
|
{
|
|
|
|
SetCrossHairPosition( block->GetEnd() );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2018-11-14 21:54:53 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2010-12-20 17:44:25 +00:00
|
|
|
{
|
2012-03-26 23:47:08 +00:00
|
|
|
switch( block->GetCommand() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
case BLOCK_IDLE:
|
2007-08-20 01:20:48 +00:00
|
|
|
DisplayError( this, wxT( "Error in HandleBlockPLace()" ) );
|
|
|
|
break;
|
|
|
|
|
2013-10-15 16:18:30 +00:00
|
|
|
case BLOCK_DRAG:
|
2014-07-29 16:38:27 +00:00
|
|
|
case BLOCK_DRAG_ITEM: // Drag from a drag command
|
2012-05-20 19:18:06 +00:00
|
|
|
case BLOCK_MOVE:
|
2017-07-04 08:08:33 +00:00
|
|
|
case BLOCK_DUPLICATE:
|
2018-09-06 21:42:51 +00:00
|
|
|
case BLOCK_PRESELECT_MOVE:
|
|
|
|
if( block->GetCommand() == BLOCK_DRAG_ITEM )
|
2012-11-20 11:35:09 +00:00
|
|
|
{
|
2014-07-29 16:38:27 +00:00
|
|
|
// This is a drag command, not a mouse block command
|
|
|
|
// Only this item is put in list
|
2018-09-06 21:42:51 +00:00
|
|
|
if( GetScreen()->GetCurItem() )
|
|
|
|
{
|
|
|
|
ITEM_PICKER picker;
|
|
|
|
picker.SetItem( GetScreen()->GetCurItem() );
|
|
|
|
block->PushItem( picker );
|
|
|
|
}
|
2012-11-20 11:35:09 +00:00
|
|
|
}
|
2018-09-06 21:42:51 +00:00
|
|
|
else if( block->GetCommand() != BLOCK_PRESELECT_MOVE )
|
2013-10-15 16:18:30 +00:00
|
|
|
{
|
2014-07-29 16:38:27 +00:00
|
|
|
// Collect all items in the locate block
|
2012-11-20 11:35:09 +00:00
|
|
|
GetScreen()->UpdatePickList();
|
2013-10-15 16:18:30 +00:00
|
|
|
}
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2018-09-06 21:42:51 +00:00
|
|
|
GetScreen()->SelectBlockItems();
|
|
|
|
|
|
|
|
if( block->GetCommand() == BLOCK_DUPLICATE )
|
|
|
|
{
|
|
|
|
DuplicateItemsInList( GetScreen(), block->GetItems(), block->GetMoveVector() );
|
2018-11-14 21:54:53 +00:00
|
|
|
block->SetLastCursorPosition( GetCrossHairPosition() );
|
2018-09-06 21:42:51 +00:00
|
|
|
SaveCopyInUndoList( block->GetItems(), UR_NEW );
|
2019-02-17 10:13:30 +00:00
|
|
|
block->SetAppendUndo();
|
2018-09-06 21:42:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-11-13 11:02:24 +00:00
|
|
|
nextcmd = true;
|
2018-09-06 21:42:51 +00:00
|
|
|
block->SetState( STATE_BLOCK_MOVE );
|
2018-03-08 00:38:48 +00:00
|
|
|
|
2018-11-07 14:22:29 +00:00
|
|
|
if( block->GetCommand() != BLOCK_DRAG && block->GetCommand() != BLOCK_DRAG_ITEM )
|
2018-10-29 18:11:04 +00:00
|
|
|
{
|
2018-11-07 14:22:29 +00:00
|
|
|
// Mark dangling pins at the edges of the block:
|
|
|
|
std::vector<DANGLING_END_ITEM> internalPoints;
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < block->GetCount(); ++i )
|
|
|
|
{
|
|
|
|
auto item = static_cast<SCH_ITEM*>( block->GetItem( i ) );
|
|
|
|
item->GetEndPoints( internalPoints );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < block->GetCount(); ++i )
|
|
|
|
{
|
|
|
|
auto item = static_cast<SCH_ITEM*>( block->GetItem( i ) );
|
|
|
|
item->UpdateDanglingState( internalPoints );
|
|
|
|
}
|
2018-10-29 18:11:04 +00:00
|
|
|
}
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetMouseCaptureCallback( DrawMovingBlockOutlines );
|
2013-10-15 16:18:30 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-15 16:18:30 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, false );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( NULL, NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-02-12 16:23:30 +00:00
|
|
|
case BLOCK_CUT:
|
2013-10-15 16:18:30 +00:00
|
|
|
case BLOCK_DELETE:
|
2011-01-10 16:50:40 +00:00
|
|
|
GetScreen()->UpdatePickList();
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2018-02-12 16:23:30 +00:00
|
|
|
// The CUT variant needs to copy the items from their originial position
|
|
|
|
if( ( block->GetCommand() == BLOCK_CUT ) && block->GetCount() )
|
|
|
|
{
|
|
|
|
wxPoint move_vector = -GetScreen()->m_BlockLocate.GetLastCursorPosition();
|
2018-09-07 21:35:04 +00:00
|
|
|
copyBlockItems( block->GetItems(), move_vector );
|
2018-02-12 16:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We set this in a while loop to catch any newly created items
|
|
|
|
// as a result of the delete (e.g. merged wires)
|
|
|
|
while( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2018-02-12 16:23:30 +00:00
|
|
|
DeleteItemsInList( block->GetItems(), append );
|
2017-11-27 19:27:24 +00:00
|
|
|
SchematicCleanUp( true );
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2018-02-12 16:23:30 +00:00
|
|
|
block->ClearItemsList();
|
|
|
|
GetScreen()->UpdatePickList();
|
|
|
|
append = true;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2018-02-12 16:23:30 +00:00
|
|
|
|
2018-10-16 13:11:33 +00:00
|
|
|
TestDanglingEnds();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2017-07-04 08:08:33 +00:00
|
|
|
case BLOCK_COPY: // Save a copy of items in paste buffer
|
2011-01-10 16:50:40 +00:00
|
|
|
GetScreen()->UpdatePickList();
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-03-26 23:47:08 +00:00
|
|
|
wxPoint move_vector = -GetScreen()->m_BlockLocate.GetLastCursorPosition();
|
2018-09-07 21:35:04 +00:00
|
|
|
copyBlockItems( block->GetItems(), move_vector );
|
2017-07-03 11:46:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
block->ClearItemsList();
|
|
|
|
break;
|
|
|
|
|
2013-10-15 16:18:30 +00:00
|
|
|
case BLOCK_ZOOM:
|
2018-09-06 21:42:51 +00:00
|
|
|
Window_Zoom( GetScreen()->m_BlockLocate );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2012-05-20 19:18:06 +00:00
|
|
|
default:
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-12-20 17:44:25 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-12-21 22:45:37 +00:00
|
|
|
if( block->GetCommand() == BLOCK_ABORT )
|
|
|
|
{
|
|
|
|
if( block->AppendUndo() )
|
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST* undo = GetScreen()->PopCommandFromUndoList();
|
|
|
|
PutDataInPreviousState( undo, false );
|
|
|
|
undo->ClearListAndDeleteItems();
|
|
|
|
delete undo;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We set the dangling ends to the block-scope, so we must set them back to
|
|
|
|
// schematic-scope.
|
|
|
|
TestDanglingEnds();
|
2019-01-28 13:45:57 +00:00
|
|
|
|
|
|
|
view->ShowSelectionArea( false );
|
|
|
|
view->ClearHiddenFlags();
|
2018-12-21 22:45:37 +00:00
|
|
|
}
|
|
|
|
|
2018-09-04 16:12:15 +00:00
|
|
|
if( !nextcmd )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2018-12-21 22:45:37 +00:00
|
|
|
GetScreen()->ClearBlockCommand();
|
2018-09-06 21:42:51 +00:00
|
|
|
GetScreen()->ClearDrawingState();
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetCurItem( NULL );
|
2018-08-27 13:28:21 +00:00
|
|
|
m_canvas->EndMouseCapture( GetToolId(), GetGalCanvas()->GetCurrentCursor(), wxEmptyString,
|
2012-03-26 23:47:08 +00:00
|
|
|
false );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
view->ShowSelectionArea( false );
|
2019-01-31 01:49:44 +00:00
|
|
|
if( !nextcmd )
|
|
|
|
view->ClearPreview();
|
2018-09-06 21:42:51 +00:00
|
|
|
view->ShowPreview( nextcmd );
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
return nextcmd;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Traces the outline of the search block structures
|
|
|
|
* The entire block follows the cursor
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2011-02-03 19:27:28 +00:00
|
|
|
static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2018-09-06 14:26:00 +00:00
|
|
|
SCH_DRAW_PANEL* panel =static_cast<SCH_DRAW_PANEL*>( aPanel );
|
|
|
|
KIGFX::SCH_VIEW* view = panel->GetView();
|
|
|
|
KIGFX::VIEW_GROUP* preview = view->GetPreview();
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2018-09-06 14:26:00 +00:00
|
|
|
BASE_SCREEN* screen = aPanel->GetScreen();
|
|
|
|
BLOCK_SELECTOR* block = &screen->m_BlockLocate;
|
|
|
|
SCH_ITEM* schitem;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
block->SetMoveVector( panel->GetParent()->GetCrossHairPosition() - block->GetLastCursorPosition() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
preview->Clear();
|
|
|
|
view->SetVisible( preview, true );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
for( unsigned ii = 0; ii < block->GetCount(); ii++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-03-26 23:47:08 +00:00
|
|
|
schitem = (SCH_ITEM*) block->GetItem( ii );
|
2018-09-06 14:26:00 +00:00
|
|
|
SCH_ITEM* copy = static_cast<SCH_ITEM*>( schitem->Clone() );
|
2018-09-06 21:42:51 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
copy->Move( block->GetMoveVector() );
|
2018-09-06 21:42:51 +00:00
|
|
|
copy->SetFlags( IS_MOVED );
|
2018-08-03 12:18:26 +00:00
|
|
|
preview->Add( copy );
|
2018-09-05 22:17:22 +00:00
|
|
|
|
2018-09-06 21:42:51 +00:00
|
|
|
view->Hide( schitem );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2018-08-03 12:18:26 +00:00
|
|
|
|
|
|
|
view->Update( preview );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-07 21:35:04 +00:00
|
|
|
void SCH_EDIT_FRAME::copyBlockItems( PICKED_ITEMS_LIST& aItemsList, const wxPoint& aMoveVector )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-01-07 19:24:24 +00:00
|
|
|
m_blockItems.ClearListAndDeleteItems(); // delete previous saved list, if exists
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-10-30 10:48:23 +00:00
|
|
|
wxRect bounds;
|
|
|
|
|
|
|
|
if( aItemsList.GetCount() > 0 )
|
|
|
|
bounds = aItemsList.GetPickedItem( 0 )->GetBoundingBox();
|
|
|
|
|
|
|
|
for( unsigned i = 1; i < aItemsList.GetCount(); ++i )
|
|
|
|
bounds.Union( aItemsList.GetPickedItem( i )->GetBoundingBox() );
|
|
|
|
|
|
|
|
wxPoint center( ( bounds.GetLeft() + bounds.GetRight() ) / 2,
|
|
|
|
( bounds.GetTop() + bounds.GetBottom() ) / 2 );
|
2018-11-05 10:57:30 +00:00
|
|
|
center = GetNearestGridPosition( center );
|
2018-10-30 10:48:23 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-12-23 13:16:06 +00:00
|
|
|
// Clear m_Flag member of selected items:
|
2011-03-10 19:36:30 +00:00
|
|
|
aItemsList.GetPickedItem( ii )->ClearFlags();
|
2012-03-26 23:47:08 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
/* Make a copy of the original picked item. */
|
2011-03-10 19:36:30 +00:00
|
|
|
SCH_ITEM* copy = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
|
|
|
|
copy->SetParent( NULL );
|
2018-01-24 21:27:56 +00:00
|
|
|
copy->SetFlags( copy->GetFlags() | UR_TRANSIENT );
|
2018-10-30 10:48:23 +00:00
|
|
|
copy->Move( -center );
|
2018-01-24 21:27:56 +00:00
|
|
|
ITEM_PICKER item( copy, UR_NEW );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2011-01-07 19:24:24 +00:00
|
|
|
m_blockItems.PushItem( item );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2015-06-07 20:31:55 +00:00
|
|
|
unsigned i;
|
|
|
|
SCH_ITEM* item;
|
2016-03-06 21:22:01 +00:00
|
|
|
SCH_SHEET_LIST hierarchy( g_RootSheet ); // This is the entire schematic hierarcy.
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-07 19:24:24 +00:00
|
|
|
if( m_blockItems.GetCount() == 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2015-06-07 20:31:55 +00:00
|
|
|
DisplayError( this, _( "No item to paste." ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-07 20:31:55 +00:00
|
|
|
wxFileName destFn = m_CurrentSheet->Last()->GetFileName();
|
|
|
|
|
|
|
|
if( destFn.IsRelative() )
|
|
|
|
destFn.MakeAbsolute( Prj().GetProjectPath() );
|
|
|
|
|
|
|
|
// Make sure any sheets in the block to be pasted will not cause recursion in
|
2018-09-04 16:46:03 +00:00
|
|
|
// the destination sheet. Moreover new sheets create new sheetpaths, and component
|
|
|
|
// alternante references must be created and cleared
|
|
|
|
bool hasSheetPasted = false;
|
|
|
|
// Keep trace of existing sheet paths. Paste block can modify this list
|
|
|
|
SCH_SHEET_LIST initial_sheetpathList( g_RootSheet );
|
|
|
|
|
2015-06-07 20:31:55 +00:00
|
|
|
for( i = 0; i < m_blockItems.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
item = (SCH_ITEM*) m_blockItems.GetItem( i );
|
|
|
|
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*)item;
|
|
|
|
wxFileName srcFn = sheet->GetFileName();
|
|
|
|
|
|
|
|
if( srcFn.IsRelative() )
|
|
|
|
srcFn.MakeAbsolute( Prj().GetProjectPath() );
|
|
|
|
|
2016-02-15 20:12:42 +00:00
|
|
|
SCH_SHEET_LIST sheetHierarchy( sheet );
|
2015-06-07 20:31:55 +00:00
|
|
|
|
2016-02-15 20:12:42 +00:00
|
|
|
if( hierarchy.TestForRecursion( sheetHierarchy,
|
|
|
|
destFn.GetFullPath( wxPATH_UNIX ) ) )
|
2015-06-07 20:31:55 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
msg.Printf( _( "The sheet changes cannot be made because the destination "
|
2017-12-15 11:37:46 +00:00
|
|
|
"sheet already has the sheet \"%s\" or one of it's subsheets "
|
2015-06-07 20:31:55 +00:00
|
|
|
"as a parent somewhere in the schematic hierarchy." ),
|
|
|
|
GetChars( sheet->GetFileName() ) );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duplicate sheet names and sheet time stamps are not valid. Use a time stamp
|
|
|
|
// based sheet name and update the time stamp for each sheet in the block.
|
2017-12-07 10:11:24 +00:00
|
|
|
timestamp_t timeStamp = GetNewTimeStamp();
|
2015-06-07 20:31:55 +00:00
|
|
|
|
2017-12-07 10:11:24 +00:00
|
|
|
sheet->SetName( wxString::Format( wxT( "sheet%8.8lX" ), (unsigned long)timeStamp ) );
|
|
|
|
sheet->SetTimeStamp( timeStamp );
|
2018-09-04 16:46:03 +00:00
|
|
|
hasSheetPasted = true;
|
2015-06-07 20:31:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
PICKED_ITEMS_LIST picklist;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2015-06-07 20:31:55 +00:00
|
|
|
for( i = 0; i < m_blockItems.GetCount(); i++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2015-06-07 20:31:55 +00:00
|
|
|
item = DuplicateStruct( (SCH_ITEM*) m_blockItems.GetItem( i ) );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
|
|
|
// Creates data, and push it as new data in undo item list buffer
|
2015-06-07 20:31:55 +00:00
|
|
|
ITEM_PICKER picker( item, UR_NEW );
|
2009-07-25 04:53:39 +00:00
|
|
|
picklist.PushItem( picker );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2015-06-07 20:31:55 +00:00
|
|
|
// Clear annotation and init new time stamp for the new components and sheets:
|
|
|
|
if( item->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
2018-03-22 09:55:32 +00:00
|
|
|
SCH_COMPONENT* cmp = static_cast<SCH_COMPONENT*>( item );
|
|
|
|
cmp->SetTimeStamp( GetNewTimeStamp() );
|
|
|
|
|
|
|
|
// clear the annotation, but preserve the selected unit
|
|
|
|
int unit = cmp->GetUnit();
|
|
|
|
cmp->ClearAnnotation( NULL );
|
|
|
|
cmp->SetUnit( unit );
|
2015-06-07 20:31:55 +00:00
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_SHEET_T )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2015-06-07 20:31:55 +00:00
|
|
|
( (SCH_SHEET*) item )->SetTimeStamp( GetNewTimeStamp() );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-26 17:16:42 +00:00
|
|
|
SaveCopyInUndoList( picklist, UR_NEW );
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2018-09-05 22:17:22 +00:00
|
|
|
for( i = 0; i < picklist.GetCount(); ++i )
|
|
|
|
{
|
|
|
|
item = (SCH_ITEM*) picklist.GetPickedItem( i );
|
|
|
|
|
|
|
|
item->Move( GetScreen()->m_BlockLocate.GetMoveVector() );
|
|
|
|
|
|
|
|
SetSchItemParent( item, GetScreen() );
|
|
|
|
AddToScreen( item );
|
|
|
|
}
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2018-09-04 16:46:03 +00:00
|
|
|
if( hasSheetPasted )
|
|
|
|
{
|
|
|
|
// We clear annotation of new sheet paths.
|
|
|
|
// Annotation of new components added in current sheet is already cleared.
|
|
|
|
SCH_SCREENS screensList( g_RootSheet );
|
|
|
|
screensList.ClearAnnotationOfNewSheetPaths( initial_sheetpathList );
|
|
|
|
}
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
// Clear flags for all items.
|
2010-11-03 14:13:15 +00:00
|
|
|
GetScreen()->ClearDrawingState();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2018-08-03 12:18:26 +00:00
|
|
|
|
|
|
|
void DrawAndSizingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
|
|
|
{
|
|
|
|
auto panel =static_cast<SCH_DRAW_PANEL*>(aPanel);
|
|
|
|
auto area = panel->GetView()->GetSelectionArea();
|
|
|
|
auto frame = static_cast<EDA_BASE_FRAME*>(aPanel->GetParent());
|
|
|
|
|
|
|
|
BLOCK_SELECTOR* block;
|
|
|
|
bool isLibEdit = frame->IsType( FRAME_SCH_LIB_EDITOR );
|
|
|
|
|
|
|
|
block = &aPanel->GetScreen()->m_BlockLocate;
|
|
|
|
block->SetMoveVector( wxPoint( 0, 0 ) );
|
|
|
|
block->SetLastCursorPosition( aPanel->GetParent()->GetCrossHairPosition( isLibEdit ) );
|
|
|
|
block->SetEnd( aPanel->GetParent()->GetCrossHairPosition() );
|
|
|
|
|
|
|
|
panel->GetView()->ClearPreview();
|
|
|
|
panel->GetView()->ClearHiddenFlags();
|
|
|
|
|
|
|
|
area->SetOrigin( block->GetOrigin() );;
|
2018-09-05 22:17:22 +00:00
|
|
|
area->SetEnd( block->GetEnd() );
|
2018-08-03 12:18:26 +00:00
|
|
|
|
|
|
|
panel->GetView()->SetVisible( area );
|
|
|
|
panel->GetView()->Hide( area, false );
|
|
|
|
panel->GetView()->Update( area );
|
|
|
|
|
|
|
|
if( block->GetState() == STATE_BLOCK_INIT )
|
|
|
|
{
|
|
|
|
if( block->GetWidth() || block->GetHeight() )
|
|
|
|
// 2nd point exists: the rectangle is not surface anywhere
|
|
|
|
block->SetState( STATE_BLOCK_END );
|
|
|
|
}
|
|
|
|
}
|