2008-04-15 19:38:19 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Name: class_hierarchical_PIN_sheet.cpp
|
2009-11-04 20:46:53 +00:00
|
|
|
// Purpose: member functions SCH_SHEET_PIN
|
2009-11-03 13:26:31 +00:00
|
|
|
// header = class_drawsheet.h
|
2008-04-15 19:38:19 +00:00
|
|
|
// Author: jean-pierre Charras
|
|
|
|
// Modified by:
|
|
|
|
// Created: 08/02/2006 18:37:02
|
|
|
|
// RCS-ID:
|
|
|
|
// Copyright: License GNU
|
2009-11-03 13:26:31 +00:00
|
|
|
// License:
|
2008-04-15 19:38:19 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "drawtxt.h"
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************/
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET_PIN::SCH_SHEET_PIN( SCH_SHEET* parent,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxString& text ) :
|
2008-04-22 16:38:23 +00:00
|
|
|
SCH_ITEM( parent, DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ),
|
2008-04-15 19:38:19 +00:00
|
|
|
EDA_TextStruct( text )
|
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/*******************************************************************/
|
2008-04-22 16:38:23 +00:00
|
|
|
wxASSERT( parent );
|
|
|
|
wxASSERT( Pnext == NULL );
|
2008-12-29 18:02:54 +00:00
|
|
|
m_Layer = LAYER_SHEETLABEL;
|
|
|
|
m_Pos = pos;
|
|
|
|
m_Edge = 0;
|
|
|
|
m_Shape = NET_INPUT;
|
2008-04-15 19:38:19 +00:00
|
|
|
m_IsDangling = TRUE;
|
2008-12-29 18:02:54 +00:00
|
|
|
m_Number = 2;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************/
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET_PIN* SCH_SHEET_PIN::GenCopy()
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/***********************************************************/
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET_PIN* newitem =
|
|
|
|
new SCH_SHEET_PIN( (SCH_SHEET*) m_Parent, m_Pos, m_Text );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2008-12-29 18:02:54 +00:00
|
|
|
newitem->m_Edge = m_Edge;
|
|
|
|
newitem->m_Shape = m_Shape;
|
2008-04-15 19:38:19 +00:00
|
|
|
newitem->m_Number = m_Number;
|
|
|
|
|
|
|
|
return newitem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-30 19:21:41 +00:00
|
|
|
/** Function GetPenSize
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
int SCH_SHEET_PIN::GetPenSize()
|
2009-06-30 19:21:41 +00:00
|
|
|
{
|
|
|
|
return g_DrawDefaultLineThickness;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/*****************************************************************************/
|
2009-11-04 20:46:53 +00:00
|
|
|
void SCH_SHEET_PIN::Draw( WinEDA_DrawPanel* panel,
|
|
|
|
wxDC* DC,
|
|
|
|
const wxPoint& offset,
|
|
|
|
int DrawMode,
|
|
|
|
int Color )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Routine to create hierarchical labels */
|
|
|
|
GRTextHorizJustifyType side;
|
|
|
|
EDA_Colors txtcolor;
|
2009-05-05 18:25:47 +00:00
|
|
|
int posx, tposx, posy;
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2009-05-05 18:25:47 +00:00
|
|
|
static std::vector <wxPoint> Poly;
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
int LineWidth = GetPenSize();
|
2008-04-15 19:38:19 +00:00
|
|
|
|
|
|
|
if( Color >= 0 )
|
2008-12-29 18:02:54 +00:00
|
|
|
txtcolor = (EDA_Colors) Color;
|
2008-04-15 19:38:19 +00:00
|
|
|
else
|
|
|
|
txtcolor = ReturnLayerColor( m_Layer );
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
posx = m_Pos.x + offset.x;
|
|
|
|
posy = m_Pos.y + offset.y;
|
2009-05-05 18:25:47 +00:00
|
|
|
wxSize size = m_Size;
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
if( !m_Text.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( m_Edge )
|
|
|
|
{
|
|
|
|
tposx = posx - size.x;
|
|
|
|
side = GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tposx = posx + size.x + (size.x / 8);
|
|
|
|
side = GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
}
|
|
|
|
DrawGraphicText( panel, DC, wxPoint( tposx, posy ), txtcolor,
|
2009-11-03 13:26:31 +00:00
|
|
|
m_Text, TEXT_ORIENT_HORIZ, size, side,
|
|
|
|
GR_TEXT_VJUSTIFY_CENTER, LineWidth, false, false );
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
2009-05-05 18:25:47 +00:00
|
|
|
/* Draw the graphic symbol */
|
|
|
|
CreateGraphicShape( Poly, m_Pos + offset );
|
|
|
|
int FillShape = false;
|
|
|
|
GRPoly( &panel->m_ClipBox, DC, Poly.size(), &Poly[0],
|
2009-11-03 13:26:31 +00:00
|
|
|
FillShape, LineWidth, txtcolor, txtcolor );
|
2009-05-05 18:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** function CreateGraphicShape
|
|
|
|
* Calculates the graphic shape (a polygon) associated to the text
|
|
|
|
* @param aCorner_list = list to fill with polygon corners coordinates
|
|
|
|
* @param Pos = Position of the shape
|
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
void SCH_SHEET_PIN::CreateGraphicShape( std::vector <wxPoint>& aCorner_list,
|
|
|
|
const wxPoint& Pos )
|
2009-05-05 18:25:47 +00:00
|
|
|
{
|
|
|
|
wxSize size = m_Size;
|
|
|
|
|
|
|
|
aCorner_list.clear();
|
2008-04-15 19:38:19 +00:00
|
|
|
if( m_Edge )
|
|
|
|
{
|
|
|
|
size.x = -size.x;
|
|
|
|
size.y = -size.y;
|
|
|
|
}
|
|
|
|
|
2009-05-05 18:25:47 +00:00
|
|
|
int size2 = size.x / 2;
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2009-05-05 18:25:47 +00:00
|
|
|
aCorner_list.push_back( Pos );
|
2008-04-15 19:38:19 +00:00
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case 0: /* input |> */
|
2009-05-05 18:25:47 +00:00
|
|
|
aCorner_list.push_back( wxPoint( Pos.x, Pos.y - size2 ) );
|
|
|
|
aCorner_list.push_back( wxPoint( Pos.x + size2, Pos.y - size2 ) );
|
|
|
|
aCorner_list.push_back( wxPoint( Pos.x + size.x, Pos.y ) );
|
|
|
|
aCorner_list.push_back( wxPoint( Pos.x + size2, Pos.y + size2 ) );
|
|
|
|
aCorner_list.push_back( wxPoint( Pos.x, Pos.y + size2 ) );
|
|
|
|
aCorner_list.push_back( Pos );
|
2008-04-15 19:38:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* output <| */
|
2009-05-05 18:25:47 +00:00
|
|
|
aCorner_list.push_back( wxPoint( Pos.x + size2, Pos.y - size2 ) );
|
|
|
|
aCorner_list.push_back( wxPoint( Pos.x + size.x, Pos.y - size2 ) );
|
|
|
|
aCorner_list.push_back( wxPoint( Pos.x + size.x, Pos.y + size2 ) );
|
|
|
|
aCorner_list.push_back( wxPoint( Pos.x + size2, Pos.y + size2 ) );
|
|
|
|
aCorner_list.push_back( Pos );
|
2008-04-15 19:38:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* bidi <> */
|
|
|
|
case 3: /* TriSt <> */
|
2009-05-05 18:25:47 +00:00
|
|
|
aCorner_list.push_back( wxPoint( Pos.x + size2, Pos.y - size2 ) );
|
|
|
|
aCorner_list.push_back( wxPoint( Pos.x + size.x, Pos.y ) );
|
|
|
|
aCorner_list.push_back( wxPoint( Pos.x + size2, Pos.y + size2 ) );
|
|
|
|
aCorner_list.push_back( Pos );
|
2008-04-15 19:38:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* unsp []*/
|
2009-05-05 18:25:47 +00:00
|
|
|
aCorner_list.push_back( wxPoint( Pos.x, Pos.y - size2 ) );
|
|
|
|
aCorner_list.push_back( wxPoint( Pos.x + size.x, Pos.y - size2 ) );
|
|
|
|
aCorner_list.push_back( wxPoint( Pos.x + size.x, Pos.y + size2 ) );
|
|
|
|
aCorner_list.push_back( wxPoint( Pos.x, Pos.y + size2 ) );
|
|
|
|
aCorner_list.push_back( Pos );
|
2008-04-15 19:38:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
bool SCH_SHEET_PIN::Save( FILE* aFile ) const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
int type = 'U', side = 'L';
|
|
|
|
|
|
|
|
if( m_Text.IsEmpty() )
|
|
|
|
return true;
|
|
|
|
if( m_Edge )
|
|
|
|
side = 'R';
|
|
|
|
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case NET_INPUT:
|
|
|
|
type = 'I'; break;
|
|
|
|
|
|
|
|
case NET_OUTPUT:
|
|
|
|
type = 'O'; break;
|
|
|
|
|
|
|
|
case NET_BIDI:
|
|
|
|
type = 'B'; break;
|
|
|
|
|
|
|
|
case NET_TRISTATE:
|
|
|
|
type = 'T'; break;
|
|
|
|
|
|
|
|
case NET_UNSPECIFIED:
|
|
|
|
type = 'U'; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fprintf( aFile, "F%d \"%s\" %c %c %-3d %-3d %-3d\n", m_Number,
|
2009-11-03 13:26:31 +00:00
|
|
|
CONV_TO_UTF8( m_Text ), type, side, m_Pos.x, m_Pos.y,
|
2008-12-29 18:02:54 +00:00
|
|
|
m_Size.x ) == EOF )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
bool SCH_SHEET_PIN::Matches( wxFindReplaceData& aSearchData )
|
|
|
|
{
|
|
|
|
return SCH_ITEM::Matches( m_Text, aSearchData );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
#if defined(DEBUG)
|
2009-11-04 20:46:53 +00:00
|
|
|
void SCH_SHEET_PIN::Show( int nestLevel, std::ostream& os )
|
2008-04-22 16:38:23 +00:00
|
|
|
{
|
|
|
|
// XML output:
|
|
|
|
wxString s = GetClass();
|
|
|
|
|
|
|
|
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">"
|
2009-11-03 13:26:31 +00:00
|
|
|
<< " pin_name=\"" << CONV_TO_UTF8( m_Text )
|
|
|
|
<< '"' << "/>\n" << std::flush;
|
2008-04-22 16:38:23 +00:00
|
|
|
|
|
|
|
// NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n";
|
|
|
|
}
|
|
|
|
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
#endif
|