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
|
2019-11-06 19:15:42 +00:00
|
|
|
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/view_group.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>
|
2019-05-26 15:36:40 +00:00
|
|
|
#include <ws_proxy_view_item.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
|
|
|
#include <class_libentry.h>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_screen.h>
|
2018-12-24 11:17:35 +00:00
|
|
|
#include <sch_component.h>
|
2020-05-21 02:27:48 +00:00
|
|
|
#include <schematic.h>
|
2018-12-24 11:17:35 +00:00
|
|
|
#include <lib_pin.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <preview_items/selection_area.h>
|
2018-11-19 09:21:28 +00:00
|
|
|
#include <sch_edit_frame.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;
|
2018-11-18 19:04:17 +00:00
|
|
|
// Set m_boundary to define the max working area size. The default value
|
2018-11-20 14:11:22 +00:00
|
|
|
// is acceptable for Pcbnew and Gerbview, but too large for Eeschema due to
|
|
|
|
// very different internal units.
|
2018-11-18 19:04:17 +00:00
|
|
|
// So we have to use a smaller value.
|
2019-05-26 15:36:40 +00:00
|
|
|
// A full size = 3 * MAX_PAGE_SIZE_MILS size allows a wide margin
|
2018-11-20 14:11:22 +00:00
|
|
|
// around the worksheet.
|
2019-12-30 18:28:00 +00:00
|
|
|
double max_size = Mils2iu( MAX_PAGE_SIZE_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-11-20 14:26:51 +00:00
|
|
|
|
|
|
|
m_selectionArea.reset( new KIGFX::PREVIEW::SELECTION_AREA() );
|
|
|
|
m_preview.reset( new KIGFX::VIEW_GROUP() );
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-08 09:06:53 +00:00
|
|
|
void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
|
|
|
|
{
|
|
|
|
VIEW::SetScale( aScale, aAnchor );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
//Redraw selection halos since their width is dependent on zoom
|
2019-08-08 09:06:53 +00:00
|
|
|
if( m_frame )
|
|
|
|
m_frame->RefreshSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-20 14:30:18 +00:00
|
|
|
void SCH_VIEW::ResizeSheetWorkingArea( 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();
|
2019-12-30 18:28:00 +00:00
|
|
|
double max_size_x = page_info.GetWidthIU() * 3.0;
|
|
|
|
double max_size_y = page_info.GetHeightIU() * 3.0;
|
|
|
|
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
|
|
|
|
2018-11-20 14:11:22 +00:00
|
|
|
void SCH_VIEW::DisplaySheet( SCH_SCREEN *aScreen )
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto item : aScreen->Items() )
|
2018-09-04 20:53:04 +00:00
|
|
|
Add( item );
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
m_worksheet.reset( new KIGFX::WS_PROXY_VIEW_ITEM( static_cast< int >( IU_PER_MILS ),
|
|
|
|
&aScreen->GetPageSettings(),
|
2020-05-21 02:27:48 +00:00
|
|
|
&aScreen->Schematic()->Prj(),
|
2018-11-16 08:36:10 +00:00
|
|
|
&aScreen->GetTitleBlock() ) );
|
|
|
|
m_worksheet->SetSheetNumber( aScreen->m_ScreenNumber );
|
|
|
|
m_worksheet->SetSheetCount( aScreen->m_NumberOfScreens );
|
2018-11-19 09:21:28 +00:00
|
|
|
m_worksheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
|
2020-01-13 01:44:19 +00:00
|
|
|
m_worksheet->SetColorLayer( LAYER_SCHEMATIC_WORKSHEET );
|
2018-11-19 09:21:28 +00:00
|
|
|
|
|
|
|
if( m_frame && m_frame->IsType( FRAME_SCH ) )
|
|
|
|
m_worksheet->SetSheetName( TO_UTF8( m_frame->GetScreenDesc() ) );
|
|
|
|
else
|
|
|
|
m_worksheet->SetSheetName( "" );
|
2018-11-16 08:36:10 +00:00
|
|
|
|
2018-11-20 14:11:22 +00:00
|
|
|
ResizeSheetWorkingArea( aScreen );
|
|
|
|
|
2018-11-20 14:30:18 +00:00
|
|
|
m_selectionArea.reset( new KIGFX::PREVIEW::SELECTION_AREA() );
|
|
|
|
m_preview.reset( new KIGFX::VIEW_GROUP() );
|
2018-09-16 21:19:33 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
Add( m_worksheet.get() );
|
|
|
|
Add( m_selectionArea.get() );
|
|
|
|
Add( m_preview.get() );
|
|
|
|
}
|
|
|
|
|
2018-09-16 21:19:33 +00:00
|
|
|
|
2018-11-20 14:30:18 +00:00
|
|
|
void SCH_VIEW::DisplaySheet( SCH_SHEET* aSheet )
|
2018-08-03 12:18:26 +00:00
|
|
|
{
|
|
|
|
DisplaySheet( aSheet->GetScreen() );
|
|
|
|
}
|
|
|
|
|
2018-09-16 21:19:33 +00:00
|
|
|
|
2018-11-20 14:30:18 +00:00
|
|
|
void SCH_VIEW::DisplayComponent( LIB_PART* aPart )
|
2018-08-03 12:18:26 +00:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
|
2018-10-11 13:31:17 +00:00
|
|
|
if( !aPart )
|
|
|
|
return;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
std::shared_ptr< LIB_PART > parent;
|
|
|
|
LIB_PART* drawnPart = aPart;
|
|
|
|
|
2019-11-07 14:09:24 +00:00
|
|
|
// Draw the mandatory fields for aliases and parent symbols.
|
|
|
|
for( auto& item : aPart->GetDrawItems() )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2019-11-07 14:09:24 +00:00
|
|
|
if( item.Type() != LIB_FIELD_T )
|
|
|
|
continue;
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2020-06-01 17:45:46 +00:00
|
|
|
LIB_FIELD* field = static_cast< LIB_FIELD* >( &item );
|
|
|
|
|
|
|
|
wxCHECK2( field, continue );
|
|
|
|
|
|
|
|
if( field->GetText().IsEmpty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Add( &item );
|
2019-11-07 14:09:24 +00:00
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2019-11-07 14:09:24 +00:00
|
|
|
// Draw the parent items if the symbol is inherited from another symbol.
|
|
|
|
if( aPart->IsAlias() )
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
parent = aPart->GetParent().lock();
|
|
|
|
|
|
|
|
wxCHECK( parent, /* void */ );
|
|
|
|
|
|
|
|
drawnPart = parent.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto& item : drawnPart->GetDrawItems() )
|
|
|
|
{
|
2020-06-01 17:45:46 +00:00
|
|
|
// Don't show parent symbol fields. Users may be confused by shown fields that can not
|
|
|
|
// be edited.
|
|
|
|
if( aPart->IsAlias() && item.Type() == LIB_FIELD_T )
|
|
|
|
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
|
|
|
}
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2018-11-20 14:30:18 +00:00
|
|
|
m_selectionArea.reset( new KIGFX::PREVIEW::SELECTION_AREA() );
|
|
|
|
m_preview.reset( new KIGFX::VIEW_GROUP() );
|
2018-08-03 12:18:26 +00:00
|
|
|
Add( m_selectionArea.get() );
|
|
|
|
Add( m_preview.get() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_VIEW::ClearPreview()
|
|
|
|
{
|
|
|
|
m_preview->Clear();
|
2018-09-16 21:19:33 +00:00
|
|
|
|
2018-10-18 09:50:43 +00:00
|
|
|
for( auto item : m_ownedItems )
|
2018-08-03 12:18:26 +00:00
|
|
|
delete item;
|
|
|
|
|
2018-10-18 09:50:43 +00:00
|
|
|
m_ownedItems.clear();
|
|
|
|
Update( m_preview.get() );
|
2018-08-03 12:18:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-16 21:19:33 +00:00
|
|
|
|
2018-11-20 14:30:18 +00:00
|
|
|
void SCH_VIEW::AddToPreview( EDA_ITEM* aItem, bool aTakeOwnership )
|
2018-08-03 12:18:26 +00:00
|
|
|
{
|
2018-10-18 09:50:43 +00:00
|
|
|
Hide( aItem, false );
|
2018-09-10 10:58:50 +00:00
|
|
|
m_preview->Add( aItem );
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2018-11-20 14:30:18 +00:00
|
|
|
if( aTakeOwnership )
|
2018-10-18 09:50:43 +00:00
|
|
|
m_ownedItems.push_back( aItem );
|
2018-09-10 10:58:50 +00:00
|
|
|
|
|
|
|
SetVisible( m_preview.get(), true );
|
|
|
|
Hide( m_preview.get(), false );
|
|
|
|
Update( m_preview.get() );
|
2018-08-03 12:18:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-16 21:19:33 +00:00
|
|
|
|
2018-11-20 14:30:18 +00:00
|
|
|
void SCH_VIEW::ShowPreview( bool aShow )
|
2018-08-03 12:18:26 +00:00
|
|
|
{
|
|
|
|
SetVisible( m_preview.get(), aShow );
|
|
|
|
}
|
|
|
|
|
2018-09-16 21:19:33 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
void SCH_VIEW::ClearHiddenFlags()
|
|
|
|
{
|
2018-07-05 06:35:50 +00:00
|
|
|
for( auto 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
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
void SCH_VIEW::HideWorksheet()
|
|
|
|
{
|
2018-11-20 14:30:18 +00:00
|
|
|
// SetVisible( m_worksheet.get(), false );
|
2018-08-03 12:18:26 +00:00
|
|
|
}
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
|
2018-12-24 11:17:35 +00:00
|
|
|
void SCH_VIEW::HighlightItem( EDA_ITEM *aItem, LIB_PIN* aPin )
|
|
|
|
{
|
2019-06-26 18:35:56 +00:00
|
|
|
if( aItem && aItem->Type() == SCH_COMPONENT_T && aPin )
|
|
|
|
{
|
|
|
|
static_cast<SCH_COMPONENT*>( aItem )->HighlightPin( aPin );
|
2019-09-27 18:57:14 +00:00
|
|
|
Update( aItem, REPAINT );
|
2019-06-26 18:35:56 +00:00
|
|
|
}
|
|
|
|
else if( aItem )
|
|
|
|
{
|
|
|
|
aItem->SetFlags( HIGHLIGHTED );
|
2019-09-27 18:57:14 +00:00
|
|
|
Update( aItem, REPAINT );
|
2019-06-26 18:35:56 +00:00
|
|
|
}
|
|
|
|
else
|
2018-12-24 11:17:35 +00:00
|
|
|
{
|
|
|
|
for( auto item : *m_allItems )
|
|
|
|
{
|
2018-12-31 12:54:26 +00:00
|
|
|
// Not all view items can be highlighted, only EDA_ITEMs
|
|
|
|
// So clear flag of only EDA_ITEMs.
|
2019-06-26 18:35:56 +00:00
|
|
|
EDA_ITEM* eitem = dynamic_cast<EDA_ITEM*>( item );
|
2018-12-24 11:17:35 +00:00
|
|
|
|
2018-12-31 12:54:26 +00:00
|
|
|
if( eitem )
|
2018-12-24 11:17:35 +00:00
|
|
|
{
|
2019-09-27 18:57:14 +00:00
|
|
|
if( eitem->IsHighlighted() )
|
|
|
|
{
|
|
|
|
eitem->ClearFlags( HIGHLIGHTED );
|
|
|
|
Update( eitem, REPAINT );
|
|
|
|
}
|
2018-12-31 12:54:26 +00:00
|
|
|
|
|
|
|
if( eitem->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
|
|
|
// Items inside a component (pins, fields can be highlighted.
|
|
|
|
static_cast<SCH_COMPONENT*>( eitem )->ClearAllHighlightFlags();
|
|
|
|
}
|
2018-12-24 11:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-16 21:19:33 +00:00
|
|
|
|
2018-11-20 14:30:18 +00:00
|
|
|
}; // namespace KIGFX
|