Commit 6f7209aa authored by dickelbeck's avatar dickelbeck

start of new search stuff, beautification

parent abd187e3
......@@ -5,6 +5,12 @@ Please add newer entries at the top, list the date and your name with
email address.
2007-Aug-06 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
+ pcbnew & common
Started sketching out a new search architecture. To learn more:
look for "INSPECTOR" text in base_struct.h.
2007-Aug-05 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
......
......@@ -224,10 +224,46 @@ void EDA_BaseStruct::Show( int nestLevel, std::ostream& os )
std::ostream& EDA_BaseStruct::NestedSpace( int nestLevel, std::ostream& os )
{
for( int i=0; i<nestLevel; ++i )
os << ' '; // number of spaces here controls indent per nest level
os << " "; // number of spaces here controls indent per nest level
return os;
}
// see base_struct.h
SEARCH_RESULT EDA_BaseStruct::IterateForward( EDA_BaseStruct* listStart,
INSPECTOR* inspector, void* testData, const KICAD_T scanTypes[] )
{
EDA_BaseStruct* p = listStart;
for( ; p; p = p->Pnext )
{
if( SEARCH_QUIT == p->Traverse( inspector, testData, scanTypes ) )
return SEARCH_QUIT;
}
return SEARCH_CONTINUE;
}
// see base_struct.h
SEARCH_RESULT EDA_BaseStruct::Traverse( INSPECTOR* inspector, void* testData,
const KICAD_T scanTypes[] )
{
KICAD_T stype;
for( const KICAD_T* p = scanTypes; (stype=*p) != EOT; ++p )
{
// If caller wants to inspect my type
if( stype == m_StructType )
{
if( SEARCH_QUIT == inspector->Inspect( this, testData ) )
return SEARCH_QUIT;
break;
}
}
return SEARCH_CONTINUE;
}
#endif
......
......@@ -13,6 +13,9 @@
/* Id for class identification, at run time */
enum DrawStructureType {
EOT = 0, // search types array terminator (End Of Types)
TYPE_NOT_INIT = 0,
TYPEPCB,
......@@ -70,6 +73,49 @@ enum DrawStructureType {
};
#if defined(DEBUG) // new searching technique incubator
enum SEARCH_RESULT {
SEARCH_QUIT,
SEARCH_CONTINUE
};
typedef DrawStructureType KICAD_T; // shorter name
class EDA_BaseStruct;
/**
* Class INSPECTOR
* is an abstract class that is used to inspect and possibly collect the
* (search) results of Iterating over a list or tree of KICAD_T objects.
* Extend from this class and implment the Inspect function and provide for
* a way for the extension to collect the results of the search/scan data and
* provide them to the caller.
*/
class INSPECTOR
{
public:
virtual ~INSPECTOR() {}
/**
* Function Inspect
* is the function type that can be passed to the Iterate function,
* used primarily for searching, but not exclusively.
* @param testData is arbitrary data needed by the inspector to determine
* if the EDA_BaseStruct under test meets its match criteria.
* @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan,
* else SCAN_CONTINUE;
*/
SEARCH_RESULT virtual Inspect( EDA_BaseStruct* testItem,
void* testData ) = 0;
// derived classes add more functions for collecting and subsequent
// retrieval here.
};
#endif
/********************************************************************/
/* Classes de base: servent a deriver les classes reellement utiles */
/********************************************************************/
......@@ -139,6 +185,7 @@ public:
*/
virtual void Show( int nestLevel, std::ostream& os );
/**
* Function NestedSpace
* outputs nested space for pretty indenting.
......@@ -147,6 +194,60 @@ public:
* @return std::ostream& - for continuation.
**/
static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
/**
* Function IterateForward
* walks through the object tree calling the testFunc on each object
* type requested in structTypes.
*
* @param listStart The first in a list of EDA_BaseStructs to iterate over.
* @param inspector Is an INSPECTOR to call on each object that is of one of
* the requested itemTypes.
* @param testData Is an aid to testFunc, and should be sufficient to
* allow it to fully determine if an item meets the match criteria, but it
* may also be used to collect output.
* @param scanTypes Is a char array of KICAD_T that is EOT
* terminated, and provides both the order and interest level of of
* the types of objects to be iterated over.
* @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan,
* else SCAN_CONTINUE;
*/
static SEARCH_RESULT IterateForward( EDA_BaseStruct* listStart,
INSPECTOR* inspector, void* testData, const KICAD_T scanTypes[] );
/**
* Function Traverse
* should be re-implemented for each derrived class in order to handle
* all the types given by its member data. Implementations should call
* inspector->Inspect() on types in scanTypes[], and may use IterateForward()
* to do so on lists of such data.
* @param inspector An INSPECTOR instance to use in the inspection.
* @param testData Arbitrary data used by the inspector.
* @param scanTypes Which KICAD_T types are of interest and the order
* is significant too, terminated by EOT.
* @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan,
* else SCAN_CONTINUE;
*/
virtual SEARCH_RESULT Traverse( INSPECTOR* inspector, void* testData,
const KICAD_T scanTypes[] );
/**
* Function ListHas
* scans the given array and detects if the given type t is present.
* @param list An array of KICAD_T, terminated with EOT.
* @param t A KICAD_T to check for.
* @return bool - true if present, else false.
*/
static bool ListHas( const KICAD_T list[], KICAD_T t )
{
for( const KICAD_T* p = list; *p != EOT; ++p )
if( *p == t )
return true;
return false;
}
#endif
};
......
......@@ -242,6 +242,16 @@ public:
* @param os The ostream& to output to.
*/
virtual void Show( int nestLevel, std::ostream& os );
/**
* Function FindModuleOrPad
* searches for either a module or a pad, giving precedence to pads.
* @param refPos The wxPoint to hit-test.
* @return EDA_BaseStruct* - if a direct hit, else NULL.
*/
EDA_BaseStruct* FindModuleOrPad( const wxPoint& refPos );
#endif
};
......
......@@ -286,4 +286,62 @@ void BOARD::Show( int nestLevel, std::ostream& os )
NestedSpace( nestLevel, os ) << "</" << ReturnClassName().mb_str() << ">\n";
}
class ModuleOrPad : public INSPECTOR
{
public:
EDA_BaseStruct* found;
ModuleOrPad() :
found(0)
{
}
SEARCH_RESULT Inspect( EDA_BaseStruct* testItem, void* testData )
{
const wxPoint* refPos = (const wxPoint*) testData;
if( testItem->m_StructType == TYPEMODULE )
{
/* not finished
if( testItem->HitTest( &refPos ) )
{
found = testItem;
return SEARCH_QUIT;
}
*/
}
else if( testItem->m_StructType == TYPEPAD )
{
/* not finished
if( testItem->HitTest( &refPos ) )
{
found = testItem;
return SEARCH_QUIT;
}
*/
}
return SEARCH_CONTINUE;
}
};
// see pcbstruct.h
EDA_BaseStruct* BOARD::FindModuleOrPad( const wxPoint& refPos )
{
ModuleOrPad inspector;
static const KICAD_T scanTypes[] = { TYPEMODULE, TYPEPAD, EOT };
if( SEARCH_QUIT == IterateForward( m_Modules, &inspector, (void*) &refPos, scanTypes ) )
return inspector.found;
return NULL;
}
#endif
This diff is collapsed.
/**************************************************************/
/* class_edge_module.h : description des contours d'un module */
/**************************************************************/
/**************************************************************/
/* class_edge_module.h : description des contours d'un module */
/**************************************************************/
class Pcb3D_GLCanvas;
/* description des contours (empreintes ) et TYPES des CONTOURS : */
class EDGE_MODULE: public EDA_BaseLineStruct
{
public:
int m_Shape ; // voir "enum Track_Shapes"
class EDGE_MODULE : public EDA_BaseLineStruct
{
public:
int m_Shape; // voir "enum Track_Shapes"
wxPoint m_Start0; // coord relatives a l'ancre du point de depart(Orient 0)
wxPoint m_End0; // coord relatives a l'ancre du point de fin (Orient 0)
int m_Angle; // pour les arcs de cercle: longueur de l'arc en 0,1 degres
int m_PolyCount; // For polygons : number of points (> 2)
int * m_PolyList; // For polygons: coord list (1 point = 2 coord)
// Coord are relative to Origine, orient 0
int* m_PolyList; // For polygons: coord list (1 point = 2 coord)
// Coord are relative to Origin, orient 0
public:
EDGE_MODULE(MODULE * parent );
EDGE_MODULE(EDGE_MODULE * edge );
public:
EDGE_MODULE( MODULE* parent );
EDGE_MODULE( EDGE_MODULE* edge );
~EDGE_MODULE();
/* supprime du chainage la structure Struct */
void UnLink( void );
void Copy(EDGE_MODULE * source); // copy structure
void Copy( EDGE_MODULE* source ); // copy structure
/* Readind and writing data on files */
int WriteDescr( FILE * File );
int ReadDescr( char * Line, FILE * File, int * LineNum = NULL);
/* Reading and writing data on files */
int WriteDescr( FILE* File );
int ReadDescr( char* Line, FILE* File, int* LineNum = NULL );
// Mise a jour des coordonées pour l'affichage
void SetDrawCoord(void);
// Mise a jour des coordon�s pour l'affichage
void SetDrawCoord( void );
/* drawing functions */
void Draw(WinEDA_DrawPanel * panel, wxDC * DC, const wxPoint & offset,
int draw_mode);
void Draw3D(Pcb3D_GLCanvas * glcanvas);
void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
int draw_mode );
void Draw3D( Pcb3D_GLCanvas* glcanvas );
#if defined(DEBUG)
/**
* Function Show
* is used to output the object tree, currently for debugging only.
* @param nestLevel An aid to prettier tree indenting, and is the level
* of nesting of this object within the overall tree.
* @param os The ostream& to output to.
*/
virtual void Show( int nestLevel, std::ostream& os );
#endif
};
......@@ -208,7 +208,9 @@ void MODULE::Copy( MODULE* Module )
/* Copy des elements complementaires Drawings 3D */
m_3D_Drawings->Copy( Module->m_3D_Drawings );
Struct3D_Master* Struct3D, * NewStruct3D, * CurrStruct3D;
Struct3D = (Struct3D_Master*) Module->m_3D_Drawings->Pnext;
CurrStruct3D = m_3D_Drawings;
for( ; Struct3D != NULL; Struct3D = (Struct3D_Master*) Struct3D->Pnext )
......@@ -370,6 +372,7 @@ int MODULE::WriteDescr( FILE* File )
StringStat[0] = 'F';
else
StringStat[0] = '~';
if( m_ModuleStatus & MODULE_is_PLACED )
StringStat[1] = 'P';
else
......@@ -649,9 +652,9 @@ int MODULE::ReadDescr( FILE* File, int* LineNum )
Read_3D_Descr( File, LineNum );
}
if( strlen( Line ) < 4 )
continue;
PtLine = Line + 3;
/* Pointe 1er code utile de la ligne */
......@@ -811,13 +814,16 @@ void MODULE::SetPosition( const wxPoint& newpos )
int deltaY = newpos.y - m_Pos.y;
/* deplacement de l'ancre */
m_Pos.x += deltaX; m_Pos.y += deltaY;
m_Pos.x += deltaX;
m_Pos.y += deltaY;
/* deplacement de la reference */
m_Reference->m_Pos.x += deltaX; m_Reference->m_Pos.y += deltaY;
m_Reference->m_Pos.x += deltaX;
m_Reference->m_Pos.y += deltaY;
/* deplacement de la Valeur */
m_Value->m_Pos.x += deltaX; m_Value->m_Pos.y += deltaY;
m_Value->m_Pos.x += deltaX;
m_Value->m_Pos.y += deltaY;
/* deplacement des pastilles */
D_PAD* pad = m_Pads;
......@@ -1153,22 +1159,70 @@ void MODULE::Show( int nestLevel, std::ostream& os )
// for now, make it look like XML, expand on this later.
NestedSpace( nestLevel, os ) << '<' << ReturnClassName().mb_str() <<
" ref=\"" << m_Reference->m_Text.mb_str() <<
// " ref=\"" << m_Reference->m_Text.mb_str() <<
// "\" value=\"" << m_Value->m_Text.mb_str() << '"' <<
">\n";
EDA_BaseStruct* p;
p = m_Reference;
for( ; p; p = p->Pnext )
p->Show( nestLevel+1, os );
"\" value=\"" << m_Value->m_Text.mb_str() <<
"\">\n";
p = m_Value;
for( ; p; p = p->Pnext )
p->Show( nestLevel+1, os );
EDA_BaseStruct* p = m_Drawings;
p = m_Drawings;
for( ; p; p = p->Pnext )
p->Show( nestLevel+1, os );
EDA_BaseStruct* kid = m_Son;
for( ; kid; kid = kid->Pnext )
p = m_Son;
for( ; p; p = p->Pnext )
{
kid->Show( nestLevel+1, os );
p->Show( nestLevel+1, os );
}
NestedSpace( nestLevel, os ) << "</" << ReturnClassName().mb_str() << ">\n";
}
// see class_module.h
SEARCH_RESULT MODULE::Traverse( INSPECTOR* inspector, void* testData,
const KICAD_T scanTypes[] )
{
KICAD_T stype;
for( const KICAD_T* p = scanTypes; (stype=*p) != EOT; ++p )
{
// If caller wants to inspect my type
if( stype == m_StructType )
{
if( SEARCH_QUIT == inspector->Inspect( this, testData ) )
return SEARCH_QUIT;
}
else if( stype == TYPEEDGEMODULE )
{
// iterate over m_Drawings
if( SEARCH_QUIT == IterateForward( m_Drawings, inspector,
testData, scanTypes ) )
return SEARCH_QUIT;
}
else if( stype == TYPETEXTEMODULE )
{
// iterate over m_Reference
if( SEARCH_QUIT == IterateForward( m_Reference, inspector,
testData, scanTypes ) )
return SEARCH_QUIT;
// iterate over m_Value
if( SEARCH_QUIT == IterateForward( m_Value, inspector,
testData, scanTypes ) )
return SEARCH_QUIT;
}
}
return SEARCH_CONTINUE;
}
#endif
......@@ -142,6 +142,24 @@ public:
* @param os The ostream& to output to.
*/
virtual void Show( int nestLevel, std::ostream& os );
/**
* Function Traverse
* should be re-implemented for each derrived class in order to handle
* all the types given by its member data. Implementations should call
* inspector->Inspect() on types in scanTypes[], and may use IterateForward()
* to do so on lists of such data.
* @param inspector An INSPECTOR instance to use in the inspection.
* @param testData Arbitrary data used by the inspector.
* @param scanTypes Which KICAD_T types are of interest and the order
* is significant too, terminated by EOT.
* @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan,
* else SCAN_CONTINUE;
*/
virtual SEARCH_RESULT Traverse( INSPECTOR* inspector, void* testData,
const KICAD_T scanTypes[] );
#endif
};
/**********************************/
/* class_pad.h : Pads description */
/**********************************/
/**********************************/
/* class_pad.h : Pads description */
/**********************************/
class Pcb3D_GLCanvas;
......@@ -20,66 +20,77 @@ class Pcb3D_GLCanvas;
#define PAD_STACK 0x80 // bit 7 de .attrib (flag)
/* Definition type Structure d'un pad */
class D_PAD: public EDA_BaseStruct
class D_PAD : public EDA_BaseStruct
{
public:
union {
union
{
unsigned long m_NumPadName;
char m_Padname[4] ; /* nom (numero) de la pastille (assimilable a un long)*/
char m_Padname[4]; /* nom (numero) de la pastille (assimilable a un long)*/
};
wxString m_Netname; /* Net Name */
int m_Masque_Layer; // (Bit a Bit :1= cuivre, 15= cmp,
// 2..14 = interne
// 16 .. 31 = couches non cuivre
int m_PadShape; // forme CERCLE, RECT, OVALE, TRAPEZE ou libre
int m_DrillShape; // forme CERCLE, OVAL
wxPoint m_Pos; // Position de reference du pad
wxSize m_Drill; // Drill diam (drill shape = CIRCLE) or drill size(shape = OVAL)
// for drill shape = CIRCLE, drill diam = m_Drill.x
wxSize m_Offset; // Offset de la forme (pastilles excentrees)
wxSize m_Size; // Dimensions X et Y ( si orient 0 x = axe X
// y = axe Y
wxSize m_DeltaSize; // delta sur formes rectangle -> trapezes
wxPoint m_Pos0; // Coord relatives a l'ancre du pad en orientation 0
int m_Rayon; // rayon du cercle exinscrit du pad
int m_Attribut; // NORMAL, SMD, CONN, Bit 7 = STACK
int m_Orient ; // en 1/10 degres
int m_Orient; // en 1/10 degres
int m_NetCode; /* Numero de net pour comparaisons rapides */
int m_logical_connexion; // variable utilisee lors du calcul du chevelu:
// contient de numero de block pour une connexion type ratsnet
int m_physical_connexion; // variable utilisee lors du calcul de la connexité:
int m_physical_connexion; // variable utilisee lors du calcul de la connexit�
// contient de numero de block pour une connexion type piste
public:
D_PAD(MODULE * parent);
D_PAD(D_PAD * pad);
~D_PAD(void);
D_PAD( MODULE* parent );
D_PAD( D_PAD* pad );
~D_PAD( void );
void Copy(D_PAD * source);
D_PAD * Next(void)
{ return (D_PAD *) Pnext; }
void Copy( D_PAD* source );
D_PAD* Next( void ) { return (D_PAD*) Pnext; }
/* supprime du chainage la structure Struct */
void UnLink( void );
/* Readind and writing data on files */
int ReadDescr( FILE * File, int * LineNum = NULL);
int WriteDescr( FILE * File );
int ReadDescr( FILE* File, int* LineNum = NULL );
int WriteDescr( FILE* File );
/* drawing functions */
void Draw(WinEDA_DrawPanel * panel, wxDC * DC, const wxPoint & offset, int draw_mode);
void Draw3D(Pcb3D_GLCanvas * glcanvas);
void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode );
void Draw3D( Pcb3D_GLCanvas* glcanvas );
// autres
void SetPadName(const wxString & name); // Change pade name
wxString ReturnStringPadName(void); // Return pad name as string in a wxString
void ReturnStringPadName(wxString & text); // Return pad name as string in a buffer
void ComputeRayon(void); // met a jour m_Rayon, rayon du cercle exinscrit
const wxPoint ReturnShapePos(void); // retourne la position
void SetPadName( const wxString& name ); // Change pade name
wxString ReturnStringPadName( void ); // Return pad name as string in a wxString
void ReturnStringPadName( wxString& text ); // Return pad name as string in a buffer
void ComputeRayon( void ); // met a jour m_Rayon, rayon du cercle exinscrit
const wxPoint ReturnShapePos( void ); // retourne la position
// de la forme (pastilles excentrees)
void Display_Infos(WinEDA_BasePcbFrame * frame);
void Display_Infos( WinEDA_BasePcbFrame* frame );
};
typedef class D_PAD * LISTE_PAD;
......@@ -294,3 +294,23 @@ int TEXTE_MODULE::GetDrawRotation( void )
return rotation;
}
#if defined(DEBUG)
/**
* Function Show
* is used to output the object tree, currently for debugging only.
* @param nestLevel An aid to prettier tree indenting, and is the level
* of nesting of this object within the overall tree.
* @param os The ostream& to output to.
*/
void TEXTE_MODULE::Show( int nestLevel, std::ostream& os )
{
// for now, make it look like XML, expand on this later.
NestedSpace( nestLevel, os ) << '<' << ReturnClassName().mb_str() << ">\n";
NestedSpace( nestLevel+1, os ) << m_Text.mb_str() << '\n';
NestedSpace( nestLevel, os ) << "</" << ReturnClassName().mb_str() << ">\n";
}
#endif
......@@ -58,4 +58,16 @@ public:
* @return bool - true if a hit, else false
*/
bool HitTest( const wxPoint& posref );
#if defined(DEBUG)
/**
* Function Show
* is used to output the object tree, currently for debugging only.
* @param nestLevel An aid to prettier tree indenting, and is the level
* of nesting of this object within the overall tree.
* @param os The ostream& to output to.
*/
virtual void Show( int nestLevel, std::ostream& os );
#endif
};
......@@ -935,6 +935,7 @@ TRACK* Locate_Piste_Connectee( TRACK* PtRefSegm, TRACK* pt_base,
{
if( (PtSegmN == NULL) && (PtSegmB == NULL) )
break;
if( PtSegmN )
{
if( PtSegmN->GetState( BUSY | DELETED ) )
......@@ -1054,6 +1055,7 @@ TRACK* Locate_Pistes( TRACK* start_adresse, const wxPoint& ref_pos, int MasqueLa
continue;
if( (g_DesignSettings.m_LayerColor[Track->m_Layer] & ITEM_NOT_SHOW) )
continue;
/* calcul des coordonnees du segment teste */
l_piste = Track->m_Width >> 1; /* l_piste = demi largeur piste */
ux0 = Track->m_Start.x; uy0 = Track->m_Start.y; /* coord de depart */
......@@ -1074,7 +1076,8 @@ TRACK* Locate_Pistes( TRACK* start_adresse, const wxPoint& ref_pos, int MasqueLa
if( MasqueLayer != -1 )
if( (g_TabOneLayerMask[Track->m_Layer] & MasqueLayer) == 0 )
continue;/* Segments sur couches differentes */
continue; /* Segments sur couches differentes */
if( distance( l_piste ) )
return Track;
}
......@@ -1100,7 +1103,6 @@ TRACK* Locate_Pistes( TRACK* start_adresse, const wxPoint& ref_pos, int MasqueLa
*
* La recherche commence a l'adresse start_adresse
*/
TRACK* Locate_Zone( TRACK* start_adresse, int layer, int typeloc )
{
wxPoint ref_pos = RefPos( typeloc );
......@@ -1287,6 +1289,7 @@ int distance( int seuil )
angle = (int) ( atan2( (float) segY, (float) segX ) * 1800 / M_PI);
cXrot = pointX; cYrot = pointY;
RotatePoint( &cXrot, &cYrot, angle ); /* Rotation du point a tester */
RotatePoint( &segX, &segY, angle ); /* Rotation du segment */
......
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