← Back to team overview

kicad-developers team mailing list archive

Re: EESchema XOR-Artifacts

 

Hi,

I have had a look at your changes, Dick, and added some Stuff for other 
objects (junctions and components).

I have attached a patch. Am I on the right track? If yes, commit my changes to 
svn please. If no, please give me some hints on what to improve.

I noticed that there are some functions GetBoundaryBox() (in classes 
PartTextStruct, EDA_LibComponentStruct, EDA_SchComponentStruct) which seem to 
have similar functionality. However, they are not exactly what I needed: 
EDA_SchComponentStruct, for instance, does only return the BBox of the 
component itself, not the associated text fields. So I have used that only 
for a basis of my EDA_SchComponentStruct::GetBoundingBox() and joined the 
BBoxes of the text field myself. Here, I cheated a bit to save calculating 
the boundary of pin ends... :-)

Best regards,
Jonas.
 --Boundary-00=_PZw2HxA9VY22csI Content-Type: text/x-diff;
charset="utf-8";
name="eeschema_redraw.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="eeschema_redraw.patch"

diff -r 8402af9e65ea -r ae89fdcc3b94 kicad/eeschema/block.cpp
--- a/kicad/eeschema/block.cpp	Fri Mar 14 18:17:05 2008 +0000
+++ b/kicad/eeschema/block.cpp	Sat Mar 15 00:05:48 2008 +0100
@@ -962,10 +962,12 @@ void DeleteStruct( WinEDA_DrawPanel* pan
{
screen->RemoveFromDrawList( DrawStruct );

- if( DrawStruct->Type() == DRAW_SEGMENT_STRUCT_TYPE )
+ if( (DrawStruct->Type() == DRAW_SEGMENT_STRUCT_TYPE) ||
+ (DrawStruct->Type() == DRAW_JUNCTION_STRUCT_TYPE) ||
+ (DrawStruct->Type() == DRAW_LIB_ITEM_STRUCT_TYPE) )
{
- D( printf("PostDirtyRect()\n"); )
- panel->PostDirtyRect( ((EDA_DrawLineStruct*)DrawStruct)->GetBoundingBox() );
+ D( printf("PostDirtyRect()\n") );
+ panel->PostDirtyRect( DrawStruct->GetBoundingBox() );
}
else
RedrawOneStruct( panel, DC, DrawStruct, g_XorMode );
diff -r 8402af9e65ea -r ae89fdcc3b94 kicad/eeschema/cmpclass.cpp
--- a/kicad/eeschema/cmpclass.cpp	Fri Mar 14 18:17:05 2008 +0000
+++ b/kicad/eeschema/cmpclass.cpp	Sat Mar 15 00:05:48 2008 +0100
@@ -257,7 +257,49 @@ EDA_Rect EDA_DrawLineStruct::GetBounding
return ret;
}

+EDA_Rect DrawJunctionStruct::GetBoundingBox() const
+{
+ int width = DRAWJUNCTION_SIZE * 2;
+ int xmin = m_Pos.x - DRAWJUNCTION_SIZE ;
+ int ymin = m_Pos.y - DRAWJUNCTION_SIZE;
+ 
+ EDA_Rect ret( wxPoint( xmin, ymin ), wxSize( width, width ) );

+ return ret;
+};
+
+
+EDA_Rect EDA_SchComponentStruct::GetBoundingBox() const
+{
+ const int PADDING = 40;
+ int xmin, xmax, ymin, ymax;
+ 
+ // This gives a reasonable approximation (but some things are missing so...
+ EDA_Rect ret = GetBoundaryBox();
+ xmin = ret.m_Pos.x;
+ ymin = ret.m_Pos.y;
+ xmax = ret.m_Pos.x + ret.m_Size.x;
+ ymax = ret.m_Pos.y + ret.m_Size.y;
+ 
+ // Include BoundingBoxes of fields
+ for(int i = REFERENCE; i < NUMBER_OF_FIELDS; i++ )
+ {
+ EDA_Rect box = m_Field[i].GetBoundaryBox();
+ xmin = MIN( xmin, box.m_Pos.x);
+ ymin = MIN( ymin, box.m_Pos.y);
+ xmax = MAX( xmax, box.m_Pos.x + box.m_Size.x);
+ ymax = MAX( ymax, box.m_Pos.y + box.m_Size.y);
+ }
+ 
+ // ... add padding TODO: improve this
+ ret.m_Pos.x = xmin - PADDING;
+ ret.m_Pos.y = ymin - PADDING;
+ ret.m_Size.x = xmax - xmin + 2*PADDING;
+ ret.m_Size.y = ymax - ymin + 2*PADDING;
+ 
+ D( printf("final box: %d,%d, %d,%d\n", ret.m_Pos.x, ret.m_Pos.y, ret.m_Size.x, ret.m_Size.y) );
+ return ret;
+}

/****************************/
/* Class DrawPolylineStruct */
diff -r 8402af9e65ea -r ae89fdcc3b94 kicad/eeschema/component_class.cpp
--- a/kicad/eeschema/component_class.cpp	Fri Mar 14 18:17:05 2008 +0000
+++ b/kicad/eeschema/component_class.cpp	Sat Mar 15 00:05:48 2008 +0100
@@ -234,7 +234,7 @@ EDA_SchComponentStruct::EDA_SchComponent

/************************************************/
-EDA_Rect EDA_SchComponentStruct::GetBoundaryBox()
+EDA_Rect EDA_SchComponentStruct::GetBoundaryBox() const
/************************************************/
{
EDA_LibComponentStruct* Entry = FindLibPart( m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
@@ -733,7 +733,7 @@ bool PartTextStruct::IsVoid()


/********************************************/
-EDA_Rect PartTextStruct::GetBoundaryBox()
+EDA_Rect PartTextStruct::GetBoundaryBox() const
/********************************************/

/* return
diff -r 8402af9e65ea -r ae89fdcc3b94 kicad/eeschema/component_class.h
--- a/kicad/eeschema/component_class.h	Fri Mar 14 18:17:05 2008 +0000
+++ b/kicad/eeschema/component_class.h	Sat Mar 15 00:05:48 2008 +0100
@@ -59,7 +59,7 @@ public:
void PartTextCopy( PartTextStruct* target );
void Place( WinEDA_DrawFrame* frame, wxDC* DC );

- EDA_Rect GetBoundaryBox();
+ EDA_Rect GetBoundaryBox() const;
bool IsVoid();
void SwapData( PartTextStruct* copyitem );
};
@@ -123,8 +123,9 @@ public:
wxPoint GetScreenCoord( const wxPoint& coord );
void Display_Infos( WinEDA_DrawFrame* frame );
void ClearAnnotation();
- EDA_Rect GetBoundaryBox();
-
+ EDA_Rect GetBoundaryBox() const;
+ virtual EDA_Rect GetBoundingBox() const;
+ 
const wxString& ReturnFieldName( int aFieldNdx ) const;


diff -r 8402af9e65ea -r ae89fdcc3b94 kicad/eeschema/program.h
--- a/kicad/eeschema/program.h	Fri Mar 14 18:17:05 2008 +0000
+++ b/kicad/eeschema/program.h	Sat Mar 15 00:05:48 2008 +0100
@@ -96,7 +96,7 @@ public:
* Function GetBoundingBox
* returns the bounding box of this TRACK
*/
- EDA_Rect GetBoundingBox() const;
+ virtual EDA_Rect GetBoundingBox() const;

virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode,
int Color = -1 );
@@ -234,6 +234,11 @@ public:
return wxT( "DrawJunction" );
}

+ /**
+ * Function GetBoundingBox
+ * returns the bounding box of this junction
+ */
+ virtual EDA_Rect GetBoundingBox() const;

DrawJunctionStruct* GenCopy();
virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
diff -r 8402af9e65ea -r ae89fdcc3b94 kicad/include/base_struct.h
--- a/kicad/include/base_struct.h	Fri Mar 14 18:17:05 2008 +0000
+++ b/kicad/include/base_struct.h	Sat Mar 15 00:05:48 2008 +0100
@@ -125,6 +125,77 @@ public:
};


+
+/**
+ * Class EDA_Rect
+ * handles the component boundary box.
+ * This class is similar to wxRect, but some wxRect functions are very curious,
+ * so I prefer this suitable class
+ */
+class EDA_Rect
+{
+ public:
+ wxPoint m_Pos; // Rectangle Origin
+ wxSize m_Size; // Rectangle Size
+
+ public:
+ EDA_Rect() { };
+ EDA_Rect( const wxPoint& aPos, const wxSize& aSize ) :
+ m_Pos( aPos ), m_Size( aSize )
+ {}
+
+ wxPoint Centre()
+ {
+ return wxPoint( m_Pos.x + (m_Size.x >> 1), m_Pos.y + (m_Size.y >> 1) );
+ }
+
+
+ void Normalize(); // Ensure the height and width are >= 0
+ bool Inside( const wxPoint& point ); // Return TRUE if point is in Rect
+
+ bool Inside( int x, int y ) { return Inside( wxPoint( x, y ) ); }
+ wxSize GetSize() { return m_Size; }
+ int GetX() { return m_Pos.x; }
+ int GetY() { return m_Pos.y; }
+ wxPoint GetOrigin() { return m_Pos; }
+ wxPoint GetPosition() { return m_Pos; }
+ wxPoint GetEnd() { return wxPoint( GetRight(), GetBottom() ); }
+ int GetWidth() { return m_Size.x; }
+ int GetHeight() { return m_Size.y; }
+ int GetRight() { return m_Pos.x + m_Size.x; }
+ int GetBottom() { return m_Pos.y + m_Size.y; }
+ void SetOrigin( const wxPoint& pos ) { m_Pos = pos; }
+ void SetOrigin( int x, int y ) { m_Pos.x = x; m_Pos.y = y; }
+ void SetSize( const wxSize& size ) { m_Size = size; }
+ void SetSize( int w, int h ) { m_Size.x = w; m_Size.y = h; }
+ void Offset( int dx, int dy ) { m_Pos.x += dx; m_Pos.y += dy; }
+ void Offset( const wxPoint& offset ) { m_Pos.x += offset.x; m_Pos.y += offset.y; }
+ void SetX( int val ) { m_Pos.x = val; }
+ void SetY( int val ) { m_Pos.y = val; }
+ void SetWidth( int val ) { m_Size.x = val; }
+ void SetHeight( int val ) { m_Size.y = val; }
+ void SetEnd( const wxPoint& pos )
+ {
+ m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y;
+ }
+
+ /**
+ * Function Intersects
+ * @return bool - true if the argument rectangle intersects this rectangle.
+ */
+ bool Intersects( const EDA_Rect aRect ) const;
+
+
+ /**
+ * Function operator(wxRect)
+ * overloads the cast operator to return a wxRect
+ */
+ operator wxRect() const { return wxRect( m_Pos, m_Size ); }
+
+ EDA_Rect& Inflate( wxCoord dx, wxCoord dy );
+};
+
+
/********************************************************************/
/* Classes de base: servent a deriver les classes reellement utiles */
/********************************************************************/
@@ -268,6 +339,17 @@ public:
return false; // derived classes should override this function
}

+ /**
+ * Function GetBoundingBox
+ * returns the bounding box of this struct. 
+ * This box should include any visible components of the struct. It is OK to overestimate (TODO: really?)
+ */
+ virtual EDA_Rect GetBoundingBox( void ) const
+ {
+ // return a zero-sized box per default. derived classes should override this
+ EDA_Rect ret( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
+ return ret;
+ }

/**
* Function IterateForward
@@ -414,7 +496,7 @@ public:
virtual ~EDA_TextStruct();
void CreateDrawData();

- int GetLength() { return m_Text.Length(); };
+ int GetLength() const { return m_Text.Length(); };

/** Function Pitch()
* @return distance between 2 caracteres
@@ -600,74 +682,4 @@ public:
DrawPickedStruct* Next() { return (DrawPickedStruct*) Pnext; }
};

-
-/**
- * Class EDA_Rect
- * handles the component boundary box.
- * This class is similar to wxRect, but some wxRect functions are very curious,
- * so I prefer this suitable class
- */
-class EDA_Rect
-{
-public:
- wxPoint m_Pos; // Rectangle Origin
- wxSize m_Size; // Rectangle Size
-
-public:
- EDA_Rect() { };
- EDA_Rect( const wxPoint& aPos, const wxSize& aSize ) :
- m_Pos( aPos ), m_Size( aSize )
- {}
-
- wxPoint Centre()
- {
- return wxPoint( m_Pos.x + (m_Size.x >> 1), m_Pos.y + (m_Size.y >> 1) );
- }
-
-
- void Normalize(); // Ensure the height and width are >= 0
- bool Inside( const wxPoint& point ); // Return TRUE if point is in Rect
-
- bool Inside( int x, int y ) { return Inside( wxPoint( x, y ) ); }
- wxSize GetSize() { return m_Size; }
- int GetX() { return m_Pos.x; }
- int GetY() { return m_Pos.y; }
- wxPoint GetOrigin() { return m_Pos; }
- wxPoint GetPosition() { return m_Pos; }
- wxPoint GetEnd() { return wxPoint( GetRight(), GetBottom() ); }
- int GetWidth() { return m_Size.x; }
- int GetHeight() { return m_Size.y; }
- int GetRight() { return m_Pos.x + m_Size.x; }
- int GetBottom() { return m_Pos.y + m_Size.y; }
- void SetOrigin( const wxPoint& pos ) { m_Pos = pos; }
- void SetOrigin( int x, int y ) { m_Pos.x = x; m_Pos.y = y; }
- void SetSize( const wxSize& size ) { m_Size = size; }
- void SetSize( int w, int h ) { m_Size.x = w; m_Size.y = h; }
- void Offset( int dx, int dy ) { m_Pos.x += dx; m_Pos.y += dy; }
- void Offset( const wxPoint& offset ) { m_Pos.x += offset.x; m_Pos.y += offset.y; }
- void SetX( int val ) { m_Pos.x = val; }
- void SetY( int val ) { m_Pos.y = val; }
- void SetWidth( int val ) { m_Size.x = val; }
- void SetHeight( int val ) { m_Size.y = val; }
- void SetEnd( const wxPoint& pos )
- {
- m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y;
- }
-
- /**
- * Function Intersects
- * @return bool - true if the argument rectangle intersects this rectangle.
- */
- bool Intersects( const EDA_Rect aRect ) const;
-
-
- /**
- * Function operator(wxRect)
- * overloads the cast operator to return a wxRect
- */
- operator wxRect() const { return wxRect( m_Pos, m_Size ); }
-
- EDA_Rect& Inflate( wxCoord dx, wxCoord dy );
-};
-
#endif /* BASE_STRUCT_H */
 --Boundary-00=_PZw2HxA9VY22csI-- 




Follow ups

References