Commit 17cc6f49 authored by charras's avatar charras

eeschema: code cleaning, comments added, and the true number of sheets and...

eeschema: code cleaning, comments added, and the true number of sheets and sheets numbers in complex hierarchies
parent 79472a68
/******************************************/
/* drawpanel.cpp - WinEDA_DrawPanel class */
/******************************************/
#ifdef __GNUG__
#pragma implementation
#endif
#include "fctsys.h"
#include "common.h"
......@@ -580,10 +574,14 @@ void WinEDA_DrawPanel::EraseScreen( wxDC* DC )
}
//#define USE_GCDC_IN_KICAD
#ifdef USE_GCDC_IN_KICAD
#include <wx/dcgraph.h>
#if wxUSE_GRAPHICS_CONTEXT
// note: wxUSE_GRAPHICS_CONTEXT must be set to 1 in wxWidgets
// see setup.h in wx Widgets.
// wxWidgets configure can need option --enable-graphics_ctx
// Currently, **only for tests**
//#define USE_GCDC_IN_KICAD // uncommment it to use wxGCDC
#endif
/***************************************************/
void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event )
/***************************************************/
......
......@@ -15,6 +15,7 @@ set(EESCHEMA_SRCS
busentry.cpp
bus-wire-junction.cpp
class_drawsheet.cpp
class_drawsheetpath.cpp
class_hierarchical_PIN_sheet.cpp
class_libentry.cpp
class_libentry_fields.cpp
......
......@@ -55,7 +55,7 @@ void WinEDA_SchematicFrame::UpdateSheetNumberAndDate()
****************************************************************************/
void ReAnnotatePowerSymbolsOnly( void )
{
/* Build the screen list (screen, not sheet) */
/* Build the sheet list (sheet, not screen) */
EDA_SheetList SheetList( NULL );
DrawSheetPath* sheet;
......
This diff is collapsed.
......@@ -13,7 +13,11 @@
extern DrawSheetStruct* g_RootSheet;
/* class Hierarchical_PIN_Sheet_Struct
* a Hierarchical_PIN_Sheet_Struct is for a hierarchical sheet like a pin for a component
* At root level, a Hierarchical_PIN_Sheet_Struct must be connected to a wire, bus or label
* A sheet level it corresponds to a hierarchical label.
*/
class Hierarchical_PIN_Sheet_Struct : public SCH_ITEM,
public EDA_TextStruct
{
......@@ -26,7 +30,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() { }
......@@ -64,7 +68,6 @@ public:
/* class DrawSheetStruct
* This class is the sheet symbol placed in a schematic, and is the entry point for a sub schematic
*/
WX_DEFINE_ARRAY( DrawSheetStruct *, SheetGrowArray );
class DrawSheetStruct : public SCH_ITEM
{
......@@ -107,130 +110,95 @@ public:
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)
// comment inherited by Doxygen from Base_Struct
void Show( int nestLevel, std::ostream& os );
#endif
};
/**********************************************/
/* class to handle a series of sheets *********/
/* a 'path' so to speak.. *********************/
/**********************************************/
class DrawSheetPath
{
public:
int m_numSheets;
#define DSLSZ 32 // Max number of levels for a sheet path
DrawSheetStruct* m_sheets[DSLSZ];
DrawSheetPath();
~DrawSheetPath() { };
void Clear() { m_numSheets = 0; }
int Cmp( const DrawSheetPath& d ) const;
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
/** Function CleanupSheet
* Delete pinsheets which are not corresponding to a hierarchal label
* @param aRedraw = true to redraw Sheet
* @param aFrame = the schematic frame
*/
wxString Path();
void CleanupSheet( WinEDA_SchematicFrame* frame, bool aRedraw );
/** 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)
/** Function Draw
* Draw the hierarchical sheet shape
* @param aPanel = the current DrawPanel
* @param aDc = the current Device Context
* @param aOffset = draw offset (usually wxPoint(0,0))
* @param aDrawMode = draw mode
* @param aColor = color used to draw sheet. Usually -1 to use the normal color for sheet items
*/
wxString PathHumanReadable();
void Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset,
int aDrawMode, int aColor = -1 );
/**
* Function UpdateAllScreenReferences
* updates the reference and the m_Multi parameter (part selection) for all
* components on a screen depending on the actual sheet path.
* Mandatory in complex hierarchies because sheets use the same screen (basic schematic)
* but with different references and part selection according to the displayed sheet
/** Function GetBoundingBox
* @return an EDA_Rect giving the bouding box of the sheet
*/
void UpdateAllScreenReferences();
bool operator =( const DrawSheetPath& d1 );
bool operator ==( const DrawSheetPath& d1 );
bool operator !=( const DrawSheetPath& d1 );
};
EDA_Rect GetBoundingBox();
void SwapData( DrawSheetStruct* copyitem );
/** Function ComponentCount
* count our own components, without the power components.
* @return the copponent count.
*/
int ComponentCount();
/*******************************************************/
/* Class to handle the list of *Sheets* in a hierarchy */
/*******************************************************/
/** Function Load.
* for the sheet: load the file m_FileName
* if a screen already exists, the file is already read.
* m_AssociatedScreen point on the screen, and its m_RefCount is incremented
* else creates a new associated screen and load the data file.
* @param aFrame = a WinEDA_SchematicFrame pointer to the maim schematic frame
* @return true if OK
*/
bool Load( WinEDA_SchematicFrame* aFrame );
// sheets are not unique - can have many sheets with the same
// filename and the same SCH_SCREEN reference.
class EDA_SheetList
{
private:
DrawSheetPath* m_List;
int m_count; /* Number of sheets included in hierarchy,
* starting at the given sheet in constructor . the given sheet is counted
*/
int m_index;
DrawSheetPath m_currList;
/** Function SearchHierarchy
* search the existing hierarchy for an instance of screen "FileName".
* @param aFilename = the filename to find
* @param aFilename = a location to return a pointer to the screen (if found)
* @return bool if found, and a pointer to the screen
*/
bool SearchHierarchy( wxString aFilename, SCH_SCREEN** aScreen );
/** Function LocatePathOfScreen
* search the existing hierarchy for an instance of screen "FileName".
* don't bother looking at the root sheet - it must be unique,
* no other references to its m_AssociatedScreen otherwise there would be loops
* in the hierarchy.
* @param aScreen = the SCH_SCREEN* screen that we search for
* @param aList = the DrawSheetPath* that must be used
* @return true if found
*/
bool LocatePathOfScreen( SCH_SCREEN* aScreen, DrawSheetPath* aList );
int CountSheets();
wxString GetFileName( void );
public:
EDA_SheetList( DrawSheetStruct* sheet )
// Set a new filename without changing anything else
void SetFileName( const wxString& aFilename )
{
m_index = 0;
m_count = 0;
m_List = NULL;
if( sheet == NULL )
sheet = g_RootSheet;
BuildSheetList( sheet );
m_FileName = aFilename;
}
~EDA_SheetList()
{
if( m_List )
{
free( m_List );
}
m_List = NULL;
}
/** Function ChangeFileName
* Set a new filename and manage data and associated screen
* The main difficulty is the filename change in a complex hierarchy.
* - if new filename is not already used: change to the new name (and if an existing file is found, load it on request)
* - if new filename is already used (a complex hierarchy) : reference the sheet.
* @param aFileName = the new filename
* @param aFrame = the schematic frame
*/
bool ChangeFileName( WinEDA_SchematicFrame* aFrame, const wxString& aFileName );
//void RemoveSheet(DrawSheetStruct* sheet);
//to remove a sheet, just delete it
//-- the destructor should take care of everything else.
#if defined (DEBUG)
int GetCount() { return m_count; }
DrawSheetPath* GetFirst();
DrawSheetPath* GetNext();
DrawSheetPath* GetSheet( int index );
// comment inherited by Doxygen from Base_Struct
void Show( int nestLevel, std::ostream& os );
private:
void BuildSheetList( DrawSheetStruct* sheet );
#endif
};
#endif /* CLASS_DRAWSHEET_H */
/////////////////////////////////////////////////////////////////////////////
// Name: class_drawsheet.cpp
// Purpose: member functions for DrawSheetStruct
// header = class_drawsheet.h
// Author: jean-pierre Charras
// Modified by:
// Created: 08/02/2006 18:37:02
// RCS-ID:
// Copyright:
// Licence: License GNU
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "fctsys.h"
#include "common.h"
#include "program.h"
#include "libcmp.h"
#include "general.h"
/**********************************************/
/* class to handle a series of sheets *********/
/* a 'path' so to speak.. *********************/
/**********************************************/
DrawSheetPath::DrawSheetPath()
{
for( int i = 0; i<DSLSZ; i++ )
m_sheets[i] = NULL;
m_numSheets = 0;
}
int DrawSheetPath::Cmp( const DrawSheetPath& d ) const
{
if( m_numSheets > d.m_numSheets )
return 1;
if( m_numSheets < d.m_numSheets )
return -1;
//otherwise, same number of sheets.
for( int i = 0; i<m_numSheets; i++ )
{
if( m_sheets[i]->m_TimeStamp > d.m_sheets[i]->m_TimeStamp )
return 1;
if( m_sheets[i]->m_TimeStamp < d.m_sheets[i]->m_TimeStamp )
return -1;
}
return 0;
}
DrawSheetStruct* DrawSheetPath::Last()
{
if( m_numSheets )
return m_sheets[m_numSheets - 1];
return NULL;
}
SCH_SCREEN* DrawSheetPath::LastScreen()
{
if( m_numSheets )
return m_sheets[m_numSheets - 1]->m_AssociatedScreen;
return NULL;
}
EDA_BaseStruct* DrawSheetPath::LastDrawList()
{
if( m_numSheets && m_sheets[m_numSheets - 1]->m_AssociatedScreen )
return m_sheets[m_numSheets - 1]->m_AssociatedScreen->EEDrawList;
return NULL;
}
void DrawSheetPath::Push( DrawSheetStruct* sheet )
{
wxASSERT( m_numSheets <= DSLSZ );
if( m_numSheets < DSLSZ )
{
m_sheets[m_numSheets] = sheet;
m_numSheets++;
}
}
DrawSheetStruct* DrawSheetPath::Pop()
{
if( m_numSheets > 0 )
{
m_numSheets--;
return m_sheets[m_numSheets];
}
return NULL;
}
wxString DrawSheetPath::Path()
{
wxString s, t;
s = wxT( "/" );
//start at 1 to avoid the root sheet,
//which does not need to be added to the path
//it's timestamp changes anyway.
for( int i = 1; i< m_numSheets; i++ )
{
t.Printf( _( "%8.8lX/" ), m_sheets[i]->m_TimeStamp );
s = s + t;
}
return s;
}
wxString DrawSheetPath::PathHumanReadable()
{
wxString s, t;
s = wxT( "/" );
//start at 1 to avoid the root sheet, as above.
for( int i = 1; i< m_numSheets; i++ )
{
s = s + m_sheets[i]->m_SheetName + wxT( "/" );
}
return s;
}
/***********************************************/
void DrawSheetPath::UpdateAllScreenReferences()
/***********************************************/
{
EDA_BaseStruct* t = LastDrawList();
while( t )
{
if( t->Type() == TYPE_SCH_COMPONENT )
{
SCH_COMPONENT* component = (SCH_COMPONENT*) t;
component->GetField(REFERENCE)->m_Text = component->GetRef( this );
component->m_Multi = component->GetUnitSelection( this );
}
t = t->Next();
}
}
bool DrawSheetPath::operator=( const DrawSheetPath& d1 )
{
m_numSheets = d1.m_numSheets;
int i;
for( i = 0; i<m_numSheets; i++ )
{
m_sheets[i] = d1.m_sheets[i];
}
for( ; i<DSLSZ; i++ )
{
m_sheets[i] = 0;
}
return true;
}
bool DrawSheetPath::operator==( const DrawSheetPath& d1 )
{
if( m_numSheets != d1.m_numSheets )
return false;
for( int i = 0; i<m_numSheets; i++ )
{
if( m_sheets[i] != d1.m_sheets[i] )
return false;
}
return true;
}
bool DrawSheetPath::operator!=( const DrawSheetPath& d1 )
{
if( m_numSheets != d1.m_numSheets )
return true;
for( int i = 0; i<m_numSheets; i++ )
{
if( m_sheets[i] != d1.m_sheets[i] )
return true;
}
return false;
}
/*********************************************************************/
/* Class EDA_SheetList to handle the list of Sheets in a hierarchy */
/*********************************************************************/
/*****************************************/
DrawSheetPath* EDA_SheetList::GetFirst()
/*****************************************/
{
m_index = 0;
if( m_count > 0 )
return &( m_List[0] );
return NULL;
}
/*****************************************/
DrawSheetPath* EDA_SheetList::GetNext()
/*****************************************/
{
if( m_index < m_count )
m_index++;
return GetSheet( m_index );
}
/************************************************/
DrawSheetPath* EDA_SheetList::GetSheet( int index )
/************************************************/
/* return the m_List[index] item
*/
{
if( index < m_count )
return &(m_List[index]);
return NULL;
}
/************************************************************************/
void EDA_SheetList::BuildSheetList( DrawSheetStruct* sheet )
/************************************************************************/
{
if( m_List == NULL )
{
int count = sheet->CountSheets();
m_count = count;
m_index = 0;
count *= sizeof(DrawSheetPath);
m_List = (DrawSheetPath*) MyZMalloc( count );
m_currList.Clear();
}
m_currList.Push( sheet );
m_List[m_index] = m_currList;
m_index++;
if( sheet->m_AssociatedScreen != NULL )
{
EDA_BaseStruct* strct = m_currList.LastDrawList();
while( strct )
{
if( strct->Type() == DRAW_SHEET_STRUCT_TYPE )
{
DrawSheetStruct* sht = (DrawSheetStruct*) strct;
BuildSheetList( sht );
}
strct = strct->Next();
}
}
m_currList.Pop();
}
/********************************************/
/* Definitions for the EESchema program: */
/********************************************/
#ifndef CLASS_DRAWSHEET_PATH_H
#define CLASS_DRAWSHEET_PATH_H
#ifndef eda_global
#define eda_global extern
#endif
#include "base_struct.h"
/**********************************************/
/* class to handle a series of sheets *********/
/* a 'path' so to speak.. *********************/
/**********************************************/
class DrawSheetPath
{
public:
int m_numSheets;
#define DSLSZ 32 // Max number of levels for a sheet path
DrawSheetStruct* m_sheets[DSLSZ];
DrawSheetPath();
~DrawSheetPath() { };
void Clear() { m_numSheets = 0; }
int Cmp( const DrawSheetPath& d ) const;
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();
/** 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();
/**
* Function UpdateAllScreenReferences
* updates the reference and the m_Multi parameter (part selection) for all
* components on a screen depending on the actual sheet path.
* 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();
bool operator =( const DrawSheetPath& d1 );
bool operator ==( const DrawSheetPath& d1 );
bool operator !=( const DrawSheetPath& d1 );
};
/*******************************************************/
/* Class to handle the list of *Sheets* in a hierarchy */
/*******************************************************/
/* sheets are not unique - can have many sheets with the same
* filename and the same SCH_SCREEN reference.
* the schematic (SCH_SCREEN) is shared between these sheets,
* and component references are specific to a sheet path.
* When a sheet is entered, component references and sheet number are updated
*/
class EDA_SheetList
{
private:
DrawSheetPath* m_List;
int m_count; /* Number of sheets included in hierarchy,
* starting at the given sheet in constructor . the given sheet is counted
*/
int m_index;
DrawSheetPath m_currList;
public:
EDA_SheetList( DrawSheetStruct* sheet )
{
m_index = 0;
m_count = 0;
m_List = NULL;
if( sheet == NULL )
sheet = g_RootSheet;
BuildSheetList( sheet );
}
~EDA_SheetList()
{
if( m_List )
{
free( m_List );
}
m_List = NULL;
}
int GetCount() { return m_count; }
DrawSheetPath* GetFirst();
DrawSheetPath* GetNext();
DrawSheetPath* GetSheet( int index );
private:
void BuildSheetList( DrawSheetStruct* sheet );
};
#endif /* CLASS_DRAWSHEET_PATH_H */
......@@ -107,8 +107,8 @@ SCH_SCREEN::SCH_SCREEN( KICAD_T type ) : BASE_SCREEN( type )
for( i = 0; i < SCHEMATIC_GRID_LIST_CNT; i++ )
AddGrid( SchematicGridList[i] );
SetGrid( wxSize( 50, 50 ) ); /* pas de la grille */
m_UndoRedoCountMax = 10;
SetGrid( wxSize( 50, 50 ) ); /* usual grid size */
m_UndoRedoCountMax = 10; // Undo/redo levels count. 10 is a reasonnable value
m_RefCount = 0;
m_Center = false; // Suitable for schematic only. for libedit and viewlib, must be set to true
InitDatas();
......@@ -286,77 +286,3 @@ void EDA_ScreenList::BuildScreenList( EDA_BaseStruct* s )
}
}
/*********************************************************************/
/* Class EDA_SheetList to handle the list of Sheets in a hierarchy */
/*********************************************************************/
/*****************************************/
DrawSheetPath* EDA_SheetList::GetFirst()
/*****************************************/
{
m_index = 0;
if( m_count > 0 )
return &( m_List[0] );
return NULL;
}
/*****************************************/
DrawSheetPath* EDA_SheetList::GetNext()
/*****************************************/
{
if( m_index < m_count )
m_index++;
return GetSheet( m_index );
}
/************************************************/
DrawSheetPath* EDA_SheetList::GetSheet( int index )
/************************************************/
/* return the m_List[index] item
*/
{
if( index < m_count )
return &(m_List[index]);
return NULL;
}
/************************************************************************/
void EDA_SheetList::BuildSheetList( DrawSheetStruct* sheet )
/************************************************************************/
{
if( m_List == NULL )
{
int count = sheet->CountSheets();
m_count = count;
m_index = 0;
if( m_List )
free( m_List );
m_List = NULL;
count *= sizeof(DrawSheetPath);
m_List = (DrawSheetPath*) MyZMalloc( count );
memset( (void*) m_List, 0, count );
m_currList.Clear();
}
m_currList.Push( sheet );
m_List[m_index] = m_currList;
m_index++;
if( sheet->m_AssociatedScreen != NULL )
{
EDA_BaseStruct* strct = m_currList.LastDrawList();
while( strct )
{
if( strct->Type() == DRAW_SHEET_STRUCT_TYPE )
{
DrawSheetStruct* sht = (DrawSheetStruct*) strct;
BuildSheetList( sht );
}
strct = strct->Next();
}
}
m_currList.Pop();
}
......@@ -89,7 +89,7 @@ private:
public:
WinEDA_HierFrame( WinEDA_SchematicFrame* parent, wxDC* DC, const wxPoint& pos );
void BuildSheetList( DrawSheetPath* list, wxTreeItemId* previousmenu );
void BuildSheetsTree( DrawSheetPath* list, wxTreeItemId* previousmenu );
~WinEDA_HierFrame();
......@@ -150,7 +150,7 @@ WinEDA_HierFrame::WinEDA_HierFrame( WinEDA_SchematicFrame* parent, wxDC* DC,
m_Tree->SelectItem( cellule ); //root.
maxposx = 15;
BuildSheetList( &list, &cellule );
BuildSheetsTree( &list, &cellule );
if( m_nbsheets > 1 )
{
......@@ -180,7 +180,7 @@ void WinEDA_HierFrame::OnQuit( wxCommandEvent& WXUNUSED (event) )
/********************************************************************/
void WinEDA_HierFrame::BuildSheetList( DrawSheetPath* list,
void WinEDA_HierFrame::BuildSheetsTree( DrawSheetPath* list,
wxTreeItemId* previousmenu )
/********************************************************************/
......@@ -196,7 +196,7 @@ void WinEDA_HierFrame::BuildSheetList( DrawSheetPath* list,
if( m_nbsheets == (NB_MAX_SHEET + 1) )
{
wxString msg;
msg << wxT( "BuildSheetList: Error: nbsheets > " ) << NB_MAX_SHEET;
msg << wxT( "BuildSheetsTree: Error: nbsheets > " ) << NB_MAX_SHEET;
DisplayError( this, msg );
m_nbsheets++;
}
......@@ -229,7 +229,7 @@ void WinEDA_HierFrame::BuildSheetList( DrawSheetPath* list,
m_Tree->EnsureVisible( menu );
m_Tree->SelectItem( menu );
}
BuildSheetList( list, &menu );
BuildSheetsTree( list, &menu );
m_Tree->Expand( menu );
list->Pop();
}
......
......@@ -25,6 +25,7 @@ OBJECTS = eeschema.o\
class_sch_cmp_field.o\
classes_body_items.o\
class_drawsheet.o\
class_drawsheetpath.o\
class_pin.o\
class_hierarchical_PIN_sheet.o\
class_text-label.o\
......
......@@ -17,6 +17,7 @@
#include "component_class.h"
#include "class_screen.h"
#include "class_drawsheet.h"
#include "class_drawsheetpath.h"
#include "class_text-label.h"
#include "class_schematic_items.h"
......
This diff is collapsed.
......@@ -62,6 +62,7 @@ endif
SYSWXLIB = `$(WXWIN)/wx-config --libs gl`\
-lwxpng-$(LIBVERSION) -lwxjpeg-$(LIBVERSION) -lwxzlib-$(LIBVERSION) $(PYLIBS)
CC = gcc
.cpp.o:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment