2011-10-21 13:59:15 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-04-16 15:26:51 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2011-10-21 13:59:15 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
2015-04-16 15:26:51 +00:00
|
|
|
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-21 13:59:15 +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 sheetlab.cpp
|
|
|
|
* @brief Create and edit the SCH_SHEET_PIN items.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
2015-02-21 09:46:44 +00:00
|
|
|
#include <schframe.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <general.h>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <dialog_helpers.h>
|
|
|
|
|
|
|
|
#include <dialogs/dialog_sch_edit_sheet_pin.h>
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2008-02-27 19:38:16 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
int SCH_EDIT_FRAME::m_lastSheetPinType = NET_INPUT;
|
2014-05-16 13:57:53 +00:00
|
|
|
wxSize SCH_EDIT_FRAME::m_lastSheetPinTextSize( -1, -1 );
|
2011-03-30 19:26:05 +00:00
|
|
|
wxPoint SCH_EDIT_FRAME::m_lastSheetPinPosition;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2014-05-16 13:57:53 +00:00
|
|
|
const wxSize &SCH_EDIT_FRAME::GetLastSheetPinTextSize()
|
|
|
|
{
|
|
|
|
// Delayed initialization (need the preferences to be loaded)
|
|
|
|
if( m_lastSheetPinTextSize.x == -1 )
|
|
|
|
{
|
|
|
|
m_lastSheetPinTextSize.x = GetDefaultTextSize();
|
|
|
|
m_lastSheetPinTextSize.y = GetDefaultTextSize();
|
|
|
|
}
|
|
|
|
return m_lastSheetPinTextSize;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-06-27 09:12:32 +00:00
|
|
|
int SCH_EDIT_FRAME::EditSheetPin( SCH_SHEET_PIN* aSheetPin, bool aRedraw )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
if( aSheetPin == NULL )
|
2009-12-06 18:04:41 +00:00
|
|
|
return wxID_CANCEL;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
DIALOG_SCH_EDIT_SHEET_PIN dlg( this );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
dlg.SetLabelName( aSheetPin->GetText() );
|
* 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
|
|
|
dlg.SetTextHeight( StringFromValue( g_UserUnit, aSheetPin->GetSize().y ) );
|
2010-11-20 21:59:00 +00:00
|
|
|
dlg.SetTextHeightUnits( GetUnitsLabel( g_UserUnit ) );
|
* 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
|
|
|
dlg.SetTextWidth( StringFromValue( g_UserUnit, aSheetPin->GetSize().x ) );
|
2010-11-20 21:59:00 +00:00
|
|
|
dlg.SetTextWidthUnits( GetUnitsLabel( g_UserUnit ) );
|
2011-12-08 15:45:01 +00:00
|
|
|
dlg.SetConnectionType( aSheetPin->GetShape() );
|
2009-12-06 18:04:41 +00:00
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
/* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for
|
|
|
|
* the flex grid sizer in wxGTK that prevents the last column from being sized
|
|
|
|
* correctly. It doesn't cause any problems on win32 so it doesn't need to wrapped
|
|
|
|
* in ugly #ifdef __WXGTK__ #endif.
|
|
|
|
*/
|
|
|
|
dlg.Layout();
|
|
|
|
dlg.Fit();
|
|
|
|
dlg.SetMinSize( dlg.GetSize() );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return wxID_CANCEL;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-10-21 13:59:15 +00:00
|
|
|
if( !aSheetPin->IsNew() )
|
|
|
|
{
|
|
|
|
SaveCopyInUndoList( (SCH_ITEM*) aSheetPin->GetParent(), UR_CHANGED );
|
|
|
|
GetScreen()->SetCurItem( NULL );
|
|
|
|
}
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
aSheetPin->SetText( dlg.GetLabelName() );
|
2015-04-16 15:26:51 +00:00
|
|
|
aSheetPin->SetSize( wxSize( ValueFromString( g_UserUnit, dlg.GetTextWidth() ),
|
|
|
|
ValueFromString( g_UserUnit, dlg.GetTextHeight() ) ) );
|
2011-12-08 15:45:01 +00:00
|
|
|
aSheetPin->SetShape( dlg.GetConnectionType() );
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2015-06-27 09:12:32 +00:00
|
|
|
OnModify();
|
|
|
|
|
|
|
|
if( aRedraw )
|
|
|
|
m_canvas->Refresh();
|
2010-11-20 21:59:00 +00:00
|
|
|
|
|
|
|
return wxID_OK;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN* SCH_EDIT_FRAME::CreateSheetPin( SCH_SHEET* aSheet, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
wxString line;
|
|
|
|
SCH_SHEET_PIN* sheetPin;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), line );
|
|
|
|
sheetPin->SetFlags( IS_NEW );
|
2014-05-16 13:57:53 +00:00
|
|
|
sheetPin->SetSize( GetLastSheetPinTextSize() );
|
2011-12-08 15:45:01 +00:00
|
|
|
sheetPin->SetShape( m_lastSheetPinType );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-06-27 09:12:32 +00:00
|
|
|
int response = EditSheetPin( sheetPin, false );
|
2009-12-06 18:04:41 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
if( sheetPin->GetText().IsEmpty() || (response == wxID_CANCEL) )
|
2009-12-06 18:04:41 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
delete sheetPin;
|
2009-12-06 18:04:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
m_lastSheetPinType = sheetPin->GetShape();
|
2013-03-18 19:36:07 +00:00
|
|
|
m_lastSheetPinTextSize = sheetPin->GetSize();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-11-19 16:27:13 +00:00
|
|
|
sheetPin->SetPosition( GetCrossHairPosition() );
|
|
|
|
sheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2015-02-28 16:56:09 +00:00
|
|
|
PrepareMoveItem( (SCH_ITEM*) sheetPin, aDC );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2011-03-30 19:26:05 +00:00
|
|
|
return sheetPin;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN* SCH_EDIT_FRAME::ImportSheetPin( SCH_SHEET* aSheet, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
EDA_ITEM* item;
|
|
|
|
SCH_SHEET_PIN* sheetPin;
|
|
|
|
SCH_HIERLABEL* label = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( !aSheet->GetScreen() )
|
2009-11-04 20:46:53 +00:00
|
|
|
return NULL;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
item = aSheet->GetScreen()->GetDrawItems();
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
for( ; item != NULL; item = item->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
if( item->Type() != SCH_HIERARCHICAL_LABEL_T )
|
2007-08-20 01:20:48 +00:00
|
|
|
continue;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
label = (SCH_HIERLABEL*) item;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
/* A global label has been found: check if there a corresponding sheet label. */
|
2013-03-18 19:36:07 +00:00
|
|
|
if( !aSheet->HasPin( label->GetText() ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
label = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( label == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
DisplayInfoMessage( this, _( "No new hierarchical labels found." ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), label->GetText() );
|
2011-03-30 19:26:05 +00:00
|
|
|
sheetPin->SetFlags( IS_NEW );
|
2014-05-16 13:57:53 +00:00
|
|
|
sheetPin->SetSize( GetLastSheetPinTextSize() );
|
2011-12-08 15:45:01 +00:00
|
|
|
m_lastSheetPinType = label->GetShape();
|
|
|
|
sheetPin->SetShape( label->GetShape() );
|
2013-11-19 16:27:13 +00:00
|
|
|
sheetPin->SetPosition( GetCrossHairPosition() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-11-19 16:27:13 +00:00
|
|
|
sheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2015-02-28 16:56:09 +00:00
|
|
|
PrepareMoveItem( (SCH_ITEM*) sheetPin, aDC );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
return sheetPin;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|