+ 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
|
@ -94,7 +94,7 @@ App::DocumentObjectExecReturn *SketchObject::execute(void)
|
|||
appendConflictMsg(sketch.getConflicting(), msg);
|
||||
return new App::DocumentObjectExecReturn(msg.c_str(),this);
|
||||
}
|
||||
|
||||
|
||||
// solve the sketch
|
||||
if (sketch.solve() != 0)
|
||||
return new App::DocumentObjectExecReturn("Solving the sketch failed",this);
|
||||
|
@ -563,7 +563,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||
newConstr->FirstPos = none;
|
||||
newConstr->Second = newGeoId;
|
||||
addConstraint(newConstr);
|
||||
|
||||
|
||||
delete newConstr;
|
||||
return 0;
|
||||
}
|
||||
|
@ -608,37 +608,32 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||
}
|
||||
} else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) {
|
||||
const Part::GeomCircle *circle = dynamic_cast<const Part::GeomCircle*>(geo);
|
||||
|
||||
Base::Vector3d center = circle->getCenter();
|
||||
|
||||
double startangle, endangle, angle, circ;
|
||||
|
||||
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 theta2 = atan2(point2.y - center.y, point2.x - center.x);
|
||||
|
||||
if (theta0 < theta1 && theta0 < theta2) {
|
||||
if(theta1 > theta2)
|
||||
if (theta1 > theta2)
|
||||
theta1 -= 2*M_PI;
|
||||
else
|
||||
theta2 -= 2*M_PI;
|
||||
} else if (theta0 > theta1 && theta0 > theta2) {
|
||||
if(theta1 > theta2)
|
||||
if (theta1 > theta2)
|
||||
theta2 += 2*M_PI;
|
||||
else
|
||||
theta1 += 2*M_PI;
|
||||
}
|
||||
|
||||
if(theta1 > theta2) {
|
||||
if (theta1 > theta2) {
|
||||
std::swap(GeoId1,GeoId2);
|
||||
std::swap(point1,point2);
|
||||
std::swap(theta1,theta2);
|
||||
}
|
||||
|
||||
// Trim Point between intersection points
|
||||
if(theta1 < theta0 && theta2 > theta0) {
|
||||
if (theta1 < theta0 && theta2 > theta0) {
|
||||
Part::GeomArcOfCircle *geo = new Part::GeomArcOfCircle();
|
||||
geo->setCenter(center);
|
||||
geo->setRadius(circle->getRadius());
|
||||
|
@ -647,7 +642,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||
delGeometry(GeoId);
|
||||
int newGeoId = addGeometry(dynamic_cast<Part::Geometry *>(geo));
|
||||
delete(geo);
|
||||
|
||||
|
||||
// go through all constraints and replace the point (GeoId,end) with (newGeoId,end)
|
||||
const std::vector<Constraint *> &constraints = this->Constraints.getValues();
|
||||
std::vector<Constraint *> newVals(constraints);
|
||||
|
@ -660,7 +655,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||
constraints[i]->Second = newGeoId;
|
||||
}
|
||||
// constrain the trimming points on the corresponding geometries
|
||||
|
||||
|
||||
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
|
||||
newConstr->Type = Sketcher::PointOnObject;
|
||||
newConstr->First = newGeoId;
|
||||
|
@ -668,7 +663,6 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||
newConstr->Second = GeoId1;
|
||||
addConstraint(newConstr);
|
||||
|
||||
|
||||
newConstr->First = newGeoId;
|
||||
newConstr->FirstPos = start;
|
||||
newConstr->Second = GeoId2;
|
||||
|
@ -678,7 +672,6 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||
//movePoint(newGeoId, start, point2);
|
||||
//movePoint(newGeoId, end, point1);
|
||||
|
||||
|
||||
return 0;
|
||||
} else
|
||||
return -1;
|
||||
|
@ -689,26 +682,25 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||
|
||||
Base::Vector3d center = aoc->getCenter();
|
||||
|
||||
double startangle, endangle, angle, circ;
|
||||
double startangle, endangle;
|
||||
aoc->getRange(startangle, endangle);
|
||||
|
||||
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 theta2 = atan2(point2.y - center.y, point2.x - center.x);
|
||||
|
||||
double u1,v1;
|
||||
u1= theta1;
|
||||
v1 = theta2;
|
||||
|
||||
double u1 = (theta1 >= 0) ? theta1 : theta1 + 2*M_PI;
|
||||
double v1 = (theta2 >= 0) ? theta2 : theta2 + 2*M_PI;
|
||||
|
||||
if (theta0 < theta1 && theta0 < theta2) {
|
||||
if(theta1 > theta2)
|
||||
if (theta1 > theta2)
|
||||
theta1 -= 2*M_PI;
|
||||
else
|
||||
theta2 -= 2*M_PI;
|
||||
} else if (theta0 > theta1 && theta0 > theta2) {
|
||||
if(theta1 > theta2)
|
||||
if (theta1 > theta2)
|
||||
theta2 += 2*M_PI;
|
||||
else
|
||||
theta1 += 2*M_PI;
|
||||
|
@ -719,30 +711,20 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||
u = fmod(u, 2.f*M_PI);
|
||||
v = fmod(v, 2.f*M_PI);
|
||||
|
||||
|
||||
if(u1 < 0)
|
||||
u1 += 2 * M_PI;
|
||||
bool swap = (u > v);
|
||||
|
||||
if(v1 < 0)
|
||||
v1 += 2 * M_PI;
|
||||
|
||||
bool swap = false;
|
||||
if(u > v) {
|
||||
swap = true;
|
||||
}
|
||||
|
||||
if(theta1 > theta2) {
|
||||
if (theta1 > theta2) {
|
||||
std::swap(GeoId1,GeoId2);
|
||||
std::swap(point1,point2);
|
||||
std::swap(theta1,theta2);
|
||||
}
|
||||
|
||||
|
||||
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) ) ) {
|
||||
// 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
|
||||
|
||||
|
||||
int newGeoId = addGeometry(geo);
|
||||
Part::GeomArcOfCircle *aoc = dynamic_cast<Part::GeomArcOfCircle*>(geomlist[GeoId]);
|
||||
Part::GeomArcOfCircle *aoc2 = dynamic_cast<Part::GeomArcOfCircle*>(geomlist[newGeoId]);
|
||||
|
@ -757,9 +739,8 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||
constraints[i]->SecondPos == end)
|
||||
constraints[i]->Second = newGeoId;
|
||||
}
|
||||
|
||||
|
||||
// Setting the range manually to improve stability before adding constraints
|
||||
|
||||
|
||||
aoc->getRange(u,v);
|
||||
u = fmod(u, 2.f*M_PI);
|
||||
|
@ -796,46 +777,46 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||
if (GeoId1 >= 0) {
|
||||
double theta1 = atan2(point1.y - center.y, point1.x - center.x);
|
||||
|
||||
if(theta0 < 0)
|
||||
if (theta0 < 0)
|
||||
theta0 += 2*M_PI;
|
||||
|
||||
if(theta1 < 0)
|
||||
if (theta1 < 0)
|
||||
theta1 += 2*M_PI;
|
||||
|
||||
double u,v;
|
||||
aoc->getRange(u,v);
|
||||
u = fmod(u, 2*M_PI);
|
||||
v = fmod(v, 2*M_PI);
|
||||
|
||||
startangle = fmod(startangle, 2*M_PI);
|
||||
endangle = fmod(endangle, 2*M_PI);
|
||||
|
||||
if (theta1 > theta0) { // trim en
|
||||
delConstraintOnPoint(GeoId, start, false);
|
||||
startangle = fmod(startangle, 2*M_PI);
|
||||
endangle = fmod(endangle, 2*M_PI);
|
||||
|
||||
movePoint(GeoId, start, point1);
|
||||
// constrain the trimming point on the corresponding geometry
|
||||
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
|
||||
newConstr->Type = Sketcher::PointOnObject;
|
||||
newConstr->First = GeoId;
|
||||
newConstr->FirstPos = start;
|
||||
newConstr->Second = GeoId1;
|
||||
addConstraint(newConstr);
|
||||
delete newConstr;
|
||||
return 0;
|
||||
}
|
||||
else if (theta1 < theta0) { // trim line end
|
||||
delConstraintOnPoint(GeoId, end, false);
|
||||
movePoint(GeoId, end, point1);
|
||||
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
|
||||
newConstr->Type = Sketcher::PointOnObject;
|
||||
newConstr->First = GeoId;
|
||||
newConstr->FirstPos = end;
|
||||
newConstr->Second = GeoId1;
|
||||
addConstraint(newConstr);
|
||||
delete newConstr;
|
||||
return 0;
|
||||
}
|
||||
if (theta1 > theta0) { // trim en
|
||||
delConstraintOnPoint(GeoId, start, false);
|
||||
|
||||
movePoint(GeoId, start, point1);
|
||||
// constrain the trimming point on the corresponding geometry
|
||||
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
|
||||
newConstr->Type = Sketcher::PointOnObject;
|
||||
newConstr->First = GeoId;
|
||||
newConstr->FirstPos = start;
|
||||
newConstr->Second = GeoId1;
|
||||
addConstraint(newConstr);
|
||||
delete newConstr;
|
||||
return 0;
|
||||
}
|
||||
else if (theta1 < theta0) { // trim line end
|
||||
delConstraintOnPoint(GeoId, end, false);
|
||||
movePoint(GeoId, end, point1);
|
||||
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
|
||||
newConstr->Type = Sketcher::PointOnObject;
|
||||
newConstr->First = GeoId;
|
||||
newConstr->FirstPos = end;
|
||||
newConstr->Second = GeoId1;
|
||||
addConstraint(newConstr);
|
||||
delete newConstr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1027,7 +1027,7 @@ void CmdSketcherConstrainParallel::activated(int iMsg)
|
|||
// only one sketch with its subelements are allowed to be selected
|
||||
if (selection.size() != 1) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1037,17 +1037,17 @@ void CmdSketcherConstrainParallel::activated(int iMsg)
|
|||
const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues();
|
||||
const std::vector<Part::Geometry *> &geomlist = Obj->Geometry.getValues();
|
||||
|
||||
|
||||
|
||||
// go through the selected subelements
|
||||
|
||||
if (SubNames.size() < 2) {
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
std::string subName = *it;
|
||||
if (subName.size() > 4 && subName.substr(0,4) == "Edge")
|
||||
|
@ -1071,7 +1071,7 @@ void CmdSketcherConstrainParallel::activated(int iMsg)
|
|||
// undo command open
|
||||
openCommand("add parallel constraint");
|
||||
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)
|
||||
break;
|
||||
|
||||
|
@ -1134,7 +1134,6 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg)
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
int GeoId1,GeoId2;
|
||||
if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge")
|
||||
GeoId1 = std::atoi(SubNames[0].substr(4,4000).c_str());
|
||||
|
@ -1154,15 +1153,15 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg)
|
|||
|
||||
Part::Geometry *geo1 = geomlist[GeoId1];
|
||||
Part::Geometry *geo2 = geomlist[GeoId2];
|
||||
|
||||
|
||||
if (geo1->getTypeId() != Part::GeomLineSegment::getClassTypeId() ||
|
||||
geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) {
|
||||
|
||||
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select exactly two lines from the sketch."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// undo command open
|
||||
openCommand("add perpendicular constraint");
|
||||
Gui::Command::doCommand(
|
||||
|
@ -1545,7 +1544,6 @@ void CmdSketcherConstrainEqual::activated(int iMsg)
|
|||
const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues();
|
||||
const std::vector<Part::Geometry *> &geomlist = Obj->Geometry.getValues();
|
||||
|
||||
|
||||
// go through the selected subelements
|
||||
|
||||
if (SubNames.size() < 2) {
|
||||
|
@ -1556,8 +1554,8 @@ void CmdSketcherConstrainEqual::activated(int iMsg)
|
|||
|
||||
std::vector<int> ids;
|
||||
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;
|
||||
std::string subName = *it;
|
||||
if (subName.size() > 4 && subName.substr(0,4) == "Edge")
|
||||
|
@ -1584,15 +1582,16 @@ void CmdSketcherConstrainEqual::activated(int iMsg)
|
|||
ids.push_back(index);
|
||||
}
|
||||
|
||||
if(lineSel && (arcSel || circSel)) {
|
||||
if (lineSel && (arcSel || circSel)) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select geometry of similar type"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// undo command open
|
||||
openCommand("add equality constraint");
|
||||
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)
|
||||
break;
|
||||
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 width = aspectRatio * (float) height;
|
||||
|
||||
|
||||
|
||||
this->bbx = width;
|
||||
this->bby = height;
|
||||
|
||||
|
|
|
@ -38,9 +38,8 @@
|
|||
|
||||
namespace SketcherGui {
|
||||
|
||||
class SketcherGuiExport SoDatumLabel : public SoShape {
|
||||
typedef SoNode inherited;
|
||||
|
||||
class SketcherGuiExport SoDatumLabel : public SoShape {
|
||||
typedef SoShape inherited;
|
||||
|
||||
SO_NODE_HEADER(SoDatumLabel);
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
namespace SketcherGui {
|
||||
|
||||
class SketcherGuiExport SoZoomTranslation : public SoTranslation {
|
||||
typedef SoNode inherited;
|
||||
typedef SoTranslation inherited;
|
||||
|
||||
SO_NODE_HEADER(SoZoomTranslation);
|
||||
|
||||
|
@ -53,4 +53,4 @@ private:
|
|||
};
|
||||
|
||||
}
|
||||
#endif // SKETCHERGUI_SOZOOMTRANSLATION_H
|
||||
#endif // SKETCHERGUI_SOZOOMTRANSLATION_H
|
||||
|
|
|
@ -1690,7 +1690,7 @@ Restart:
|
|||
|
||||
dynamic_cast<SoZoomTranslation *>(sep->getChild(1))->abPos = SbVec3f(midpos.x, midpos.y, zConstr); //Absolute Reference
|
||||
|
||||
//Reference Position that is scaled according to zoom
|
||||
//Reference Position that is scaled according to zoom
|
||||
dynamic_cast<SoZoomTranslation *>(sep->getChild(1))->translation = SbVec3f(relPos.x, relPos.y, 0);
|
||||
|
||||
}
|
||||
|
@ -1961,7 +1961,7 @@ Restart:
|
|||
|
||||
// Get Current Scale Factor
|
||||
float scale = dynamic_cast<SoZoomTranslation *>(sep->getChild(1))->getScaleFactor();
|
||||
|
||||
|
||||
Base::Vector3d constrPos1 = midpos1 + (norm1 * scale * 2.5);
|
||||
constrPos1 = seekConstraintPosition(constrPos1, dir1, scale * 2.5, edit->constrGroup->getChild(i));
|
||||
|
||||
|
@ -2371,9 +2371,9 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
|
|||
case Horizontal:
|
||||
case Vertical:
|
||||
{
|
||||
sep->addChild(new SoZoomTranslation()); // 1.
|
||||
sep->addChild(new SoZoomTranslation()); // 1.
|
||||
sep->addChild(new SoImage()); // 2. constraint icon
|
||||
|
||||
|
||||
// remember the type of this constraint node
|
||||
edit->vConstrType.push_back((*it)->Type);
|
||||
}
|
||||
|
@ -2387,29 +2387,20 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
|
|||
{
|
||||
// Add new nodes to Constraint Seperator
|
||||
sep->addChild(new SoZoomTranslation()); // 1.
|
||||
sep->addChild(new SoImage()); // 2. first constraint icon
|
||||
sep->addChild(new SoImage()); // 2. first constraint icon
|
||||
sep->addChild(new SoZoomTranslation()); // 3.
|
||||
sep->addChild(new SoImage()); // 4. second constraint icon
|
||||
|
||||
sep->addChild(new SoImage()); // 4. second constraint icon
|
||||
|
||||
// remember the type of this constraint node
|
||||
edit->vConstrType.push_back((*it)->Type);
|
||||
}
|
||||
break;
|
||||
case PointOnObject:
|
||||
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
|
||||
sep->addChild(new SoZoomTranslation());
|
||||
sep->addChild(new SoImage()); // constraint icon
|
||||
sep->addChild(new SoZoomTranslation()); // 1.
|
||||
sep->addChild(new SoImage()); // 2. constraint icon
|
||||
|
||||
if ((*it)->Type == Tangent) {
|
||||
Part::Geometry *geo1 = getSketchObject()->Geometry.getValues()[(*it)->First];
|
||||
|
@ -2417,13 +2408,28 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
|
|||
if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
|
||||
geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
|
||||
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);
|
||||
}
|
||||
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:
|
||||
edit->vConstrType.push_back(None);
|
||||
}
|
||||
|
@ -2977,7 +2983,7 @@ bool ViewProviderSketch::onDelete(const std::vector<std::string> &subList)
|
|||
edit->PreselectConstraint = -1;
|
||||
this->drawConstraintIcons();
|
||||
this->updateColor();
|
||||
// if in edit not delet the object
|
||||
// if in edit not delete the object
|
||||
return false;
|
||||
}
|
||||
// if not in edit delete the whole object
|
||||
|
|
Loading…
Reference in New Issue
Block a user