Skip to content

Commit

Permalink
Version 1.4.
Browse files Browse the repository at this point in the history
Support the "rounded rectangle" pad shape (introduced with KiCad 5).
Support SMD pads as reverse side (edge connectors).
Allow for path recursion in collecting libraries.
Automatic adjustment of zoom when switching from one footprint/symbol to the next, to always show a component at a reasonable size.
Bug fix in conversion of layer set between s-expr and legacy.
  • Loading branch information
compuphase committed Dec 18, 2018
1 parent f10880a commit 8110816
Show file tree
Hide file tree
Showing 66 changed files with 5,181 additions and 9,346 deletions.
Binary file modified doc/LibraryFileFormats.pdf
Binary file not shown.
Binary file modified doc/kicadlibrarian.pdf
Binary file not shown.
8 changes: 4 additions & 4 deletions src/cxffont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*
* $Id: cxffont.cpp 5685 2017-05-23 10:35:40Z thiadmer $
* $Id: cxffont.cpp 5686 2017-05-24 13:56:46Z thiadmer $
*/
#include <cstdio>
#include <cstring>
Expand Down Expand Up @@ -132,7 +132,7 @@ bool CXFFont::Read(const char *path)
width = x2;
}
if (stroke.GetCount() > 0)
glyph.AddStroke(stroke); /* add the final stroke */
glyph.AddStroke(stroke); /* add the final stroke */
glyph.SetWidth(width);
m_Glyphs.push_back(glyph);
}
Expand Down Expand Up @@ -239,10 +239,10 @@ void CXFFont::DrawText(const wchar_t* text, std::vector<CXFPolyLine>* strokes) c
ypos = 0;
break;
case CXF_ALIGNTOP:
ypos = m_Ascender * m_ScaleY * 1.15; /* assume 15% internal leading above the ascender */
ypos = m_Ascender * m_ScaleY * 1.15; /* assume 15% internal leading above the ascender */
break;
case CXF_ALIGNBOTTOM:
ypos = m_Descender * m_ScaleY * 1.1; /* assume 10% internal leading below the descender */
ypos = m_Descender * m_ScaleY * 1.1; /* assume 10% internal leading below the descender */
break;
case CXF_ALIGNCENTRE:
ypos = (m_Ascender + m_Descender) * m_ScaleY;
Expand Down
300 changes: 150 additions & 150 deletions src/libmngr_dlgnewfootprint.cpp
Original file line number Diff line number Diff line change
@@ -1,150 +1,150 @@
/*
* Librarian for KiCad, a free EDA CAD application.
* The dialog with the templates for new components.
*
* Copyright (C) 2013-2016 CompuPhase
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* $Id: libmngr_dlgnewfootprint.cpp 5580 2016-10-03 09:21:56Z thiadmer $
*/

#include "libmngr_dlgnewfootprint.h"
#include "librarymanager.h"
#include "libraryfunctions.h"
#include <wx/dir.h>
#include <wx/filename.h>
#include <wx/textfile.h>

libmngrDlgNewFootprint::libmngrDlgNewFootprint(wxWindow* parent)
: DlgNewFootprint(parent)
{
m_libraryname = wxEmptyString;
m_templatename = wxEmptyString;
m_partname = wxEmptyString;
m_previews.Clear();
m_currentpreview = 0;

/* list all templates */
wxDir dir(theApp->GetTemplatePath());
if (!dir.IsOpened())
return; /* error message already given */
wxArrayString list;
dir.GetAllFiles(theApp->GetTemplatePath(), &list, wxT("*.mt"), wxDIR_FILES);

/* remove the paths and extensions on all filenames, but add the brief description */
for (unsigned idx = 0; idx < list.Count(); idx++) {
wxFileName fname(list[idx]);
wxString name = fname.GetName();
wxString line = GetTemplateHeaderField(name, wxT("brief"), false);
if (line.length() > 0)
name += wxT(" - ") + line;
list[idx] = name;
}
list.Sort();
m_lstTemplates->InsertItems(list, 0);
}

void libmngrDlgNewFootprint::OnTemplateSelect(wxCommandEvent& /*event*/)
{
int idx = m_lstTemplates->GetSelection();
if (idx < 0)
return;
wxASSERT((unsigned)idx < m_lstTemplates->GetCount());

/* get the template name */
wxString line = m_lstTemplates->GetString(idx);
wxString name = GetToken(&line); /* the template is the start of the name */

/* load the base image for the template */
m_previews.Clear();
wxString path = theApp->GetTemplatePath() + wxT(DIRSEP_STR) + name + wxT(".bmp");
wxImage bitmap(path, wxBITMAP_TYPE_BMP);
if (bitmap.IsOk()) {
m_previews.Add(path);
m_bmpExample->SetBitmap(bitmap);
}

/* get the prefix (which is the name if absent) */
wxString prefix = GetTemplateHeaderField(name, wxT("prefix"), false);
if (prefix.length() == 0)
prefix = name;
m_txtName->SetValue(prefix);

/* load the description */
wxString note = GetTemplateHeaderField(name, wxT("note"), false);
m_txtDescription->SetValue(note);

/* count the number of additional images */
wxString field = GetTemplateHeaderField(name, wxT("model"), false);
wxArrayString models = wxSplit(field, wxT(' '));
for (idx = 0; idx < (int)models.Count(); idx++) {
path = theApp->GetTemplatePath() + wxT(DIRSEP_STR) + wxT("model_") + models[idx] + wxT(".bmp");
if (wxFileExists(path))
m_previews.Add(path);
}
if (m_currentpreview >= (int)m_previews.Count())
m_currentpreview = m_previews.Count() - 1;
m_spinPreview->Enable(m_previews.Count() > 1);
}

void libmngrDlgNewFootprint::OnOk(wxCommandEvent& event)
{
/* save the selected template & part names */
int idx = m_lstTemplates->GetSelection();
if (idx >= 0) {
wxASSERT((unsigned)idx < m_lstTemplates->GetCount());
wxString line = m_lstTemplates->GetString(idx);
m_templatename = GetToken(&line);
}
m_partname = m_txtName->GetValue();

if (m_templatename.length() == 0 || m_partname.length() == 0) {
wxMessageBox(wxT("Please select a template and specify a name for the footprint."));
return;
}
wxString prefix = GetTemplateHeaderField(m_templatename, wxT("prefix"), false);
if (m_templatename.CmpNoCase(m_partname) == 0 || prefix.CmpNoCase(m_partname) == 0) {
if (wxMessageBox(wxT("The footprint name is the same as the template name or the prefix.\nIs this what you want?"), wxT("Confirm footprint name"), wxYES_NO | wxICON_QUESTION) != wxYES)
return;
}

/* optionally verify whether the footprint already exists in the library */
if (m_libraryname.length() > 0 && ExistFootprint(m_libraryname, m_partname)) {
wxString msg = wxString::Format(wxT("Footprint %s already exists.\nOverwrite?"), m_partname.c_str());
if (wxMessageBox(msg, wxT("Confirm overwrite"), wxYES_NO | wxICON_QUESTION) != wxYES)
return;
}

event.Skip();
}

void libmngrDlgNewFootprint::OnNextImage(wxSpinEvent& /*event*/)
{
if (m_previews.Count() > 1) {
m_currentpreview = (m_currentpreview < (int)m_previews.Count() - 1) ? m_currentpreview + 1 : 0;
wxImage bitmap(m_previews[m_currentpreview], wxBITMAP_TYPE_BMP);
if (bitmap.IsOk())
m_bmpExample->SetBitmap(bitmap);
}
}

void libmngrDlgNewFootprint::OnPrevImage(wxSpinEvent& /*event*/)
{
if (m_previews.Count() > 1) {
m_currentpreview = (m_currentpreview > 0) ? m_currentpreview - 1 : m_previews.Count() - 1;
wxImage bitmap(m_previews[m_currentpreview], wxBITMAP_TYPE_BMP);
if (bitmap.IsOk())
m_bmpExample->SetBitmap(bitmap);
}
}
/*
* Librarian for KiCad, a free EDA CAD application.
* The dialog with the templates for new components.
*
* Copyright (C) 2013-2016 CompuPhase
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* $Id: libmngr_dlgnewfootprint.cpp 5686 2017-05-24 13:56:46Z thiadmer $
*/

#include "libmngr_dlgnewfootprint.h"
#include "librarymanager.h"
#include "libraryfunctions.h"
#include <wx/dir.h>
#include <wx/filename.h>
#include <wx/textfile.h>

libmngrDlgNewFootprint::libmngrDlgNewFootprint(wxWindow* parent)
: DlgNewFootprint(parent)
{
m_libraryname = wxEmptyString;
m_templatename = wxEmptyString;
m_partname = wxEmptyString;
m_previews.Clear();
m_currentpreview = 0;

/* list all templates */
wxDir dir(theApp->GetTemplatePath());
if (!dir.IsOpened())
return; /* error message already given */
wxArrayString list;
dir.GetAllFiles(theApp->GetTemplatePath(), &list, wxT("*.mt"), wxDIR_FILES);

/* remove the paths and extensions on all filenames, but add the brief description */
for (unsigned idx = 0; idx < list.Count(); idx++) {
wxFileName fname(list[idx]);
wxString name = fname.GetName();
wxString line = GetTemplateHeaderField(name, wxT("brief"), false);
if (line.length() > 0)
name += wxT(" - ") + line;
list[idx] = name;
}
list.Sort();
m_lstTemplates->InsertItems(list, 0);
}

void libmngrDlgNewFootprint::OnTemplateSelect(wxCommandEvent& /*event*/)
{
int idx = m_lstTemplates->GetSelection();
if (idx < 0)
return;
wxASSERT((unsigned)idx < m_lstTemplates->GetCount());

/* get the template name */
wxString line = m_lstTemplates->GetString(idx);
wxString name = GetToken(&line); /* the template is the start of the name */

/* load the base image for the template */
m_previews.Clear();
wxString path = theApp->GetTemplatePath() + wxT(DIRSEP_STR) + name + wxT(".bmp");
wxImage bitmap(path, wxBITMAP_TYPE_BMP);
if (bitmap.IsOk()) {
m_previews.Add(path);
m_bmpExample->SetBitmap(bitmap);
}

/* get the prefix (which is the name if absent) */
wxString prefix = GetTemplateHeaderField(name, wxT("prefix"), false);
if (prefix.length() == 0)
prefix = name;
m_txtName->SetValue(prefix);

/* load the description */
wxString note = GetTemplateHeaderField(name, wxT("note"), false);
m_txtDescription->SetValue(note);

/* count the number of additional images */
wxString field = GetTemplateHeaderField(name, wxT("model"), false);
wxArrayString models = wxSplit(field, wxT(' '));
for (idx = 0; idx < (int)models.Count(); idx++) {
path = theApp->GetTemplatePath() + wxT(DIRSEP_STR) + wxT("model_") + models[idx] + wxT(".bmp");
if (wxFileExists(path))
m_previews.Add(path);
}
if (m_currentpreview >= (int)m_previews.Count())
m_currentpreview = m_previews.Count() - 1;
m_spinPreview->Enable(m_previews.Count() > 1);
}

void libmngrDlgNewFootprint::OnOk(wxCommandEvent& event)
{
/* save the selected template & part names */
int idx = m_lstTemplates->GetSelection();
if (idx >= 0) {
wxASSERT((unsigned)idx < m_lstTemplates->GetCount());
wxString line = m_lstTemplates->GetString(idx);
m_templatename = GetToken(&line);
}
m_partname = m_txtName->GetValue();

if (m_templatename.length() == 0 || m_partname.length() == 0) {
wxMessageBox(wxT("Please select a template and specify a name for the footprint."));
return;
}
wxString prefix = GetTemplateHeaderField(m_templatename, wxT("prefix"), false);
if (m_templatename.CmpNoCase(m_partname) == 0 || prefix.CmpNoCase(m_partname) == 0) {
if (wxMessageBox(wxT("The footprint name is the same as the template name or the prefix.\nIs this what you want?"), wxT("Confirm footprint name"), wxYES_NO | wxICON_QUESTION) != wxYES)
return;
}

/* optionally verify whether the footprint already exists in the library */
if (m_libraryname.length() > 0 && ExistFootprint(m_libraryname, m_partname)) {
wxString msg = wxString::Format(wxT("Footprint %s already exists.\nOverwrite?"), m_partname.c_str());
if (wxMessageBox(msg, wxT("Confirm overwrite"), wxYES_NO | wxICON_QUESTION) != wxYES)
return;
}

event.Skip();
}

void libmngrDlgNewFootprint::OnNextImage(wxSpinEvent& /*event*/)
{
if (m_previews.Count() > 1) {
m_currentpreview = (m_currentpreview < (int)m_previews.Count() - 1) ? m_currentpreview + 1 : 0;
wxImage bitmap(m_previews[m_currentpreview], wxBITMAP_TYPE_BMP);
if (bitmap.IsOk())
m_bmpExample->SetBitmap(bitmap);
}
}

void libmngrDlgNewFootprint::OnPrevImage(wxSpinEvent& /*event*/)
{
if (m_previews.Count() > 1) {
m_currentpreview = (m_currentpreview > 0) ? m_currentpreview - 1 : m_previews.Count() - 1;
wxImage bitmap(m_previews[m_currentpreview], wxBITMAP_TYPE_BMP);
if (bitmap.IsOk())
m_bmpExample->SetBitmap(bitmap);
}
}
Loading

0 comments on commit 8110816

Please sign in to comment.