diff --git a/common/base_struct.cpp b/common/base_struct.cpp index 387230788a..60172bcb1c 100644 --- a/common/base_struct.cpp +++ b/common/base_struct.cpp @@ -171,7 +171,7 @@ EDA_TextStruct::EDA_TextStruct( const wxString& text ) m_Orient = 0; /* Orient in 0.1 degrees */ m_Attributs = 0; m_Mirror = false; // display mirror if true - m_HJustify = GR_TEXT_HJUSTIFY_CENTER; + m_HJustify = GR_TEXT_HJUSTIFY_LEFT; m_VJustify = GR_TEXT_VJUSTIFY_CENTER; /* Justifications Horiz et Vert du texte */ m_Width = 0; /* thickness */ m_Italic = false; /* true = italic shape */ @@ -264,7 +264,6 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode, GRFillMode aDisplayMode, EDA_Colors aAnchor_color ) /***************************************************************/ - /** Function Draw * @param aPanel = the current DrawPanel * @param aDC = the current Device Context @@ -274,45 +273,69 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, * @param aDisplayMode = FILAIRE, FILLED or SKETCH * @param EDA_Colors aAnchor_color = anchor color ( UNSPECIFIED_COLOR = do not draw anchor ). */ + { - int width; + wxPoint pos = m_Pos; + wxArrayString* list = wxStringSplit( m_Text, '\n'); - width = m_Width; - if( aDisplayMode == FILAIRE ) - width = 0; - - if( aDrawMode != -1 ) - GRSetDrawMode( aDC, aDrawMode ); - - /* Draw text anchor, if allowed */ - if( aAnchor_color != UNSPECIFIED_COLOR ) + for( int i=0;iCount();i++) { - int anchor_size = aPanel->GetScreen()->Unscale( 2 ); - aAnchor_color = (EDA_Colors) (aAnchor_color & MASKCOLOR); - - int cX = m_Pos.x + aOffset.x; - int cY = m_Pos.y + aOffset.y; - - GRLine( &aPanel->m_ClipBox, aDC, cX - anchor_size, cY, - cX + anchor_size, cY, 0, aAnchor_color ); - - GRLine( &aPanel->m_ClipBox, aDC, cX, cY - anchor_size, - cX, cY + anchor_size, 0, aAnchor_color ); + wxString txt = list->Item(i); + wxSize size=DrawOneLine(aPanel,aDC,aOffset,aColor,aDrawMode,aDisplayMode,aAnchor_color,txt,pos); + pos.y+=1.5*(size.y); } - - if( aDisplayMode == SKETCH ) - width = -width; - wxSize size = m_Size; - if ( m_Mirror ) - size.x = -size.x; - - DrawGraphicText( aPanel, aDC, - aOffset + m_Pos, aColor, m_Text, - m_Orient, size, - m_HJustify, m_VJustify, width, m_Italic ); + delete (list); + } + +wxSize EDA_TextStruct::DrawOneLine( WinEDA_DrawPanel* aPanel, wxDC* aDC, + const wxPoint& aOffset, EDA_Colors aColor, + int aDrawMode, + GRFillMode aDisplayMode, EDA_Colors aAnchor_color, + wxString txt, wxPoint pos ) +{ + int width = m_Width; + if( aDisplayMode == FILAIRE ) + width = 0; + + if( aDrawMode != -1 ) + GRSetDrawMode( aDC, aDrawMode ); + + /* Draw text anchor, if allowed */ + if( aAnchor_color != UNSPECIFIED_COLOR ) + { + int anchor_size = aPanel->GetScreen()->Unscale( 2 ); + aAnchor_color = (EDA_Colors) (aAnchor_color & MASKCOLOR); + + int cX = pos.x + aOffset.x; + int cY = pos.y + aOffset.y; + + GRLine( &aPanel->m_ClipBox, aDC, cX - anchor_size, cY, + cX + anchor_size, cY, 0, aAnchor_color ); + + GRLine( &aPanel->m_ClipBox, aDC, cX, cY - anchor_size, + cX, cY + anchor_size, 0, aAnchor_color ); + } + + if( aDisplayMode == SKETCH ) + width = -width; + + wxSize size = m_Size; + + if ( m_Mirror ) + size.x = -size.x; + + + + DrawGraphicText( aPanel, aDC, + aOffset + pos, aColor, txt, + m_Orient, size, + m_HJustify, m_VJustify, width, m_Italic ); + return size; +} + /******************/ /* Class EDA_Rect */ /******************/ diff --git a/common/common.cpp b/common/common.cpp index c6cff55924..83042a23eb 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -378,6 +378,38 @@ int ReturnValueFromString( int Units, const wxString& TextValue, return Value; } +/** + * Function wxStringSplit + * Split a String to a String List when founding 'splitter' + * @return the list + * @param txt : wxString : a String text + * @param splitter : wxChar : the 'split' character + */ +/**********************************************************/ +wxArrayString* wxStringSplit(wxString txt, wxChar splitter) +/**********************************************************/ +{ + wxArrayString* list = new wxArrayString(); + while (1) + { + int index=txt.Find(splitter); + if (index == wxNOT_FOUND) + break; + + wxString tmp; + tmp = txt.Mid(0,index); + txt = txt.Mid( index+1, txt.size() - index); + list->Add(tmp); + } + + if (!txt.IsEmpty()) + { + list->Add(txt); + } + + return list; +} + /******************************************************************/ double To_User_Unit( bool is_metric, int val, int internal_unit_value ) diff --git a/common/wxwineda.cpp b/common/wxwineda.cpp index d50a2b0244..4938282a0f 100644 --- a/common/wxwineda.cpp +++ b/common/wxwineda.cpp @@ -12,13 +12,13 @@ /**********************************************************************************/ -/* Classe WinEDA_EnterText pour entrer une ligne texte au clavier dans les frames */ +/* Classe WinEDA_EnterText pour entrer une ou plusieurs ligne texte au clavier dans les frames */ /**********************************************************************************/ WinEDA_EnterText::WinEDA_EnterText( wxWindow* parent, const wxString& Title, const wxString& TextToEdit, wxBoxSizer* BoxSizer, - const wxSize& Size ) + const wxSize& Size, bool Multiline ) { m_Modify = FALSE; if( ! TextToEdit.IsEmpty() ) @@ -28,7 +28,12 @@ WinEDA_EnterText::WinEDA_EnterText( wxWindow* parent, BoxSizer->Add( m_Title, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE, 5 ); - m_FrameText = new wxTextCtrl( parent, -1, TextToEdit, wxDefaultPosition, Size ); + long style = 0; + + if (Multiline) + style = wxTE_MULTILINE; + + m_FrameText = new wxTextCtrl( parent, -1, TextToEdit, wxDefaultPosition, Size,style ); m_FrameText->SetInsertionPoint( 1 ); BoxSizer->Add( m_FrameText, diff --git a/eeschema/class_text-label.cpp b/eeschema/class_text-label.cpp index 36c13ebe68..e794221192 100644 --- a/eeschema/class_text-label.cpp +++ b/eeschema/class_text-label.cpp @@ -189,46 +189,68 @@ void SCH_TEXT::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, color = ReturnLayerColor( m_Layer ); GRSetDrawMode( DC, DrawMode ); + wxArrayString* list = wxStringSplit(m_Text, '\n'); + + wxPoint pos; + int orientation; + GRTextHorizJustifyType Hjustify; + GRTextVertJustifyType Vjustify; + pos = m_Pos + offset; + switch( m_Orient ) { case 0: /* Horiz Normal Orientation (left justified) */ - DrawGraphicText( panel, DC, - wxPoint( m_Pos.x + offset.x, m_Pos.y - TXTMARGE + offset.y ), - color, m_Text, TEXT_ORIENT_HORIZ, m_Size, - GR_TEXT_HJUSTIFY_LEFT, - GR_TEXT_VJUSTIFY_BOTTOM, width, m_Italic, true ); + orientation = TEXT_ORIENT_HORIZ; + Hjustify = GR_TEXT_HJUSTIFY_LEFT; + Vjustify = GR_TEXT_VJUSTIFY_BOTTOM; + pos.y-=TXTMARGE; break; case 1: /* Vert Orientation UP */ - DrawGraphicText( panel, DC, - wxPoint( m_Pos.x - TXTMARGE + offset.x, - m_Pos.y + offset.y ), - color, m_Text, TEXT_ORIENT_VERT, m_Size, - GR_TEXT_HJUSTIFY_RIGHT, - GR_TEXT_VJUSTIFY_BOTTOM, width, m_Italic, true ); + orientation = TEXT_ORIENT_VERT; + Hjustify = GR_TEXT_HJUSTIFY_RIGHT; + Vjustify = GR_TEXT_VJUSTIFY_BOTTOM; + pos.x-=TXTMARGE; break; case 2: /* Horiz Orientation - Right justified */ - DrawGraphicText( panel, DC, - wxPoint( m_Pos.x + offset.x, m_Pos.y - - TXTMARGE + offset.y ), - color, m_Text, TEXT_ORIENT_HORIZ, m_Size, - GR_TEXT_HJUSTIFY_RIGHT, - GR_TEXT_VJUSTIFY_BOTTOM, width, m_Italic, true ); + orientation = TEXT_ORIENT_HORIZ; + Hjustify = GR_TEXT_HJUSTIFY_RIGHT; + Vjustify = GR_TEXT_VJUSTIFY_BOTTOM; + pos.y-=TXTMARGE; break; case 3: /* Vert Orientation BOTTOM */ - DrawGraphicText( panel, DC, - wxPoint( m_Pos.x - TXTMARGE + offset.x, - m_Pos.y + offset.y ), - color, m_Text, TEXT_ORIENT_VERT, m_Size, - GR_TEXT_HJUSTIFY_RIGHT, - GR_TEXT_VJUSTIFY_TOP, width, m_Italic, true ); + orientation = TEXT_ORIENT_VERT; + Hjustify = GR_TEXT_HJUSTIFY_RIGHT; + Vjustify = GR_TEXT_VJUSTIFY_TOP; + pos.x-=TXTMARGE; break; } + for( int i=0;iCount();i++) + { + wxString txt = list->Item(i); + + + DrawGraphicText( panel, DC, + pos, + color, txt, orientation, m_Size, + Hjustify, + Vjustify, width, m_Italic, true ); + + if (orientation == TEXT_ORIENT_HORIZ) + pos.y+= 1.5*(m_Size.y); + else + pos.x+= 1.5*(m_Size.x); + } + + + delete (list); + if( m_IsDangling ) DrawDanglingSymbol( panel, DC, m_Pos + offset, color ); + } diff --git a/eeschema/dialog_edit_label.cpp b/eeschema/dialog_edit_label.cpp index 55fb99f697..e2259db1cb 100644 --- a/eeschema/dialog_edit_label.cpp +++ b/eeschema/dialog_edit_label.cpp @@ -21,8 +21,22 @@ int DialogLabelEditor::ShowModally( WinEDA_SchematicFrame* parent, SCH_TEXT * CurrentText ) { int ret; + bool multiline; - DialogLabelEditor* dialog = new DialogLabelEditor( parent, CurrentText ); + switch( CurrentText->Type() ) + { + case TYPE_SCH_GLOBALLABEL: + case TYPE_SCH_HIERLABEL: + case TYPE_SCH_LABEL: + multiline = false; + break; + + default: + multiline = true; + break; + } + + DialogLabelEditor* dialog = new DialogLabelEditor( parent, CurrentText, multiline ); // doing any post construction resizing is better done here than in // OnInitDialog() since it tends to flash/redraw the dialog less. @@ -35,8 +49,8 @@ int DialogLabelEditor::ShowModally( WinEDA_SchematicFrame* parent, SCH_TEXT * C -DialogLabelEditor::DialogLabelEditor( WinEDA_SchematicFrame* parent, SCH_TEXT* CurrentText ) : - DialogLabelEditor_Base( parent ) +DialogLabelEditor::DialogLabelEditor( WinEDA_SchematicFrame* parent, SCH_TEXT* CurrentText,bool multiline ) : + DialogLabelEditor_Base( parent,wxID_ANY,multiline ) { m_Parent = parent; m_CurrentText = CurrentText; @@ -67,6 +81,7 @@ void DialogLabelEditor::init() default: SetTitle( _( "Text Properties" ) ); + m_TextLabel->Disconnect(wxEVT_COMMAND_TEXT_ENTER , wxCommandEventHandler ( DialogLabelEditor::onEnterKey ), NULL, this); break; } @@ -111,6 +126,14 @@ void DialogLabelEditor::init() } } +/*! + * wxTE_PROCESS_ENTER event handler for m_TextLabel + */ + +void DialogLabelEditor::onEnterKey( wxCommandEvent& event ) +{ + TextPropertiesAccept( event ); +} /*! * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK @@ -132,12 +155,3 @@ void DialogLabelEditor::OnButtonCANCEL_Click( wxCommandEvent& event ) EndModal( -1 ); } -/*! - * wxTE_PROCESS_ENTER event handler for m_TextLabel - */ - -void DialogLabelEditor::onEnterKey( wxCommandEvent& event ) -{ - TextPropertiesAccept( event ); -} - diff --git a/eeschema/dialog_edit_label.h b/eeschema/dialog_edit_label.h index 60b1acd436..6346a9cd71 100644 --- a/eeschema/dialog_edit_label.h +++ b/eeschema/dialog_edit_label.h @@ -18,7 +18,7 @@ private: protected: // these are protected so that the static ShowModally() gets used. - DialogLabelEditor( WinEDA_SchematicFrame* parent, SCH_TEXT * CurrentText); + DialogLabelEditor( WinEDA_SchematicFrame* parent, SCH_TEXT * CurrentText, bool multiline); ~DialogLabelEditor(){}; @@ -35,7 +35,7 @@ public: private: void init( ); - void onEnterKey( wxCommandEvent& event ); + void onEnterKey( wxCommandEvent& event ); void OnButtonOKClick( wxCommandEvent& event ); void OnButtonCANCEL_Click( wxCommandEvent& event ); void TextPropertiesAccept( wxCommandEvent& event ); diff --git a/eeschema/dialog_edit_label_base.cpp b/eeschema/dialog_edit_label_base.cpp index c41b491bee..6069024ddf 100644 --- a/eeschema/dialog_edit_label_base.cpp +++ b/eeschema/dialog_edit_label_base.cpp @@ -9,7 +9,7 @@ /////////////////////////////////////////////////////////////////////////// -DialogLabelEditor_Base::DialogLabelEditor_Base( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) +DialogLabelEditor_Base::DialogLabelEditor_Base( wxWindow* parent, wxWindowID id, bool multiline, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); @@ -19,11 +19,18 @@ DialogLabelEditor_Base::DialogLabelEditor_Base( wxWindow* parent, wxWindowID id, wxBoxSizer* bSizer2; bSizer2 = new wxBoxSizer( wxVERTICAL ); - m_staticText1 = new wxStaticText( this, wxID_ANY, _("Text"), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticText1->Wrap( -1 ); + m_staticText1 = new wxStaticText( this, wxID_ANY, _("Text"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText1->Wrap( -1 ); bSizer2->Add( m_staticText1, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - m_TextLabel = new wxTextCtrl( this, wxID_VALUE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); + if (multiline) + { + m_TextLabel = new wxTextCtrl( this, wxID_VALUE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER | wxTE_MULTILINE ); + } + else + { + m_TextLabel = new wxTextCtrl( this, wxID_VALUE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); + } m_TextLabel->SetToolTip( _("Enter the text to be used within the schematic") ); bSizer2->Add( m_TextLabel, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); diff --git a/eeschema/dialog_edit_label_base.h b/eeschema/dialog_edit_label_base.h index 6cfbaf3493..8730323dac 100644 --- a/eeschema/dialog_edit_label_base.h +++ b/eeschema/dialog_edit_label_base.h @@ -56,7 +56,7 @@ class DialogLabelEditor_Base : public wxDialog public: - DialogLabelEditor_Base( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Text Editor"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 600,300 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + DialogLabelEditor_Base( wxWindow* parent, wxWindowID id = wxID_ANY, bool multiline = false, const wxString& title = _("Text Editor"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 600,300 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DialogLabelEditor_Base(); }; diff --git a/include/base_struct.h b/include/base_struct.h index c3cdd04347..c404f5b2c1 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -527,6 +527,10 @@ public: int aDisplayMode, GRFillMode aDisplay_mode = FILAIRE, EDA_Colors aAnchor_color = UNSPECIFIED_COLOR ); + wxSize DrawOneLine( WinEDA_DrawPanel* aPanel, wxDC* aDC, + const wxPoint& aOffset, EDA_Colors aColor, + int aDisplayMode, GRFillMode aDisplay_mode = FILAIRE, + EDA_Colors aAnchor_color = UNSPECIFIED_COLOR, wxString txt=wxString(),wxPoint pos=wxPoint(0,0) ); /** * Function HitTest * tests if the given wxPoint is within the bounds of this object. diff --git a/include/common.h b/include/common.h index ae8da53642..6e91933236 100644 --- a/include/common.h +++ b/include/common.h @@ -351,6 +351,11 @@ void PutValueInLocalUnits( wxTextCtrl& TextCtr, int Value, int ReturnValueFromTextCtrl( const wxTextCtrl& TextCtr, int Internal_Unit ); +/* return a String List from a string, whith a specific splitter*/ +//WX_DECLARE_LIST( wxString, StringList ); +//WX_DEFINE_LIST( StringList ); +wxArrayString* wxStringSplit(wxString txt, wxChar splitter); + /** * Function To_User_Unit * Convert in inch or mm the variable "val" (double)given in internal units diff --git a/include/wxstruct.h b/include/wxstruct.h index 625a8434d2..3635a21f63 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -398,7 +398,7 @@ public: // Constructor and destructor WinEDA_EnterText( wxWindow* parent, const wxString& Title, const wxString& TextToEdit, wxBoxSizer* BoxSizer, - const wxSize& Size ); + const wxSize& Size, bool Multiline = false ); ~WinEDA_EnterText() { diff --git a/pcbnew/dialog_pcb_text_properties.cpp b/pcbnew/dialog_pcb_text_properties.cpp index d8bad3732c..9d4ac242fb 100644 --- a/pcbnew/dialog_pcb_text_properties.cpp +++ b/pcbnew/dialog_pcb_text_properties.cpp @@ -107,7 +107,7 @@ WinEDA_TextPCBPropertiesFrame::WinEDA_TextPCBPropertiesFrame( WinEDA_PcbFrame* p m_Name = new WinEDA_EnterText( this, _( "Text:" ), TextPCB->m_Text, - LeftBoxSizer, wxSize( 200, -1 ) ); + LeftBoxSizer, wxSize( 200, 60 ),true ); m_Name->SetFocus(); m_Name->SetSelection( -1, -1 ); @@ -232,7 +232,7 @@ void WinEDA_TextPCBPropertiesFrame::OnOkClick( wxCommandEvent& event ) CurrentTextPCB->SetLayer( m_SelLayerBox->GetChoice() ); CurrentTextPCB->m_Italic = m_Style->GetSelection() ? 1 : 0; - if( m_DC ) // Displya new text + if( m_DC ) // Display new text { CurrentTextPCB->Draw( m_Parent->DrawPanel, m_DC, GR_OR ); }