CAD
1、QCAD
QCAD - dxflib -- dxflib主页,配套开源库
https://github.com/mcneel/opennurbs -- 配套开源库
QCAD: Introduction, Overviews, Howtos
最早的版本v2.0.5:QCad binary for Windows download | SourceForge.net
QCAD v2.2.2.1 最后一个v2.x系列的版本
QCAD v3.0.9.0 从v3.x开始使用ECMA Script interface
qcad的dxf读取在\src\io\dxf\RDxfImporter.cpp void RDxfImporter::endEntity() { QSharedPointer<RSplineEntity> entity(new RSplineEntity(document, RSplineData(spline))); importEntity(entity); } qcad的样条曲线的绘图在/src/core/RPainterPath.cpp void RPainterPath::addSpline(const RSpline& spline) { int degree = spline.getDegree(); if (degree<=3) { moveTo(spline.getStartPoint()); } QList<RSpline> list = spline.getBezierSegments(); for (int i=0; i<list.count(); i++) { QList<RVector> cps = list[i].getControlPoints(); // very rare splines of degree >= 4: if ((cps.size()>=5 && degree==cps.size()-1)) { QList<QSharedPointer<RShape> > segments = spline.getExploded(16); for (int k=0; k<segments.length(); k++) { QSharedPointer<RLine> l = segments[k].dynamicCast<RLine>(); if (k==0) { moveTo(l->getStartPoint()); } lineTo(l->getEndPoint()); } } else if (cps.size()==4 && degree==3) { cubicTo(cps[1], cps[2], cps[3]); } else if (cps.size()==3 && degree==2) { quadTo(cps[1], cps[2]); } else if (cps.size()==2 && degree==1) { lineTo(cps[1]); } else { qWarning() << "RPainterPath::addSpline: invalid bezier segment: " << list[i]; continue; } } } //\src\core\RPainterPath.h void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty) { QPainterPath::quadTo(ctrlPtx, ctrlPty, endPtx, endPty); } void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, qreal endPtx, qreal endPty) { QPainterPath::cubicTo(ctrlPt1x, ctrlPt1y, ctrlPt2x, ctrlPt2y, endPtx, endPty); } //QPainterPath源码来自Qt官方\Qt\Qt5.12.7\5.12.7\Src\qtbase\src\gui\painting //cubicTo和quadTo都是用来实现贝塞尔曲线的,那有什么不一样呢? 官方是这么说的: Same as cubicTo, but the coordinates are considered relative to the current point on this contour. 说白了,就是多了一个控制点而已。 //https://doc.qt.io/qt-5/qpainterpath.html //https://qtdebug.com/qt-smooth-curve/
2、LibreCAD
LibreCAD 是一款开源免费的 2D CAD 制图软件,原名为 CADuntu 。它是基于社区版本 QCad 构建,并利用 Qt4 进行了重构,原生支持 Mac OSX, Windows 和 Linux 。它提供了基于 GPL 协议的读取/修改/创建 CAD 文件 (.dxf ) 方案。
LibreCAD最早源自QCad的老版本,v2.0.5,using mingw-5.1.4 and qt-3.3.x-p8.
LibreCAD - Free Open Source 2D CAD
LibreCAD download | SourceForge.net
LibreCAD v1.0.4 最后一个v1.x系列的版本
LibreCAD v2.0.0alpha2 开始使用c++ boost库
3、KiCAD EDA
A Cross Platform and Open Source Electronics Design Automation Suite
KiCad / KiCad Source Code / kicad · GitLab ++ wxWidgets: Cross-Platform GUI Library 界面不是用Qt写的,而是wxWidgets
https://github.com/KiCad/kicad-source-mirror
thirdparty/tinyspline_lib · master · KiCad / KiCad Source Code / kicad · GitLab 改版的tinyspline,可以和QCAD的dxflib配套
https://github.com/msteinbeck/tinyspline 原版的tinyspline
thirdparty/dxflib_qcad · master · KiCad / KiCad Source Code / kicad · GitLab 改版的dxflib
QCAD - dxflib 原版的dxflib
请重点关注pcbnew/import_gfx/dxf_import_plugin.cpp · master · KiCad / KiCad Source Code / kicad · GitLab,它用dxflib库解析dxf文件
\pcbnew\import_gfx\dxf_import_plugin.cpp #include "tinyspline_lib/tinysplinecpp.h" void DXF_IMPORT_PLUGIN::insertSpline( int aWidth ) { unsigned imax = m_curr_entity.m_SplineControlPointList.size(); if( imax < 2 ) // malformed spline return; // Use bezier curves, supported by pcbnew, to approximate the spline tinyspline::BSpline dxfspline( m_curr_entity.m_SplineControlPointList.size(), /* coord dim */ 2, m_curr_entity.m_SplineDegree ); std::vector<double> ctrlp; for( unsigned ii = 0; ii < imax; ++ii ) { ctrlp.push_back( m_curr_entity.m_SplineControlPointList[ii].m_x ); ctrlp.push_back( m_curr_entity.m_SplineControlPointList[ii].m_y ); } dxfspline.setCtrlp( ctrlp ); dxfspline.setKnots( m_curr_entity.m_SplineKnotsList ); tinyspline::BSpline beziers( dxfspline.toBeziers() ); std::vector<double> coords = beziers.ctrlp(); // Each Bezier curve uses 4 vertices (a start point, 2 control points and a end point). // So we can have more than one Bezier curve ( there are one curve each four vertices) for( unsigned ii = 0; ii < coords.size(); ii += 8 ) { VECTOR2D start( mapX( coords[ii] ), mapY( coords[ii+1] ) ); VECTOR2D bezierControl1( mapX( coords[ii+2] ), mapY( coords[ii+3] ) ); VECTOR2D bezierControl2( mapX( coords[ii+4] ), mapY( coords[ii+5] ) ); VECTOR2D end( mapX( coords[ii+6] ), mapY( coords[ii+7] ) ); m_internalImporter.AddSpline( start, bezierControl1, bezierControl2, end , aWidth ); } } \pcbnew\import_gfx\graphics_importer_buffer.h void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override { aImporter.AddSpline( m_start, m_bezierControl1, m_bezierControl2, m_end, m_width ); } \pcbnew\import_gfx\graphics_importer_pcbnew.cpp void GRAPHICS_IMPORTER_PCBNEW::AddSpline( const VECTOR2D& aStart, const VECTOR2D& BezierControl1, const VECTOR2D& BezierControl2, const VECTOR2D& aEnd, double aWidth ) { unique_ptr<DRAWSEGMENT> spline( createDrawing() ); spline->SetShape( S_CURVE ); spline->SetLayer( GetLayer() ); spline->SetWidth( MapLineWidth( aWidth ) ); spline->SetStart( MapCoordinate( aStart ) ); spline->SetBezControl1( MapCoordinate( BezierControl1 ) ); spline->SetBezControl2( MapCoordinate( BezierControl2 ) ); spline->SetEnd( MapCoordinate( aEnd ) ); spline->RebuildBezierToSegmentsPointsList( aWidth ); if( spline->Type() == PCB_MODULE_EDGE_T ) static_cast<EDGE_MODULE*>( spline.get() )->SetLocalCoord(); addItem( std::move( spline ) ); } \pcbnew\class_drawsegment.cpp void DRAWSEGMENT::RebuildBezierToSegmentsPointsList( int aMinSegLen ) { // Has meaning only for S_CURVE DRAW_SEGMENT shape if( m_Shape != S_CURVE ) { m_BezierPoints.clear(); return; } // Rebuild the m_BezierPoints vertex list that approximate the Bezier curve std::vector<wxPoint> ctrlPoints = { m_Start, m_BezierC1, m_BezierC2, m_End }; BEZIER_POLY converter( ctrlPoints ); converter.GetPoly( m_BezierPoints, aMinSegLen ); } \common\bezier_curves.cpp void BEZIER_POLY::GetPoly( std::vector<wxPoint>& aOutput, int aMinSegLen ) { }
4、BRL-CAD
BRL-CAD 是一个构造实体几何(CSG) 实体模型计算机辅助设计(CAD) 系统。
BRL-CAD download | SourceForge.net
BRL-CAD: Open Source Solid Modeling
5、openscad
https://github.com/openscad/openscad
OpenSCAD - The Programmers Solid 3D CAD Modeller OpenSCAD是一个创建立体3D CAD物体的得力软件
6、RapCAD
https://github.com/GilesBathgate/RapCAD
7、AnyCAD 国产软件
AnyCAD三维控件 · Professional 3D Graphics Component for CAD/CAE/CAM Developers.
8、Vero WorkNC
CNC刀路设计软件。WorkNC是vero worknc系列软件的新版本,软件具有多种自动刀具路径类型,可以满足用户的各种需求,包括粗加工、精加工、优化加工、清根加工、外形轮廓加工、曲线加工及钻孔等,可以实现全局粗加工刀具路径通过允许微小刀柄近似来访问更难的区域。
9、Coin3D
https://bitbucket.org/Coin3D/coin/wiki/Home
10、某位大牛的作品
11、NaroCAD
NaroCAD is a fully fledged and extensible 3D parametric modeling CAD application. It is based on OpenCascade.