add remaining coordinate system selections

This commit is contained in:
Stefan Tröger 2015-05-22 06:32:15 +02:00
parent 96584f776a
commit 7cb6606dc2

View File

@ -71,6 +71,8 @@ void CoordinateSystem::initHints()
std::multiset<QString> key; std::multiset<QString> key;
std::set<QString> value; std::set<QString> value;
//Point first ----------------------
key.insert(POINT); key.insert(POINT);
value.insert(PLANE); value.insert(PLANE);
value.insert(LINE); value.insert(LINE);
@ -93,23 +95,133 @@ void CoordinateSystem::initHints()
key.clear(); value.clear(); key.clear(); value.clear();
key.insert(POINT); key.insert(POINT);
key.insert(LINE); key.insert(LINE);
value.insert(PLANE);
value.insert(LINE);
value.insert(DONE); value.insert(DONE);
hints[key] = value; hints[key] = value;
/* key.clear(); value.clear();
key.insert(POINT);
key.insert(LINE);
key.insert(PLANE);
hints[key] = Done;
key.clear(); value.clear();
key.insert(POINT);
key.insert(LINE);
key.insert(LINE);
hints[key] = Done;
//Plane First -------------------------
key.clear(); value.clear(); key.clear(); value.clear();
key.insert(PLANE); key.insert(PLANE);
value.insert(LINE); value.insert(LINE);
value.insert(POINT);
value.insert(DONE);
hints[key] = value;
key.clear(); value.clear();
key.insert(PLANE);
key.insert(LINE);
value.insert(POINT);
value.insert(LINE);
value.insert(DONE); value.insert(DONE);
hints[key] = value; hints[key] = value;
key.clear(); value.clear(); key.clear(); value.clear();
key.insert(PLANE); key.insert(PLANE);
key.insert(LINE); key.insert(LINE);
key.insert(LINE);
hints[key] = Done;
key.clear(); value.clear();
key.insert(PLANE);
key.insert(LINE);
key.insert(POINT);
hints[key] = Done;
key.clear(); value.clear();
key.insert(PLANE);
key.insert(POINT);
value.insert(LINE); value.insert(LINE);
value.insert(DONE); value.insert(DONE);
hints[key] = value;*/ hints[key] = value;
key.clear(); value.clear();
key.insert(PLANE);
key.insert(POINT);
key.insert(LINE);
hints[key] = Done;
//Line First -------------------------
key.clear(); value.clear();
key.insert(LINE);
value.insert(PLANE);
value.insert(LINE);
value.insert(POINT);
value.insert(DONE);
hints[key] = value;
key.clear(); value.clear();
key.insert(LINE);
key.insert(PLANE);
value.insert(POINT);
value.insert(LINE);
value.insert(DONE);
hints[key] = value;
key.clear(); value.clear();
key.insert(LINE);
key.insert(PLANE);
key.insert(LINE);
hints[key] = Done;
key.clear(); value.clear();
key.insert(LINE);
key.insert(PLANE);
key.insert(POINT);
hints[key] = Done;
key.clear(); value.clear();
key.insert(LINE);
key.insert(LINE);
value.insert(PLANE);
value.insert(POINT);
value.insert(DONE);
hints[key] = value;
key.clear(); value.clear();
key.insert(LINE);
key.insert(LINE);
key.insert(PLANE);
hints[key] = Done;
key.clear(); value.clear();
key.insert(LINE);
key.insert(LINE);
key.insert(POINT);
hints[key] = Done;
key.clear(); value.clear();
key.insert(LINE);
key.insert(POINT);
value.insert(PLANE);
value.insert(LINE);
value.insert(DONE);
hints[key] = value;
key.clear(); value.clear();
key.insert(LINE);
key.insert(POINT);
key.insert(PLANE);
hints[key] = Done;
key.clear(); value.clear();
key.insert(LINE);
key.insert(PLANE);
key.insert(POINT);
hints[key] = Done;
} }
// ============================================================================ // ============================================================================
@ -159,9 +271,9 @@ void CoordinateSystem::onChanged(const App::Property *prop)
return; //throw Base::Exception("Can not build coordinate system from given references"); // incomplete references return; //throw Base::Exception("Can not build coordinate system from given references"); // incomplete references
//build the placement from the references //build the placement from the references
bool plane = false, lineX = false, lineY = false, origin = false; bool plane = false, line1 = false, line2 = false, origin = false;
gp_Pln pln; gp_Pln pln;
gp_Lin linX, linY; gp_Lin lin1, lin2;
gp_Pnt org; gp_Pnt org;
int count = 0; int count = 0;
@ -204,13 +316,13 @@ void CoordinateSystem::onChanged(const App::Property *prop)
} }
else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) { else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
PartDesign::Line* p = static_cast<PartDesign::Line*>(refs[i]); PartDesign::Line* p = static_cast<PartDesign::Line*>(refs[i]);
if(!lineX) { if(!line1) {
linX = gp_Lin(GP_POINT(p->getBasePoint()), GP_DIR(p->getDirection())); lin1 = gp_Lin(GP_POINT(p->getBasePoint()), GP_DIR(p->getDirection()));
lineX = true; line1 = true;
} }
else if(!lineY) { else if(!line2) {
linY = gp_Lin(GP_POINT(p->getBasePoint()), GP_DIR(p->getDirection())); lin2 = gp_Lin(GP_POINT(p->getBasePoint()), GP_DIR(p->getDirection()));
lineY = true; line2 = true;
} }
else else
return; //throw Base::Exception("Too many lines in coordinate syste references");; //too much lines selected return; //throw Base::Exception("Too many lines in coordinate syste references");; //too much lines selected
@ -226,13 +338,13 @@ void CoordinateSystem::onChanged(const App::Property *prop)
else if (strcmp(p->getNameInDocument(), App::Part::BaselineTypes[2]) == 0) else if (strcmp(p->getNameInDocument(), App::Part::BaselineTypes[2]) == 0)
dir = gp_Dir(0,0,1); dir = gp_Dir(0,0,1);
if(!lineX) { if(!line1) {
linX = gp_Lin(base, dir); lin1 = gp_Lin(base, dir);
lineX=true; line1=true;
} }
else if(!lineY) { else if(!line2) {
linY = gp_Lin(base, dir); lin2 = gp_Lin(base, dir);
lineY=true; line2=true;
} }
else else
return; //throw Base::Exception("Too many lines in coordinate syste references"); return; //throw Base::Exception("Too many lines in coordinate syste references");
@ -263,13 +375,13 @@ void CoordinateSystem::onChanged(const App::Property *prop)
if (adapt.GetType() != GeomAbs_Line) if (adapt.GetType() != GeomAbs_Line)
return; //throw Base::Exception("Only straight edges are supported"); return; //throw Base::Exception("Only straight edges are supported");
if(!lineX) { if(!line1) {
linX = adapt.Line(); lin1 = adapt.Line();
lineX=true; line1=true;
} }
else if(!lineY) { else if(!line2) {
linY = adapt.Line(); lin2 = adapt.Line();
lineY=true; line2=true;
} }
else else
return; //throw Base::Exception("Too many lines in coordinate system references"); return; //throw Base::Exception("Too many lines in coordinate system references");
@ -303,40 +415,55 @@ void CoordinateSystem::onChanged(const App::Property *prop)
gp_Ax3 ax; gp_Ax3 ax;
if(origin) { if(origin) {
Base::Vector3d base(org.X(), org.Y(), org.Z());
if(plane) { if(plane) {
if(!pln.Contains(org, Precision::Confusion())) if(!pln.Contains(org, Precision::Confusion()))
return; //throw Base::Exception("Point must lie on plane"); return; //throw Base::Exception("Point must lie on plane");
if(lineX) { if(line1) {
if(!pln.Contains(linX, Precision::Confusion(), Precision::Confusion())) if(!pln.Contains(lin1, Precision::Confusion(), Precision::Confusion()))
return; //throw Base::Exception("Line must lie on plane"); return; //throw Base::Exception("Line must lie on plane");
ax = gp_Ax3(org, pln.Axis().Direction(), linX.Direction()); ax = gp_Ax3(org, pln.Axis().Direction(), lin1.Direction());
} }
else { else {
ax = gp_Ax3(org, pln.Axis().Direction(), pln.XAxis().Direction()); ax = gp_Ax3(org, pln.Axis().Direction(), pln.XAxis().Direction());
} }
} }
else if(lineX) { else if(line1) {
if(lineY) { if(line2) {
if(linY.Angle(linX)<Precision::Angular()) if(lin2.Angle(lin1)<Precision::Angular())
return; return;
ax = gp_Ax3(org, linX.Direction().Crossed(linY.Direction()), linX.Direction()); ax = gp_Ax3(org, lin1.Direction(), lin2.Direction());
}
else if(!linX.Contains(org, Precision::Confusion())) {
gp_Lin nor = linX.Normal(org);
ax = gp_Ax3(nor.Location(), nor.Direction().Crossed(linX.Direction()), linX.Direction());
} }
else else
return; ax = gp_Ax3(org, lin1.Direction());
} }
else else
ax = gp_Ax3(org, gp_Dir(0,0,1), gp_Dir(1,0,0)); ax = gp_Ax3(org, gp_Dir(0,0,1), gp_Dir(1,0,0));
} }
else if(plane) {
if(line1) {
if(!pln.Contains(lin1, Precision::Confusion(), Precision::Confusion()))
return; //throw Base::Exception("Line must lie on plane");
ax = gp_Ax3(pln.Location(), pln.Axis().Direction(), lin1.Direction());
}
else {
ax = gp_Ax3(pln.Location(), pln.Axis().Direction(), pln.XAxis().Direction());
}
}
else if(line1) {
if(line2) {
ax = gp_Ax3(lin1.Location(), lin1.Direction(), lin2.Direction());
}
else
ax = gp_Ax3(lin1.Location(), lin1.Direction());
}
//build the placement //build the placement
gp_Trsf trans; gp_Trsf trans;