const BOX2I LIB_EDIT_FRAME::GetDocumentExtents() const { LIB_PART* part = GetCurPart(); 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() ) ); } }
const BOX2I LIB_VIEW_FRAME::GetDocumentExtents() const { LIB_ALIAS* alias = getSelectedAlias(); LIB_PART* part = alias ? alias->GetPart() : nullptr; if( !part ) { return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) ); } else { EDA_RECT bbox = part->GetUnitBoundingBox( m_unit, m_convert ); return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) ); } }
double LIB_VIEW_FRAME::BestZoom() { LIB_PART* part = NULL; double defaultLibraryZoom = 7.33; if( m_libraryName.IsEmpty() || m_entryName.IsEmpty() ) { SetScrollCenterPosition( wxPoint( 0, 0 ) ); return defaultLibraryZoom; } LIB_ALIAS* alias = nullptr; try { alias = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName ); } catch( ... ) { } if( alias ) part = alias->GetPart(); if( !part ) { SetScrollCenterPosition( wxPoint( 0, 0 ) ); return defaultLibraryZoom; } EDA_RECT boundingBox = part->GetUnitBoundingBox( m_unit, m_convert ); double sizeX = (double) boundingBox.GetWidth(); double sizeY = (double) boundingBox.GetHeight(); wxPoint centre = boundingBox.Centre(); // Reserve a 20% margin around component bounding box. double margin_scale_factor = 1.2; return bestZoom( sizeX, sizeY, margin_scale_factor, centre ); }
double LIB_EDIT_FRAME::BestZoom() { LIB_PART* part = GetCurPart(); double defaultLibraryZoom = 7.33; if( !part ) { SetScrollCenterPosition( wxPoint( 0, 0 ) ); return defaultLibraryZoom; } EDA_RECT boundingBox = part->GetUnitBoundingBox( m_unit, m_convert ); double sizeX = (double) boundingBox.GetWidth(); double sizeY = (double) boundingBox.GetHeight(); wxPoint centre = boundingBox.Centre(); // Reserve a 20% margin around component bounding box. double margin_scale_factor = 1.2; return bestZoom( sizeX, sizeY, margin_scale_factor, centre); }
void LIB_EDIT_FRAME::OnPlotCurrentComponent( wxCommandEvent& event ) { wxString fullFileName; wxString file_ext; wxString mask; LIB_PART* part = GetCurPart(); if( !part ) { wxMessageBox( _( "No component" ) ); return; } switch( event.GetId() ) { case ID_LIBEDIT_GEN_PNG_FILE: { bool fmt_is_jpeg = false; // could be selectable later. so keep this option. file_ext = fmt_is_jpeg ? wxT( "jpg" ) : wxT( "png" ); mask = wxT( "*." ) + file_ext; wxFileName fn( part->GetName() ); fn.SetExt( file_ext ); wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() ); fullFileName = EDA_FILE_SELECTOR( _( "Filename:" ), pro_dir, fn.GetFullName(), file_ext, mask, this, wxFD_SAVE, true ); if( fullFileName.IsEmpty() ) return; // calling wxYield is mandatory under Linux, after closing the file selector dialog // to refresh the screen before creating the PNG or JPEG image from screen wxYield(); CreatePNGorJPEGFile( fullFileName, fmt_is_jpeg ); } break; case ID_LIBEDIT_GEN_SVG_FILE: { file_ext = wxT( "svg" ); mask = wxT( "*." ) + file_ext; wxFileName fn( part->GetName() ); fn.SetExt( file_ext ); wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() ); fullFileName = EDA_FILE_SELECTOR( _( "Filename:" ), pro_dir, fn.GetFullName(), file_ext, mask, this, wxFD_SAVE, true ); if( fullFileName.IsEmpty() ) return; PAGE_INFO pageSave = GetScreen()->GetPageSettings(); PAGE_INFO pageTemp = pageSave; wxSize componentSize = part->GetUnitBoundingBox( m_unit, m_convert ).GetSize(); // Add a small margin to the plot bounding box pageTemp.SetWidthMils( int( componentSize.x * 1.2 ) ); pageTemp.SetHeightMils( int( componentSize.y * 1.2 ) ); GetScreen()->SetPageSettings( pageTemp ); SVG_PlotComponent( fullFileName ); GetScreen()->SetPageSettings( pageSave ); } break; } }