2016-09-02 10:08:40 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
|
|
|
*
|
|
|
|
* 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 OCE_VIS_OCE_UTILS_H
|
|
|
|
#define OCE_VIS_OCE_UTILS_H
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
#include "base.h"
|
|
|
|
#include "kicadpcb.h"
|
|
|
|
#include "kicadcurve.h"
|
|
|
|
|
|
|
|
#include <BRepBuilderAPI_MakeWire.hxx>
|
|
|
|
#include <TDocStd_Document.hxx>
|
|
|
|
#include <XCAFApp_Application.hxx>
|
|
|
|
#include <XCAFDoc_ShapeTool.hxx>
|
|
|
|
#include <TopoDS_Shape.hxx>
|
|
|
|
#include <TopoDS_Edge.hxx>
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::pair< std::string, TDF_Label > MODEL_DATUM;
|
|
|
|
typedef std::map< std::string, TDF_Label > MODEL_MAP;
|
|
|
|
|
|
|
|
class KICADPAD;
|
|
|
|
|
|
|
|
class OUTLINE
|
|
|
|
{
|
|
|
|
private:
|
2018-06-19 08:14:10 +00:00
|
|
|
bool m_closed; // set true if the loop is closed
|
|
|
|
double m_minDistance2; // min squared distance to treat points as separate entities (mm)
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
bool addEdge( BRepBuilderAPI_MakeWire* aWire, KICADCURVE& aCurve, DOUBLET& aLastPoint );
|
2020-11-18 19:50:36 +00:00
|
|
|
bool testClosed( const KICADCURVE& aFrontCurve, const KICADCURVE& aBackCurve );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
std::list< KICADCURVE > m_curves; // list of contiguous segments
|
|
|
|
OUTLINE();
|
|
|
|
virtual ~OUTLINE();
|
|
|
|
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
// attempt to add a curve to the outline; on success returns true
|
|
|
|
bool AddSegment( const KICADCURVE& aCurve );
|
|
|
|
|
|
|
|
bool IsClosed()
|
|
|
|
{
|
|
|
|
return m_closed;
|
|
|
|
}
|
|
|
|
|
2018-06-19 08:14:10 +00:00
|
|
|
void SetMinSqDistance( double aDistance )
|
|
|
|
{
|
|
|
|
m_minDistance2 = aDistance;
|
|
|
|
}
|
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
bool MakeShape( TopoDS_Shape& aShape, double aThickness );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class PCBMODEL
|
|
|
|
{
|
|
|
|
Handle( XCAFApp_Application ) m_app;
|
|
|
|
Handle( TDocStd_Document ) m_doc;
|
|
|
|
Handle( XCAFDoc_ShapeTool ) m_assy;
|
|
|
|
TDF_Label m_assy_label;
|
|
|
|
bool m_hasPCB; // set true if CreatePCB() has been invoked
|
|
|
|
TDF_Label m_pcb_label; // label for the PCB model
|
|
|
|
MODEL_MAP m_models; // map of file names to model labels
|
|
|
|
int m_components; // number of successfully loaded components;
|
|
|
|
double m_precision; // model (length unit) numeric precision
|
|
|
|
double m_angleprec; // angle numeric precision
|
|
|
|
double m_thickness; // PCB thickness, mm
|
|
|
|
double m_minx; // minimum X value in curves (leftmost curve feature)
|
2018-06-19 08:14:10 +00:00
|
|
|
double m_minDistance2; // minimum squared distance between items (mm)
|
2016-09-02 10:08:40 +00:00
|
|
|
std::list< KICADCURVE >::iterator m_mincurve; // iterator to the leftmost curve
|
|
|
|
|
|
|
|
std::list< KICADCURVE > m_curves;
|
|
|
|
std::vector< TopoDS_Shape > m_cutouts;
|
|
|
|
|
2020-10-30 19:31:23 +00:00
|
|
|
bool getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_Label& aLabel );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
bool getModelLocation( bool aBottom, DOUBLET aPosition, double aRotation,
|
|
|
|
TRIPLET aOffset, TRIPLET aOrientation, TopLoc_Location& aLocation );
|
|
|
|
|
|
|
|
bool readIGES( Handle( TDocStd_Document )& m_doc, const char* fname );
|
|
|
|
bool readSTEP( Handle( TDocStd_Document )& m_doc, const char* fname );
|
|
|
|
|
|
|
|
TDF_Label transferModel( Handle( TDocStd_Document )& source,
|
2019-05-28 15:40:34 +00:00
|
|
|
Handle( TDocStd_Document )& dest, TRIPLET aScale );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
PCBMODEL();
|
|
|
|
virtual ~PCBMODEL();
|
|
|
|
|
|
|
|
// add an outline segment (must be in final position)
|
|
|
|
bool AddOutlineSegment( KICADCURVE* aCurve );
|
|
|
|
|
|
|
|
// add a pad hole or slot (must be in final position)
|
2020-11-18 19:50:36 +00:00
|
|
|
bool AddPadHole( const KICADPAD* aPad );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
// add a component at the given position and orientation
|
2018-03-19 11:17:09 +00:00
|
|
|
bool AddComponent( const std::string& aFileName, const std::string& aRefDes,
|
2016-09-02 10:08:40 +00:00
|
|
|
bool aBottom, DOUBLET aPosition, double aRotation,
|
2019-05-28 15:40:34 +00:00
|
|
|
TRIPLET aOffset, TRIPLET aOrientation, TRIPLET aScale );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
// set the thickness of the PCB (mm); the top of the PCB shall be at Z = aThickness
|
|
|
|
// aThickness < 0.0 == use default thickness
|
|
|
|
// aThickness <= THICKNESS_MIN == use THICKNESS_MIN
|
|
|
|
// aThickness > THICKNESS_MIN == use aThickness
|
|
|
|
void SetPCBThickness( double aThickness );
|
|
|
|
|
2021-01-03 10:01:03 +00:00
|
|
|
// Set the minimum distance (in mm) to consider 2 points have the same coordinates
|
2021-01-03 08:40:40 +00:00
|
|
|
void SetMinDistance( double aDistance );
|
2018-06-19 08:14:10 +00:00
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
// create the PCB model using the current outlines and drill holes
|
|
|
|
bool CreatePCB();
|
|
|
|
|
|
|
|
#ifdef SUPPORTS_IGES
|
|
|
|
// write the assembly model in IGES format
|
2018-09-20 09:05:52 +00:00
|
|
|
bool WriteIGES( const wxString& aFileName );
|
2016-09-02 10:08:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// write the assembly model in STEP format
|
2018-09-20 09:05:52 +00:00
|
|
|
bool WriteSTEP( const wxString& aFileName );
|
2016-09-02 10:08:40 +00:00
|
|
|
};
|
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
#endif // OCE_VIS_OCE_UTILS_H
|