KiCad PCB EDA Suite
SHAPE Class Referenceabstract

SHAPE. More...

#include <shape.h>

Inheritance diagram for SHAPE:
SHAPE_BASE SHAPE_ARC SHAPE_CIRCLE SHAPE_COMPOUND SHAPE_LINE_CHAIN_BASE SHAPE_NULL SHAPE_POLY_SET SHAPE_RECT SHAPE_SEGMENT

Public Member Functions

 SHAPE (SHAPE_TYPE aType)
 Constructor. More...
 
virtual ~SHAPE ()
 
virtual SHAPEClone () const
 Function Clone() More...
 
bool IsNull () const
 Function IsNull() More...
 
virtual bool Collide (const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr) const
 Function Collide() More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const
 Function Collide() More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance=0, int *aActual=nullptr) const
 
virtual bool Collide (const SEG &aSeg, int aClearance=0, int *aActual=nullptr) const =0
 Function Collide() More...
 
virtual const BOX2I BBox (int aClearance=0) const =0
 Function BBox() More...
 
virtual VECTOR2I Centre () const
 Function Centre() More...
 
virtual void Rotate (double aAngle, const VECTOR2I &aCenter={ 0, 0 })=0
 Function Rotate. More...
 
virtual void Move (const VECTOR2I &aVector)=0
 
virtual bool IsSolid () const =0
 
virtual bool Parse (std::stringstream &aStream)
 
virtual const std::string Format () const
 
 ~SHAPE ()
 
FACETNewFacet ()
 
SGNODECalcShape (SGNODE *aParent, SGNODE *aColor, WRL1_ORDER aVertexOrder, float aCreaseLimit=0.74317, bool isVRML2=false)
 
SHAPE_TYPE Type () const
 Function Type() More...
 
virtual bool HasIndexableSubshapes () const
 
virtual size_t GetIndexableSubshapeCount ()
 
virtual void GetIndexableSubshape (SHAPE_BASE &aSubshape) const
 

Protected Types

typedef VECTOR2I::extended_type ecoord
 

Protected Attributes

SHAPE_TYPE m_type
 

type of our shape

More...
 

Private Attributes

std::list< FACET * > facets
 

Detailed Description

SHAPE.

Represents an abstract shape on 2D plane.

Definition at line 120 of file shape.h.

Member Typedef Documentation

◆ ecoord

Definition at line 123 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE()

SHAPE::SHAPE ( SHAPE_TYPE  aType)
inline

Constructor.

Creates an empty shape of type aType

Definition at line 132 of file shape.h.

132  : SHAPE_BASE( aType )
133  {}
SHAPE_BASE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:83

◆ ~SHAPE() [1/2]

SHAPE::~SHAPE ( )
inlinevirtual

Definition at line 136 of file shape.h.

137  {}

◆ ~SHAPE() [2/2]

SHAPE::~SHAPE ( )

Member Function Documentation

◆ BBox()

virtual const BOX2I SHAPE::BBox ( int  aClearance = 0) const
pure virtual

Function BBox()

Computes a bounding box of the shape, with a margin of aClearance a collision.

Parameters
aClearancehow much the bounding box is expanded wrs to the minimum enclosing rectangle for the shape.
Returns
the bounding box.

Implemented in SHAPE_POLY_SET, SHAPE_LINE_CHAIN, SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI, SHAPE_SIMPLE, SHAPE_ARC, SHAPE_RECT, SHAPE_COMPOUND, SHAPE_CIRCLE, SHAPE_NULL, and SHAPE_SEGMENT.

Referenced by PNS::INDEX::Add(), boundingBox(), Centre(), PNS::ARC::ChangedArea(), PNS::VIA::ChangedArea(), SHAPE_INDEX_LIST< PNS::ITEM * >::Query(), SHAPE_INDEX< T >::Query(), SHAPE_INDEX_LIST< T, >::query_iterator::query_iterator(), SHAPE_INDEX_LIST< T, >::SHAPE_ENTRY::SHAPE_ENTRY(), and ROUTER_PREVIEW_ITEM::ViewBBox().

◆ CalcShape()

SGNODE * SHAPE::CalcShape ( SGNODE aParent,
SGNODE aColor,
WRL1_ORDER  aVertexOrder,
float  aCreaseLimit = 0.74317,
bool  isVRML2 = false 
)

Definition at line 713 of file wrlfacet.cpp.

715 {
716  if( facets.empty() || !facets.front()->HasMinPoints() )
717  return NULL;
718 
719  std::vector< std::list< FACET* > > flist;
720 
721  // determine the max. index and size flist as appropriate
722  std::list< FACET* >::iterator sF = facets.begin();
723  std::list< FACET* >::iterator eF = facets.end();
724 
725  int maxIdx = 0;
726  int tmi;
727  float maxV = 0.0;
728  float tV = 0.0;
729 
730  while( sF != eF )
731  {
732  tV = (*sF)->CalcFaceNormal();
733  tmi = (*sF)->GetMaxIndex();
734 
735  if( tmi > maxIdx )
736  maxIdx = tmi;
737 
738  if( tV > maxV )
739  maxV = tV;
740 
741  ++sF;
742  }
743 
744  ++maxIdx;
745 
746  if( maxIdx < 3 )
747  return NULL;
748 
749  flist.resize( maxIdx );
750 
751  // create the lists of facets common to indices
752  sF = facets.begin();
753 
754  while( sF != eF )
755  {
756  (*sF)->Renormalize( tV );
757  (*sF)->CollectVertices( flist );
758  ++sF;
759  }
760 
761  // calculate the normals
762  size_t vs = flist.size();
763 
764  for( size_t i = 0; i < vs; ++i )
765  {
766  sF = flist[i].begin();
767  eF = flist[i].end();
768 
769  while( sF != eF )
770  {
771  (*sF)->CalcVertexNormal( i, flist[i], aCreaseLimit );
772  ++sF;
773  }
774  }
775 
776  std::vector< WRLVEC3F > vertices;
777  std::vector< WRLVEC3F > normals;
778  std::vector< SGCOLOR > colors;
779 
780  // push the facet data to the final output list
781  sF = facets.begin();
782  eF = facets.end();
783 
784  while( sF != eF )
785  {
786  (*sF)->GetData( vertices, normals, colors, aVertexOrder );
787  ++sF;
788  }
789 
790  flist.clear();
791 
792  if( vertices.size() < 3 )
793  return NULL;
794 
795  IFSG_SHAPE shapeNode( false );
796 
797  if( !isVRML2 )
798  {
799  shapeNode.NewNode( aParent );
800 
801  if( aColor )
802  {
803  if( NULL == S3D::GetSGNodeParent( aColor ) )
804  shapeNode.AddChildNode( aColor );
805  else
806  shapeNode.AddRefNode( aColor );
807  }
808  }
809 
810  std::vector< SGPOINT > lCPts; // vertex points in SGPOINT (double) format
811  std::vector< SGVECTOR > lCNorm; // per-vertex normals
812  vs = vertices.size();
813 
814  for( size_t i = 0; i < vs; ++i )
815  {
816  SGPOINT pt;
817  pt.x = vertices[i].x;
818  pt.y = vertices[i].y;
819  pt.z = vertices[i].z;
820  lCPts.push_back( pt );
821  lCNorm.emplace_back( normals[i].x, normals[i].y, normals[i].z );
822  }
823 
824  vertices.clear();
825  normals.clear();
826 
827  IFSG_FACESET fsNode( false );
828 
829  if( !isVRML2 )
830  fsNode.NewNode( shapeNode );
831  else
832  fsNode.NewNode( aParent );
833 
834  IFSG_COORDS cpNode( fsNode );
835  cpNode.SetCoordsList( lCPts.size(), &lCPts[0] );
836  IFSG_COORDINDEX ciNode( fsNode );
837 
838  for( int i = 0; i < (int)lCPts.size(); ++i )
839  ciNode.AddIndex( i );
840 
841  IFSG_NORMALS nmNode( fsNode );
842  nmNode.SetNormalList( lCNorm.size(), &lCNorm[0] );
843 
844  if( !colors.empty() )
845  {
846  IFSG_COLORS nmColor( fsNode );
847  nmColor.SetColorList( colors.size(), &colors[0] );
848  colors.clear();
849  }
850 
851  if( !isVRML2 )
852  return shapeNode.GetRawPtr();
853 
854  return fsNode.GetRawPtr();
855 }
double x
Definition: sg_base.h:70
IFSG_COORDS is the wrapper for SGCOORDS.
Definition: ifsg_coords.h:40
IFSG_COORDINDEX is the wrapper for SGCOORDINDEX.
IFSG_COLORS is the wrapper for SGCOLORS.
Definition: ifsg_colors.h:41
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:636
double y
Definition: sg_base.h:71
IFSG_NORMALS is the wrapper for the SGNORMALS class.
Definition: ifsg_normals.h:40
#define NULL
std::list< FACET * > facets
Definition: wrlfacet.h:143
IFSG_FACESET is the wrapper for the SGFACESET class.
Definition: ifsg_faceset.h:40
double z
Definition: sg_base.h:72
static VRML_COLOR colors[VRML_COLOR_LAST]
IFSG_SHAPE is the wrapper for the SGSHAPE class.
Definition: ifsg_shape.h:40

References IFSG_NODE::AddChildNode(), IFSG_INDEX::AddIndex(), IFSG_NODE::AddRefNode(), colors, facets, IFSG_NODE::GetRawPtr(), S3D::GetSGNodeParent(), IFSG_FACESET::NewNode(), IFSG_SHAPE::NewNode(), NULL, IFSG_COLORS::SetColorList(), IFSG_COORDS::SetCoordsList(), IFSG_NORMALS::SetNormalList(), SGPOINT::x, SGPOINT::y, and SGPOINT::z.

Referenced by WRL1FACESET::TranslateToSG(), X3DIFACESET::TranslateToSG(), and WRL2FACESET::TranslateToSG().

◆ Centre()

virtual VECTOR2I SHAPE::Centre ( ) const
inlinevirtual

Function Centre()

Computes a center-of-mass of the shape

Returns
the center-of-mass point

Definition at line 220 of file shape.h.

221  {
222  return BBox( 0 ).Centre(); // if nothing better is available....
223  }
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
Vec Centre() const
Definition: box2.h:79

References BBox(), and BOX2< Vec >::Centre().

Referenced by PNS_PCBNEW_RULE_RESOLVER::CollideHoles().

◆ Clone()

virtual SHAPE* SHAPE::Clone ( ) const
inlinevirtual

Function Clone()

Returns a dynamically allocated copy of the shape

Return values
copyof the shape

Reimplemented in SHAPE_POLY_SET, SHAPE_LINE_CHAIN, SHAPE_RECT, SHAPE_SIMPLE, SHAPE_ARC, SHAPE_CIRCLE, SHAPE_SEGMENT, SHAPE_NULL, and SHAPE_COMPOUND.

Definition at line 146 of file shape.h.

147  {
148  assert( false );
149  return NULL;
150  };
#define NULL

References NULL.

Referenced by PNS::SOLID::SOLID(), and ROUTER_PREVIEW_ITEM::Update().

◆ Collide() [1/4]

virtual bool SHAPE::Collide ( const VECTOR2I aP,
int  aClearance = 0,
int *  aActual = nullptr 
) const
inlinevirtual

Function Collide()

Checks if the boundary of shape (this) lies closer to the point aP than aClearance, indicating a collision.

Parameters
aActualan optional pointer to an int to store the actual distance in the event of a collision.
Returns
true, if there is a collision.

Reimplemented in SHAPE_POLY_SET, SHAPE_LINE_CHAIN_BASE, SHAPE_SEGMENT, and SHAPE_ARC.

Definition at line 172 of file shape.h.

173  {
174  return Collide( SEG( aP, aP ), aClearance, aActual );
175  }
Definition: seg.h:39
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr) const
Function Collide()
Definition: shape.h:172

Referenced by SHAPE_COMPOUND::Collide(), SHAPE_SEGMENT::Collide(), collide(), SHAPE_RECT::Collide(), PNS::ITEM::collideSimple(), PNS::SHOVE::onCollidingVia(), PNS::HIT_VISITOR::operator()(), and PNS::OPTIMIZER::smartPadsSingle().

◆ Collide() [2/4]

bool SHAPE::Collide ( const SHAPE aShape,
int  aClearance,
VECTOR2I aMTV 
) const
virtual

Function Collide()

Checks if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating a collision.

Parameters
aShapeshape to check collision against
aClearanceminimum clearance
aMTVminimum translation vector
aActualan optional pointer to an int to store the actual distance in the event of a collision.
Returns
true, if there is a collision.

Reimplemented in SHAPE_RECT, SHAPE_SEGMENT, and SHAPE_COMPOUND.

Definition at line 719 of file shape_collisions.cpp.

720 {
721  return collideShapes( this, aShape, aClearance, nullptr, aMTV );
722 }
static bool collideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aMTV)

References collideShapes().

◆ Collide() [3/4]

bool SHAPE::Collide ( const SHAPE aShape,
int  aClearance = 0,
int *  aActual = nullptr 
) const
virtual

Reimplemented in SHAPE_RECT, SHAPE_SEGMENT, and SHAPE_COMPOUND.

Definition at line 725 of file shape_collisions.cpp.

726 {
727  return collideShapes( this, aShape, aClearance, aActual, nullptr );
728 }
static bool collideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aMTV)

References collideShapes().

◆ Collide() [4/4]

virtual bool SHAPE::Collide ( const SEG aSeg,
int  aClearance = 0,
int *  aActual = nullptr 
) const
pure virtual

Function Collide()

Checks if the boundary of shape (this) lies closer to the segment aSeg than aClearance, indicating a collision. @aActual an optional pointer to an int to be updated with the actual distance in the case of collision.

Returns
true, if there is a collision.

Implemented in SHAPE_POLY_SET, SHAPE_LINE_CHAIN_BASE, SHAPE_SIMPLE, SHAPE_RECT, SHAPE_ARC, SHAPE_SEGMENT, SHAPE_CIRCLE, SHAPE_NULL, and SHAPE_COMPOUND.

◆ Format()

const std::string SHAPE::Format ( ) const
virtual

Reimplemented in SHAPE_POLY_SET, SHAPE_LINE_CHAIN, and SHAPE_COMPOUND.

Definition at line 35 of file shape.cpp.

36 {
37  assert( false );
38  return std::string( "" );
39 }

Referenced by SHAPE_FILE_IO::Write().

◆ GetIndexableSubshape()

virtual void SHAPE_BASE::GetIndexableSubshape ( SHAPE_BASE aSubshape) const
inlinevirtualinherited

Definition at line 108 of file shape.h.

108 {};

◆ GetIndexableSubshapeCount()

virtual size_t SHAPE_BASE::GetIndexableSubshapeCount ( )
inlinevirtualinherited

Definition at line 106 of file shape.h.

106 { return 0; }

◆ HasIndexableSubshapes()

virtual bool SHAPE_BASE::HasIndexableSubshapes ( ) const
inlinevirtualinherited

Definition at line 101 of file shape.h.

102  {
103  return false;
104  }

◆ IsNull()

bool SHAPE::IsNull ( ) const
inline

Function IsNull()

Returns true if the shape is a null shape.

Return values
trueif null :-)

Definition at line 158 of file shape.h.

159  {
160  return m_type == SH_NULL;
161  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:108
circular arc
Definition: shape.h:50

References SHAPE_BASE::m_type, and SH_NULL.

◆ IsSolid()

◆ Move()

◆ NewFacet()

FACET * SHAPE::NewFacet ( )

Definition at line 705 of file wrlfacet.cpp.

706 {
707  FACET* fp = new FACET;
708  facets.push_back( fp );
709  return fp;
710 }
Definition: wrlfacet.h:41
std::list< FACET * > facets
Definition: wrlfacet.h:143

References facets.

Referenced by WRL1FACESET::TranslateToSG(), X3DIFACESET::TranslateToSG(), and WRL2FACESET::TranslateToSG().

◆ Parse()

bool SHAPE::Parse ( std::stringstream &  aStream)
virtual

Reimplemented in SHAPE_POLY_SET, and SHAPE_LINE_CHAIN.

Definition at line 28 of file shape.cpp.

29 {
30  assert( false );
31  return false;
32 }

◆ Rotate()

virtual void SHAPE::Rotate ( double  aAngle,
const VECTOR2I aCenter = { 0, 0 } 
)
pure virtual

Function Rotate.

Parameters
aCenteris the rotation center
aAnglerotation angle in radians

Implemented in SHAPE_POLY_SET, SHAPE_LINE_CHAIN, SHAPE_SIMPLE, SHAPE_RECT, SHAPE_SEGMENT, SHAPE_CIRCLE, SHAPE_ARC, SHAPE_COMPOUND, SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI, and SHAPE_NULL.

◆ Type()

SHAPE_TYPE SHAPE_BASE::Type ( ) const
inlineinherited

Function Type()

Returns the type of the shape.

Return values
thetype

Definition at line 96 of file shape.h.

97  {
98  return m_type;
99  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:108

References SHAPE_BASE::m_type.

Referenced by PNS::DP_GATEWAYS::BuildFromPrimitivePair(), collideShapes(), collideSingleShapes(), PNS::OPTIMIZER::computeBreakouts(), ROUTER_PREVIEW_ITEM::ViewDraw(), and SHAPE_FILE_IO::Write().

Member Data Documentation

◆ facets

std::list< FACET* > SHAPE::facets
private

Definition at line 143 of file wrlfacet.h.

Referenced by CalcShape(), and NewFacet().

◆ m_type

SHAPE_TYPE SHAPE_BASE::m_type
protectedinherited

type of our shape

Definition at line 108 of file shape.h.

Referenced by IsNull(), and SHAPE_BASE::Type().


The documentation for this class was generated from the following files: