2011-10-27 13:34:28 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.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 sheet.cpp
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_sheet.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialogs/dialog_sch_sheet_props.h>
|
2012-02-16 20:03:33 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2014-11-02 13:17:48 +00:00
|
|
|
#include <project.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, wxDC* aDC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aSheet == NULL )
|
|
|
|
return false;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-08-05 21:02:41 +00:00
|
|
|
// Get the new texts
|
2009-12-15 21:11:05 +00:00
|
|
|
DIALOG_SCH_SHEET_PROPS dlg( this );
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
wxString units = GetUnitsLabel( g_UserUnit );
|
2009-12-15 21:11:05 +00:00
|
|
|
dlg.SetFileName( aSheet->GetFileName() );
|
* 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.SetFileNameTextSize( StringFromValue( g_UserUnit, aSheet->GetFileNameSize() ) );
|
2009-12-15 21:11:05 +00:00
|
|
|
dlg.SetFileNameTextSizeUnits( units );
|
2011-12-08 15:45:01 +00:00
|
|
|
dlg.SetSheetName( aSheet->GetName() );
|
* 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.SetSheetNameTextSize( StringFromValue( g_UserUnit, aSheet->GetSheetNameSize() ) );
|
2009-12-15 21:11:05 +00:00
|
|
|
dlg.SetSheetNameTextSizeUnits( units );
|
2013-12-14 19:03:38 +00:00
|
|
|
dlg.SetSheetTimeStamp( wxString::Format( wxT("%8.8lX"),
|
|
|
|
(unsigned long) aSheet->GetTimeStamp() ) );
|
2009-12-15 21:11:05 +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() );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxFileName fileName = dlg.GetFileName();
|
|
|
|
fileName.SetExt( SchematicFileExtension );
|
|
|
|
|
|
|
|
if( !fileName.IsOk() )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "File name is not valid!" ) );
|
2014-08-24 22:49:31 +00:00
|
|
|
|
|
|
|
if( m_canvas )
|
|
|
|
m_canvas->Refresh();
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-31 13:27:05 +00:00
|
|
|
// Duplicate sheet names are not valid.
|
|
|
|
const SCH_SHEET* sheet = GetScreen()->GetSheet( dlg.GetSheetName() );
|
|
|
|
|
2014-11-02 13:17:48 +00:00
|
|
|
if( sheet && sheet != aSheet )
|
2011-08-31 13:27:05 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, wxString::Format( _( "A sheet named \"%s\" already exists." ),
|
|
|
|
GetChars( dlg.GetSheetName() ) ) );
|
2014-08-24 22:49:31 +00:00
|
|
|
|
|
|
|
if( m_canvas )
|
|
|
|
m_canvas->Refresh();
|
|
|
|
|
2011-08-31 13:27:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
wxString msg;
|
|
|
|
wxString tmp;
|
|
|
|
bool loadFromFile = false;
|
|
|
|
SCH_SCREEN* useScreen = NULL;
|
|
|
|
|
2014-11-02 13:17:48 +00:00
|
|
|
wxString newFilename = fileName.GetFullPath();
|
|
|
|
|
|
|
|
// Search for a schematic file having the same filename
|
|
|
|
// already in use in the hierarchy or on disk, in order to reuse it.
|
|
|
|
if( !g_RootSheet->SearchHierarchy( newFilename, &useScreen ) )
|
|
|
|
{
|
|
|
|
// if user entered a relative path, allow that to stay, but do the
|
|
|
|
// file existence test with an absolute (full) path. This transformation
|
|
|
|
// is local to this scope, but is the same one used at load time later.
|
|
|
|
wxString absolute = Prj().AbsolutePath( newFilename );
|
2012-10-13 18:54:33 +00:00
|
|
|
|
2014-11-02 13:17:48 +00:00
|
|
|
loadFromFile = wxFileExists( absolute );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inside Eeschema, filenames are stored using unix notation
|
|
|
|
newFilename.Replace( wxT("\\"), wxT("/") );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
|
|
|
if( aSheet->GetScreen() == NULL ) // New sheet.
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2014-11-02 13:17:48 +00:00
|
|
|
if( useScreen || loadFromFile ) // Load from existing file.
|
2011-01-20 16:34:57 +00:00
|
|
|
{
|
|
|
|
if( useScreen != NULL )
|
2013-04-09 17:49:01 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
msg.Printf( _( "A file named '%s' already exists in the current schematic hierarchy." ),
|
2014-11-02 13:17:48 +00:00
|
|
|
GetChars( newFilename ) );
|
2013-04-09 17:49:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
msg.Printf( _( "A file named '%s' already exists." ),
|
2014-11-02 13:17:48 +00:00
|
|
|
GetChars( newFilename ) );
|
2013-04-09 17:49:01 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-04-09 17:49:01 +00:00
|
|
|
msg += _("\n\nDo you want to create a sheet with the contents of this file?" );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
|
|
|
if( !IsOK( this, msg ) )
|
2014-08-24 22:49:31 +00:00
|
|
|
{
|
|
|
|
if( m_canvas )
|
|
|
|
m_canvas->Refresh();
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
return false;
|
2014-08-24 22:49:31 +00:00
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
}
|
|
|
|
else // New file.
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
aSheet->SetScreen( new SCH_SCREEN( &Kiway() ) );
|
2014-11-02 13:17:48 +00:00
|
|
|
aSheet->GetScreen()->SetFileName( newFilename );
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
}
|
|
|
|
else // Existing sheet.
|
|
|
|
{
|
|
|
|
bool isUndoable = true;
|
|
|
|
bool renameFile = false;
|
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
// We are always using here a case insensitive comparison
|
|
|
|
// to avoid issues under Windows, although under Unix
|
|
|
|
// filenames are case sensitive.
|
|
|
|
// But many users create schematic under both Unix and Windows
|
2014-11-02 13:17:48 +00:00
|
|
|
if( newFilename.CmpNoCase( aSheet->GetFileName() ) != 0 )
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
// Sheet file name changes cannot be undone.
|
|
|
|
isUndoable = false;
|
|
|
|
msg = _( "Changing the sheet file name cannot be undone. " );
|
|
|
|
|
2014-11-02 13:17:48 +00:00
|
|
|
if( useScreen || loadFromFile ) // Load from existing file.
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2013-04-09 17:49:01 +00:00
|
|
|
wxString tmp;
|
2011-01-20 16:34:57 +00:00
|
|
|
if( useScreen != NULL )
|
2013-04-09 17:49:01 +00:00
|
|
|
{
|
|
|
|
tmp.Printf( _( "A file named <%s> already exists in the current schematic hierarchy." ),
|
2014-11-02 13:17:48 +00:00
|
|
|
GetChars( newFilename ) );
|
2013-04-09 17:49:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp.Printf( _( "A file named <%s> already exists." ),
|
2014-11-02 13:17:48 +00:00
|
|
|
GetChars( newFilename ) );
|
2013-04-09 17:49:01 +00:00
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2013-04-09 17:49:01 +00:00
|
|
|
msg += tmp;
|
|
|
|
msg += _("\n\nDo you want to replace the sheet with the contents of this file?" );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
if( loadFromFile )
|
|
|
|
aSheet->SetScreen( NULL );
|
|
|
|
}
|
|
|
|
else // Save to new file name.
|
|
|
|
{
|
|
|
|
if( aSheet->GetScreenCount() > 1 )
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
msg += _( "This sheet uses shared data in a complex hierarchy.\n\n" );
|
|
|
|
msg += _( "Do you wish to convert it to a simple hierarchical sheet?" );
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
if( !IsOK( NULL, msg ) )
|
|
|
|
return false;
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
|
|
|
|
renameFile = true;
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
}
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
aSheet->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetIgnoreMouseEvents( true );
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
if( isUndoable )
|
|
|
|
SaveCopyInUndoList( aSheet, UR_CHANGED );
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
if( renameFile )
|
|
|
|
{
|
2014-11-02 13:17:48 +00:00
|
|
|
aSheet->GetScreen()->SetFileName( newFilename );
|
2012-09-28 17:47:41 +00:00
|
|
|
SaveEEFile( aSheet->GetScreen() );
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
// If the the associated screen is shared by more than one sheet, remove the
|
|
|
|
// screen and reload the file to a new screen. Failure to do this will trash
|
|
|
|
// the screen reference counting in complex hierarchies.
|
|
|
|
if( aSheet->GetScreenCount() > 1 )
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
aSheet->SetScreen( NULL );
|
|
|
|
loadFromFile = true;
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2014-11-02 13:17:48 +00:00
|
|
|
aSheet->SetFileName( newFilename );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
|
|
|
if( useScreen )
|
|
|
|
aSheet->SetScreen( useScreen );
|
|
|
|
else if( loadFromFile )
|
|
|
|
aSheet->Load( this );
|
|
|
|
|
* 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
|
|
|
aSheet->SetFileNameSize( ValueFromString( g_UserUnit, dlg.GetFileNameTextSize() ) );
|
2011-12-08 15:45:01 +00:00
|
|
|
aSheet->SetName( dlg.GetSheetName() );
|
* 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
|
|
|
aSheet->SetSheetNameSize( ValueFromString( g_UserUnit, dlg.GetSheetNameTextSize() ) );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( aSheet->GetName().IsEmpty() )
|
|
|
|
aSheet->SetName( wxString::Format( wxT( "Sheet%8.8lX" ), aSheet->GetTimeStamp() ) );
|
2009-06-11 14:26:17 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetIgnoreMouseEvents( false );
|
2011-12-22 13:28:11 +00:00
|
|
|
aSheet->Draw( m_canvas, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2011-10-27 13:34:28 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
/* Move selected sheet with the cursor.
|
2011-02-11 20:48:13 +00:00
|
|
|
* Callback function use by m_mouseCaptureCallback.
|
2008-02-29 12:33:07 +00:00
|
|
|
*/
|
2011-02-03 19:27:28 +00:00
|
|
|
static void MoveOrResizeSheet( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxPoint moveVector;
|
|
|
|
BASE_SCREEN* screen = aPanel->GetScreen();
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) screen->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aErase )
|
2011-01-10 16:50:40 +00:00
|
|
|
sheet->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
wxPoint pos = sheet->GetPosition();
|
|
|
|
|
2011-07-08 19:55:41 +00:00
|
|
|
if( sheet->IsResized() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
int width = aPanel->GetParent()->GetCrossHairPosition().x - sheet->GetPosition().x;
|
|
|
|
int height = aPanel->GetParent()->GetCrossHairPosition().y - sheet->GetPosition().y;
|
2011-06-07 15:29:01 +00:00
|
|
|
|
|
|
|
// If the sheet doesn't have any pins, clamp the minimum size to the default values.
|
|
|
|
width = ( width < MIN_SHEET_WIDTH ) ? MIN_SHEET_WIDTH : width;
|
|
|
|
height = ( height < MIN_SHEET_HEIGHT ) ? MIN_SHEET_HEIGHT : height;
|
|
|
|
|
|
|
|
if( sheet->HasPins() )
|
|
|
|
{
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
int gridSizeX = KiROUND( screen->GetGridSize().x );
|
|
|
|
int gridSizeY = KiROUND( screen->GetGridSize().y );
|
2011-06-07 15:29:01 +00:00
|
|
|
|
|
|
|
// If the sheet has pins, use the pin positions to clamp the minimum height.
|
|
|
|
height = ( height < sheet->GetMinHeight() + gridSizeY ) ?
|
2011-12-08 15:45:01 +00:00
|
|
|
sheet->GetMinHeight() + gridSizeY : height;
|
2011-06-07 15:29:01 +00:00
|
|
|
width = ( width < sheet->GetMinWidth() + gridSizeX ) ?
|
2011-12-08 15:45:01 +00:00
|
|
|
sheet->GetMinWidth() + gridSizeX : width;
|
2011-06-07 15:29:01 +00:00
|
|
|
}
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
wxPoint grid = aPanel->GetParent()->GetNearestGridPosition(
|
|
|
|
wxPoint( pos.x + width, pos.y + height ) );
|
2011-12-08 15:45:01 +00:00
|
|
|
sheet->Resize( wxSize( grid.x - pos.x, grid.y - pos.y ) );
|
2008-03-30 15:12:08 +00:00
|
|
|
}
|
2011-07-08 19:55:41 +00:00
|
|
|
else if( sheet->IsMoving() )
|
2008-02-28 20:39:04 +00:00
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
moveVector = aPanel->GetParent()->GetCrossHairPosition() - pos;
|
2009-12-15 21:11:05 +00:00
|
|
|
sheet->Move( moveVector );
|
2008-02-28 20:39:04 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-10 16:50:40 +00:00
|
|
|
sheet->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-08-05 21:02:41 +00:00
|
|
|
// Complete sheet move.
|
2011-01-21 19:30:59 +00:00
|
|
|
static void ExitSheet( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
|
2013-08-05 21:02:41 +00:00
|
|
|
SCH_ITEM* item = screen->GetCurItem();
|
|
|
|
|
Modular-Kicad milestone B), major portions:
*) Rework the set language support, simplify it by using KIWAY. Now any major
frame with a "change language" menu can change the language for all KIWAY_PLAYERs
in the whole KIWAY. Multiple KIWAYs are not supported yet.
*) Simplify "modal wxFrame" support, and add that support exclusively to
KIWAY_PLAYER where it is inherited by all derivatives. The function
KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable.
*) Remove the requirements and assumptions that the wxFrame hierarchy always
had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers
and editors. This is no longer the case, nor required.
*) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the
KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame
quickly. It also gives control to the KIWAY as to frame hierarchical
relationships.
*) Change single_top to use the KIWAY for loading a KIFACE and instantiating
the single KIWAY_PLAYER, see bullet immediately above.
*) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this
gives the KIFACEs a chance to save their final configuration dope to disk.
*) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and
these modal frames are distinctly different than their non-modal equivalents.
KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor,
so this is another important reason for having a dedicated FRAME_T for each
modal wxFrame.
On balance, more lines were deleted than were added to achieve all this.
2014-05-03 17:40:19 +00:00
|
|
|
SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-06-07 15:29:01 +00:00
|
|
|
if( (item == NULL) || (item->Type() != SCH_SHEET_T) || (parent == NULL) )
|
2009-12-15 21:11:05 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-06-07 15:29:01 +00:00
|
|
|
parent->SetRepeatItem( NULL );
|
|
|
|
|
|
|
|
item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
|
|
|
|
|
|
|
if( item->IsNew() )
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2013-04-28 14:28:13 +00:00
|
|
|
delete item;
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
2011-07-08 19:55:41 +00:00
|
|
|
else if( item->IsMoving() || item->IsResized() )
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
screen->Remove( item );
|
2011-06-07 15:29:01 +00:00
|
|
|
delete item;
|
|
|
|
|
|
|
|
item = parent->GetUndoItem();
|
|
|
|
|
|
|
|
wxCHECK_RET( item != NULL, wxT( "Cannot restore undefined last sheet item." ) );
|
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
screen->Append( item );
|
2011-06-16 19:52:12 +00:00
|
|
|
// the owner of item is no more parent, this is the draw list of screen:
|
2011-06-07 15:29:01 +00:00
|
|
|
parent->SetUndoItem( NULL );
|
2011-06-16 19:52:12 +00:00
|
|
|
|
2011-06-07 15:29:01 +00:00
|
|
|
item->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
|
|
|
item->ClearFlags();
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-07 15:29:01 +00:00
|
|
|
item->ClearFlags();
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
screen->SetCurItem( NULL );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-05 21:02:41 +00:00
|
|
|
// Create hierarchy sheet.
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_SHEET* SCH_EDIT_FRAME::CreateSheet( wxDC* aDC )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2013-08-05 21:02:41 +00:00
|
|
|
SetRepeatItem( NULL );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
SCH_SHEET* sheet = new SCH_SHEET( GetCrossHairPosition() );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-04-05 14:46:51 +00:00
|
|
|
sheet->SetFlags( IS_NEW | IS_RESIZED );
|
2011-12-12 08:37:05 +00:00
|
|
|
sheet->SetTimeStamp( GetNewTimeStamp() );
|
2009-12-15 21:11:05 +00:00
|
|
|
sheet->SetParent( GetScreen() );
|
2011-01-20 16:34:57 +00:00
|
|
|
sheet->SetScreen( NULL );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
// need to check if this is being added to the GetDrawItems().
|
2009-12-15 21:11:05 +00:00
|
|
|
// also need to update the hierarchy, if we are adding
|
2008-02-26 19:19:54 +00:00
|
|
|
// a sheet to a screen that already has multiple instances (!)
|
2009-12-15 21:11:05 +00:00
|
|
|
GetScreen()->SetCurItem( sheet );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( MoveOrResizeSheet, ExitSheet );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, false );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC );
|
2013-08-03 05:15:23 +00:00
|
|
|
|
|
|
|
SetCrossHairPosition( sheet->GetResizePosition() );
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
|
|
|
m_canvas->CrossHairOn( aDC );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
return sheet;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::ReSizeSheet( SCH_SHEET* aSheet, wxDC* aDC )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2011-02-21 13:54:29 +00:00
|
|
|
if( aSheet == NULL || aSheet->IsNew() )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2011-06-07 15:29:01 +00:00
|
|
|
wxCHECK_RET( aSheet->Type() == SCH_SHEET_T,
|
|
|
|
wxString::Format( wxT( "Cannot perform sheet resize on %s object." ),
|
|
|
|
GetChars( aSheet->GetClass() ) ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC );
|
2013-08-03 05:15:23 +00:00
|
|
|
SetCrossHairPosition( aSheet->GetResizePosition() );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
|
|
|
m_canvas->CrossHairOn( aDC );
|
2011-07-08 19:55:41 +00:00
|
|
|
|
2011-06-07 15:29:01 +00:00
|
|
|
SetUndoItem( aSheet );
|
|
|
|
aSheet->SetFlags( IS_RESIZED );
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( MoveOrResizeSheet, ExitSheet );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, true );
|
2010-03-24 18:26:04 +00:00
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
if( aSheet->IsNew() ) // not already in edit, save a copy for undo/redo
|
2011-04-05 14:46:51 +00:00
|
|
|
SetUndoItem( aSheet );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::StartMoveSheet( SCH_SHEET* aSheet, wxDC* aDC )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( ( aSheet == NULL ) || ( aSheet->Type() != SCH_SHEET_T ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC );
|
2013-08-03 05:15:23 +00:00
|
|
|
SetCrossHairPosition( aSheet->GetPosition() );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-06-07 15:29:01 +00:00
|
|
|
if( !aSheet->IsNew() )
|
|
|
|
SetUndoItem( aSheet );
|
|
|
|
|
|
|
|
aSheet->SetFlags( IS_MOVED );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( MoveOrResizeSheet, ExitSheet );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, true );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOn( aDC );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|