+ issue #0001475: Implement a 3 point arc similar to solidworks in sketcher
This commit is contained in:
parent
d1341f36f7
commit
a7aca65e77
|
@ -130,7 +130,7 @@ public:
|
||||||
|
|
||||||
/// retrieves for a Vertex number the corresponding GeoId and PosId
|
/// retrieves for a Vertex number the corresponding GeoId and PosId
|
||||||
void getGeoVertexIndex(int VertexId, int &GeoId, PointPos &PosId) const;
|
void getGeoVertexIndex(int VertexId, int &GeoId, PointPos &PosId) const;
|
||||||
int getHighestVertexIndex(void) const { return VertexId2GeoId.size() - 1; }
|
int getHighestVertexIndex(void) const { return VertexId2GeoId.size() - 1; } // Most recently created
|
||||||
int getHighestCurveIndex(void) const { return Geometry.getSize() - 1; }
|
int getHighestCurveIndex(void) const { return Geometry.getSize() - 1; }
|
||||||
void rebuildVertexIndex(void);
|
void rebuildVertexIndex(void);
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ public:
|
||||||
virtual unsigned int getMemSize(void) const;
|
virtual unsigned int getMemSize(void) const;
|
||||||
virtual void Save(Base::Writer &/*writer*/) const;
|
virtual void Save(Base::Writer &/*writer*/) const;
|
||||||
virtual void Restore(Base::XMLReader &/*reader*/);
|
virtual void Restore(Base::XMLReader &/*reader*/);
|
||||||
|
|
||||||
/// returns the number of construction lines (to be used as axes)
|
/// returns the number of construction lines (to be used as axes)
|
||||||
virtual int getAxisCount(void) const;
|
virtual int getAxisCount(void) const;
|
||||||
/// retrieves an axis iterating through the construction lines of the sketch (indices start at 0)
|
/// retrieves an axis iterating through the construction lines of the sketch (indices start at 0)
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace SketcherGui;
|
using namespace SketcherGui;
|
||||||
|
|
||||||
|
|
||||||
/* helper functions ======================================================*/
|
/* helper functions ======================================================*/
|
||||||
|
|
||||||
// Return counter-clockwise angle from horizontal out of p1 to p2 in radians.
|
// Return counter-clockwise angle from horizontal out of p1 to p2 in radians.
|
||||||
|
@ -78,15 +79,14 @@ Base::Vector2D GetCircleCenter (const Base::Vector2D &p1, const Base::Vector2D &
|
||||||
{
|
{
|
||||||
double m12p = (p1.fX - p2.fX) / (p2.fY - p1.fY);
|
double m12p = (p1.fX - p2.fX) / (p2.fY - p1.fY);
|
||||||
double m23p = (p2.fX - p3.fX) / (p3.fY - p2.fY);
|
double m23p = (p2.fX - p3.fX) / (p3.fY - p2.fY);
|
||||||
double x = 1/( 2*(m12p - m23p) ) * ( (pow(p3.fX, 2) - pow(p2.fX, 2)) / (p3.fY - p2.fY) -
|
double x = 1/( 2*(m12p - m23p) ) * ( m12p*(p1.fX + p2.fX) -
|
||||||
(pow(p2.fX, 2) - pow(p1.fX, 2)) / (p2.fY - p1.fY) +
|
m23p*(p2.fX + p3.fX) +
|
||||||
p3.fY - p1.fY );
|
p3.fY - p1.fY );
|
||||||
double y = m12p * ( x - (p1.fX + p2.fX)/2 ) + (p1.fY + p2.fY)/2;
|
double y = m12p * ( x - (p1.fX + p2.fX)/2 ) + (p1.fY + p2.fY)/2;
|
||||||
|
|
||||||
return Base::Vector2D(x, y);
|
return Base::Vector2D(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ActivateHandler(Gui::Document *doc,DrawSketchHandler *handler)
|
void ActivateHandler(Gui::Document *doc,DrawSketchHandler *handler)
|
||||||
{
|
{
|
||||||
if (doc) {
|
if (doc) {
|
||||||
|
@ -121,6 +121,7 @@ SketcherGui::ViewProviderSketch* getSketchViewprovider(Gui::Document *doc)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Sketch commands =======================================================*/
|
/* Sketch commands =======================================================*/
|
||||||
|
|
||||||
/* XPM */
|
/* XPM */
|
||||||
|
@ -256,8 +257,6 @@ protected:
|
||||||
std::vector<AutoConstraint> sugConstr1, sugConstr2;
|
std::vector<AutoConstraint> sugConstr1, sugConstr2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DEF_STD_CMD_A(CmdSketcherCreateLine);
|
DEF_STD_CMD_A(CmdSketcherCreateLine);
|
||||||
|
|
||||||
CmdSketcherCreateLine::CmdSketcherCreateLine()
|
CmdSketcherCreateLine::CmdSketcherCreateLine()
|
||||||
|
@ -464,8 +463,6 @@ protected:
|
||||||
std::vector<AutoConstraint> sugConstr1, sugConstr2;
|
std::vector<AutoConstraint> sugConstr1, sugConstr2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DEF_STD_CMD_A(CmdSketcherCreateRectangle);
|
DEF_STD_CMD_A(CmdSketcherCreateRectangle);
|
||||||
|
|
||||||
CmdSketcherCreateRectangle::CmdSketcherCreateRectangle()
|
CmdSketcherCreateRectangle::CmdSketcherCreateRectangle()
|
||||||
|
@ -989,7 +986,6 @@ protected:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
DEF_STD_CMD_A(CmdSketcherCreatePolyline);
|
DEF_STD_CMD_A(CmdSketcherCreatePolyline);
|
||||||
|
|
||||||
CmdSketcherCreatePolyline::CmdSketcherCreatePolyline()
|
CmdSketcherCreatePolyline::CmdSketcherCreatePolyline()
|
||||||
|
@ -1015,6 +1011,7 @@ bool CmdSketcherCreatePolyline::isActive(void)
|
||||||
return isCreateGeoActive(getActiveGuiDocument());
|
return isCreateGeoActive(getActiveGuiDocument());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ======================================================================================
|
// ======================================================================================
|
||||||
|
|
||||||
/* XPM */
|
/* XPM */
|
||||||
|
@ -1363,19 +1360,39 @@ public:
|
||||||
double angle2 = GetPointAngle(CenterPoint, SecondPoint);
|
double angle2 = GetPointAngle(CenterPoint, SecondPoint);
|
||||||
double angle3 = GetPointAngle(CenterPoint, onSketchPos);
|
double angle3 = GetPointAngle(CenterPoint, onSketchPos);
|
||||||
|
|
||||||
// angle3 == angle1 or angle2 shouldn't be allowed but not sure...catch/try?
|
// Always build arc counter-clockwise
|
||||||
// Point 3 is between Point 1 and 2
|
// Point 3 is between Point 1 and 2
|
||||||
if ( angle3 > min(angle1, angle2) && angle3 < max(angle1, angle2) ) {
|
if ( angle3 > min(angle1, angle2) && angle3 < max(angle1, angle2) ) {
|
||||||
EditCurve[0] = angle2 > angle1 ? FirstPoint : SecondPoint;
|
if (angle2 > angle1) {
|
||||||
EditCurve[29] = angle2 > angle1 ? SecondPoint : FirstPoint;
|
EditCurve[0] = FirstPoint;
|
||||||
|
EditCurve[29] = SecondPoint;
|
||||||
|
arcPos1 = Sketcher::start;
|
||||||
|
arcPos2 = Sketcher::end;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
EditCurve[0] = SecondPoint;
|
||||||
|
EditCurve[29] = FirstPoint;
|
||||||
|
arcPos1 = Sketcher::end;
|
||||||
|
arcPos2 = Sketcher::start;
|
||||||
|
}
|
||||||
startAngle = min(angle1, angle2);
|
startAngle = min(angle1, angle2);
|
||||||
endAngle = max(angle1, angle2);
|
endAngle = max(angle1, angle2);
|
||||||
arcAngle = endAngle - startAngle;
|
arcAngle = endAngle - startAngle;
|
||||||
}
|
}
|
||||||
// Point 3 is not between Point 1 and 2
|
// Point 3 is not between Point 1 and 2
|
||||||
else {
|
else {
|
||||||
EditCurve[0] = angle2 > angle1 ? SecondPoint : FirstPoint;
|
if (angle2 > angle1) {
|
||||||
EditCurve[29] = angle2 > angle1 ? FirstPoint : SecondPoint;
|
EditCurve[0] = SecondPoint;
|
||||||
|
EditCurve[29] = FirstPoint;
|
||||||
|
arcPos1 = Sketcher::end;
|
||||||
|
arcPos2 = Sketcher::start;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
EditCurve[0] = FirstPoint;
|
||||||
|
EditCurve[29] = SecondPoint;
|
||||||
|
arcPos1 = Sketcher::start;
|
||||||
|
arcPos2 = Sketcher::end;
|
||||||
|
}
|
||||||
startAngle = max(angle1, angle2);
|
startAngle = max(angle1, angle2);
|
||||||
endAngle = min(angle1, angle2);
|
endAngle = min(angle1, angle2);
|
||||||
arcAngle = 2*M_PI - (startAngle - endAngle);
|
arcAngle = 2*M_PI - (startAngle - endAngle);
|
||||||
|
@ -1394,6 +1411,9 @@ public:
|
||||||
|
|
||||||
sketchgui->drawEdit(EditCurve);
|
sketchgui->drawEdit(EditCurve);
|
||||||
if (seekAutoConstraint(sugConstr3, onSketchPos, Base::Vector2D(0.0,0.0))) {
|
if (seekAutoConstraint(sugConstr3, onSketchPos, Base::Vector2D(0.0,0.0))) {
|
||||||
|
// seekAutoConstraint doesn't handle this correctly because Coincident
|
||||||
|
// cannot snap to an arc yet it picks coincident because I click a point.
|
||||||
|
sugConstr3.back().Type = Sketcher::PointOnObject;
|
||||||
renderSuggestConstraintsCursor(sugConstr3);
|
renderSuggestConstraintsCursor(sugConstr3);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1447,21 +1467,21 @@ public:
|
||||||
Gui::Command::commitCommand();
|
Gui::Command::commitCommand();
|
||||||
Gui::Command::updateActive();
|
Gui::Command::updateActive();
|
||||||
|
|
||||||
// Auto Constraint center point
|
// Auto Constraint first picked point
|
||||||
if (sugConstr1.size() > 0) {
|
if (sugConstr1.size() > 0) {
|
||||||
createAutoConstraints(sugConstr1, getHighestCurveIndex(), Sketcher::mid);
|
createAutoConstraints(sugConstr1, getHighestCurveIndex(), arcPos1);
|
||||||
sugConstr1.clear();
|
sugConstr1.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto Constraint first picked point
|
// Auto Constraint second picked point
|
||||||
if (sugConstr2.size() > 0) {
|
if (sugConstr2.size() > 0) {
|
||||||
createAutoConstraints(sugConstr2, getHighestCurveIndex(), (arcAngle > 0) ? Sketcher::start : Sketcher::end );
|
createAutoConstraints(sugConstr2, getHighestCurveIndex(), arcPos2);
|
||||||
sugConstr2.clear();
|
sugConstr2.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto Constraint second picked point
|
// Auto Constraint third picked point
|
||||||
if (sugConstr3.size() > 0) {
|
if (sugConstr3.size() > 0) {
|
||||||
createAutoConstraints(sugConstr3, getHighestCurveIndex(), (arcAngle > 0) ? Sketcher::end : Sketcher::start);
|
createAutoConstraints(sugConstr3, getHighestCurveIndex(), Sketcher::none);
|
||||||
sugConstr3.clear();
|
sugConstr3.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1477,9 +1497,9 @@ protected:
|
||||||
Base::Vector2D CenterPoint, FirstPoint, SecondPoint;
|
Base::Vector2D CenterPoint, FirstPoint, SecondPoint;
|
||||||
double radius, startAngle, endAngle, arcAngle;
|
double radius, startAngle, endAngle, arcAngle;
|
||||||
std::vector<AutoConstraint> sugConstr1, sugConstr2, sugConstr3;
|
std::vector<AutoConstraint> sugConstr1, sugConstr2, sugConstr3;
|
||||||
|
Sketcher::PointPos arcPos1, arcPos2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
DEF_STD_CMD_A(CmdSketcherCreate3PointArc);
|
DEF_STD_CMD_A(CmdSketcherCreate3PointArc);
|
||||||
|
|
||||||
CmdSketcherCreate3PointArc::CmdSketcherCreate3PointArc()
|
CmdSketcherCreate3PointArc::CmdSketcherCreate3PointArc()
|
||||||
|
@ -1505,6 +1525,7 @@ bool CmdSketcherCreate3PointArc::isActive(void)
|
||||||
return isCreateGeoActive(getActiveGuiDocument());
|
return isCreateGeoActive(getActiveGuiDocument());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DEF_STD_CMD_ACL(CmdSketcherCompCreateArc);
|
DEF_STD_CMD_ACL(CmdSketcherCompCreateArc);
|
||||||
|
|
||||||
CmdSketcherCompCreateArc::CmdSketcherCompCreateArc()
|
CmdSketcherCompCreateArc::CmdSketcherCompCreateArc()
|
||||||
|
@ -1583,7 +1604,6 @@ bool CmdSketcherCompCreateArc::isActive(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ======================================================================================
|
// ======================================================================================
|
||||||
|
|
||||||
/* XPM */
|
/* XPM */
|
||||||
|
@ -1760,6 +1780,7 @@ bool CmdSketcherCreateCircle::isActive(void)
|
||||||
return isCreateGeoActive(getActiveGuiDocument());
|
return isCreateGeoActive(getActiveGuiDocument());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ======================================================================================
|
// ======================================================================================
|
||||||
|
|
||||||
/* XPM */
|
/* XPM */
|
||||||
|
@ -1858,7 +1879,6 @@ protected:
|
||||||
std::vector<AutoConstraint> sugConstr;
|
std::vector<AutoConstraint> sugConstr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
DEF_STD_CMD_A(CmdSketcherCreatePoint);
|
DEF_STD_CMD_A(CmdSketcherCreatePoint);
|
||||||
|
|
||||||
CmdSketcherCreatePoint::CmdSketcherCreatePoint()
|
CmdSketcherCreatePoint::CmdSketcherCreatePoint()
|
||||||
|
@ -1884,6 +1904,7 @@ bool CmdSketcherCreatePoint::isActive(void)
|
||||||
return isCreateGeoActive(getActiveGuiDocument());
|
return isCreateGeoActive(getActiveGuiDocument());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ======================================================================================
|
// ======================================================================================
|
||||||
|
|
||||||
DEF_STD_CMD_A(CmdSketcherCreateText);
|
DEF_STD_CMD_A(CmdSketcherCreateText);
|
||||||
|
@ -1910,6 +1931,7 @@ bool CmdSketcherCreateText::isActive(void)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ======================================================================================
|
// ======================================================================================
|
||||||
|
|
||||||
DEF_STD_CMD_A(CmdSketcherCreateDraftLine);
|
DEF_STD_CMD_A(CmdSketcherCreateDraftLine);
|
||||||
|
@ -1936,6 +1958,7 @@ bool CmdSketcherCreateDraftLine::isActive(void)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ======================================================================================
|
// ======================================================================================
|
||||||
|
|
||||||
namespace SketcherGui {
|
namespace SketcherGui {
|
||||||
|
@ -1980,6 +2003,7 @@ namespace SketcherGui {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* XPM */
|
/* XPM */
|
||||||
static const char *cursor_createfillet[]={
|
static const char *cursor_createfillet[]={
|
||||||
"32 32 3 1",
|
"32 32 3 1",
|
||||||
|
@ -2183,6 +2207,8 @@ bool CmdSketcherCreateFillet::isActive(void)
|
||||||
{
|
{
|
||||||
return isCreateGeoActive(getActiveGuiDocument());
|
return isCreateGeoActive(getActiveGuiDocument());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ======================================================================================
|
// ======================================================================================
|
||||||
|
|
||||||
namespace SketcherGui {
|
namespace SketcherGui {
|
||||||
|
@ -2215,6 +2241,7 @@ namespace SketcherGui {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* XPM */
|
/* XPM */
|
||||||
static const char *cursor_trimming[]={
|
static const char *cursor_trimming[]={
|
||||||
"32 32 3 1",
|
"32 32 3 1",
|
||||||
|
@ -2335,6 +2362,7 @@ bool CmdSketcherTrimming::isActive(void)
|
||||||
return isCreateGeoActive(getActiveGuiDocument());
|
return isCreateGeoActive(getActiveGuiDocument());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ======================================================================================
|
// ======================================================================================
|
||||||
|
|
||||||
namespace SketcherGui {
|
namespace SketcherGui {
|
||||||
|
@ -2366,6 +2394,7 @@ namespace SketcherGui {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* XPM */
|
/* XPM */
|
||||||
static const char *cursor_external[]={
|
static const char *cursor_external[]={
|
||||||
"32 32 3 1",
|
"32 32 3 1",
|
||||||
|
|
|
@ -127,7 +127,7 @@ SbVec2s ViewProviderSketch::newCursorPos;
|
||||||
//**************************************************************************
|
//**************************************************************************
|
||||||
// Edit data structure
|
// Edit data structure
|
||||||
|
|
||||||
/// Data structure while edit the sketch
|
/// Data structure while editing the sketch
|
||||||
struct EditData {
|
struct EditData {
|
||||||
EditData():
|
EditData():
|
||||||
sketchHandler(0),
|
sketchHandler(0),
|
||||||
|
|
|
@ -67,7 +67,7 @@ class DrawSketchHandler;
|
||||||
/** The Sketch ViewProvider
|
/** The Sketch ViewProvider
|
||||||
* This class handles mainly the drawing and editing of the sketch.
|
* This class handles mainly the drawing and editing of the sketch.
|
||||||
* It draws the geometry and the constraints applied to the sketch.
|
* It draws the geometry and the constraints applied to the sketch.
|
||||||
* It uses the class DrawSketchHandler to facilitade the creation
|
* It uses the class DrawSketchHandler to facilitate the creation
|
||||||
* of new geometry while editing.
|
* of new geometry while editing.
|
||||||
*/
|
*/
|
||||||
class SketcherGuiExport ViewProviderSketch : public PartGui::ViewProvider2DObject, public Gui::SelectionObserver
|
class SketcherGuiExport ViewProviderSketch : public PartGui::ViewProvider2DObject, public Gui::SelectionObserver
|
||||||
|
@ -116,7 +116,7 @@ public:
|
||||||
enum SketchMode{
|
enum SketchMode{
|
||||||
STATUS_NONE, /**< enum value View provider is in neutral. */
|
STATUS_NONE, /**< enum value View provider is in neutral. */
|
||||||
STATUS_SELECT_Point, /**< enum value a point was selected. */
|
STATUS_SELECT_Point, /**< enum value a point was selected. */
|
||||||
STATUS_SELECT_Edge, /**< enum value a edge was selected. */
|
STATUS_SELECT_Edge, /**< enum value an edge was selected. */
|
||||||
STATUS_SELECT_Constraint, /**< enum value a constraint was selected. */
|
STATUS_SELECT_Constraint, /**< enum value a constraint was selected. */
|
||||||
STATUS_SELECT_Cross, /**< enum value the base coordinate system was selected. */
|
STATUS_SELECT_Cross, /**< enum value the base coordinate system was selected. */
|
||||||
STATUS_SKETCH_DragPoint, /**< enum value while dragging a point. */
|
STATUS_SKETCH_DragPoint, /**< enum value while dragging a point. */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user