[Sketcher]fix cursor display of angles

This commit is contained in:
wandererfan
2023-01-30 12:41:13 -05:00
committed by WandererFan
parent 27012bb23c
commit a810fa68b4
2 changed files with 870 additions and 718 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -22,11 +22,11 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cfloat>
#include <cfloat>
# include <QCursor>
# include <QLocale>
# include <QRegularExpression>
#include <QCursor>
#include <QLocale>
#include <QRegularExpression>
#endif
#include <App/Application.h>
@@ -39,8 +39,8 @@
#include <Mod/Sketcher/App/GeometryFacade.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include "Utils.h"
#include "DrawSketchHandler.h"
#include "Utils.h"
#include "ViewProviderSketch.h"
@@ -48,18 +48,19 @@ using namespace std;
using namespace SketcherGui;
using namespace Sketcher;
bool SketcherGui::tryAutoRecompute(Sketcher::SketchObject* obj, bool &autoremoveredundants)
bool SketcherGui::tryAutoRecompute(Sketcher::SketchObject* obj, bool& autoremoveredundants)
{
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");
bool autoRecompute = hGrp->GetBool("AutoRecompute",false);
bool autoRemoveRedundants = hGrp->GetBool("AutoRemoveRedundants",false);
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Sketcher");
bool autoRecompute = hGrp->GetBool("AutoRecompute", false);
bool autoRemoveRedundants = hGrp->GetBool("AutoRemoveRedundants", false);
// We need to make sure the solver has right redundancy information before trying to remove the redundants.
// for example if a non-driving constraint has been added.
if(autoRemoveRedundants && autoRecompute)
if (autoRemoveRedundants && autoRecompute)
obj->solve();
if(autoRemoveRedundants)
if (autoRemoveRedundants)
obj->autoRemoveRedundants();
if (autoRecompute)
@@ -74,17 +75,17 @@ bool SketcherGui::tryAutoRecompute(Sketcher::SketchObject* obj)
{
bool autoremoveredundants;
return tryAutoRecompute(obj,autoremoveredundants);
return tryAutoRecompute(obj, autoremoveredundants);
}
void SketcherGui::tryAutoRecomputeIfNotSolve(Sketcher::SketchObject* obj)
{
bool autoremoveredundants;
if(!tryAutoRecompute(obj,autoremoveredundants)) {
if (!tryAutoRecompute(obj, autoremoveredundants)) {
obj->solve();
if(autoremoveredundants) {
if (autoremoveredundants) {
obj->autoRemoveRedundants();
}
}
@@ -94,20 +95,23 @@ std::string SketcherGui::getStrippedPythonExceptionString(const Base::Exception&
{
std::string msg = e.what();
if( msg.length() > 26 && msg.substr(0,26) == "FreeCAD exception thrown (") {
return msg.substr(26, msg.length()-27);
if (msg.length() > 26 && msg.substr(0, 26) == "FreeCAD exception thrown (") {
return msg.substr(26, msg.length() - 27);
}
else
return msg;
}
bool SketcherGui::ReleaseHandler(Gui::Document* doc) {
bool SketcherGui::ReleaseHandler(Gui::Document* doc)
{
if (doc) {
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) {
SketcherGui::ViewProviderSketch* vp = static_cast<SketcherGui::ViewProviderSketch*> (doc->getInEdit());
if (doc->getInEdit()
&& doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) {
SketcherGui::ViewProviderSketch* vp =
static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
if (static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit())
->getSketchMode() == ViewProviderSketch::STATUS_SKETCH_UseHandler) {
if (static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit())->getSketchMode()
== ViewProviderSketch::STATUS_SKETCH_UseHandler) {
vp->purgeHandler();
return true;
@@ -117,28 +121,28 @@ bool SketcherGui::ReleaseHandler(Gui::Document* doc) {
return false;
}
void SketcherGui::getIdsFromName(const std::string &name, const Sketcher::SketchObject* Obj,
int &GeoId, PointPos &PosId)
void SketcherGui::getIdsFromName(const std::string& name, const Sketcher::SketchObject* Obj,
int& GeoId, PointPos& PosId)
{
GeoId = GeoEnum::GeoUndef;
PosId = Sketcher::PointPos::none;
if (name.size() > 4 && name.substr(0,4) == "Edge") {
GeoId = std::atoi(name.substr(4,4000).c_str()) - 1;
if (name.size() > 4 && name.substr(0, 4) == "Edge") {
GeoId = std::atoi(name.substr(4, 4000).c_str()) - 1;
}
else if (name.size() == 9 && name.substr(0,9) == "RootPoint") {
else if (name.size() == 9 && name.substr(0, 9) == "RootPoint") {
GeoId = Sketcher::GeoEnum::RtPnt;
PosId = Sketcher::PointPos::start;
}
else if (name.size() == 6 && name.substr(0,6) == "H_Axis")
else if (name.size() == 6 && name.substr(0, 6) == "H_Axis")
GeoId = Sketcher::GeoEnum::HAxis;
else if (name.size() == 6 && name.substr(0,6) == "V_Axis")
else if (name.size() == 6 && name.substr(0, 6) == "V_Axis")
GeoId = Sketcher::GeoEnum::VAxis;
else if (name.size() > 12 && name.substr(0,12) == "ExternalEdge")
GeoId = Sketcher::GeoEnum::RefExt + 1 - std::atoi(name.substr(12,4000).c_str());
else if (name.size() > 6 && name.substr(0,6) == "Vertex") {
int VtId = std::atoi(name.substr(6,4000).c_str()) - 1;
Obj->getGeoVertexIndex(VtId,GeoId,PosId);
else if (name.size() > 12 && name.substr(0, 12) == "ExternalEdge")
GeoId = Sketcher::GeoEnum::RefExt + 1 - std::atoi(name.substr(12, 4000).c_str());
else if (name.size() > 6 && name.substr(0, 6) == "Vertex") {
int VtId = std::atoi(name.substr(6, 4000).c_str()) - 1;
Obj->getGeoVertexIndex(VtId, GeoId, PosId);
}
}
@@ -152,42 +156,51 @@ bool SketcherGui::checkBothExternal(int GeoId1, int GeoId2)
bool SketcherGui::isPointOrSegmentFixed(const Sketcher::SketchObject* Obj, int GeoId)
{
const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues();
const std::vector<Sketcher::Constraint*>& vals = Obj->Constraints.getValues();
if (GeoId == GeoEnum::GeoUndef)
return false;
else
return checkConstraint(vals, Sketcher::Block, GeoId, Sketcher::PointPos::none) || GeoId <= Sketcher::GeoEnum::RtPnt;
return checkConstraint(vals, Sketcher::Block, GeoId, Sketcher::PointPos::none)
|| GeoId <= Sketcher::GeoEnum::RtPnt;
}
bool SketcherGui::areBothPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, int GeoId1, int GeoId2)
bool SketcherGui::areBothPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, int GeoId1,
int GeoId2)
{
const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues();
const std::vector<Sketcher::Constraint*>& vals = Obj->Constraints.getValues();
if (GeoId1 == GeoEnum::GeoUndef || GeoId2 == GeoEnum::GeoUndef)
return false;
else
return ((checkConstraint(vals, Sketcher::Block, GeoId1, Sketcher::PointPos::none) || GeoId1 <= Sketcher::GeoEnum::RtPnt) &&
(checkConstraint(vals, Sketcher::Block, GeoId2, Sketcher::PointPos::none) || GeoId2 <= Sketcher::GeoEnum::RtPnt));
return ((checkConstraint(vals, Sketcher::Block, GeoId1, Sketcher::PointPos::none)
|| GeoId1 <= Sketcher::GeoEnum::RtPnt)
&& (checkConstraint(vals, Sketcher::Block, GeoId2, Sketcher::PointPos::none)
|| GeoId2 <= Sketcher::GeoEnum::RtPnt));
}
bool SketcherGui::areAllPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, int GeoId1, int GeoId2, int GeoId3)
bool SketcherGui::areAllPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, int GeoId1,
int GeoId2, int GeoId3)
{
const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues();
const std::vector<Sketcher::Constraint*>& vals = Obj->Constraints.getValues();
if (GeoId1 == GeoEnum::GeoUndef || GeoId2 == GeoEnum::GeoUndef || GeoId3 == GeoEnum::GeoUndef)
return false;
else
return ((checkConstraint(vals, Sketcher::Block, GeoId1, Sketcher::PointPos::none) || GeoId1 <= Sketcher::GeoEnum::RtPnt) &&
(checkConstraint(vals, Sketcher::Block, GeoId2, Sketcher::PointPos::none) || GeoId2 <= Sketcher::GeoEnum::RtPnt) &&
(checkConstraint(vals, Sketcher::Block, GeoId3, Sketcher::PointPos::none) || GeoId3 <= Sketcher::GeoEnum::RtPnt));
return ((checkConstraint(vals, Sketcher::Block, GeoId1, Sketcher::PointPos::none)
|| GeoId1 <= Sketcher::GeoEnum::RtPnt)
&& (checkConstraint(vals, Sketcher::Block, GeoId2, Sketcher::PointPos::none)
|| GeoId2 <= Sketcher::GeoEnum::RtPnt)
&& (checkConstraint(vals, Sketcher::Block, GeoId3, Sketcher::PointPos::none)
|| GeoId3 <= Sketcher::GeoEnum::RtPnt));
}
bool SketcherGui::isSimpleVertex(const Sketcher::SketchObject* Obj, int GeoId, PointPos PosId)
{
if (PosId == Sketcher::PointPos::start && (GeoId == Sketcher::GeoEnum::HAxis || GeoId == Sketcher::GeoEnum::VAxis))
if (PosId == Sketcher::PointPos::start
&& (GeoId == Sketcher::GeoEnum::HAxis || GeoId == Sketcher::GeoEnum::VAxis))
return true;
const Part::Geometry *geo = Obj->getGeometry(GeoId);
const Part::Geometry* geo = Obj->getGeometry(GeoId);
if (geo->getTypeId() == Part::GeomPoint::getClassTypeId())
return true;
else if (PosId == Sketcher::PointPos::mid)
@@ -202,22 +215,24 @@ bool SketcherGui::isBsplineKnot(const Sketcher::SketchObject* Obj, int GeoId)
return (gf && gf->getInternalType() == Sketcher::InternalType::BSplineKnotPoint);
}
bool SketcherGui::isBsplineKnotOrEndPoint(const Sketcher::SketchObject* Obj, int GeoId, Sketcher::PointPos PosId)
bool SketcherGui::isBsplineKnotOrEndPoint(const Sketcher::SketchObject* Obj, int GeoId,
Sketcher::PointPos PosId)
{
// check first using geometry facade
if (isBsplineKnot(Obj, GeoId))
return true;
const Part::Geometry *geo = Obj->getGeometry(GeoId);
const Part::Geometry* geo = Obj->getGeometry(GeoId);
// end points of B-Splines are also knots
if (geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId() &&
(PosId == Sketcher::PointPos::start || PosId == Sketcher::PointPos::end))
if (geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()
&& (PosId == Sketcher::PointPos::start || PosId == Sketcher::PointPos::end))
return true;
return false;
}
bool SketcherGui::IsPointAlreadyOnCurve(int GeoIdCurve, int GeoIdPoint, Sketcher::PointPos PosIdPoint, Sketcher::SketchObject* Obj)
bool SketcherGui::IsPointAlreadyOnCurve(int GeoIdCurve, int GeoIdPoint,
Sketcher::PointPos PosIdPoint, Sketcher::SketchObject* Obj)
{
//This func is a "smartness" behind three-element tangent-, perp.- and angle-via-point.
//We want to find out, if the point supplied by user is already on
@@ -230,13 +245,12 @@ bool SketcherGui::IsPointAlreadyOnCurve(int GeoIdCurve, int GeoIdPoint, Sketcher
// too much trouble, IMO(DeepSOIC).
// One exception: check for knots on their B-splines, at least until point on B-spline is implemented. (Ajinkya)
if (isBsplineKnot(Obj, GeoIdPoint)) {
const Part::Geometry *geoCurve = Obj->getGeometry(GeoIdCurve);
const Part::Geometry* geoCurve = Obj->getGeometry(GeoIdCurve);
if (geoCurve->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) {
const std::vector<Constraint *> &constraints = Obj->Constraints.getValues();
for (const auto& constraint: constraints) {
if (constraint->Type == Sketcher::ConstraintType::InternalAlignment &&
constraint->First == GeoIdPoint &&
constraint->Second == GeoIdCurve)
const std::vector<Constraint*>& constraints = Obj->Constraints.getValues();
for (const auto& constraint : constraints) {
if (constraint->Type == Sketcher::ConstraintType::InternalAlignment
&& constraint->First == GeoIdPoint && constraint->Second == GeoIdCurve)
return true;
}
}
@@ -246,11 +260,11 @@ bool SketcherGui::IsPointAlreadyOnCurve(int GeoIdCurve, int GeoIdPoint, Sketcher
return Obj->isPointOnCurve(GeoIdCurve, p.x, p.y);
}
bool SketcherGui::isBsplinePole(const Part::Geometry * geo)
bool SketcherGui::isBsplinePole(const Part::Geometry* geo)
{
auto gf = GeometryFacade::getFacade(geo);
if(gf)
if (gf)
return gf->getInternalType() == InternalType::BSplineControlPoint;
THROWM(Base::ValueError, "Null geometry in isBsplinePole - please report")
@@ -264,10 +278,12 @@ bool SketcherGui::isBsplinePole(const Sketcher::SketchObject* Obj, int GeoId)
return isBsplinePole(geom);
}
bool SketcherGui::checkConstraint(const std::vector< Sketcher::Constraint * > &vals, ConstraintType type, int geoid, PointPos pos)
bool SketcherGui::checkConstraint(const std::vector<Sketcher::Constraint*>& vals,
ConstraintType type, int geoid, PointPos pos)
{
for (std::vector< Sketcher::Constraint * >::const_iterator itc= vals.begin(); itc != vals.end(); ++itc) {
if ((*itc)->Type == type && (*itc)->First == geoid && (*itc)->FirstPos == pos){
for (std::vector<Sketcher::Constraint*>::const_iterator itc = vals.begin(); itc != vals.end();
++itc) {
if ((*itc)->Type == type && (*itc)->First == geoid && (*itc)->FirstPos == pos) {
return true;
}
}
@@ -278,37 +294,42 @@ bool SketcherGui::checkConstraint(const std::vector< Sketcher::Constraint * > &v
/* helper functions ======================================================*/
// Return counter-clockwise angle from horizontal out of p1 to p2 in radians.
double SketcherGui::GetPointAngle (const Base::Vector2d &p1, const Base::Vector2d &p2)
double SketcherGui::GetPointAngle(const Base::Vector2d& p1, const Base::Vector2d& p2)
{
double dX = p2.x - p1.x;
double dY = p2.y - p1.y;
return dY >= 0 ? atan2(dY, dX) : atan2(dY, dX) + 2*M_PI;
double dX = p2.x - p1.x;
double dY = p2.y - p1.y;
return dY >= 0 ? atan2(dY, dX) : atan2(dY, dX) + 2 * M_PI;
}
void SketcherGui::ActivateHandler(Gui::Document *doc, DrawSketchHandler *handler)
void SketcherGui::ActivateHandler(Gui::Document* doc, DrawSketchHandler* handler)
{
std::unique_ptr<DrawSketchHandler> ptr(handler);
if (doc) {
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) {
SketcherGui::ViewProviderSketch* vp = static_cast<SketcherGui::ViewProviderSketch*> (doc->getInEdit());
if (doc->getInEdit()
&& doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) {
SketcherGui::ViewProviderSketch* vp =
static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
vp->purgeHandler();
vp->activateHandler(ptr.release());
}
}
}
bool SketcherGui::isCommandActive(Gui::Document *doc, bool actsOnSelection)
bool SketcherGui::isCommandActive(Gui::Document* doc, bool actsOnSelection)
{
if (doc) {
// checks if a Sketch Viewprovider is in Edit and is in no special mode
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) {
auto mode = static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit())
->getSketchMode();
if (mode == ViewProviderSketch::STATUS_NONE ||
mode == ViewProviderSketch::STATUS_SKETCH_UseHandler) {
if (doc->getInEdit()
&& doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) {
auto mode =
static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit())->getSketchMode();
if (mode == ViewProviderSketch::STATUS_NONE
|| mode == ViewProviderSketch::STATUS_SKETCH_UseHandler) {
if (!actsOnSelection)
return true;
else if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0)
else if (Gui::Selection().countObjectsOfType(
Sketcher::SketchObject::getClassTypeId())
> 0)
return true;
}
}
@@ -317,19 +338,19 @@ bool SketcherGui::isCommandActive(Gui::Document *doc, bool actsOnSelection)
return false;
}
SketcherGui::ViewProviderSketch* SketcherGui::getSketchViewprovider(Gui::Document *doc)
SketcherGui::ViewProviderSketch* SketcherGui::getSketchViewprovider(Gui::Document* doc)
{
if (doc) {
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom
(SketcherGui::ViewProviderSketch::getClassTypeId()) )
if (doc->getInEdit()
&& doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId()))
return dynamic_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
}
return nullptr;
}
void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* psketch,
std::vector<AutoConstraint> &sug1,
std::vector<AutoConstraint> &sug2)
std::vector<AutoConstraint>& sug1,
std::vector<AutoConstraint>& sug2)
{
if (!sug1.empty() && !sug2.empty()) {
@@ -338,8 +359,10 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske
// we look for:
// 1. Coincident to external on both endpoints
// 2. Coincident in one endpoint to origin and pointonobject/tangent to an axis on the other
auto detectredundant = [psketch](std::vector<AutoConstraint> &sug, bool &ext, bool &orig, bool &axis) {
auto detectredundant = [psketch](std::vector<AutoConstraint>& sug,
bool& ext,
bool& orig,
bool& axis) {
ext = false;
orig = false;
axis = false;
@@ -347,9 +370,10 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske
for (std::vector<AutoConstraint>::const_iterator it = sug.begin(); it != sug.end();
++it) {
if ((*it).Type == Sketcher::Coincident && !ext) {
const std::map<int, Sketcher::PointPos> coincidents = psketch->getAllCoincidentPoints((*it).GeoId, (*it).PosId);
const std::map<int, Sketcher::PointPos> coincidents =
psketch->getAllCoincidentPoints((*it).GeoId, (*it).PosId);
if(!coincidents.empty()) {
if (!coincidents.empty()) {
// the keys are ordered, so if the first is negative, it is coincident with external
ext = coincidents.begin()->first < 0;
@@ -357,12 +381,12 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske
geoId1iterator = coincidents.find(-1);
if( geoId1iterator != coincidents.end()) {
if( (*geoId1iterator).second == Sketcher::PointPos::start )
if (geoId1iterator != coincidents.end()) {
if ((*geoId1iterator).second == Sketcher::PointPos::start)
orig = true;
}
}
else { // it may be that there is no constraint at all, but there is external geometry
else {// it may be that there is no constraint at all, but there is external geometry
ext = (*it).GeoId < 0;
orig = ((*it).GeoId == -1 && (*it).PosId == Sketcher::PointPos::start);
}
@@ -371,52 +395,69 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske
axis = (((*it).GeoId == -1 && (*it).PosId == Sketcher::PointPos::none)
|| ((*it).GeoId == -2 && (*it).PosId == Sketcher::PointPos::none));
}
}
};
bool firstext = false, secondext = false, firstorig = false, secondorig = false, firstaxis = false, secondaxis = false;
bool firstext = false, secondext = false, firstorig = false, secondorig = false,
firstaxis = false, secondaxis = false;
detectredundant(sug1, firstext, firstorig, firstaxis);
detectredundant(sug2, secondext, secondorig, secondaxis);
rmvhorvert = ((firstext && secondext) || // coincident with external on both endpoints
(firstorig && secondaxis) || // coincident origin and point on object on other
rmvhorvert = ((firstext && secondext) || // coincident with external on both endpoints
(firstorig && secondaxis) ||// coincident origin and point on object on other
(secondorig && firstaxis));
if(rmvhorvert) {
for(std::vector<AutoConstraint>::reverse_iterator it = sug2.rbegin(); it!=sug2.rend(); ++it) {
if( (*it).Type == Sketcher::Horizontal || (*it).Type == Sketcher::Vertical) {
if (rmvhorvert) {
for (std::vector<AutoConstraint>::reverse_iterator it = sug2.rbegin();
it != sug2.rend();
++it) {
if ((*it).Type == Sketcher::Horizontal || (*it).Type == Sketcher::Vertical) {
sug2.erase(std::next(it).base());
it = sug2.rbegin(); // erase invalidates the iterator
it = sug2.rbegin();// erase invalidates the iterator
}
}
}
}
}
void SketcherGui::ConstraintToAttachment(Sketcher::GeoElementId element, Sketcher::GeoElementId attachment, double distance, App::DocumentObject* obj) {
void SketcherGui::ConstraintToAttachment(Sketcher::GeoElementId element,
Sketcher::GeoElementId attachment, double distance,
App::DocumentObject* obj)
{
if (distance == 0.) {
if(attachment.isCurve()) {
Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ",
element.GeoId, element.posIdAsInt(), attachment.GeoId);
if (attachment.isCurve()) {
Gui::cmdAppObjectArgs(obj,
"addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ",
element.GeoId,
element.posIdAsInt(),
attachment.GeoId);
}
else {
Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ",
element.GeoId, element.posIdAsInt(), attachment.GeoId, attachment.posIdAsInt());
Gui::cmdAppObjectArgs(obj,
"addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ",
element.GeoId,
element.posIdAsInt(),
attachment.GeoId,
attachment.posIdAsInt());
}
}
else {
if(attachment == Sketcher::GeoElementId::VAxis) {
Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%f)) ",
element.GeoId, element.posIdAsInt(), distance);
if (attachment == Sketcher::GeoElementId::VAxis) {
Gui::cmdAppObjectArgs(obj,
"addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%f)) ",
element.GeoId,
element.posIdAsInt(),
distance);
}
else if(attachment == Sketcher::GeoElementId::HAxis) {
Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%f)) ",
element.GeoId, element.posIdAsInt(), distance);
else if (attachment == Sketcher::GeoElementId::HAxis) {
Gui::cmdAppObjectArgs(obj,
"addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%f)) ",
element.GeoId,
element.posIdAsInt(),
distance);
}
}
}
@@ -425,25 +466,31 @@ void SketcherGui::ConstraintToAttachment(Sketcher::GeoElementId element, Sketche
//convenience functions for cursor display
bool SketcherGui::hideUnits()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/Sketcher");
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/Sketcher");
return hGrp->GetBool("HideUnits", false);
}
bool SketcherGui::showCursorCoords()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/Sketcher");
return hGrp->GetBool("ShowCursorCoords", true); //true for testing. set to false for prod.
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/Sketcher");
return hGrp->GetBool("ShowCursorCoords", true);//true for testing. set to false for prod.
}
bool SketcherGui::useSystemDecimals()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/Sketcher");
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/Sketcher");
return hGrp->GetBool("UseSystemDecimals", true);
}
@@ -459,8 +506,7 @@ std::string SketcherGui::lengthToDisplayFormat(double value, int digits)
asQuantity.setValue(value);
asQuantity.setUnit(Base::Unit::Length);
QString qUserString = asQuantity.getUserString();
if ( Base::UnitsApi::isMultiUnitLength() ||
(!hideUnits() && useSystemDecimals()) ) {
if (Base::UnitsApi::isMultiUnitLength() || (!hideUnits() && useSystemDecimals())) {
//just return the user string
return Base::Tools::toStdString(qUserString);
}
@@ -472,26 +518,27 @@ std::string SketcherGui::lengthToDisplayFormat(double value, int digits)
QString unitPart = QString::fromUtf8(" ") + qUnitString;
//get the numeric part of the user string
QRegularExpression rxNoUnits(QString::fromUtf8("(.*) \\D*$")); // text before space + any non digits at end of string
QRegularExpression rxNoUnits(
QString::fromUtf8("(.*) \\D*$"));// text before space + any non digits at end of string
QRegularExpressionMatch match = rxNoUnits.match(qUserString);
if (!match.hasMatch()) {
//no units in userString?
return Base::Tools::toStdString(qUserString);
}
QString matched = match.captured(1); //matched is the numeric part of user string
QString matched = match.captured(1);//matched is the numeric part of user string
int dpPos = matched.indexOf(QLocale().decimalPoint());
if (dpPos < 0) {
//no decimal separator (ie an integer), return all the digits
if (hideUnits()) {
return Base::Tools::toStdString(matched);
} else {
}
else {
return Base::Tools::toStdString(matched + unitPart);
}
}
//real number
if (useSystemDecimals() &&
hideUnits() ) {
if (useSystemDecimals() && hideUnits()) {
//return just the numeric part of the user string
return Base::Tools::toStdString(matched);
}
@@ -520,13 +567,13 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits)
asQuantity.setValue(value);
asQuantity.setUnit(Base::Unit::Angle);
QString qUserString = asQuantity.getUserString();
if ( Base::UnitsApi::isMultiUnitAngle() ) {
if (Base::UnitsApi::isMultiUnitAngle()) {
//just return the user string
//Coin SbString doesn't handle utf8 well, so we convert to ascii
QString schemeMinute = QString::fromUtf8("\xE2\x80\xB2"); //prime symbol
QString schemeSecond = QString::fromUtf8("\xE2\x80\xB3"); //double prime symbol
QString escapeMinute = QString::fromLatin1("\'"); //substitute ascii single quote
QString escapeSecond = QString::fromLatin1("\""); //substitute ascii double quote
QString schemeMinute = QString::fromUtf8("\xE2\x80\xB2");//prime symbol
QString schemeSecond = QString::fromUtf8("\xE2\x80\xB3");//double prime symbol
QString escapeMinute = QString::fromLatin1("\'"); //substitute ascii single quote
QString escapeSecond = QString::fromLatin1("\""); //substitute ascii double quote
QString displayString = qUserString.replace(schemeMinute, escapeMinute);
displayString = displayString.replace(schemeSecond, escapeSecond);
return Base::Tools::toStdString(displayString);
@@ -537,13 +584,14 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits)
QString qUnitString = QString::fromUtf8("°");
//get the numeric part of the user string
QRegularExpression rxNoUnits(QString::fromUtf8("(.*)\\D*$")); // text before any non digits at end of string
QRegularExpression rxNoUnits(
QString::fromUtf8("(\\d*\\.?\\d*)(\\D*)$"));// number + non digits at end of string
QRegularExpressionMatch match = rxNoUnits.match(qUserString);
if (!match.hasMatch()) {
//no units in userString?
return Base::Tools::toStdString(qUserString);
}
QString matched = match.captured(1); //matched is the numeric part of user string
QString matched = match.captured(1);//matched is the numeric part of user string
int dpPos = matched.indexOf(QLocale().decimalPoint());
if (dpPos < 0) {
//no decimal separator (ie an integer), return all the digits
@@ -551,7 +599,7 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits)
}
//real number
if (useSystemDecimals() ) {
if (useSystemDecimals()) {
//return just the numeric part of the user string + degree symbol
return Base::Tools::toStdString(matched + qUnitString);
}