+ improve coding style and fix typos
+ fix positioning of symmetry constraint icon git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5002 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
parent
a2082838bb
commit
b252fe7e1f
|
@ -608,37 +608,32 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
||||||
}
|
}
|
||||||
} else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) {
|
} else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) {
|
||||||
const Part::GeomCircle *circle = dynamic_cast<const Part::GeomCircle*>(geo);
|
const Part::GeomCircle *circle = dynamic_cast<const Part::GeomCircle*>(geo);
|
||||||
|
|
||||||
Base::Vector3d center = circle->getCenter();
|
Base::Vector3d center = circle->getCenter();
|
||||||
|
|
||||||
double startangle, endangle, angle, circ;
|
|
||||||
|
|
||||||
double theta0 = atan2(point.y - center.y,point.x - center.x);
|
double theta0 = atan2(point.y - center.y,point.x - center.x);
|
||||||
|
if (GeoId1 >= 0 && GeoId2 >= 0) {
|
||||||
if(GeoId1 >= 0 && GeoId2 >= 0) {
|
|
||||||
double theta1 = atan2(point1.y - center.y, point1.x - center.x);
|
double theta1 = atan2(point1.y - center.y, point1.x - center.x);
|
||||||
double theta2 = atan2(point2.y - center.y, point2.x - center.x);
|
double theta2 = atan2(point2.y - center.y, point2.x - center.x);
|
||||||
|
|
||||||
if (theta0 < theta1 && theta0 < theta2) {
|
if (theta0 < theta1 && theta0 < theta2) {
|
||||||
if(theta1 > theta2)
|
if (theta1 > theta2)
|
||||||
theta1 -= 2*M_PI;
|
theta1 -= 2*M_PI;
|
||||||
else
|
else
|
||||||
theta2 -= 2*M_PI;
|
theta2 -= 2*M_PI;
|
||||||
} else if (theta0 > theta1 && theta0 > theta2) {
|
} else if (theta0 > theta1 && theta0 > theta2) {
|
||||||
if(theta1 > theta2)
|
if (theta1 > theta2)
|
||||||
theta2 += 2*M_PI;
|
theta2 += 2*M_PI;
|
||||||
else
|
else
|
||||||
theta1 += 2*M_PI;
|
theta1 += 2*M_PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(theta1 > theta2) {
|
if (theta1 > theta2) {
|
||||||
std::swap(GeoId1,GeoId2);
|
std::swap(GeoId1,GeoId2);
|
||||||
std::swap(point1,point2);
|
std::swap(point1,point2);
|
||||||
std::swap(theta1,theta2);
|
std::swap(theta1,theta2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim Point between intersection points
|
// Trim Point between intersection points
|
||||||
if(theta1 < theta0 && theta2 > theta0) {
|
if (theta1 < theta0 && theta2 > theta0) {
|
||||||
Part::GeomArcOfCircle *geo = new Part::GeomArcOfCircle();
|
Part::GeomArcOfCircle *geo = new Part::GeomArcOfCircle();
|
||||||
geo->setCenter(center);
|
geo->setCenter(center);
|
||||||
geo->setRadius(circle->getRadius());
|
geo->setRadius(circle->getRadius());
|
||||||
|
@ -668,7 +663,6 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
||||||
newConstr->Second = GeoId1;
|
newConstr->Second = GeoId1;
|
||||||
addConstraint(newConstr);
|
addConstraint(newConstr);
|
||||||
|
|
||||||
|
|
||||||
newConstr->First = newGeoId;
|
newConstr->First = newGeoId;
|
||||||
newConstr->FirstPos = start;
|
newConstr->FirstPos = start;
|
||||||
newConstr->Second = GeoId2;
|
newConstr->Second = GeoId2;
|
||||||
|
@ -678,7 +672,6 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
||||||
//movePoint(newGeoId, start, point2);
|
//movePoint(newGeoId, start, point2);
|
||||||
//movePoint(newGeoId, end, point1);
|
//movePoint(newGeoId, end, point1);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -689,26 +682,25 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
||||||
|
|
||||||
Base::Vector3d center = aoc->getCenter();
|
Base::Vector3d center = aoc->getCenter();
|
||||||
|
|
||||||
double startangle, endangle, angle, circ;
|
double startangle, endangle;
|
||||||
aoc->getRange(startangle, endangle);
|
aoc->getRange(startangle, endangle);
|
||||||
|
|
||||||
double theta0 = atan2(point.y - center.y,point.x - center.x);
|
double theta0 = atan2(point.y - center.y,point.x - center.x);
|
||||||
|
|
||||||
if(GeoId1 >= 0 && GeoId2 >= 0) {
|
if (GeoId1 >= 0 && GeoId2 >= 0) {
|
||||||
double theta1 = atan2(point1.y - center.y, point1.x - center.x);
|
double theta1 = atan2(point1.y - center.y, point1.x - center.x);
|
||||||
double theta2 = atan2(point2.y - center.y, point2.x - center.x);
|
double theta2 = atan2(point2.y - center.y, point2.x - center.x);
|
||||||
|
|
||||||
double u1,v1;
|
double u1 = (theta1 >= 0) ? theta1 : theta1 + 2*M_PI;
|
||||||
u1= theta1;
|
double v1 = (theta2 >= 0) ? theta2 : theta2 + 2*M_PI;
|
||||||
v1 = theta2;
|
|
||||||
|
|
||||||
if (theta0 < theta1 && theta0 < theta2) {
|
if (theta0 < theta1 && theta0 < theta2) {
|
||||||
if(theta1 > theta2)
|
if (theta1 > theta2)
|
||||||
theta1 -= 2*M_PI;
|
theta1 -= 2*M_PI;
|
||||||
else
|
else
|
||||||
theta2 -= 2*M_PI;
|
theta2 -= 2*M_PI;
|
||||||
} else if (theta0 > theta1 && theta0 > theta2) {
|
} else if (theta0 > theta1 && theta0 > theta2) {
|
||||||
if(theta1 > theta2)
|
if (theta1 > theta2)
|
||||||
theta2 += 2*M_PI;
|
theta2 += 2*M_PI;
|
||||||
else
|
else
|
||||||
theta1 += 2*M_PI;
|
theta1 += 2*M_PI;
|
||||||
|
@ -719,19 +711,9 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
||||||
u = fmod(u, 2.f*M_PI);
|
u = fmod(u, 2.f*M_PI);
|
||||||
v = fmod(v, 2.f*M_PI);
|
v = fmod(v, 2.f*M_PI);
|
||||||
|
|
||||||
|
bool swap = (u > v);
|
||||||
|
|
||||||
if(u1 < 0)
|
if (theta1 > theta2) {
|
||||||
u1 += 2 * M_PI;
|
|
||||||
|
|
||||||
if(v1 < 0)
|
|
||||||
v1 += 2 * M_PI;
|
|
||||||
|
|
||||||
bool swap = false;
|
|
||||||
if(u > v) {
|
|
||||||
swap = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(theta1 > theta2) {
|
|
||||||
std::swap(GeoId1,GeoId2);
|
std::swap(GeoId1,GeoId2);
|
||||||
std::swap(point1,point2);
|
std::swap(point1,point2);
|
||||||
std::swap(theta1,theta2);
|
std::swap(theta1,theta2);
|
||||||
|
@ -740,7 +722,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
||||||
if ((swap && (!(u1 <= (1.001*u) && u1 >= 0.999 * v) && !(v1 <= (1.001*u) && v1 >= 0.999*v)) ) ||
|
if ((swap && (!(u1 <= (1.001*u) && u1 >= 0.999 * v) && !(v1 <= (1.001*u) && v1 >= 0.999*v)) ) ||
|
||||||
(!swap && (u1 >= (1.001*u ) && u1 <= 0.999*v) && (v1 >= (1.001*u ) && v1 <= 0.999*v) ) ) {
|
(!swap && (u1 >= (1.001*u ) && u1 <= 0.999*v) && (v1 >= (1.001*u ) && v1 <= 0.999*v) ) ) {
|
||||||
// Trim Point between intersection points
|
// Trim Point between intersection points
|
||||||
if(theta1 < theta0 && theta2 > theta0) {
|
if (theta1 < theta0 && theta2 > theta0) {
|
||||||
// Setting the range manually to improve stability before adding constraints
|
// Setting the range manually to improve stability before adding constraints
|
||||||
|
|
||||||
int newGeoId = addGeometry(geo);
|
int newGeoId = addGeometry(geo);
|
||||||
|
@ -760,7 +742,6 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
||||||
|
|
||||||
// Setting the range manually to improve stability before adding constraints
|
// Setting the range manually to improve stability before adding constraints
|
||||||
|
|
||||||
|
|
||||||
aoc->getRange(u,v);
|
aoc->getRange(u,v);
|
||||||
u = fmod(u, 2.f*M_PI);
|
u = fmod(u, 2.f*M_PI);
|
||||||
v = fmod(v, 2.f*M_PI);
|
v = fmod(v, 2.f*M_PI);
|
||||||
|
@ -796,10 +777,10 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
||||||
if (GeoId1 >= 0) {
|
if (GeoId1 >= 0) {
|
||||||
double theta1 = atan2(point1.y - center.y, point1.x - center.x);
|
double theta1 = atan2(point1.y - center.y, point1.x - center.x);
|
||||||
|
|
||||||
if(theta0 < 0)
|
if (theta0 < 0)
|
||||||
theta0 += 2*M_PI;
|
theta0 += 2*M_PI;
|
||||||
|
|
||||||
if(theta1 < 0)
|
if (theta1 < 0)
|
||||||
theta1 += 2*M_PI;
|
theta1 += 2*M_PI;
|
||||||
|
|
||||||
double u,v;
|
double u,v;
|
||||||
|
|
|
@ -1027,7 +1027,7 @@ void CmdSketcherConstrainParallel::activated(int iMsg)
|
||||||
// only one sketch with its subelements are allowed to be selected
|
// only one sketch with its subelements are allowed to be selected
|
||||||
if (selection.size() != 1) {
|
if (selection.size() != 1) {
|
||||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||||
QObject::tr("Select an edge from the sketch."));
|
QObject::tr("Select two or more lines from the sketch."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1042,12 +1042,12 @@ void CmdSketcherConstrainParallel::activated(int iMsg)
|
||||||
|
|
||||||
if (SubNames.size() < 2) {
|
if (SubNames.size() < 2) {
|
||||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||||
QObject::tr("Select atleast two lines from the sketch."));
|
QObject::tr("Select at least two lines from the sketch."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> ids;
|
std::vector<int> ids;
|
||||||
for(std::vector<std::string>::const_iterator it=SubNames.begin();it!=SubNames.end();++it) {
|
for (std::vector<std::string>::const_iterator it=SubNames.begin();it!=SubNames.end();++it) {
|
||||||
int index;
|
int index;
|
||||||
std::string subName = *it;
|
std::string subName = *it;
|
||||||
if (subName.size() > 4 && subName.substr(0,4) == "Edge")
|
if (subName.size() > 4 && subName.substr(0,4) == "Edge")
|
||||||
|
@ -1071,7 +1071,7 @@ void CmdSketcherConstrainParallel::activated(int iMsg)
|
||||||
// undo command open
|
// undo command open
|
||||||
openCommand("add parallel constraint");
|
openCommand("add parallel constraint");
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(std::vector<int>::iterator it = ids.begin(); it!=ids.end();++it, i++) {
|
for (std::vector<int>::iterator it = ids.begin(); it!=ids.end();++it, i++) {
|
||||||
if(i == ids.size() - 1)
|
if(i == ids.size() - 1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1134,7 +1134,6 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int GeoId1,GeoId2;
|
int GeoId1,GeoId2;
|
||||||
if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge")
|
if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge")
|
||||||
GeoId1 = std::atoi(SubNames[0].substr(4,4000).c_str());
|
GeoId1 = std::atoi(SubNames[0].substr(4,4000).c_str());
|
||||||
|
@ -1545,7 +1544,6 @@ void CmdSketcherConstrainEqual::activated(int iMsg)
|
||||||
const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues();
|
const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues();
|
||||||
const std::vector<Part::Geometry *> &geomlist = Obj->Geometry.getValues();
|
const std::vector<Part::Geometry *> &geomlist = Obj->Geometry.getValues();
|
||||||
|
|
||||||
|
|
||||||
// go through the selected subelements
|
// go through the selected subelements
|
||||||
|
|
||||||
if (SubNames.size() < 2) {
|
if (SubNames.size() < 2) {
|
||||||
|
@ -1557,7 +1555,7 @@ void CmdSketcherConstrainEqual::activated(int iMsg)
|
||||||
std::vector<int> ids;
|
std::vector<int> ids;
|
||||||
bool lineSel = false, arcSel = false, circSel = false;
|
bool lineSel = false, arcSel = false, circSel = false;
|
||||||
|
|
||||||
for(std::vector<std::string>::const_iterator it=SubNames.begin();it!=SubNames.end();++it) {
|
for (std::vector<std::string>::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) {
|
||||||
int index;
|
int index;
|
||||||
std::string subName = *it;
|
std::string subName = *it;
|
||||||
if (subName.size() > 4 && subName.substr(0,4) == "Edge")
|
if (subName.size() > 4 && subName.substr(0,4) == "Edge")
|
||||||
|
@ -1584,15 +1582,16 @@ void CmdSketcherConstrainEqual::activated(int iMsg)
|
||||||
ids.push_back(index);
|
ids.push_back(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lineSel && (arcSel || circSel)) {
|
if (lineSel && (arcSel || circSel)) {
|
||||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||||
QObject::tr("Select geometry of similar type"));
|
QObject::tr("Select geometry of similar type"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// undo command open
|
// undo command open
|
||||||
openCommand("add equality constraint");
|
openCommand("add equality constraint");
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(std::vector<int>::iterator it = ids.begin(); it!=ids.end();it++, i++) {
|
for (std::vector<int>::iterator it = ids.begin(); it!=ids.end();it++, i++) {
|
||||||
if( i == ids.size() - 1)
|
if( i == ids.size() - 1)
|
||||||
break;
|
break;
|
||||||
Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Equal',%d,%d)) ",
|
Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Equal',%d,%d)) ",
|
||||||
|
|
|
@ -271,8 +271,6 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
|
||||||
float height = scale / (float) srch;
|
float height = scale / (float) srch;
|
||||||
float width = aspectRatio * (float) height;
|
float width = aspectRatio * (float) height;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this->bbx = width;
|
this->bbx = width;
|
||||||
this->bby = height;
|
this->bby = height;
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,7 @@
|
||||||
namespace SketcherGui {
|
namespace SketcherGui {
|
||||||
|
|
||||||
class SketcherGuiExport SoDatumLabel : public SoShape {
|
class SketcherGuiExport SoDatumLabel : public SoShape {
|
||||||
typedef SoNode inherited;
|
typedef SoShape inherited;
|
||||||
|
|
||||||
|
|
||||||
SO_NODE_HEADER(SoDatumLabel);
|
SO_NODE_HEADER(SoDatumLabel);
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
namespace SketcherGui {
|
namespace SketcherGui {
|
||||||
|
|
||||||
class SketcherGuiExport SoZoomTranslation : public SoTranslation {
|
class SketcherGuiExport SoZoomTranslation : public SoTranslation {
|
||||||
typedef SoNode inherited;
|
typedef SoTranslation inherited;
|
||||||
|
|
||||||
SO_NODE_HEADER(SoZoomTranslation);
|
SO_NODE_HEADER(SoZoomTranslation);
|
||||||
|
|
||||||
|
|
|
@ -2397,19 +2397,10 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
|
||||||
break;
|
break;
|
||||||
case PointOnObject:
|
case PointOnObject:
|
||||||
case Tangent:
|
case Tangent:
|
||||||
case Symmetric:
|
|
||||||
{
|
{
|
||||||
if ((*it)->Type == Symmetric) {
|
|
||||||
SoSeparator *sepArrows = new SoSeparator();
|
|
||||||
sepArrows->addChild(new SoCoordinate3());
|
|
||||||
SoLineSet *lineSet = new SoLineSet;
|
|
||||||
sepArrows->addChild(lineSet);
|
|
||||||
sep->addChild(sepArrows);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add new nodes to Constraint Seperator
|
// Add new nodes to Constraint Seperator
|
||||||
sep->addChild(new SoZoomTranslation());
|
sep->addChild(new SoZoomTranslation()); // 1.
|
||||||
sep->addChild(new SoImage()); // constraint icon
|
sep->addChild(new SoImage()); // 2. constraint icon
|
||||||
|
|
||||||
if ((*it)->Type == Tangent) {
|
if ((*it)->Type == Tangent) {
|
||||||
Part::Geometry *geo1 = getSketchObject()->Geometry.getValues()[(*it)->First];
|
Part::Geometry *geo1 = getSketchObject()->Geometry.getValues()[(*it)->First];
|
||||||
|
@ -2417,13 +2408,28 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
|
||||||
if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
|
if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
|
||||||
geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
|
geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
|
||||||
sep->addChild(new SoZoomTranslation());
|
sep->addChild(new SoZoomTranslation());
|
||||||
sep->addChild(new SoImage()); // second constraint icon
|
sep->addChild(new SoImage()); // 3. second constraint icon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
edit->vConstrType.push_back((*it)->Type);
|
edit->vConstrType.push_back((*it)->Type);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Symmetric:
|
||||||
|
{
|
||||||
|
SoSeparator *sepArrows = new SoSeparator();
|
||||||
|
sepArrows->addChild(new SoCoordinate3());
|
||||||
|
SoLineSet *lineSet = new SoLineSet;
|
||||||
|
sepArrows->addChild(lineSet);
|
||||||
|
sep->addChild(sepArrows); // 1.
|
||||||
|
|
||||||
|
// Add new nodes to Constraint Seperator
|
||||||
|
sep->addChild(new SoTranslation()); // 2.
|
||||||
|
sep->addChild(new SoImage()); // 3. constraint icon
|
||||||
|
|
||||||
|
edit->vConstrType.push_back((*it)->Type);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
edit->vConstrType.push_back(None);
|
edit->vConstrType.push_back(None);
|
||||||
}
|
}
|
||||||
|
@ -2977,7 +2983,7 @@ bool ViewProviderSketch::onDelete(const std::vector<std::string> &subList)
|
||||||
edit->PreselectConstraint = -1;
|
edit->PreselectConstraint = -1;
|
||||||
this->drawConstraintIcons();
|
this->drawConstraintIcons();
|
||||||
this->updateColor();
|
this->updateColor();
|
||||||
// if in edit not delet the object
|
// if in edit not delete the object
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// if not in edit delete the whole object
|
// if not in edit delete the whole object
|
||||||
|
|
Loading…
Reference in New Issue
Block a user