+ fix issues with angle constraints

This commit is contained in:
wmayer 2014-05-17 18:27:56 +02:00
parent da4f1bda47
commit 81bfcc8717
3 changed files with 43 additions and 10 deletions

View File

@ -23,7 +23,9 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cfloat>
# include <QMessageBox>
# include <Precision.hxx>
#endif
#include <App/Application.h>
@ -1562,8 +1564,8 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
Base::Vector3d p1b = lineSeg1->getEndPoint();
Base::Vector3d p2a = lineSeg2->getStartPoint();
Base::Vector3d p2b = lineSeg2->getEndPoint();
double length = 1e10;
for (int i=0; i <= 1; i++)
double length = DBL_MAX;
for (int i=0; i <= 1; i++) {
for (int j=0; j <= 1; j++) {
double tmp = ((j?p2a:p2b)-(i?p1a:p1b)).Length();
if (tmp < length) {
@ -1572,12 +1574,24 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
PosId2 = j ? Sketcher::start : Sketcher::end;
}
}
}
Base::Vector3d dir1 = ((PosId1 == Sketcher::start) ? 1. : -1.) *
(lineSeg1->getEndPoint()-lineSeg1->getStartPoint());
Base::Vector3d dir2 = ((PosId2 == Sketcher::start) ? 1. : -1.) *
(lineSeg2->getEndPoint()-lineSeg2->getStartPoint());
// check if the two lines are parallel, in this case an angle is not possible
Base::Vector3d dir3 = dir1 % dir2;
if (dir3.Length() < Precision::Intersection()) {
Base::Vector3d dist = (p1a - p2a) % dir1;
if (dist.Sqr() > Precision::Intersection()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Parallel lines"),
QObject::tr("An angle constraint cannot be set for two parallel lines."));
return;
}
}
double ActAngle = atan2(-dir1.y*dir2.x+dir1.x*dir2.y,
dir1.x*dir2.x+dir1.y*dir2.y);
if (ActAngle < 0) {

View File

@ -441,7 +441,7 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
SbVec2s size;
int nc;
int srcw, srch;
int srcw=1, srch=1;
if (hasText) {
if (!this->glimagevalid) {

View File

@ -2661,14 +2661,33 @@ Restart:
// line-line intersection
{
double det = dir1.x*dir2.y - dir1.y*dir2.x;
if ((det > 0 ? det : -det) < 1e-10)
break;
if ((det > 0 ? det : -det) < 1e-10) {
// lines are coincident (or parallel) and in this case the center
// of the point pairs with the shortest distance is used
Base::Vector3d p1[2], p2[2];
p1[0] = lineSeg1->getStartPoint();
p1[1] = lineSeg1->getEndPoint();
p2[0] = lineSeg2->getStartPoint();
p2[1] = lineSeg2->getEndPoint();
double length = DBL_MAX;
for (int i=0; i <= 1; i++) {
for (int j=0; j <= 1; j++) {
double tmp = (p2[j]-p1[i]).Length();
if (tmp < length) {
length = tmp;
p0.setValue((p2[j].x+p1[i].x)/2,(p2[j].y+p1[i].y)/2,0);
}
}
}
}
else {
double c1 = dir1.y*pnt1.x - dir1.x*pnt1.y;
double c2 = dir2.y*pnt2.x - dir2.x*pnt2.y;
double x = (dir1.x*c2 - dir2.x*c1)/det;
double y = (dir1.y*c2 - dir2.y*c1)/det;
p0 = SbVec3f(x,y,0);
}
}
startangle = atan2(dir1.y,dir1.x);
range = atan2(-dir1.y*dir2.x+dir1.x*dir2.y,