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 <dialog_helpers.h>
#include <class_libentry.h> #include <class_libentry.h>
#include <class_library.h> #include <class_library.h>
#include <view/view_controls.h>
// Save previous component library viewer state. // Save previous component library viewer state.
wxString LIB_VIEW_FRAME::m_libraryName; wxString LIB_VIEW_FRAME::m_libraryName;
@ -215,6 +215,9 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
Raise(); Raise();
Show( true ); Show( true );
} }
SyncView();
GetGalCanvas()->GetViewControls()->SetSnapping( true );
} }
@ -722,3 +725,21 @@ void LIB_VIEW_FRAME::SetFilter( const SCHLIB_FILTER* aFilter )
ReCreateListLib(); 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/**
* @file viewlib_frame.h
*/
#ifndef LIBVIEWFRM_H_ #ifndef LIB_VIEW_FRAME_H__
#define LIBVIEWFRM_H_
#define LIB_VIEW_FRAME_H__
#include <wx/gdicmn.h>
#include <sch_base_frame.h> #include <sch_base_frame.h>
#include <sch_screen.h> #include <sch_screen.h>
@ -152,6 +147,9 @@ public:
bool GetShowElectricalType() { return m_showPinElectricalTypeName; } bool GetShowElectricalType() { return m_showPinElectricalTypeName; }
void SetShowElectricalType( bool aShow ) { m_showPinElectricalTypeName = aShow; } void SetShowElectricalType( bool aShow ) { m_showPinElectricalTypeName = aShow; }
LIB_PART* CurrentPart() const;
const BOX2I GetDocumentExtents() const override;
private: private:
/** /**
* Called when the frame is activated to reload the libraries and component lists * Called when the frame is activated to reload the libraries and component lists
@ -219,4 +217,5 @@ private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
#endif // LIBVIEWFRM_H_ #endif // LIB_VIEW_FRAME_H__

View File

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