From c7ec524fc755f87a6bff248730a2252ea308ee7d Mon Sep 17 00:00:00 2001 From: lifekidyeaa Date: Fri, 15 Feb 2008 23:21:33 +0000 Subject: [PATCH] eeschema: fixed: * crash when creating a sheet that does not yet have a sch file * when loading schematic file v 1 annotations are applied to all sheets independent of path in hierarchy * component reference is drawn by default upon placing a new libary comp. --- common/gr_basic.cpp | 1 + eeschema/class_drawsheet.cpp | 2 +- eeschema/component_class.cpp | 11 +++++++++++ eeschema/getpart.cpp | 2 ++ eeschema/menubar.cpp | 11 +++++------ eeschema/sheet.cpp | 16 ++++++++++------ 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/common/gr_basic.cpp b/common/gr_basic.cpp index 501fa5379a..a06d9ca5fa 100644 --- a/common/gr_basic.cpp +++ b/common/gr_basic.cpp @@ -62,6 +62,7 @@ static inline int USCALE( us arg, us num, us den ) static int inline ZoomValue( int value_to_zoom ) { int zoom = GET_ZOOM; + if( !zoom ) return 0; if( value_to_zoom >= 0 ) return ( value_to_zoom + (zoom >> 1 ) ) / zoom; diff --git a/eeschema/class_drawsheet.cpp b/eeschema/class_drawsheet.cpp index a32620a252..90d418307f 100644 --- a/eeschema/class_drawsheet.cpp +++ b/eeschema/class_drawsheet.cpp @@ -353,9 +353,9 @@ bool DrawSheetStruct::Load(WinEDA_SchematicFrame* frame) //do not need to load the sub-sheets - this has already been done. }else{ m_s = new SCH_SCREEN(SCHEMATIC_FRAME); + m_s->m_RefCount++; if(!frame->LoadOneEEFile(m_s, m_FileName)) return false; - m_s->m_RefCount++; EDA_BaseStruct* bs = m_s->EEDrawList; while(bs){ if(bs->Type() == DRAW_SHEET_STRUCT_TYPE){ diff --git a/eeschema/component_class.cpp b/eeschema/component_class.cpp index 726ab61f3f..e2b434c145 100644 --- a/eeschema/component_class.cpp +++ b/eeschema/component_class.cpp @@ -112,6 +112,15 @@ const wxString EDA_SchComponentStruct::GetRef( DrawSheetList* sheet ) return m_References[i]; } } + //if it was not found in m_Paths array, then see if it is in + // m_Field[REFERENCE] -- if so, use this as a default for this path. + // this will happen if we load a version 1 schematic file. + // it will also mean that multiple instances of the same sheet by default + // all have the same component references, but perhaps this is best. + if( !m_Field[REFERENCE].m_Text.IsEmpty() ){ + SetRef( sheet, m_Field[REFERENCE].m_Text ); + return m_Field[REFERENCE].m_Text; + } return m_PrefixString; } @@ -143,6 +152,8 @@ void EDA_SchComponentStruct::SetRef( DrawSheetList* sheet, wxString ref ) abs(m_Field[REFERENCE].m_Pos.y - m_Pos.y) > 1000)) { //move it to a reasonable position.. m_Field[REFERENCE].m_Pos = m_Pos; + m_Field[REFERENCE].m_Pos.x += 50; //a slight offset.. + m_Field[REFERENCE].m_Pos.y += 50; } m_Field[REFERENCE].m_Text = ref; //for drawing. } diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 8329dbcb45..f821524ea0 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -201,6 +201,8 @@ EDA_SchComponentStruct* WinEDA_SchematicFrame::Load_Component( wxDC* DC, if( msg.IsEmpty() ) msg = wxT( "U" ); msg += wxT( "?" ); + //update the reference -- just the prefix for now. + DrawLibItem->SetRef(GetSheet(), msg ); /* Init champ Reference */ DrawLibItem->m_Field[REFERENCE].m_Pos.x = diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp index 7cc7802780..932d445609 100644 --- a/eeschema/menubar.cpp +++ b/eeschema/menubar.cpp @@ -160,12 +160,11 @@ void WinEDA_SchematicFrame::ReCreateMenuBar() //TODO: Unify the ID names! wxMenu* placeMenu = new wxMenu; - item = new wxMenuItem( - placeMenu, - ID_COMPONENT_BUTT, - _( "&Component" ), - _( "Place the component" ) - ); + item = new wxMenuItem( + placeMenu, + ID_COMPONENT_BUTT, + _("&Component"), + _("Place a component") ); item->SetBitmap( add_component_xpm ); placeMenu->Append( item ); diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index da2c55b7de..87841338db 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -159,7 +159,7 @@ void WinEDA_SheetPropertiesFrame::CreateControls() itemBoxSizer3->Add( itemBoxSizer4, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); wxStaticText* itemStaticText5 = new wxStaticText( itemDialog1, wxID_STATIC, _( - "Filename:" ), wxDefaultPosition, + "Filename (will be created upon save if it does not already exist):" ), wxDefaultPosition, wxDefaultSize, 0 ); itemBoxSizer4->Add( itemStaticText5, 0, @@ -294,12 +294,9 @@ void WinEDA_SheetPropertiesFrame::SheetPropertiesAccept( wxCommandEvent& event ) if( wxFileExists( FileName ) )//do we reload the data from the existing file { - msg.Printf( _( "A file named %s exists, load it ?" ), FileName.GetData() ); + msg.Printf( _( "A file named %s exists, load it (otherwise overwrite it)?" ), FileName.GetData() ); if( IsOK( this, msg ) ) { - //LoadOneSheet clears the EEDrawList, - //we do not need to delete & recreate the SCH_SCREEN obj - m_CurrentSheet->m_FileName = FileName; if( m_CurrentSheet->m_s ){ m_CurrentSheet->m_s->m_RefCount--; if( m_CurrentSheet->m_s->m_RefCount == 0) @@ -308,7 +305,14 @@ void WinEDA_SheetPropertiesFrame::SheetPropertiesAccept( wxCommandEvent& event ) m_CurrentSheet->m_s = NULL; //so that we reload.. m_CurrentSheet->Load(m_Parent); } - } + }else{ + //just make a new screen if needed. + if( !m_CurrentSheet->m_s ){ + m_CurrentSheet->m_s = new SCH_SCREEN(SCHEMATIC_FRAME); + m_CurrentSheet->m_s->m_RefCount++; //be careful with these + m_CurrentSheet->m_s->m_FileName = FileName; + } + } } msg = m_FileNameSize->GetValue();