+ implement getGeometry method for accessing Geometry in SketchObject

+ increase use of constness in accessing SketchObject geometry
+ simplify DrawSketchHandler
+ variables naming improvements


git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5342 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
logari81 2011-12-24 11:47:37 +00:00
parent 590b0469c3
commit 247bf144e3
7 changed files with 95 additions and 105 deletions

View File

@ -181,7 +181,7 @@ Base::Vector3d SketchObject::getPoint(int GeoId, PointPos PosId) const
{
const std::vector< Part::Geometry * > &geomlist = this->Geometry.getValues();
assert(GeoId < (int)geomlist.size());
Part::Geometry *geo = geomlist[GeoId];
const Part::Geometry *geo = getGeometry(GeoId);
if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg = dynamic_cast<const Part::GeomLineSegment*>(geo);
if (PosId == start)
@ -480,17 +480,18 @@ int SketchObject::transferConstraints(int fromGeoId, PointPos fromPosId, int toG
int SketchObject::fillet(int GeoId, PointPos PosId, double radius, bool trim)
{
const std::vector<Part::Geometry *> &geomlist = this->Geometry.getValues();
assert(GeoId < int(geomlist.size()));
if (GeoId < 0 || GeoId > getHighestCurveIndex())
return -1;
// Find the other geometry Id associated with the coincident point
std::vector<int> GeoIdList;
std::vector<PointPos> PosIdList;
getCoincidentPoints(GeoId, PosId, GeoIdList, PosIdList);
// only coincident points between two edges can be filleted
if (GeoIdList.size() == 2) {
Part::Geometry *geo1 = geomlist[GeoIdList[0]];
Part::Geometry *geo2 = geomlist[GeoIdList[1]];
// only coincident points between two (non-external) edges can be filleted
if (GeoIdList.size() == 2 && GeoIdList[0] >= 0 && GeoIdList[1] >= 0) {
const Part::Geometry *geo1 = getGeometry(GeoIdList[0]);
const Part::Geometry *geo2 = getGeometry(GeoIdList[1]);
if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId() ) {
const Part::GeomLineSegment *lineSeg1 = dynamic_cast<const Part::GeomLineSegment*>(geo1);
@ -509,11 +510,12 @@ int SketchObject::fillet(int GeoId1, int GeoId2,
const Base::Vector3d& refPnt1, const Base::Vector3d& refPnt2,
double radius, bool trim)
{
const std::vector<Part::Geometry *> &geomlist = this->Geometry.getValues();
assert(GeoId1 < int(geomlist.size()));
assert(GeoId2 < int(geomlist.size()));
Part::Geometry *geo1 = geomlist[GeoId1];
Part::Geometry *geo2 = geomlist[GeoId2];
if (GeoId1 < 0 || GeoId1 > getHighestCurveIndex() ||
GeoId2 < 0 || GeoId2 > getHighestCurveIndex())
return -1;
const Part::Geometry *geo1 = getGeometry(GeoId1);
const Part::Geometry *geo2 = getGeometry(GeoId2);
if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId() ) {
const Part::GeomLineSegment *lineSeg1 = dynamic_cast<const Part::GeomLineSegment*>(geo1);
@ -1021,6 +1023,17 @@ int SketchObject::delExternal(int ExtGeoId)
return 0;
}
const Part::Geometry* SketchObject::getGeometry(int GeoId) const
{
if (GeoId >= 0) {
const std::vector<Part::Geometry *> &geomlist = Geometry.getValues();
if (GeoId < int(geomlist.size()))
return geomlist[GeoId];
}
return 0;
}
std::vector<Part::Geometry *> getExternalGeometry(void)
{

View File

@ -80,6 +80,12 @@ public:
/// delete external
int delExternal(int ExtGeoId);
/** returns a pointer to a given Geometry index, possible indexes are:
* id>=0 for user defined geometries,
* ...
*/
const Part::Geometry* getGeometry(int GeoId) const;
/// returns non zero if the sketch contains conflicting constraints
int hasConflicts(void) const;

View File

@ -185,7 +185,6 @@ void CmdSketcherConstrainHorizontal::activated(int iMsg)
const std::vector<std::string> &SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues();
const std::vector<Part::Geometry *> &geomlist = Obj->Geometry.getValues();
std::vector<int> ids;
// go through the selected subelements
@ -194,7 +193,7 @@ void CmdSketcherConstrainHorizontal::activated(int iMsg)
if (it->size() > 4 && it->substr(0,4) == "Edge") {
int index=std::atoi(it->substr(4,4000).c_str());
Part::Geometry *geo = geomlist[index];
const Part::Geometry *geo = Obj->getGeometry(index);
if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Impossible constraint"),
QObject::tr("The selected edge is not a line segment"));
@ -271,7 +270,6 @@ void CmdSketcherConstrainVertical::activated(int iMsg)
const std::vector<std::string> &SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues();
const std::vector<Part::Geometry *> &geomlist = Obj->Geometry.getValues();
std::vector<int> ids;
@ -281,7 +279,7 @@ void CmdSketcherConstrainVertical::activated(int iMsg)
if (it->size() > 4 && it->substr(0,4) == "Edge") {
int index=std::atoi(it->substr(4,4000).c_str());
Part::Geometry *geo = geomlist[index];
const Part::Geometry *geo = Obj->getGeometry(index);
if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Impossible constraint"),
QObject::tr("The selected edge is not a line segment"));
@ -522,7 +520,6 @@ void CmdSketcherConstrainDistance::activated(int iMsg)
// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector<Part::Geometry *> &geo = Obj->Geometry.getValues();
if (SubNames.size() < 1 || SubNames.size() > 2) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
@ -575,7 +572,7 @@ void CmdSketcherConstrainDistance::activated(int iMsg)
Sketcher::PointPos PosId1;
Obj->getGeoVertexIndex(VtId1,GeoId1,PosId1);
Base::Vector3d pnt = Obj->getPoint(GeoId1,PosId1);
const Part::Geometry *geom = geo[GeoId2];
const Part::Geometry *geom = Obj->getGeometry(GeoId2);
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg;
lineSeg = dynamic_cast<const Part::GeomLineSegment*>(geom);
@ -602,7 +599,7 @@ void CmdSketcherConstrainDistance::activated(int iMsg)
}
}
else if (GeoId1 >= 0) { // line length
const Part::Geometry *geom = geo[GeoId1];
const Part::Geometry *geom = Obj->getGeometry(GeoId1);
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg;
lineSeg = dynamic_cast<const Part::GeomLineSegment*>(geom);
@ -669,7 +666,6 @@ void CmdSketcherConstrainPointOnObject::activated(int iMsg)
// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector<Part::Geometry *> &geo = Obj->Geometry.getValues();
if (SubNames.size() < 1 || SubNames.size() > 2) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
@ -701,7 +697,7 @@ void CmdSketcherConstrainPointOnObject::activated(int iMsg)
Sketcher::PointPos PosId1;
Obj->getGeoVertexIndex(VtId1,GeoId1,PosId1);
const Part::Geometry *geom = geo[GeoId2];
const Part::Geometry *geom = Obj->getGeometry(GeoId2);
// Currently only accepts line segments and circles
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId() ||
@ -760,7 +756,6 @@ void CmdSketcherConstrainDistanceX::activated(int iMsg)
// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector<Part::Geometry *> &geo = Obj->Geometry.getValues();
if (SubNames.size() < 1 || SubNames.size() > 2) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
@ -807,7 +802,7 @@ void CmdSketcherConstrainDistanceX::activated(int iMsg)
return;
}
else if (GeoId1 >= 0 && GeoId2 == Constraint::GeoUndef && VtId2 < 0) { // horizontal length of a line
const Part::Geometry *geom = geo[GeoId1];
const Part::Geometry *geom = Obj->getGeometry(GeoId1);
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg;
lineSeg = dynamic_cast<const Part::GeomLineSegment*>(geom);
@ -895,7 +890,6 @@ void CmdSketcherConstrainDistanceY::activated(int iMsg)
// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector<Part::Geometry *> &geo = Obj->Geometry.getValues();
if (SubNames.size() < 1 || SubNames.size() > 2) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
@ -942,7 +936,7 @@ void CmdSketcherConstrainDistanceY::activated(int iMsg)
return;
}
else if (GeoId1 >= 0 && GeoId2 == Constraint::GeoUndef && VtId2 < 0) { // horizontal length of a line
const Part::Geometry *geom = geo[GeoId1];
const Part::Geometry *geom = Obj->getGeometry(GeoId1);
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg;
lineSeg = dynamic_cast<const Part::GeomLineSegment*>(geom);
@ -1030,8 +1024,6 @@ void CmdSketcherConstrainParallel::activated(int iMsg)
// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector<Part::Geometry *> &geomlist = Obj->Geometry.getValues();
// go through the selected subelements
@ -1054,7 +1046,7 @@ void CmdSketcherConstrainParallel::activated(int iMsg)
}
// Check that the curve is a line segment
Part::Geometry *geo = geomlist[index];
const Part::Geometry *geo = Obj->getGeometry(index);
if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("The selected edge is not a valid line"));
@ -1115,8 +1107,6 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg)
// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues();
const std::vector<Part::Geometry *> &geomlist = Obj->Geometry.getValues();
if (SubNames.size() != 2) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
@ -1141,8 +1131,8 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg)
return;
}
Part::Geometry *geo1 = geomlist[GeoId1];
Part::Geometry *geo2 = geomlist[GeoId2];
const Part::Geometry *geo1 = Obj->getGeometry(GeoId1);
const Part::Geometry *geo2 = Obj->getGeometry(GeoId2);
if (geo1->getTypeId() != Part::GeomLineSegment::getClassTypeId() ||
geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) {
@ -1303,7 +1293,6 @@ void CmdSketcherConstrainRadius::activated(int iMsg)
// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector<Part::Geometry *> &geo = Obj->Geometry.getValues();
if (SubNames.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
@ -1314,7 +1303,7 @@ void CmdSketcherConstrainRadius::activated(int iMsg)
if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge") {
int GeoId = std::atoi(SubNames[0].substr(4,4000).c_str());
const Part::Geometry *geom = geo[GeoId];
const Part::Geometry *geom = Obj->getGeometry(GeoId);
if (geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) {
const Part::GeomArcOfCircle *arc = dynamic_cast<const Part::GeomArcOfCircle *>(geom);
double ActRadius = arc->getRadius();
@ -1385,7 +1374,6 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector<Part::Geometry *> &geo = Obj->Geometry.getValues();
if (SubNames.size() < 1 || SubNames.size() > 2) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
@ -1402,8 +1390,8 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
}
if (GeoId2 >= 0) { // line to line angle
const Part::Geometry *geom1 = geo[GeoId1];
const Part::Geometry *geom2 = geo[GeoId2];
const Part::Geometry *geom1 = Obj->getGeometry(GeoId1);
const Part::Geometry *geom2 = Obj->getGeometry(GeoId2);
if (geom1->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg1 = dynamic_cast<const Part::GeomLineSegment*>(geom1);
@ -1456,7 +1444,7 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
return;
}
} else if (GeoId1 >= 0) { // line angle
const Part::Geometry *geom = geo[GeoId1];
const Part::Geometry *geom = Obj->getGeometry(GeoId1);
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg;
lineSeg = dynamic_cast<const Part::GeomLineSegment*>(geom);
@ -1531,8 +1519,6 @@ void CmdSketcherConstrainEqual::activated(int iMsg)
// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues();
const std::vector<Part::Geometry *> &geomlist = Obj->Geometry.getValues();
// go through the selected subelements
@ -1556,7 +1542,7 @@ void CmdSketcherConstrainEqual::activated(int iMsg)
return;
}
Part::Geometry *geo = geomlist[index];
const Part::Geometry *geo = Obj->getGeometry(index);
if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) {
lineSel = true;
} else if (geo->getTypeId() != Part::GeomArcOfCircle::getClassTypeId()) {
@ -1619,7 +1605,6 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg)
// get the selection
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject());
const std::vector<Part::Geometry *> &geo = Obj->Geometry.getValues();
// only one sketch with its subelements are allowed to be selected
if (selection.size() != 1) {
@ -1668,7 +1653,7 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg)
Sketcher::PointPos PosId1,PosId2;
Obj->getGeoVertexIndex(VtId1,GeoId1,PosId1);
Obj->getGeoVertexIndex(VtId2,GeoId2,PosId2);
const Part::Geometry *geom = geo[GeoId3];
const Part::Geometry *geom = Obj->getGeometry(GeoId3);
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
// undo command open
openCommand("add symmetric constraint");

View File

@ -613,7 +613,7 @@ public:
// setup for the next line segment
// Use updated endPoint as autoconstraints can modify the position
Part::Geometry *geom = getObject()->Geometry.getValues()[getHighestCurveIndex()];
const Part::Geometry *geom = sketchgui->getSketchObject()->getGeometry(getHighestCurveIndex());
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg = dynamic_cast<const Part::GeomLineSegment *>(geom);
EditCurve[0] = Base::Vector2D(lineSeg->getEndPoint().x, lineSeg->getEndPoint().y);
@ -1152,8 +1152,7 @@ namespace SketcherGui {
if (element.substr(0,4) == "Edge") {
int index=std::atoi(element.substr(4,4000).c_str());
Sketcher::SketchObject *Sketch = static_cast<Sketcher::SketchObject*>(object);
const std::vector<Part::Geometry *> &geo = Sketch->Geometry.getValues();
const Part::Geometry *geom = geo[index];
const Part::Geometry *geom = Sketch->getGeometry(index);
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId())
return true;
}
@ -1163,10 +1162,9 @@ namespace SketcherGui {
std::vector<int> GeoIdList;
std::vector<Sketcher::PointPos> PosIdList;
Sketch->getCoincidentPoints(index, GeoIdList, PosIdList);
if (GeoIdList.size() == 2) {
const std::vector<Part::Geometry *> &geo = Sketch->Geometry.getValues();
const Part::Geometry *geom1 = geo[GeoIdList[0]];
const Part::Geometry *geom2 = geo[GeoIdList[1]];
if (GeoIdList.size() == 2 && GeoIdList[0] >= 0 && GeoIdList[1] >= 0) {
const Part::Geometry *geom1 = Sketch->getGeometry(GeoIdList[0]);
const Part::Geometry *geom2 = Sketch->getGeometry(GeoIdList[1]);
if (geom1->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId())
return true;
@ -1252,8 +1250,7 @@ public:
int GeoId;
Sketcher::PointPos PosId=Sketcher::none;
sketchgui->getSketchObject()->getGeoVertexIndex(VtId,GeoId,PosId);
const std::vector<Part::Geometry *> &geo = sketchgui->getSketchObject()->Geometry.getValues();
const Part::Geometry *geom = geo[GeoId];
const Part::Geometry *geom = sketchgui->getSketchObject()->getGeometry(GeoId);
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
(PosId == Sketcher::start || PosId == Sketcher::end)) {
@ -1262,15 +1259,15 @@ public:
std::vector<int> GeoIdList;
std::vector<Sketcher::PointPos> PosIdList;
sketchgui->getSketchObject()->getCoincidentPoints(GeoId, PosId, GeoIdList, PosIdList);
if (GeoIdList.size() == 2) {
const Part::Geometry *geom1 = geo[GeoIdList[0]];
const Part::Geometry *geom2 = geo[GeoIdList[1]];
if (GeoIdList.size() == 2 && GeoIdList[0] >= 0 && GeoIdList[1] >= 0) {
const Part::Geometry *geom1 = sketchgui->getSketchObject()->getGeometry(GeoIdList[0]);
const Part::Geometry *geom2 = sketchgui->getSketchObject()->getGeometry(GeoIdList[1]);
if (geom1->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg1 = dynamic_cast<const Part::GeomLineSegment *>(geom1);
const Part::GeomLineSegment *lineSeg2 = dynamic_cast<const Part::GeomLineSegment *>(geom2);
Base::Vector3d dir1 = lineSeg1->getEndPoint() - lineSeg1->getStartPoint();
Base::Vector3d dir2 = lineSeg2->getEndPoint() - lineSeg2->getStartPoint();
Base::Vector3d dir1 = lineSeg1->getEndPoint() - lineSeg1->getStartPoint();
Base::Vector3d dir2 = lineSeg2->getEndPoint() - lineSeg2->getStartPoint();
if (PosIdList[0] == Sketcher::end)
dir1 *= -1;
if (PosIdList[1] == Sketcher::end)
@ -1297,8 +1294,7 @@ public:
int GeoId = sketchgui->getPreselectCurve();
if (GeoId > -1) {
const std::vector<Part::Geometry *> &geo = sketchgui->getSketchObject()->Geometry.getValues();
const Part::Geometry *geom = geo[GeoId];
const Part::Geometry *geom = sketchgui->getSketchObject()->getGeometry(GeoId);
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
if (Mode==STATUS_SEEK_First) {
firstCurve = GeoId;
@ -1319,8 +1315,10 @@ public:
Base::Vector2D secondPos = onSketchPos;
// guess fillet radius
const Part::GeomLineSegment *lineSeg1 = dynamic_cast<const Part::GeomLineSegment *>(geo[firstCurve]);
const Part::GeomLineSegment *lineSeg2 = dynamic_cast<const Part::GeomLineSegment *>(geo[secondCurve]);
const Part::GeomLineSegment *lineSeg1 = dynamic_cast<const Part::GeomLineSegment *>
(sketchgui->getSketchObject()->getGeometry(firstCurve));
const Part::GeomLineSegment *lineSeg2 = dynamic_cast<const Part::GeomLineSegment *>
(sketchgui->getSketchObject()->getGeometry(secondCurve));
Base::Vector3d refPnt1(firstPos.fX, firstPos.fY, 0.f);
Base::Vector3d refPnt2(secondPos.fX, secondPos.fY, 0.f);
double radius = Part::suggestFilletRadius(lineSeg1, lineSeg2, refPnt1, refPnt2);
@ -1401,8 +1399,7 @@ namespace SketcherGui {
if (element.substr(0,4) == "Edge") {
int index=std::atoi(element.substr(4,4000).c_str());
Sketcher::SketchObject *Sketch = static_cast<Sketcher::SketchObject*>(object);
const std::vector<Part::Geometry *> &geo = Sketch->Geometry.getValues();
const Part::Geometry *geom = geo[index];
const Part::Geometry *geom = Sketch->getGeometry(index);
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId() ||
geom->getTypeId() == Part::GeomCircle::getClassTypeId()||
geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId())
@ -1482,8 +1479,7 @@ public:
{
int GeoId = sketchgui->getPreselectCurve();
if (GeoId > -1) {
const std::vector<Part::Geometry *> &geo = sketchgui->getSketchObject()->Geometry.getValues();
const Part::Geometry *geom = geo[GeoId];
const Part::Geometry *geom = sketchgui->getSketchObject()->getGeometry(GeoId);
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId() ||
geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() ||
geom->getTypeId() == Part::GeomCircle::getClassTypeId()

View File

@ -82,19 +82,14 @@ void DrawSketchHandler::quit(void)
//**************************************************************************
// Helpers
Sketcher::SketchObject* DrawSketchHandler::getObject(void)
{
return dynamic_cast<Sketcher::SketchObject*>(sketchgui->getObject());
}
int DrawSketchHandler::getHighestVertexIndex(void)
{
return getObject()->getHighestVertexIndex();
return sketchgui->getSketchObject()->getHighestVertexIndex();
}
int DrawSketchHandler::getHighestCurveIndex(void)
{
return getObject()->getHighestCurveIndex();
return sketchgui->getSketchObject()->getHighestCurveIndex();
}
void DrawSketchHandler::setCursor(const QPixmap &p,int x,int y)
@ -199,15 +194,15 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint> &suggested
// FIXME needs to consider when zooming out?
const float tangDeviation = 2.;
int tangId = -1;
float smlTangDist = 0;
int tangId = Constraint::GeoUndef;
float smlTangDist = 1e15;
// Get geometry list
const std::vector<Part::Geometry *> geomlist = getObject()->Geometry.getValues();
const std::vector<Part::Geometry *> geomlist = sketchgui->getSketchObject()->Geometry.getValues();
// Iterate through geometry
int i = 0;
for (std::vector<Part::Geometry *>::const_iterator it = geomlist.begin(); it != geomlist.end(); ++it, i++) {
for (std::vector<Part::Geometry *>::const_iterator it=geomlist.begin(); it != geomlist.end(); ++it, i++) {
if ((*it)->getTypeId() == Part::GeomCircle::getClassTypeId()) {
const Part::GeomCircle *circle = dynamic_cast<const Part::GeomCircle *>((*it));
@ -221,11 +216,9 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint> &suggested
projPnt = projPnt.ProjToLine(center - tmpPos, Base::Vector3d(Dir.fX, Dir.fY));
float projDist = projPnt.Length();
if ( (projDist < radius + tangDeviation ) && (projDist > radius - tangDeviation))
{
if ( (projDist < radius + tangDeviation ) && (projDist > radius - tangDeviation)) {
// Find if nearest
if (tangId == -1 || projDist< smlTangDist)
{
if (projDist < smlTangDist) {
tangId = i;
smlTangDist = projDist;
}
@ -252,7 +245,7 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint> &suggested
// if the pnt is on correct side of arc and find if nearest
if ((angle > startAngle && angle < endAngle) &&
(tangId == -1 || projDist < smlTangDist) ) {
(projDist < smlTangDist) ) {
tangId = i;
smlTangDist = projDist;
}
@ -260,7 +253,7 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint> &suggested
}
}
if (tangId != -1) {
if (tangId != Constraint::GeoUndef) {
// Suggest vertical constraint
AutoConstraint tangConstr;
tangConstr.Index = tangId;
@ -272,7 +265,7 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint> &suggested
}
void DrawSketchHandler::createAutoConstraints(const std::vector<AutoConstraint> &autoConstrs,
int geoId, Sketcher::PointPos pointPos)
int geoId1, Sketcher::PointPos posId1)
{
if (!sketchgui->Autoconstraints.getValue())
return; // If Autoconstraints property is not set quit
@ -287,47 +280,47 @@ void DrawSketchHandler::createAutoConstraints(const std::vector<AutoConstraint>
switch (it->Type)
{
case Sketcher::Coincident: {
if (pointPos == Sketcher::none)
if (posId1 == Sketcher::none)
continue;
// If the auto constraint has a point create a coincident otherwise it is an edge on a point
Sketcher::PointPos pointPos2;
Sketcher::PointPos posId2;
int geoId2;
sketchgui->getSketchObject()->getGeoVertexIndex(it->Index, geoId2, pointPos2);
sketchgui->getSketchObject()->getGeoVertexIndex(it->Index, geoId2, posId2);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%i,%i,%i,%i)) "
,sketchgui->getObject()->getNameInDocument()
,geoId, pointPos, geoId2, pointPos2
,geoId1, posId1, geoId2, posId2
);
} break;
case Sketcher::PointOnObject: {
int index = it->Index;
if (pointPos == Sketcher::none) {
if (posId1 == Sketcher::none) {
// Auto constraining an edge so swap parameters
index = geoId;
sketchgui->getSketchObject()->getGeoVertexIndex(it->Index, geoId, pointPos);
index = geoId1;
sketchgui->getSketchObject()->getGeoVertexIndex(it->Index, geoId1, posId1);
}
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%i,%i,%i)) "
,sketchgui->getObject()->getNameInDocument()
,geoId, pointPos, index
,geoId1, posId1, index
);
} break;
case Sketcher::Horizontal: {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Horizontal',%i)) "
,sketchgui->getObject()->getNameInDocument()
,geoId
,geoId1
);
} break;
case Sketcher::Vertical: {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Vertical',%i)) "
,sketchgui->getObject()->getNameInDocument()
,geoId
,geoId1
);
} break;
case Sketcher::Tangent: {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%i, %i)) "
,sketchgui->getObject()->getNameInDocument()
,geoId, it->Index
,geoId1, it->Index
);
} break;
}

View File

@ -75,7 +75,6 @@ public:
friend class ViewProviderSketch;
Sketcher::SketchObject* getObject(void);
// get the actual highest vertex index, the next use will be +1
int getHighestVertexIndex(void);
// get the actual highest edge index, the next use will be +1

View File

@ -530,9 +530,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
return true;
case STATUS_SKETCH_DragCurve:
if (edit->DragCurve != -1 && pp) {
const std::vector<Part::Geometry *> *geomlist;
geomlist = &getSketchObject()->Geometry.getValues();
Part::Geometry *geo = (*geomlist)[edit->DragCurve];
const Part::Geometry *geo = getSketchObject()->getGeometry(edit->DragCurve);
if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId() ||
geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() ||
geo->getTypeId() == Part::GeomCircle::getClassTypeId()) {
@ -769,7 +767,7 @@ bool ViewProviderSketch::mouseMove(const SbVec3f &point, const SbVec3f &normal,
Mode = STATUS_SKETCH_DragCurve;
edit->DragCurve = edit->PreselectCurve;
edit->ActSketch.initMove(edit->DragCurve, Sketcher::none);
Part::Geometry *geo = getSketchObject()->Geometry.getValues()[edit->DragCurve];
const Part::Geometry *geo = getSketchObject()->getGeometry(edit->DragCurve);
if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
relative = true;
xInit = x;
@ -1325,7 +1323,7 @@ void ViewProviderSketch::updateColor(void)
color[i] = SelectColor;
else if (edit->PreselectCurve == i)
color[i] = PreselectColor;
else if (this->getSketchObject()->Geometry.getValues()[i]->Construction)
else if (getSketchObject()->getGeometry(i)->Construction)
color[i] = CurveDraftColor;
else if (edit->FullyConstrained)
color[i] = FullyConstrainedColor;
@ -1355,7 +1353,7 @@ void ViewProviderSketch::updateColor(void)
SoMaterial *m = dynamic_cast<SoMaterial *>(s->getChild(0));
// Check Constraint Type
ConstraintType type = this->getSketchObject()->Constraints.getValues()[i]->Type;
ConstraintType type = getSketchObject()->Constraints.getValues()[i]->Type;
bool hasDatumLabel = (type == Sketcher::Angle ||
type == Sketcher::Radius ||
type == Sketcher::Distance || type == Sketcher::DistanceX || type == Sketcher::DistanceY);
@ -1424,8 +1422,8 @@ void ViewProviderSketch::drawConstraintIcons()
case Tangent:
icoType = QString::fromAscii("small/Constraint_Tangent_sm");
{ // second icon is available only for colinear line segments
Part::Geometry *geo1 = getSketchObject()->Geometry.getValues()[(*it)->First];
Part::Geometry *geo2 = getSketchObject()->Geometry.getValues()[(*it)->Second];
const Part::Geometry *geo1 = getSketchObject()->getGeometry((*it)->First);
const Part::Geometry *geo2 = getSketchObject()->getGeometry((*it)->Second);
if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
index2 = 4;
@ -2473,8 +2471,8 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
sep->addChild(new SoImage()); // 2. constraint icon
if ((*it)->Type == Tangent) {
Part::Geometry *geo1 = getSketchObject()->Geometry.getValues()[(*it)->First];
Part::Geometry *geo2 = getSketchObject()->Geometry.getValues()[(*it)->Second];
const Part::Geometry *geo1 = getSketchObject()->getGeometry((*it)->First);
const Part::Geometry *geo2 = getSketchObject()->getGeometry((*it)->Second);
if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
sep->addChild(new SoZoomTranslation());