kicad/eeschema/sheetlab.cpp

180 lines
5.5 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2015 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 sheetlab.cpp
* @brief Create and edit the SCH_SHEET_PIN items.
*/
#include <fctsys.h>
#include <gr_basic.h>
#include <macros.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <schframe.h>
#include <base_units.h>
#include <general.h>
#include <sch_sheet.h>
#include <dialog_helpers.h>
#include <dialogs/dialog_sch_edit_sheet_pin.h>
PINSHEETLABEL_SHAPE SCH_EDIT_FRAME::m_lastSheetPinType = NET_INPUT;
wxSize SCH_EDIT_FRAME::m_lastSheetPinTextSize( -1, -1 );
wxPoint SCH_EDIT_FRAME::m_lastSheetPinPosition;
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;
}
int SCH_EDIT_FRAME::EditSheetPin( SCH_SHEET_PIN* aSheetPin, bool aRedraw )
{
if( aSheetPin == NULL )
return wxID_CANCEL;
DIALOG_SCH_EDIT_SHEET_PIN dlg( this );
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 ) );
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 ) );
dlg.SetTextWidthUnits( GetUnitsLabel( g_UserUnit ) );
dlg.SetConnectionType( aSheetPin->GetShape() );
/* 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;
if( !aSheetPin->IsNew() )
{
SaveCopyInUndoList( (SCH_ITEM*) aSheetPin->GetParent(), UR_CHANGED );
GetScreen()->SetCurItem( NULL );
}
aSheetPin->SetText( dlg.GetLabelName() );
aSheetPin->SetSize( wxSize( ValueFromString( g_UserUnit, dlg.GetTextWidth() ),
ValueFromString( g_UserUnit, dlg.GetTextHeight() ) ) );
aSheetPin->SetShape( dlg.GetConnectionType() );
OnModify();
if( aRedraw )
m_canvas->Refresh();
return wxID_OK;
}
SCH_SHEET_PIN* SCH_EDIT_FRAME::CreateSheetPin( SCH_SHEET* aSheet, wxDC* aDC )
{
wxString line;
SCH_SHEET_PIN* sheetPin;
sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), line );
sheetPin->SetFlags( IS_NEW );
sheetPin->SetSize( GetLastSheetPinTextSize() );
sheetPin->SetShape( m_lastSheetPinType );
int response = EditSheetPin( sheetPin, false );
if( sheetPin->GetText().IsEmpty() || (response == wxID_CANCEL) )
{
delete sheetPin;
return NULL;
}
m_lastSheetPinType = sheetPin->GetShape();
m_lastSheetPinTextSize = sheetPin->GetSize();
sheetPin->SetPosition( GetCrossHairPosition() );
sheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
PrepareMoveItem( (SCH_ITEM*) sheetPin, aDC );
OnModify();
return sheetPin;
}
SCH_SHEET_PIN* SCH_EDIT_FRAME::ImportSheetPin( SCH_SHEET* aSheet, wxDC* aDC )
{
EDA_ITEM* item;
SCH_SHEET_PIN* sheetPin;
SCH_HIERLABEL* label = NULL;
if( !aSheet->GetScreen() )
return NULL;
item = aSheet->GetScreen()->GetDrawItems();
for( ; item != NULL; item = item->Next() )
{
if( item->Type() != SCH_HIERARCHICAL_LABEL_T )
continue;
label = (SCH_HIERLABEL*) item;
/* A global label has been found: check if there a corresponding sheet label. */
if( !aSheet->HasPin( label->GetText() ) )
break;
label = NULL;
}
if( label == NULL )
{
DisplayInfoMessage( this, _( "No new hierarchical labels found." ) );
return NULL;
}
sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), label->GetText() );
sheetPin->SetFlags( IS_NEW );
sheetPin->SetSize( GetLastSheetPinTextSize() );
m_lastSheetPinType = label->GetShape();
sheetPin->SetShape( label->GetShape() );
sheetPin->SetPosition( GetCrossHairPosition() );
sheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
PrepareMoveItem( (SCH_ITEM*) sheetPin, aDC );
return sheetPin;
}