eeschema-gal: started work on library viewer canvas

This commit is contained in:
Tomasz Wlostowski 2018-08-27 15:28:44 +02:00 committed by Jeff Young
parent 48d36f854e
commit a3563851b2
3 changed files with 52 additions and 34 deletions

View File

@ -44,7 +44,7 @@
#include <dialog_helpers.h>
#include <class_libentry.h>
#include <class_library.h>
#include <view/view_controls.h>
// Save previous component library viewer state.
wxString LIB_VIEW_FRAME::m_libraryName;
@ -215,6 +215,9 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
Raise();
Show( true );
}
SyncView();
GetGalCanvas()->GetViewControls()->SetSnapping( true );
}
@ -722,3 +725,21 @@ void LIB_VIEW_FRAME::SetFilter( const SCHLIB_FILTER* aFilter )
ReCreateListLib();
}
const BOX2I LIB_VIEW_FRAME::GetDocumentExtents() const
{
LIB_PART* part = CurrentPart();
printf("part %p\n", part);
if( !part )
{
return BOX2I( VECTOR2I(-100, -100), VECTOR2I( 200, 200 ) );
}
else
{
EDA_RECT boundingBox = part->GetUnitBoundingBox( m_unit, m_convert );
return BOX2I( boundingBox.GetOrigin(), VECTOR2I( boundingBox.GetWidth(), boundingBox.GetHeight() ) );
}
}

View File

@ -23,15 +23,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file viewlib_frame.h
*/
#ifndef LIBVIEWFRM_H_
#define LIBVIEWFRM_H_
#ifndef LIB_VIEW_FRAME_H__
#include <wx/gdicmn.h>
#define LIB_VIEW_FRAME_H__
#include <sch_base_frame.h>
#include <sch_screen.h>
@ -152,6 +147,9 @@ public:
bool GetShowElectricalType() { return m_showPinElectricalTypeName; }
void SetShowElectricalType( bool aShow ) { m_showPinElectricalTypeName = aShow; }
LIB_PART* CurrentPart() const;
const BOX2I GetDocumentExtents() const override;
private:
/**
* Called when the frame is activated to reload the libraries and component lists
@ -219,4 +217,5 @@ private:
DECLARE_EVENT_TABLE()
};
#endif // LIBVIEWFRM_H_
#endif // LIB_VIEW_FRAME_H__

View File

@ -30,6 +30,7 @@
#include <kiway.h>
#include <pgm_base.h>
#include <sch_draw_panel.h>
#include <sch_view.h>
#include <confirm.h>
#include <eda_doc.h>
@ -186,7 +187,7 @@ void LIB_VIEW_FRAME::DisplayLibInfos()
}
void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
LIB_PART* LIB_VIEW_FRAME::CurrentPart() const
{
LIB_ID id( m_libraryName, m_entryName );
LIB_ALIAS* entry = nullptr;
@ -198,48 +199,45 @@ void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
catch( const IO_ERROR& ) {} // ignore, it is handled below
if( !entry )
return;
return nullptr;
LIB_PART* part = entry->GetPart();
if( !part )
return;
wxString msg;
wxString tmp;
m_canvas->DrawBackGround( DC );
if( !entry->IsRoot() )
{
// Temporarily change the name field text to reflect the alias name.
msg = entry->GetName();
tmp = part->GetName();
auto msg = entry->GetName();
part->SetName( msg );
if( m_unit < 1 )
m_unit = 1;
if( m_convert < 1 )
m_convert = 1;
}
else
msg = _( "None" );
auto opts = PART_DRAW_OPTIONS::Default();
opts.show_elec_type = GetShowElectricalType();
part->Draw( m_canvas, DC, wxPoint( 0, 0 ), m_unit, m_convert, opts );
return part;
}
// Redraw the cursor
m_canvas->DrawCrossHair( DC );
void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
{
auto part = CurrentPart();
auto view = GetCanvas()->GetView();
printf("Part %p\n", part );
if( !tmp.IsEmpty() )
if( !part )
{
view->Clear();
return;
}
view->Add( part );
/*if( !tmp.IsEmpty() )
part->SetName( tmp );
ClearMsgPanel();
AppendMsgPanel( _( "Name" ), part->GetName(), BLUE, 6 );
AppendMsgPanel( _( "Alias" ), msg, RED, 6 );
AppendMsgPanel( _( "Description" ), entry->GetDescription(), CYAN, 6 );
AppendMsgPanel( _( "Key words" ), entry->GetKeyWords(), DARKDARKGRAY );
AppendMsgPanel( _( "Key words" ), entry->GetKeyWords(), DARKDARKGRAY );*/
}