2018-08-03 12:18:26 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-11-20 14:30:18 +00:00
|
|
|
* Copyright (C) 2013-2018 CERN
|
2023-06-12 21:33:55 +00:00
|
|
|
* Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-11-06 19:15:42 +00:00
|
|
|
*
|
2018-08-03 12:18:26 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2020-09-20 06:14:10 +00:00
|
|
|
#include <core/typeinfo.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <view/view.h>
|
2018-10-10 15:26:23 +00:00
|
|
|
#include <view/view_rtree.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <view/wx_view_controls.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_proxy_view_item.h>
|
2023-07-08 19:33:37 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2021-07-29 09:47:43 +00:00
|
|
|
#include <layer_ids.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_screen.h>
|
2020-05-21 02:27:48 +00:00
|
|
|
#include <schematic.h>
|
2020-08-01 13:20:08 +00:00
|
|
|
#include <sch_base_frame.h>
|
2022-04-09 14:38:47 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2023-09-09 04:10:57 +00:00
|
|
|
#include <string_utils.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2018-09-16 21:19:33 +00:00
|
|
|
#include "sch_view.h"
|
2018-08-03 12:18:26 +00:00
|
|
|
|
|
|
|
|
2018-09-16 21:19:33 +00:00
|
|
|
namespace KIGFX {
|
2018-08-03 12:18:26 +00:00
|
|
|
|
|
|
|
|
2018-11-19 09:21:28 +00:00
|
|
|
SCH_VIEW::SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ) :
|
2018-09-16 21:19:33 +00:00
|
|
|
VIEW( aIsDynamic )
|
2018-08-03 12:18:26 +00:00
|
|
|
{
|
2018-11-19 09:21:28 +00:00
|
|
|
m_frame = aFrame;
|
2022-10-17 13:19:39 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
// Set m_boundary to define the max working area size. The default value is acceptable for
|
|
|
|
// Pcbnew and Gerbview, but too large for Eeschema due to very different internal units.
|
|
|
|
// A full size = 3 * MAX_PAGE_SIZE_MILS size allows a wide margin around the drawing-sheet.
|
2022-09-16 23:42:20 +00:00
|
|
|
double max_size = schIUScale.MilsToIU( MAX_PAGE_SIZE_EESCHEMA_MILS ) * 3.0;
|
2018-11-20 14:11:22 +00:00
|
|
|
m_boundary.SetOrigin( -max_size/4, -max_size/4 );
|
|
|
|
m_boundary.SetSize( max_size, max_size );
|
2018-08-03 12:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-16 21:19:33 +00:00
|
|
|
SCH_VIEW::~SCH_VIEW()
|
2018-08-03 12:18:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2020-08-08 20:52:57 +00:00
|
|
|
void SCH_VIEW::Cleanup()
|
|
|
|
{
|
|
|
|
Clear();
|
2021-02-22 16:37:43 +00:00
|
|
|
m_drawingSheet.reset();
|
2020-08-08 20:52:57 +00:00
|
|
|
m_preview.reset();
|
|
|
|
}
|
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2019-08-08 09:06:53 +00:00
|
|
|
void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
|
|
|
|
{
|
|
|
|
VIEW::SetScale( aScale, aAnchor );
|
|
|
|
|
2022-05-13 21:36:20 +00:00
|
|
|
// Redraw items whose rendering is dependent on zoom
|
2019-08-08 09:06:53 +00:00
|
|
|
if( m_frame )
|
2022-05-13 21:36:20 +00:00
|
|
|
m_frame->RefreshZoomDependentItems();
|
2019-08-08 09:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
void SCH_VIEW::ResizeSheetWorkingArea( const SCH_SCREEN* aScreen )
|
2018-08-03 12:18:26 +00:00
|
|
|
{
|
2018-11-20 14:11:22 +00:00
|
|
|
const PAGE_INFO& page_info = aScreen->GetPageSettings();
|
2022-09-16 23:25:07 +00:00
|
|
|
double max_size_x = page_info.GetWidthIU( schIUScale.IU_PER_MILS ) * 3.0;
|
|
|
|
double max_size_y = page_info.GetHeightIU( schIUScale.IU_PER_MILS ) * 3.0;
|
2020-12-20 18:50:45 +00:00
|
|
|
m_boundary.SetOrigin( -max_size_x / 4, -max_size_y / 4 );
|
2018-11-20 14:11:22 +00:00
|
|
|
m_boundary.SetSize( max_size_x, max_size_y );
|
|
|
|
}
|
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
void SCH_VIEW::DisplaySheet( const SCH_SCREEN *aScreen )
|
2018-11-20 14:11:22 +00:00
|
|
|
{
|
2020-11-23 21:23:40 +00:00
|
|
|
for( SCH_ITEM* item : aScreen->Items() )
|
2018-09-04 20:53:04 +00:00
|
|
|
Add( item );
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2023-06-12 21:33:55 +00:00
|
|
|
m_drawingSheet.reset( new DS_PROXY_VIEW_ITEM( schIUScale, &aScreen->GetPageSettings(),
|
2021-02-22 23:47:17 +00:00
|
|
|
&aScreen->Schematic()->Prj(),
|
2022-09-20 14:25:03 +00:00
|
|
|
&aScreen->GetTitleBlock(),
|
|
|
|
aScreen->Schematic()->GetProperties() ) );
|
2021-02-22 16:37:43 +00:00
|
|
|
m_drawingSheet->SetPageNumber( TO_UTF8( aScreen->GetPageNumber() ) );
|
|
|
|
m_drawingSheet->SetSheetCount( aScreen->GetPageCount() );
|
|
|
|
m_drawingSheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
|
|
|
|
m_drawingSheet->SetColorLayer( LAYER_SCHEMATIC_DRAWINGSHEET );
|
2022-03-24 14:10:47 +00:00
|
|
|
m_drawingSheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_PAGE_LIMITS );
|
2021-02-22 16:37:43 +00:00
|
|
|
m_drawingSheet->SetIsFirstPage( aScreen->GetVirtualPageNumber() == 1 );
|
2018-11-19 09:21:28 +00:00
|
|
|
|
|
|
|
if( m_frame && m_frame->IsType( FRAME_SCH ) )
|
2022-04-09 14:38:47 +00:00
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
|
2022-10-17 13:19:39 +00:00
|
|
|
|
|
|
|
wxCHECK( editFrame, /* void */ );
|
|
|
|
|
2023-03-12 22:23:48 +00:00
|
|
|
m_drawingSheet->SetSheetName( TO_UTF8( editFrame->GetScreenDesc() ) );
|
|
|
|
m_drawingSheet->SetSheetPath( TO_UTF8( editFrame->GetFullScreenDesc() ) );
|
2022-04-09 14:38:47 +00:00
|
|
|
}
|
2018-11-19 09:21:28 +00:00
|
|
|
else
|
2022-04-09 14:38:47 +00:00
|
|
|
{
|
2021-02-22 16:37:43 +00:00
|
|
|
m_drawingSheet->SetSheetName( "" );
|
2022-04-09 14:38:47 +00:00
|
|
|
m_drawingSheet->SetSheetPath( "" );
|
|
|
|
}
|
2018-11-16 08:36:10 +00:00
|
|
|
|
2018-11-20 14:11:22 +00:00
|
|
|
ResizeSheetWorkingArea( aScreen );
|
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
Add( m_drawingSheet.get() );
|
2020-08-15 20:13:08 +00:00
|
|
|
|
|
|
|
InitPreview();
|
2023-07-08 19:33:37 +00:00
|
|
|
|
|
|
|
// Allow tools to add anything they require to the view (such as the selection VIEW_GROUP)
|
|
|
|
if( m_frame && m_frame->GetToolManager() )
|
|
|
|
m_frame->GetToolManager()->ResetTools( TOOL_BASE::REDRAW );
|
2018-08-03 12:18:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-16 21:19:33 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
void SCH_VIEW::DisplaySymbol( LIB_SYMBOL* aSymbol )
|
2018-08-03 12:18:26 +00:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !aSymbol )
|
2018-10-11 13:31:17 +00:00
|
|
|
return;
|
|
|
|
|
2023-04-16 21:50:04 +00:00
|
|
|
// Draw the fields.
|
2021-06-10 18:51:46 +00:00
|
|
|
for( LIB_ITEM& item : aSymbol->GetDrawItems() )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2023-04-16 21:50:04 +00:00
|
|
|
if( item.Type() == LIB_FIELD_T )
|
|
|
|
{
|
|
|
|
LIB_FIELD* field = static_cast< LIB_FIELD* >( &item );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2023-04-16 21:50:04 +00:00
|
|
|
wxCHECK2( field, continue );
|
2020-06-01 17:45:46 +00:00
|
|
|
|
2023-04-16 21:50:04 +00:00
|
|
|
Add( &item );
|
|
|
|
}
|
2019-11-07 14:09:24 +00:00
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2023-04-16 21:50:04 +00:00
|
|
|
LIB_SYMBOL* drawnSymbol = aSymbol;
|
|
|
|
|
2019-11-07 14:09:24 +00:00
|
|
|
// Draw the parent items if the symbol is inherited from another symbol.
|
2021-06-10 18:51:46 +00:00
|
|
|
if( aSymbol->IsAlias() )
|
2019-11-07 14:09:24 +00:00
|
|
|
{
|
2023-10-16 21:04:01 +00:00
|
|
|
if( std::shared_ptr< LIB_SYMBOL > parent = aSymbol->GetRootSymbol().lock() )
|
|
|
|
drawnSymbol = parent.get();
|
|
|
|
else
|
2023-10-25 07:41:08 +00:00
|
|
|
{
|
2023-10-16 21:04:01 +00:00
|
|
|
wxCHECK( false, /* void */ );
|
2023-10-25 07:41:08 +00:00
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
for( LIB_ITEM& item : drawnSymbol->GetDrawItems() )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2023-04-16 21:50:04 +00:00
|
|
|
// Fields already drawn above. (Besides, we don't want to show parent symbol fields as
|
|
|
|
// users may be confused by shown fields that can not be edited.)
|
|
|
|
if( item.Type() == LIB_FIELD_T )
|
2020-06-01 17:45:46 +00:00
|
|
|
continue;
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2018-10-23 15:02:55 +00:00
|
|
|
Add( &item );
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
2020-08-04 19:40:40 +00:00
|
|
|
|
2020-08-15 20:13:08 +00:00
|
|
|
InitPreview();
|
2018-08-03 12:18:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-16 21:19:33 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
void SCH_VIEW::ClearHiddenFlags()
|
|
|
|
{
|
2022-07-29 21:02:35 +00:00
|
|
|
for( VIEW_ITEM* item : *m_allItems )
|
2018-11-20 14:30:18 +00:00
|
|
|
Hide( item, false );
|
2018-08-03 12:18:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-16 21:19:33 +00:00
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
void SCH_VIEW::HideDrawingSheet()
|
2018-08-03 12:18:26 +00:00
|
|
|
{
|
2021-02-22 16:37:43 +00:00
|
|
|
// SetVisible( m_drawingSheet.get(), false );
|
2018-08-03 12:18:26 +00:00
|
|
|
}
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
|
2018-11-20 14:30:18 +00:00
|
|
|
}; // namespace KIGFX
|