#ifndef TITAN_PCBCAM_UTIL_H
#define TITAN_PCBCAM_UTIL_H
#include "../titanpcbcamglobal.h"
#include <QRectF>
#include "./feature.h"
#include "./symbol.h"
#include "./job.h"
#include "./step.h"
#include "./layer.h"
#include "./common.h"
#include <QPainterPath>
#include <QPen>


class TITAN_PCBCAM_EXPORT PcbCamUtil
{
public:
    static QString formatNumber(double iNumber, int iPercision = 6);
    static QVariantMap calcPathArc(const QPointF &iPs, const QPointF &iPe, const QPointF &iPc, bool iCw);
    static QPainterPath arc2path(const QPointF &iPs, const QPointF &iPe, const QPointF &iPc, bool iCw);
    static QPainterPath line2path(const QLineF &iLine);

    static QPen sym2pen(PcbCamSymbol *iSymbol);

    static QTransform matrix(const QPointF &iPos, PcbCam::Orient iOrient);
    static QTransform matrix(const QPointF &iPos, const QPointF &iDatum, qreal iAngle, bool iMirror);

    static void drawFeatures(QPainter *painter,
                             const QList<PcbCamFeature*> &iFeatures,
                             PcbCam::Polarity iPolarity,
                             const QColor &iColor,
                             const QTransform &iMatrix,
                             const QRectF &iSceneRect,
                             PcbCam::DisplayOptions iDispOption = PcbCam::DisplayFill,
                             PcbCamJob *iJob = nullptr,
                             PcbCamStep *iStep = nullptr,
                             PcbCamLayer *iLayer = nullptr);


    static int orient2angle(PcbCam::Orient iOrient);
    static bool orient2mirror(PcbCam::Orient iOrient);

    static bool isFeatMatchFilter(PcbCamFeature *iFeat,
                                  PcbCam::FeatureTypes iTypes,
                                  PcbCam::Polarities iPolarities,
                                  bool iIsFilterProfile,
                                  PcbCam::ProfileRegions iProfileRegion,
                                  const QPainterPath &iProfilePath,
                                  bool iIsFilterIncludeSymbol,
                                  QSet<PcbCamSymbol *> iIncludeSymbols,
                                  bool iIsFilterExcludeSymbol,
                                  QSet<PcbCamSymbol *> iExcludeSymbols,
                                  bool iIsFilterIncludeAttr,
                                  QList<PcbCam::AttrCompareInfo> iIncludeAttrs,
                                  PcbCam::LogicOperator iIncludeAttrLogic,
                                  bool iIsFilterExcludeAttr,
                                  QList<PcbCam::AttrCompareInfo> iExcludeAttrs,
                                  PcbCam::LogicOperator iExcludeAttrLogic);

    //点到线段的最短距离
//    static double point2segDist(double x, double y, double x1, double y1, double x2, double y2);

    //点到多段线最短距离
//    static double point2polylineDist(const QPointF &p, const QPolygonF &polyline);

    //查找封闭的painterpath
    static QPainterPath findClosedPath(const QList<PcbCamFeature*> &iFeatures, double iTol = 0.0001);

    //查找polyline
    static QList<QPainterPath> findPolyline(const QList<PcbCamFeature*> &iFeatures, double iTol = 0.0001);

};

#endif // TITAN_PCBCAM_UTIL_H
