2020-07-15 16:22:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016-2020 CERN
|
2022-01-20 20:54:22 +00:00
|
|
|
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-07-15 16:22:16 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SHAPE_COMPOUND_H
|
|
|
|
#define __SHAPE_COMPOUND_H
|
|
|
|
|
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
#include <math/box2.h>
|
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
2022-07-25 16:41:38 +00:00
|
|
|
#include <memory>
|
2022-01-20 20:54:22 +00:00
|
|
|
#include "eda_angle.h"
|
2020-07-15 16:22:16 +00:00
|
|
|
|
2020-10-07 13:13:48 +00:00
|
|
|
class SHAPE_SIMPLE;
|
|
|
|
|
2020-07-15 16:22:16 +00:00
|
|
|
class SHAPE_COMPOUND : public SHAPE
|
|
|
|
{
|
2020-10-07 13:13:48 +00:00
|
|
|
public:
|
2020-10-31 17:25:08 +00:00
|
|
|
SHAPE_COMPOUND() :
|
|
|
|
SHAPE( SH_COMPOUND ),
|
|
|
|
m_dirty( true )
|
2020-10-07 13:13:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SHAPE_COMPOUND( const std::vector<SHAPE*>& aShapes );
|
|
|
|
|
|
|
|
SHAPE_COMPOUND( const SHAPE_COMPOUND& aOther );
|
|
|
|
~SHAPE_COMPOUND();
|
|
|
|
|
|
|
|
SHAPE_COMPOUND* Clone() const override;
|
2022-10-23 22:20:02 +00:00
|
|
|
const std::string Format( bool aCplusPlus = true ) const override;
|
2020-10-07 13:13:48 +00:00
|
|
|
|
|
|
|
bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
|
2021-07-01 17:46:17 +00:00
|
|
|
VECTOR2I* aLocation = nullptr ) const override;
|
2020-10-07 13:13:48 +00:00
|
|
|
|
|
|
|
bool Collide( const SHAPE* aShape, int aClearance, VECTOR2I* aMTV ) const override
|
|
|
|
{
|
|
|
|
return SHAPE::Collide( aShape, aClearance, aMTV );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Collide( const SHAPE* aShape, int aClearance = 0, int* aActual = nullptr,
|
2020-12-12 03:43:16 +00:00
|
|
|
VECTOR2I* aLocation = nullptr ) const override
|
2020-10-07 13:13:48 +00:00
|
|
|
{
|
|
|
|
return SHAPE::Collide( aShape, aClearance, aActual, aLocation );
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<SHAPE*>& Shapes() const
|
|
|
|
{
|
|
|
|
return m_shapes;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BOX2I BBox( int aClearance = 0 ) const override;
|
|
|
|
|
|
|
|
int Distance( const SEG& aSeg ) const;
|
|
|
|
|
|
|
|
void Move( const VECTOR2I& aVector ) override;
|
|
|
|
|
|
|
|
void AddShape( SHAPE* aShape )
|
|
|
|
{
|
2020-10-25 15:01:55 +00:00
|
|
|
// Don't make clients deal with nested SHAPE_COMPOUNDs
|
|
|
|
if( aShape->HasIndexableSubshapes() )
|
|
|
|
{
|
2022-07-21 22:01:50 +00:00
|
|
|
std::vector<const SHAPE*> subshapes;
|
2020-10-25 15:01:55 +00:00
|
|
|
aShape->GetIndexableSubshapes( subshapes );
|
|
|
|
|
2022-07-21 22:01:50 +00:00
|
|
|
for( const SHAPE* subshape : subshapes )
|
2020-10-25 23:38:21 +00:00
|
|
|
m_shapes.push_back( subshape->Clone() );
|
|
|
|
|
|
|
|
delete aShape;
|
2020-10-25 15:01:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_shapes.push_back( aShape );
|
|
|
|
}
|
|
|
|
|
2020-10-07 13:13:48 +00:00
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
|
2022-07-25 15:09:27 +00:00
|
|
|
void AddShape( std::shared_ptr<SHAPE> aShape )
|
|
|
|
{
|
|
|
|
// Don't make clients deal with nested SHAPE_COMPOUNDs
|
|
|
|
if( aShape->HasIndexableSubshapes() )
|
|
|
|
{
|
|
|
|
std::vector<const SHAPE*> subshapes;
|
|
|
|
aShape->GetIndexableSubshapes( subshapes );
|
|
|
|
|
|
|
|
for( const SHAPE* subshape : subshapes )
|
|
|
|
m_shapes.push_back( subshape->Clone() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_shapes.push_back( aShape->Clone() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
|
2020-10-07 13:13:48 +00:00
|
|
|
bool Empty() const
|
|
|
|
{
|
|
|
|
return m_shapes.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Size() const
|
|
|
|
{
|
|
|
|
return m_shapes.size();
|
|
|
|
}
|
2020-07-22 23:04:13 +00:00
|
|
|
|
2022-01-20 20:54:22 +00:00
|
|
|
void Rotate( const EDA_ANGLE& aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override;
|
2020-07-15 16:22:16 +00:00
|
|
|
|
|
|
|
bool IsSolid() const override;
|
2020-10-07 13:13:48 +00:00
|
|
|
|
2020-07-22 23:04:13 +00:00
|
|
|
SHAPE* UniqueSubshape() const
|
|
|
|
{
|
2020-10-07 13:13:48 +00:00
|
|
|
return m_shapes.size() != 1 ? nullptr : m_shapes[0];
|
2020-07-22 23:04:13 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 13:13:48 +00:00
|
|
|
virtual bool HasIndexableSubshapes() const override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2020-09-18 14:22:30 +00:00
|
|
|
|
2020-10-07 13:13:48 +00:00
|
|
|
virtual size_t GetIndexableSubshapeCount() const override
|
|
|
|
{
|
|
|
|
return m_shapes.size();
|
|
|
|
}
|
2020-09-18 14:22:30 +00:00
|
|
|
|
2022-07-21 22:01:50 +00:00
|
|
|
virtual void GetIndexableSubshapes( std::vector<const SHAPE*>& aSubshapes ) const override
|
2020-10-07 13:13:48 +00:00
|
|
|
{
|
2022-07-21 22:01:50 +00:00
|
|
|
aSubshapes.clear();
|
|
|
|
aSubshapes.reserve( m_shapes.size() );
|
|
|
|
std::copy( m_shapes.begin(), m_shapes.end(), std::back_inserter( aSubshapes ) );
|
2020-10-07 13:13:48 +00:00
|
|
|
}
|
2020-09-18 14:22:30 +00:00
|
|
|
|
2020-10-07 13:13:48 +00:00
|
|
|
bool ConvertToSimplePolygon( SHAPE_SIMPLE* aOut ) const;
|
2020-07-15 16:22:16 +00:00
|
|
|
|
2020-10-07 13:13:48 +00:00
|
|
|
private:
|
|
|
|
BOX2I m_cachedBBox;
|
|
|
|
bool m_dirty;
|
|
|
|
std::vector<SHAPE*> m_shapes;
|
2020-07-15 16:22:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __SHAPE_COMPOUND_H
|