diff --git a/pcbnew/dialogs/dialog_barcode_properties.cpp b/pcbnew/dialogs/dialog_barcode_properties.cpp index cbd58ced60..5920a8b686 100644 --- a/pcbnew/dialogs/dialog_barcode_properties.cpp +++ b/pcbnew/dialogs/dialog_barcode_properties.cpp @@ -42,6 +42,7 @@ #include #include #include +#include // For BOX2D viewport checks #include @@ -235,6 +236,14 @@ bool DIALOG_BARCODE_PROPERTIES::TransferDataToWindow() bool DIALOG_BARCODE_PROPERTIES::TransferDataFromWindow() { + transferDataToBarcode( m_dummyBarcode ); + + if( !m_dummyBarcode->GetText().empty() && m_dummyBarcode->GetSymbolPoly().OutlineCount() == 0 ) + { + wxMessageBox( m_dummyBarcode->GetLastError(), _( "Barcode Error" ), wxOK | wxICON_ERROR, this ); + return false; + } + BOARD_COMMIT commit( m_parent ); commit.Modify( m_currentBarcode ); diff --git a/pcbnew/dialogs/dialog_barcode_properties_base.cpp b/pcbnew/dialogs/dialog_barcode_properties_base.cpp index 92d2fcb4f8..34f61fabd2 100644 --- a/pcbnew/dialogs/dialog_barcode_properties_base.cpp +++ b/pcbnew/dialogs/dialog_barcode_properties_base.cpp @@ -24,15 +24,21 @@ DIALOG_BARCODE_PROPERTIES_BASE::DIALOG_BARCODE_PROPERTIES_BASE( wxWindow* parent wxBoxSizer* bGeneralSizer; bGeneralSizer = new wxBoxSizer( wxVERTICAL ); + wxBoxSizer* bSizer10; + bSizer10 = new wxBoxSizer( wxHORIZONTAL ); + m_staticText28 = new wxStaticText( this, wxID_ANY, _("Text:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText28->Wrap( -1 ); - bGeneralSizer->Add( m_staticText28, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + bSizer10->Add( m_staticText28, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - bGeneralSizer->Add( 0, 3, 0, wxEXPAND, 5 ); + bSizer10->Add( 0, 3, 0, wxEXPAND, 5 ); m_textInput = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - bGeneralSizer->Add( m_textInput, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + bSizer10->Add( m_textInput, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + + + bGeneralSizer->Add( bSizer10, 0, wxEXPAND, 5 ); wxBoxSizer* bSizer8; bSizer8 = new wxBoxSizer( wxHORIZONTAL ); diff --git a/pcbnew/dialogs/dialog_barcode_properties_base.fbp b/pcbnew/dialogs/dialog_barcode_properties_base.fbp index 13d6ecd1ce..f90a0dc042 100644 --- a/pcbnew/dialogs/dialog_barcode_properties_base.fbp +++ b/pcbnew/dialogs/dialog_barcode_properties_base.fbp @@ -83,142 +83,153 @@ bGeneralSizer wxVERTICAL none - - 5 - wxTOP|wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 0 - 1 - - 1 - - 0 - 0 - wxID_ANY - Text: - 0 - - 0 - - - 0 - - 1 - m_staticText28 - 1 - - - protected - 1 - - Resizable - 1 - - - ; ; forward_declare - 0 - - - - - -1 - - 5 wxEXPAND 0 - - 3 - protected - 0 - - - - 5 - wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 0 - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - 0 - - 0 + - 1 - m_textInput - 1 - - - protected - 1 - - Resizable - 1 - - - ; ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - OnTextValueChanged + bSizer10 + wxHORIZONTAL + none + + 5 + wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + Text: + 0 + + 0 + + + 0 + + 1 + m_staticText28 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxEXPAND + 0 + + 3 + protected + 0 + + + + 5 + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT + 1 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + 0 + + 1 + m_textInput + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + OnTextValueChanged + + diff --git a/pcbnew/dialogs/dialog_barcode_properties_base.h b/pcbnew/dialogs/dialog_barcode_properties_base.h index 2bd61e4643..6ca3f7542b 100644 --- a/pcbnew/dialogs/dialog_barcode_properties_base.h +++ b/pcbnew/dialogs/dialog_barcode_properties_base.h @@ -20,8 +20,8 @@ class PCB_LAYER_BOX_SELECTOR; #include #include #include -#include #include +#include #include #include #include diff --git a/pcbnew/pcb_barcode.cpp b/pcbnew/pcb_barcode.cpp index d5c9795c77..c72d6948b2 100644 --- a/pcbnew/pcb_barcode.cpp +++ b/pcbnew/pcb_barcode.cpp @@ -52,6 +52,8 @@ #include #include +constexpr int ECI_UTF8 = 26; + PCB_BARCODE::PCB_BARCODE( BOARD_ITEM* aParent ) : BOARD_ITEM( aParent, PCB_BARCODE_T ), m_width( pcbIUScale.mmToIU( 40 ) ), @@ -301,6 +303,7 @@ void PCB_BARCODE::ComputeTextPoly() void PCB_BARCODE::ComputeBarcode() { m_symbolPoly.RemoveAllContours(); + m_lastError.clear(); std::unique_ptr symbol( ZBarcode_Create(), &ZBarcode_Delete ); @@ -345,11 +348,31 @@ void PCB_BARCODE::ComputeBarcode() if( text.empty() ) return; - if( ZBarcode_Encode( symbol.get(), dataPtr, length ) ) + if( ( m_kind == BARCODE_T::QR_CODE || m_kind == BARCODE_T::DATA_MATRIX ) && !text.IsAscii() ) + { + symbol->eci = ECI_UTF8; + } + + if( ZBarcode_Encode( symbol.get(), dataPtr, length ) >= ZINT_ERROR ) + { + if( !text.IsAscii() ) + { + m_lastError = _( "This barcode type does not support international " + "characters. Use QR Code or Data Matrix instead." ); + } + else + { + m_lastError = wxString::FromUTF8( symbol->errtxt ); + } return; + ; + } if( ZBarcode_Buffer_Vector( symbol.get(), 0 ) ) // 0 means success + { + m_lastError = wxString::FromUTF8( symbol->errtxt ); return; + } for( zint_vector_rect* rect = symbol->vector->rectangles; rect != nullptr; rect = rect->next ) { diff --git a/pcbnew/pcb_barcode.h b/pcbnew/pcb_barcode.h index 3bafb27acd..28217cb074 100644 --- a/pcbnew/pcb_barcode.h +++ b/pcbnew/pcb_barcode.h @@ -418,6 +418,8 @@ public: AssembleBarcode(); } + const wxString& GetLastError() const { return m_lastError; } + private: int m_width; ///< Barcode width int m_height; ///< Barcode height @@ -432,6 +434,7 @@ private: SHAPE_POLY_SET m_symbolPoly; ///< Barcode symbol only (cached, centered at origin) SHAPE_POLY_SET m_textPoly; ///< Human-readable text only (cached, centered/positioned) BOX2I m_bbox; ///< BBox of m_poly (ie: barcode + text) + wxString m_lastError; }; #endif // DIMENSION_H_