From 0ac832f0660af022992f897185170a7c27c3088b Mon Sep 17 00:00:00 2001 From: charras Date: Wed, 30 Apr 2008 17:04:22 +0000 Subject: [PATCH] screen number and screen count now are set --- change_log.txt | 1 + eeschema/annotate.cpp | 38 +++------------ eeschema/class_drawsheet.cpp | 8 ++- eeschema/class_drawsheet.h | 95 ++++++++++++++++++------------------ eeschema/class_screen.cpp | 2 - eeschema/files-io.cpp | 3 +- eeschema/hierarch.cpp | 1 + eeschema/save_schemas.cpp | 25 ++++++---- eeschema/schframe.cpp | 26 ++++++++++ include/class_screen.h | 33 ++++++------- include/wxEeschemaStruct.h | 8 +++ todo.txt | 11 ----- 12 files changed, 128 insertions(+), 123 deletions(-) diff --git a/change_log.txt b/change_log.txt index f30053d068..e9868cc7be 100644 --- a/change_log.txt +++ b/change_log.txt @@ -10,6 +10,7 @@ email address. ================================================================================ +eeschema: made in some dialogs the ESC key working (linux version, already working under windows) + screen number and screen count now are set 2008-Apr-29 UPDATE Dick Hollenbeck diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp index a855474bbf..9459aa0de5 100644 --- a/eeschema/annotate.cpp +++ b/eeschema/annotate.cpp @@ -22,45 +22,23 @@ static int ExistUnit( CmpListStruct* Objet, int Unit, CmpListStruct* BaseListeCmp, int NbOfCmp ); -/************************************************/ +/******************************************************/ void WinEDA_SchematicFrame::UpdateSheetNumberAndDate() -/************************************************/ +/******************************************************/ /* Set a sheet number, the sheet count for sheets in the whole schematic * and update the date in all screens */ { wxString date = GenDate(); - int sheet_number = 1; // sheet 1 is the root sheet - DrawSheetPath* sheetpath; + EDA_ScreenList s_list; - /* Build the sheet list */ - EDA_SheetList SheetList( g_RootSheet ); - int sheet_count = SheetList.GetCount(); + // Set the date + for ( SCH_SCREEN * screen = s_list.GetFirst(); screen != NULL; screen = s_list.GetNext() ) + screen->m_Date = date; - for( sheetpath = SheetList.GetFirst(); - sheetpath != NULL; - sheetpath = SheetList.GetNext() ) - { - // Read all sheets in path, but not the root sheet (jj = 1) - for( int jj = 1; jj < sheetpath->m_numSheets; jj++ ) - { - DrawSheetStruct* sheet = sheetpath->m_sheets[jj]; - sheet->m_SheetNumber = sheet_number++; - sheet->m_NumberOfSheets = sheet_count; - SCH_SCREEN* screen = sheet->m_AssociatedScreen; - if( screen != NULL ) - { - screen->m_NumberOfScreen = sheet_count; - screen->m_Date = date; - } - } - } - - g_RootSheet->m_AssociatedScreen->m_Date = date; - g_RootSheet->m_AssociatedScreen->m_NumberOfScreen = sheet_count; - g_RootSheet->m_SheetNumber = 1; - g_RootSheet->m_NumberOfSheets = sheet_count; + // Set sheet counts + SetSheetNumberAndCount(); } diff --git a/eeschema/class_drawsheet.cpp b/eeschema/class_drawsheet.cpp index c28566eb04..09fec5b837 100644 --- a/eeschema/class_drawsheet.cpp +++ b/eeschema/class_drawsheet.cpp @@ -47,8 +47,6 @@ DrawSheetStruct::DrawSheetStruct( const wxPoint& pos ) : m_AssociatedScreen = NULL; m_SheetName.Printf( wxT( "Sheet%8.8lX" ), m_TimeStamp ); m_FileName.Printf( wxT( "file%8.8lX.sch" ), m_TimeStamp ); - m_SheetNumber = 1; - m_NumberOfSheets = 1; } @@ -277,7 +275,7 @@ void DrawSheetStruct::CleanupSheet( WinEDA_SchematicFrame* aFrame, bool aRedraw } Pinsheet = NextPinsheet; } - + if( aRedraw ) aFrame->DrawPanel->PostDirtyRect( GetBoundingBox() ); @@ -499,9 +497,9 @@ bool DrawSheetStruct::Load( WinEDA_SchematicFrame* frame ) } -/*******************************************************************************/ +/**********************************/ int DrawSheetStruct::CountSheets() -/*******************************************************************************/ +/**********************************/ { int count = 1; //1 = this!! diff --git a/eeschema/class_drawsheet.h b/eeschema/class_drawsheet.h index 80851bb836..069eb96ee7 100644 --- a/eeschema/class_drawsheet.h +++ b/eeschema/class_drawsheet.h @@ -26,7 +26,7 @@ public: public: Hierarchical_PIN_Sheet_Struct( DrawSheetStruct* parent, const wxPoint& pos = wxPoint( 0, 0 ), - const wxString& text = wxEmptyString ); + const wxString& text = wxEmptyString ); ~Hierarchical_PIN_Sheet_Struct() { } @@ -36,13 +36,13 @@ public: } - Hierarchical_PIN_Sheet_Struct* GenCopy(); + Hierarchical_PIN_Sheet_Struct* GenCopy(); Hierarchical_PIN_Sheet_Struct* Next() { return (Hierarchical_PIN_Sheet_Struct*) Pnext; } - void Place( WinEDA_SchematicFrame* frame, wxDC* DC ); - void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, - int draw_mode, int Color = -1 ); + void Place( WinEDA_SchematicFrame* frame, wxDC* DC ); + void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, + int draw_mode, int Color = -1 ); /** * Function Save @@ -50,11 +50,13 @@ public: * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ - bool Save( FILE* aFile ) const; + bool Save( FILE* aFile ) const; + +#if defined (DEBUG) -#if defined(DEBUG) // comment inherited by Doxygen from Base_Struct - void Show( int nestLevel, std::ostream& os ); + void Show( int nestLevel, std::ostream& os ); + #endif }; @@ -64,7 +66,7 @@ public: */ WX_DEFINE_ARRAY( DrawSheetStruct *, SheetGrowArray ); -class DrawSheetStruct : public SCH_ITEM /*public SCH_SCREEN*/ /* Gestion de la hierarchie */ +class DrawSheetStruct : public SCH_ITEM /* Gestion de la hierarchie */ { public: wxString m_SheetName; /*this is equivalent to C101 for components: @@ -75,7 +77,6 @@ private: * reading the sheet description from file. */ public: int m_SheetNameSize; /* Size (height) of the text, used to draw the name */ - int m_FileNameSize; /* Size (height) of the text, used to draw the name */ wxPoint m_Pos; wxSize m_Size; /* Position and Size of sheet symbol */ @@ -85,8 +86,6 @@ public: SCH_SCREEN* m_AssociatedScreen; /* Associated Screen which handle the physical data * In complex hierarchies we can have many DrawSheetStruct using the same data */ - int m_SheetNumber; // sheet number (used for info) - int m_NumberOfSheets; // Sheets count in the whole schematic (used for info) public: DrawSheetStruct( const wxPoint& pos = wxPoint( 0, 0 ) ); @@ -103,32 +102,34 @@ public: * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ - bool Save( FILE* aFile ) const; + bool Save( FILE* aFile ) const; - void Place( WinEDA_SchematicFrame* frame, wxDC* DC ); - DrawSheetStruct* GenCopy(); - void Display_Infos( WinEDA_DrawFrame* frame ); - void CleanupSheet( WinEDA_SchematicFrame* frame, bool aRedraw ); - virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, - int draw_mode, int Color = -1 ); - EDA_Rect GetBoundingBox(); - void SwapData( DrawSheetStruct* copyitem ); - int ComponentCount(); - bool Load( WinEDA_SchematicFrame* frame ); - bool SearchHierarchy( wxString filename, SCH_SCREEN** screen ); //search the existing hierarchy for an instance of screen "FileName". - bool LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetPath* list ); - int CountSheets(); - wxString GetFileName( void ); - void SetFileName( const wxString& aFilename ); // Set a new filename without changing anything else - bool ChangeFileName( WinEDA_SchematicFrame* aFrame, const wxString& aFileName ); // Set a new filename and manage data and associated screen + void Place( WinEDA_SchematicFrame* frame, wxDC* DC ); + DrawSheetStruct* GenCopy(); + void Display_Infos( WinEDA_DrawFrame* frame ); + void CleanupSheet( WinEDA_SchematicFrame* frame, bool aRedraw ); + virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, + int draw_mode, int Color = -1 ); + EDA_Rect GetBoundingBox(); + void SwapData( DrawSheetStruct* copyitem ); + int ComponentCount(); + bool Load( WinEDA_SchematicFrame* frame ); + bool SearchHierarchy( wxString filename, SCH_SCREEN** screen ); //search the existing hierarchy for an instance of screen "FileName". + bool LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetPath* list ); + int CountSheets(); + wxString GetFileName( void ); + void SetFileName( const wxString& aFilename ); // Set a new filename without changing anything else + bool ChangeFileName( WinEDA_SchematicFrame* aFrame, const wxString& aFileName ); // Set a new filename and manage data and associated screen //void RemoveSheet(DrawSheetStruct* sheet); //to remove a sheet, just delete it //-- the destructor should take care of everything else. -#if defined(DEBUG) +#if defined (DEBUG) + // comment inherited by Doxygen from Base_Struct - void Show( int nestLevel, std::ostream& os ); + void Show( int nestLevel, std::ostream& os ); + #endif }; @@ -147,25 +148,25 @@ public: DrawSheetPath(); ~DrawSheetPath() { }; void Clear() { m_numSheets = 0; } - int Cmp( DrawSheetPath& d ); - DrawSheetStruct* Last(); - SCH_SCREEN* LastScreen(); - EDA_BaseStruct* LastDrawList(); - void Push( DrawSheetStruct* sheet ); - DrawSheetStruct* Pop(); + int Cmp( DrawSheetPath& d ); + DrawSheetStruct* Last(); + SCH_SCREEN* LastScreen(); + EDA_BaseStruct* LastDrawList(); + void Push( DrawSheetStruct* sheet ); + DrawSheetStruct* Pop(); /** Function Path * the path uses the time stamps which do not changes even when editing sheet parameters * a path is something like / (root) or /34005677 or /34005677/00AE4523 */ - wxString Path(); + wxString Path(); /** Function PathHumanReadable * Return the sheet path in a readable form, i.e. * as a path made from sheet names. * (the "normal" path uses the time stamps which do not changes even when editing sheet parameters) */ - wxString PathHumanReadable(); + wxString PathHumanReadable(); /** Function UpdateAllScreenReferences * Update the reference and the m_Multi parameter (part selection) for all components on a screen @@ -173,13 +174,13 @@ public: * Mandatory in complex hierarchies because sheets use the same screen (basic schematic) * but with different references and part selection according to the displayed sheet */ - void UpdateAllScreenReferences(); + void UpdateAllScreenReferences(); - bool operator =( const DrawSheetPath& d1 ); + bool operator =( const DrawSheetPath& d1 ); - bool operator ==( const DrawSheetPath& d1 ); + bool operator ==( const DrawSheetPath& d1 ); - bool operator !=( const DrawSheetPath& d1 ); + bool operator !=( const DrawSheetPath& d1 ); }; @@ -222,12 +223,12 @@ public: int GetCount() { return m_count; } - DrawSheetPath* GetFirst(); - DrawSheetPath* GetNext(); - DrawSheetPath* GetSheet( int index ); + DrawSheetPath* GetFirst(); + DrawSheetPath* GetNext(); + DrawSheetPath* GetSheet( int index ); private: - void BuildSheetList( DrawSheetStruct* sheet ); + void BuildSheetList( DrawSheetStruct* sheet ); }; #endif /* CLASS_DRAWSHEET_H */ diff --git a/eeschema/class_screen.cpp b/eeschema/class_screen.cpp index c5ecf4200d..1ebbea6e3b 100644 --- a/eeschema/class_screen.cpp +++ b/eeschema/class_screen.cpp @@ -91,8 +91,6 @@ SCH_SCREEN::SCH_SCREEN( int screentype, KICAD_T aType ) : SetGridList( g_GridList ); m_UndoRedoCountMax = 10; m_RefCount = 0; - m_ScreenNumber = 1; - m_NumberOfScreen = 1; } diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index abb12b8cb9..b969522be1 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -152,7 +152,6 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, bool IsNe { screen->m_CurrentSheetDesc = &g_Sheet_A4; screen->SetZoom( 32 ); - screen->m_ScreenNumber = screen->m_NumberOfScreen = 1; screen->m_Title = wxT( "noname.sch" ); GetScreen()->m_FileName = screen->m_Title; screen->m_Company.Empty(); @@ -162,6 +161,7 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, bool IsNe screen->m_Commentaire4.Empty(); Read_Config( wxEmptyString, TRUE ); Zoom_Automatique( TRUE ); + SetSheetNumberAndCount(); ReDrawPanel(); return 1; } @@ -226,6 +226,7 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, bool IsNe /* Reaffichage ecran de base (ROOT) si necessaire */ ActiveScreen = GetScreen(); Zoom_Automatique( FALSE ); + SetSheetNumberAndCount(); DrawPanel->Refresh( TRUE ); return diag; } diff --git a/eeschema/hierarch.cpp b/eeschema/hierarch.cpp index 213308dd06..e3592e3c25 100644 --- a/eeschema/hierarch.cpp +++ b/eeschema/hierarch.cpp @@ -316,6 +316,7 @@ static bool UpdateScreenFromSheet(WinEDA_SchematicFrame * frame) //update the References frame->m_CurrentSheet->UpdateAllScreenReferences(); + frame->SetSheetNumberAndCount(); frame->DrawPanel->m_CanStartBlock = -1; ActiveScreen = frame->m_CurrentSheet->LastScreen(); if ( NewScreen->m_FirstRedraw ){ diff --git a/eeschema/save_schemas.cpp b/eeschema/save_schemas.cpp index 3206d00d5e..ccdf9efcad 100644 --- a/eeschema/save_schemas.cpp +++ b/eeschema/save_schemas.cpp @@ -66,7 +66,7 @@ bool WinEDA_SchematicFrame::SaveEEFile( SCH_SCREEN* screen, int FileSave ) this, wxFD_SAVE, FALSE - ); + ); if( Name.IsEmpty() ) return FALSE; @@ -115,9 +115,9 @@ bool SCH_SCREEN::Save( FILE* aFile ) const * @return bool - true if success writing else false. */ { - const wxChar** LibNames; - wxString Name, msg; - Ki_PageDescr* PlotSheet; + const wxChar** LibNames; + wxString Name, msg; + Ki_PageDescr* PlotSheet; LibNames = GetLibNames(); for( int ii = 0; LibNames[ii] != NULL; ii++ ) @@ -145,7 +145,12 @@ bool SCH_SCREEN::Save( FILE* aFile ) const fprintf( aFile, "$Descr %s %d %d\n", CONV_TO_UTF8( PlotSheet->m_Name ), PlotSheet->m_Size.x, PlotSheet->m_Size.y ); + /* Write ScreenNumber and NumberOfScreen; not very meaningfull for SheetNumber and Sheet Count + * in a complex hierarchy, but usefull in simple hierarchy and flat hierarchy + * Used also to serach the root sheet ( ScreenNumber = 1 ) withing the files + */ fprintf( aFile, "Sheet %d %d\n", m_ScreenNumber, m_NumberOfScreen ); + fprintf( aFile, "Title \"%s\"\n", CONV_TO_UTF8( m_Title ) ); fprintf( aFile, "Date \"%s\"\n", CONV_TO_UTF8( m_Date ) ); fprintf( aFile, "Rev \"%s\"\n", CONV_TO_UTF8( m_Revision ) ); @@ -159,7 +164,7 @@ bool SCH_SCREEN::Save( FILE* aFile ) const /* Saving schematic items */ bool failed = FALSE; - for( SCH_ITEM* item = EEDrawList; item; item=item->Next() ) + for( SCH_ITEM* item = EEDrawList; item; item = item->Next() ) { switch( item->Type() ) { @@ -179,11 +184,11 @@ bool SCH_SCREEN::Save( FILE* aFile ) const failed = TRUE; break; - /* - case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE: - case DRAW_PICK_ITEM_STRUCT_TYPE: - break; - */ + /* + * case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE: + * case DRAW_PICK_ITEM_STRUCT_TYPE: + * break; + */ default: break; diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index d643dc0fee..71bbdf644a 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -201,6 +201,32 @@ DrawSheetPath* WinEDA_SchematicFrame::GetSheet() } +/****************************************************/ +void WinEDA_SchematicFrame::SetSheetNumberAndCount() +/****************************************************/ +/** Function SetSheetNumberAndCount + * Set the m_ScreenNumber and m_NumberOfScreen members for screens + * must be called after a delete or add sheet command, ans when entering a sheet + */ +{ + SCH_SCREEN* screen = GetScreen(); + EDA_ScreenList s_list; + + /* Set the screen count, and the screen number (1 for root sheet) + */ + int screen_num = 2; + for ( screen = s_list.GetFirst(); screen != NULL; screen = s_list.GetNext() ) + { + if ( screen == g_RootSheet->m_AssociatedScreen ) + screen->m_ScreenNumber = 1; + else + screen->m_ScreenNumber = screen_num++; + screen->m_NumberOfScreen = s_list.GetCount(); + } +} + + + SCH_SCREEN* WinEDA_SchematicFrame::GetScreen() const { return m_CurrentSheet->LastScreen(); diff --git a/include/class_screen.h b/include/class_screen.h index 98f3c84a66..5f95e6bee5 100644 --- a/include/class_screen.h +++ b/include/class_screen.h @@ -19,10 +19,8 @@ class SCH_SCREEN : public BASE_SCREEN { public: - int m_RefCount; //how many sheets reference this screen? - //delete when it goes to zero. - int m_ScreenNumber; - int m_NumberOfScreen; + int m_RefCount; /*how many sheets reference this screen? + * delete when it goes to zero. */ SCH_SCREEN( int idtype, KICAD_T aType = SCREEN_STRUCT_TYPE ); ~SCH_SCREEN(); @@ -47,29 +45,30 @@ public: } - void FreeDrawList(); // Free EESchema drawing list (does not delete the sub hierarchies) + void FreeDrawList(); // Free EESchema drawing list (does not delete the sub hierarchies) void Place( WinEDA_SchematicFrame* frame, wxDC* DC ) { }; - void RemoveFromDrawList( SCH_ITEM* DrawStruct ); /* remove DrawStruct from EEDrawList. */ - bool CheckIfOnDrawList( SCH_ITEM* st ); - void AddToDrawList( SCH_ITEM* DrawStruct ); - void ClearUndoORRedoList( EDA_BaseStruct* List ); + void RemoveFromDrawList( SCH_ITEM* DrawStruct ); /* remove DrawStruct from EEDrawList. */ + bool CheckIfOnDrawList( SCH_ITEM* st ); + void AddToDrawList( SCH_ITEM* DrawStruct ); + void ClearUndoORRedoList( EDA_BaseStruct* List ); - bool SchematicCleanUp( wxDC* DC = NULL ); - SCH_ITEM* ExtractWires( bool CreateCopy ); + bool SchematicCleanUp( wxDC* DC = NULL ); + SCH_ITEM* ExtractWires( bool CreateCopy ); /* full undo redo management : */ - virtual void ClearUndoRedoList(); - virtual void AddItemToUndoList( EDA_BaseStruct* item ); - virtual void AddItemToRedoList( EDA_BaseStruct* item ); + virtual void ClearUndoRedoList(); + virtual void AddItemToUndoList( EDA_BaseStruct* item ); + virtual void AddItemToRedoList( EDA_BaseStruct* item ); + /** * Function Save * writes the data structures for this object out to a FILE in "*.brd" format. * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ - bool Save( FILE* aFile ) const; + bool Save( FILE* aFile ) const; }; @@ -94,8 +93,8 @@ public: SCH_SCREEN* GetScreen( unsigned int index ); private: - void AddScreenToList( SCH_SCREEN* testscreen ); - void BuildScreenList( EDA_BaseStruct* sheet ); + void AddScreenToList( SCH_SCREEN* testscreen ); + void BuildScreenList( EDA_BaseStruct* sheet ); }; #endif /* CLASS_SCREEN_H */ diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 1c8f31e430..c71ca391a9 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -112,10 +112,18 @@ public: void InstallPreviousSheet(); void InstallNextScreen( DrawSheetStruct* Sheet ); + /** Function SetSheetNumberAndCount + * Set the m_ScreenNumber and m_NumberOfScreen members for screens + * must be called after a delete or add sheet command, and when entering a sheet + */ + void SetSheetNumberAndCount(); + + // Plot functions: void ToPlot_PS( wxCommandEvent& event ); void ToPlot_HPGL( wxCommandEvent& event ); void ToPostProcess( wxCommandEvent& event ); + // read and save files void Save_File( wxCommandEvent& event ); void SaveProject(); int LoadOneEEProject( const wxString& FileName, bool IsNew ); diff --git a/todo.txt b/todo.txt index a014a7d269..0102882815 100644 --- a/todo.txt +++ b/todo.txt @@ -85,15 +85,4 @@ asked by: Dick Hollenbeck loaded board. I think the number of layers should be reduced to the default and the default layer names should be used. -2008-Apr-30 Assigned To: -asked by: Dick Hollenbeck -================================================================================ -+eeschema - This line in eeschema/save_schemas.cpp is using m_ScreenNumber == 1 - regardless. - fprintf( aFile, "Sheet %d %d\n", m_ScreenNumber, m_NumberOfScreen ); - The field m_ScreenNumber needs to be updated based on where - the sheet is in the hierarchy. Until this is fixed, the code which checks - for "Sheet 1 " in kicad/treeprj_frame.cpp is broken and the project manager - is showing all *.sch files, not just the top most *.sch files.