|
 |
911124 |
#pragma once
|
|
 |
911124 |
|
|
 |
911124 |
#ifndef ASSISTANT_INCLUDED
|
|
 |
911124 |
#define ASSISTANT_INCLUDED
|
|
 |
911124 |
|
|
 |
911124 |
|
|
 |
911124 |
#include <tools track.h=""></tools>
|
|
 |
911124 |
|
|
 |
911124 |
|
|
 |
911124 |
#include <tsmartpointer.h></tsmartpointer.h>
|
|
 |
911124 |
#include <tgeometry.h></tgeometry.h>
|
|
 |
ae9154 |
#include <tmetaimage.h></tmetaimage.h>
|
|
 |
3bac66 |
#include <tproperty.h></tproperty.h>
|
|
 |
911124 |
|
|
 |
4da757 |
|
|
 |
4da757 |
#include <qcoreapplication></qcoreapplication>
|
|
 |
4da757 |
|
|
 |
911124 |
|
|
 |
911124 |
#include <vector></vector>
|
|
 |
911124 |
#include <string></string>
|
|
 |
911124 |
#include <map></map>
|
|
 |
911124 |
|
|
 |
911124 |
|
|
 |
911124 |
#undef DVAPI
|
|
 |
911124 |
#undef DVVAR
|
|
 |
911124 |
#ifdef TNZTOOLS_EXPORTS
|
|
 |
911124 |
#define DVAPI DV_EXPORT_API
|
|
 |
911124 |
#define DVVAR DV_EXPORT_VAR
|
|
 |
911124 |
#else
|
|
 |
911124 |
#define DVAPI DV_IMPORT_API
|
|
 |
911124 |
#define DVVAR DV_IMPORT_VAR
|
|
 |
911124 |
#endif
|
|
 |
911124 |
|
|
 |
911124 |
|
|
 |
911124 |
|
|
 |
911124 |
|
|
 |
911124 |
|
|
 |
911124 |
|
|
 |
3bac66 |
class TProperty;
|
|
 |
3bac66 |
class TPropertyGroup;
|
|
 |
3bac66 |
|
|
 |
911124 |
class TToolViewer;
|
|
 |
911124 |
class TAssistant;
|
|
 |
9cf8be |
class TAssistantPoint;
|
|
 |
911124 |
class TGuideline;
|
|
 |
911124 |
|
|
 |
911124 |
typedef TSmartPointerT<tguideline> TGuidelineP;</tguideline>
|
|
 |
911124 |
typedef std::vector<tguidelinep> TGuidelineList;</tguidelinep>
|
|
 |
c5e805 |
typedef std::map<tstringid, tassistantpoint=""> TAssistantPointMap;</tstringid,>
|
|
 |
7900ea |
typedef std::vector<const tassistantpoint*=""> TAssistantPointOrder;</const>
|
|
 |
911124 |
|
|
 |
911124 |
|
|
 |
911124 |
|
|
 |
4da757 |
|
|
 |
911124 |
//*****************************************************************************************
|
|
 |
911124 |
|
|
 |
911124 |
//*****************************************************************************************
|
|
 |
911124 |
|
|
 |
4df9cd |
class DVAPI TGuideline : public TSmartObject {
|
|
 |
911124 |
public:
|
|
 |
8074a5 |
const bool enabled;
|
|
 |
3d32e2 |
const double magnetism;
|
|
 |
8074a5 |
|
|
 |
8074a5 |
TGuideline(bool enabled, double magnetism):
|
|
 |
8074a5 |
enabled(enabled), magnetism(magnetism) { }
|
|
 |
3d32e2 |
|
|
 |
911124 |
virtual TTrackPoint transformPoint(const TTrackPoint &point) const
|
|
 |
911124 |
{ return point; }
|
|
 |
52242c |
|
|
 |
52242c |
// this function uses in calcTrackWeight to select best guideline,
|
|
 |
52242c |
// does not use for drawing
|
|
 |
52242c |
virtual TPointD nearestPoint(const TPointD &point) const
|
|
 |
52242c |
{ return transformPoint(TTrackPoint(point)).position; }
|
|
 |
52242c |
|
|
 |
8074a5 |
virtual void draw(bool active, bool enabled) const
|
|
 |
911124 |
{ }
|
|
 |
52242c |
|
|
 |
8074a5 |
void draw(bool active = false) const
|
|
 |
8074a5 |
{ draw(active, true); }
|
|
 |
8074a5 |
|
|
 |
8074a5 |
TTrackPoint smoothTransformPoint(const TTrackPoint &point, double magnetism = 1.0) const {
|
|
 |
8074a5 |
return enabled
|
|
 |
8074a5 |
? TTrack::interpolationLinear(point, transformPoint(point), magnetism*this->magnetism)
|
|
 |
8074a5 |
: point;
|
|
 |
8074a5 |
}
|
|
 |
911124 |
|
|
 |
8074a5 |
void drawSegment(
|
|
 |
8074a5 |
const TPointD &p0,
|
|
 |
8074a5 |
const TPointD &p1,
|
|
 |
8074a5 |
double pixelSize,
|
|
 |
8074a5 |
bool active,
|
|
 |
8074a5 |
bool enabled = true) const;
|
|
 |
4df9cd |
|
|
 |
9cf8be |
double calcTrackWeight(const TTrack &track, const TAffine &toScreen, bool &outLongEnough) const;
|
|
 |
9cf8be |
static TGuidelineP findBest(const TGuidelineList &guidelines, const TTrack &track, const TAffine &toScreen, bool &outLongEnough);
|
|
 |
911124 |
};
|
|
 |
911124 |
|
|
 |
911124 |
|
|
 |
911124 |
//*****************************************************************************************
|
|
 |
9cf8be |
|
|
 |
9cf8be |
//*****************************************************************************************
|
|
 |
9cf8be |
|
|
 |
9cf8be |
class DVAPI TAssistantPoint {
|
|
 |
9cf8be |
public:
|
|
 |
9cf8be |
enum Type {
|
|
 |
9cf8be |
Circle,
|
|
 |
9cf8be |
CircleFill,
|
|
 |
c5e805 |
CircleCross,
|
|
 |
c7854d |
CircleDots,
|
|
 |
c7854d |
CircleDoubleDots,
|
|
 |
9cf8be |
};
|
|
 |
9cf8be |
|
|
 |
c5e805 |
const TStringId name;
|
|
 |
7900ea |
const TPointD defPosition;
|
|
 |
7900ea |
|
|
 |
9cf8be |
Type type;
|
|
 |
9cf8be |
TPointD position;
|
|
 |
249386 |
double radius;
|
|
 |
c5e805 |
bool visible;
|
|
 |
c5e805 |
|
|
 |
c5e805 |
mutable bool selected;
|
|
 |
9cf8be |
|
|
 |
7900ea |
explicit TAssistantPoint(const TStringId &name, const TPointD &defPosition = TPointD());
|
|
 |
9cf8be |
};
|
|
 |
9cf8be |
|
|
 |
4da757 |
|
|
 |
4da757 |
//*****************************************************************************************
|
|
 |
4da757 |
|
|
 |
4da757 |
//*****************************************************************************************
|
|
 |
4da757 |
|
|
 |
4da757 |
class DVAPI TAssistantType: public TMetaObjectType {
|
|
 |
4da757 |
public:
|
|
 |
4da757 |
TAssistantType(const TStringId &name):
|
|
 |
4da757 |
TMetaObjectType(name) { }
|
|
 |
4da757 |
TMetaObjectHandler* createHandler(TMetaObject &obj) const override;
|
|
 |
4da757 |
virtual TAssistant* createAssistant(TMetaObject &obj) const
|
|
 |
4da757 |
{ return 0; }
|
|
 |
4da757 |
};
|
|
 |
4da757 |
|
|
 |
4da757 |
|
|
 |
4da757 |
//*****************************************************************************************
|
|
 |
4da757 |
|
|
 |
4da757 |
//*****************************************************************************************
|
|
 |
4da757 |
|
|
 |
4da757 |
template<typename t=""></typename>
|
|
 |
4da757 |
class TAssistantTypeT: public TAssistantType {
|
|
 |
4da757 |
public:
|
|
 |
4da757 |
typedef T Type;
|
|
 |
4da757 |
|
|
 |
4da757 |
explicit TAssistantTypeT(
|
|
 |
4da757 |
const TStringId &name,
|
|
 |
4da757 |
const TStringId &alias1 = TStringId(),
|
|
 |
4da757 |
const TStringId &alias2 = TStringId(),
|
|
 |
4da757 |
const TStringId &alias3 = TStringId(),
|
|
 |
4da757 |
const TStringId &alias4 = TStringId(),
|
|
 |
4da757 |
const TStringId &alias5 = TStringId()
|
|
 |
4da757 |
):
|
|
 |
4da757 |
TAssistantType(TStringId(name))
|
|
 |
4da757 |
{
|
|
 |
4da757 |
if (alias1) registerAlias(alias1);
|
|
 |
4da757 |
if (alias2) registerAlias(alias2);
|
|
 |
4da757 |
if (alias3) registerAlias(alias3);
|
|
 |
4da757 |
if (alias4) registerAlias(alias4);
|
|
 |
4da757 |
if (alias5) registerAlias(alias5);
|
|
 |
4da757 |
}
|
|
 |
4da757 |
|
|
 |
4da757 |
explicit TAssistantTypeT(
|
|
 |
4da757 |
const std::string &name,
|
|
 |
4da757 |
const std::string &alias1 = std::string(),
|
|
 |
4da757 |
const std::string &alias2 = std::string(),
|
|
 |
4da757 |
const std::string &alias3 = std::string(),
|
|
 |
4da757 |
const std::string &alias4 = std::string(),
|
|
 |
4da757 |
const std::string &alias5 = std::string()
|
|
 |
4da757 |
):
|
|
 |
4da757 |
TAssistantType(TStringId(name))
|
|
 |
4da757 |
{
|
|
 |
4da757 |
if (!alias1.empty()) registerAlias(TStringId(alias1));
|
|
 |
4da757 |
if (!alias2.empty()) registerAlias(TStringId(alias2));
|
|
 |
4da757 |
if (!alias3.empty()) registerAlias(TStringId(alias3));
|
|
 |
4da757 |
if (!alias4.empty()) registerAlias(TStringId(alias4));
|
|
 |
4da757 |
if (!alias5.empty()) registerAlias(TStringId(alias5));
|
|
 |
4da757 |
}
|
|
 |
4da757 |
|
|
 |
4da757 |
TAssistant* createAssistant(TMetaObject &obj) const override
|
|
 |
4da757 |
{ return new Type(obj); }
|
|
 |
4da757 |
QString getLocalName() const override {
|
|
 |
4da757 |
QString localName = Type::getLocalName();
|
|
 |
4da757 |
return localName.isEmpty() ? QString::fromStdString(name.str()) : localName;
|
|
 |
4da757 |
}
|
|
 |
4da757 |
};
|
|
 |
4da757 |
|
|
 |
4da757 |
|
|
 |
9cf8be |
//*****************************************************************************************
|
|
 |
911124 |
|
|
 |
911124 |
//*****************************************************************************************
|
|
 |
911124 |
|
|
 |
4df9cd |
class DVAPI TAssistant : public TMetaObjectHandler {
|
|
 |
4da757 |
Q_DECLARE_TR_FUNCTIONS(TAssistant)
|
|
 |
9cf8be |
protected:
|
|
 |
3bac66 |
const TStringId m_idEnabled;
|
|
 |
9cf8be |
const TStringId m_idPoints;
|
|
 |
9cf8be |
const TStringId m_idX;
|
|
 |
9cf8be |
const TStringId m_idY;
|
|
 |
3bac66 |
const TStringId m_idMagnetism;
|
|
 |
9cf8be |
|
|
 |
c5e805 |
TAssistantPointMap m_points;
|
|
 |
7900ea |
TAssistantPointOrder m_pointsOrder;
|
|
 |
c5e805 |
TAssistantPoint* m_basePoint;
|
|
 |
9cf8be |
|
|
 |
3bac66 |
mutable TPropertyGroup m_properties;
|
|
 |
3bac66 |
|
|
 |
911124 |
public:
|
|
 |
9cf8be |
TAssistant(TMetaObject &object);
|
|
 |
9cf8be |
|
|
 |
4da757 |
static QString getLocalName()
|
|
 |
4da757 |
{ return QString(); }
|
|
 |
4da757 |
|
|
 |
c5e805 |
inline const TAssistantPointMap& points() const
|
|
 |
9cf8be |
{ return m_points; }
|
|
 |
7900ea |
inline const TAssistantPointOrder& pointsOrder() const
|
|
 |
7900ea |
{ return m_pointsOrder; }
|
|
 |
c5e805 |
|
|
 |
c5e805 |
inline const TAssistantPoint* findPoint(const TStringId &name) const {
|
|
 |
c5e805 |
TAssistantPointMap::const_iterator i = points().find(name);
|
|
 |
c5e805 |
return i == points().end() ? 0 : &i->second;
|
|
 |
c5e805 |
}
|
|
 |
9cf8be |
|
|
 |
249386 |
void fixPoints();
|
|
 |
b15438 |
bool move(const TPointD &position);
|
|
 |
b15438 |
bool movePoint(const TStringId &name, const TPointD &position);
|
|
 |
c5e805 |
void setPointSelection(const TStringId &name, bool selected) const;
|
|
 |
c5e805 |
void setAllPointsSelection(bool selected) const;
|
|
 |
9cf8be |
|
|
 |
3bac66 |
bool getEnabled() const
|
|
 |
3bac66 |
{ return data()[m_idEnabled].getBool(); }
|
|
 |
3bac66 |
void setEnabled(bool x)
|
|
 |
3bac66 |
{ if (getEnabled() != x) data()[m_idEnabled].setBool(x); }
|
|
 |
3bac66 |
|
|
 |
3bac66 |
double getMagnetism() const
|
|
 |
3bac66 |
{ return data()[m_idMagnetism].getDouble(); }
|
|
 |
3bac66 |
void setMagnetism(double x)
|
|
 |
3bac66 |
{ if (getMagnetism() != x) data()[m_idMagnetism].setDouble(x); }
|
|
 |
3bac66 |
|
|
 |
c5e805 |
inline void selectPoint(const TStringId &name) const
|
|
 |
c5e805 |
{ setPointSelection(name, true); }
|
|
 |
c5e805 |
inline void deselectPoint(const TStringId &name) const
|
|
 |
c5e805 |
{ setPointSelection(name, false); }
|
|
 |
249386 |
inline void selectAll() const
|
|
 |
c5e805 |
{ setAllPointsSelection(true); }
|
|
 |
249386 |
inline void deselectAll() const
|
|
 |
c5e805 |
{ setAllPointsSelection(false); }
|
|
 |
9cf8be |
|
|
 |
3bac66 |
TPropertyGroup& getProperties() const
|
|
 |
3bac66 |
{ return m_properties; }
|
|
 |
3bac66 |
void propertyChanged(const TStringId &name)
|
|
 |
c7854d |
{ onPropertyChanged(name); }
|
|
 |
3bac66 |
|
|
 |
c5e805 |
const TAssistantPoint& getBasePoint() const;
|
|
 |
c5e805 |
|
|
 |
9cf8be |
protected:
|
|
 |
c5e805 |
TAssistantPoint& addPoint(
|
|
 |
c5e805 |
const TStringId &name,
|
|
 |
c5e805 |
TAssistantPoint::Type type,
|
|
 |
7900ea |
const TPointD &defPosition,
|
|
 |
c5e805 |
bool visible,
|
|
 |
c5e805 |
double radius );
|
|
 |
c5e805 |
|
|
 |
c5e805 |
TAssistantPoint& addPoint(
|
|
 |
c5e805 |
const TStringId &name,
|
|
 |
c5e805 |
TAssistantPoint::Type type = TAssistantPoint::Circle,
|
|
 |
7900ea |
const TPointD &defPosition = TPointD(),
|
|
 |
c5e805 |
bool visible = true );
|
|
 |
c5e805 |
|
|
 |
c5e805 |
inline TAssistantPoint& addPoint(
|
|
 |
c5e805 |
const std::string &name,
|
|
 |
c5e805 |
TAssistantPoint::Type type,
|
|
 |
7900ea |
const TPointD &defPosition,
|
|
 |
c5e805 |
bool visible,
|
|
 |
c5e805 |
double radius )
|
|
 |
7900ea |
{ return addPoint(TStringId(name), type, defPosition, visible, radius); }
|
|
 |
c5e805 |
|
|
 |
c5e805 |
inline TAssistantPoint& addPoint(
|
|
 |
c5e805 |
const std::string &name,
|
|
 |
c5e805 |
TAssistantPoint::Type type = TAssistantPoint::Circle,
|
|
 |
7900ea |
const TPointD &defPosition = TPointD(),
|
|
 |
c5e805 |
bool visible = true )
|
|
 |
7900ea |
{ return addPoint(TStringId(name), type, defPosition, visible); }
|
|
 |
c5e805 |
|
|
 |
3bac66 |
|
|
 |
3bac66 |
void onSetDefaults() override;
|
|
 |
9cf8be |
//! called when part of variant data changed
|
|
 |
9cf8be |
void onDataChanged(const TVariant &value) override;
|
|
 |
7900ea |
//! called when field of root struct of variant data changed
|
|
 |
7900ea |
virtual void onDataFieldChanged(const TStringId &name, const TVariant &value);
|
|
 |
9cf8be |
//! load object data from variant
|
|
 |
9cf8be |
virtual void onAllDataChanged();
|
|
 |
249386 |
//! fix positions of all points (as like as all points moved)
|
|
 |
9cf8be |
virtual void onFixPoints();
|
|
 |
9cf8be |
|
|
 |
c5e805 |
virtual void onMovePoint(TAssistantPoint &point, const TPointD &position);
|
|
 |
9cf8be |
|
|
 |
9cf8be |
virtual void onFixData();
|
|
 |
3bac66 |
//! load all properties from variant
|
|
 |
3bac66 |
virtual void updateProperties();
|
|
 |
3bac66 |
//! load single property from variant
|
|
 |
3bac66 |
virtual void updateProperty(const TStringId &name, const TVariant &value);
|
|
 |
3bac66 |
//! put value from property to variant
|
|
 |
3bac66 |
virtual void onPropertyChanged(const TStringId &name);
|
|
 |
9cf8be |
|
|
 |
c7854d |
double getDrawingAlpha(bool enabled = true) const;
|
|
 |
c7854d |
double getDrawingGridAlpha() const;
|
|
 |
c7854d |
|
|
 |
c7854d |
void drawSegment(const TPointD &p0, const TPointD &p1, double pixelSize, double alpha) const;
|
|
 |
c7854d |
void drawDot(const TPointD &p, double alpha) const;
|
|
 |
9cf8be |
void drawPoint(const TAssistantPoint &point, double pixelSize) const;
|
|
 |
ae9154 |
|
|
 |
c7854d |
inline void drawSegment(const TPointD &p0, const TPointD &p1, double pixelSize) const
|
|
 |
c7854d |
{ drawSegment(p0, p1, pixelSize, getDrawingAlpha()); }
|
|
 |
c7854d |
inline void drawDot(const TPointD &p) const
|
|
 |
c7854d |
{ drawDot(p, getDrawingAlpha()); }
|
|
 |
c7854d |
|
|
 |
4da757 |
void addProperty(TProperty *p);
|
|
 |
4da757 |
void setTranslation(const TStringId &name, const QString &localName) const;
|
|
 |
3bac66 |
|
|
 |
9cf8be |
public:
|
|
 |
4da757 |
virtual void updateTranslation() const;
|
|
 |
9cf8be |
virtual void getGuidelines(const TPointD &position, const TAffine &toTool, TGuidelineList &outGuidelines) const;
|
|
 |
8074a5 |
virtual void draw(TToolViewer *viewer, bool enabled) const;
|
|
 |
8074a5 |
void draw(TToolViewer *viewer) const { draw(viewer, true); }
|
|
 |
9cf8be |
virtual void drawEdit(TToolViewer *viewer) const;
|
|
 |
9a49d4 |
|
|
 |
9a49d4 |
static bool calcPerspectiveStep(
|
|
 |
9a49d4 |
double minStep,
|
|
 |
9a49d4 |
double minX,
|
|
 |
9a49d4 |
double maxX,
|
|
 |
9a49d4 |
double x0,
|
|
 |
9a49d4 |
double x1,
|
|
 |
9a49d4 |
double x2,
|
|
 |
9a49d4 |
double &outK,
|
|
 |
9a49d4 |
double &outMin,
|
|
 |
9a49d4 |
double &outMax );
|
|
 |
911124 |
};
|
|
 |
911124 |
|
|
 |
16421e |
|
|
 |
16421e |
//*****************************************************************************************
|
|
 |
16421e |
// export template implementations for win32
|
|
 |
16421e |
//*****************************************************************************************
|
|
 |
16421e |
|
|
 |
16421e |
#ifdef _WIN32
|
|
 |
16421e |
template class DVAPI TSmartPointerT<tguideline>;</tguideline>
|
|
 |
16421e |
#endif
|
|
 |
16421e |
|
|
 |
16421e |
|
|
 |
911124 |
#endif
|