fix selection error on datum exception

and add user feedback for failed selections
This commit is contained in:
Stefan Tröger 2015-05-22 06:59:18 +02:00
parent 7cb6606dc2
commit d3a7e9a928
7 changed files with 61 additions and 54 deletions

View File

@ -124,16 +124,9 @@ void CoordinateSystem::initHints()
key.insert(PLANE);
key.insert(LINE);
value.insert(POINT);
value.insert(LINE);
value.insert(DONE);
hints[key] = value;
key.clear(); value.clear();
key.insert(PLANE);
key.insert(LINE);
key.insert(LINE);
hints[key] = Done;
key.clear(); value.clear();
key.insert(PLANE);
key.insert(LINE);
@ -167,16 +160,9 @@ void CoordinateSystem::initHints()
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);
@ -186,17 +172,10 @@ void CoordinateSystem::initHints()
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);
@ -260,7 +239,7 @@ void CoordinateSystem::onChanged(const App::Property *prop)
const std::vector<std::string>& subrefs = References.getSubValues();
if (refs.size() != subrefs.size())
return; //throw Base::Exception("Size of references and subreferences do not match");
throw Base::Exception("Size of references and subreferences do not match");
refTypes.clear();
for (int r = 0; r < refs.size(); r++)
@ -268,7 +247,7 @@ void CoordinateSystem::onChanged(const App::Property *prop)
std::set<QString> hint = getHint();
if (refs.size() != 0 && !(hint.find(QObject::tr("Done")) != hint.end()))
return; //throw Base::Exception("Can not build coordinate system from given references"); // incomplete references
throw Base::Exception("Can not build coordinate system from given references"); // incomplete references
//build the placement from the references
bool plane = false, line1 = false, line2 = false, origin = false;
@ -286,7 +265,7 @@ void CoordinateSystem::onChanged(const App::Property *prop)
origin=true;
}
else
return; //throw Base::Exception("Too many points in coordinate system references"); //too much points selected
throw Base::Exception("Too many points in coordinate system references"); //too much points selected
}
else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
PartDesign::Plane* p = static_cast<PartDesign::Plane*>(refs[i]);
@ -295,7 +274,7 @@ void CoordinateSystem::onChanged(const App::Property *prop)
plane=true;
}
else
return; //throw Base::Exception("Too many planes in coordinate syste references");
throw Base::Exception("Too many planes in coordinate syste references");
} else if (refs[i]->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
App::Plane* p = static_cast<App::Plane*>(refs[i]);
if(!plane) {
@ -312,7 +291,7 @@ void CoordinateSystem::onChanged(const App::Property *prop)
plane=true;
}
else
return; //throw Base::Exception("Too many planes in coordinate syste references"); //too much planes selected
throw Base::Exception("Too many planes in coordinate syste references"); //too much planes selected
}
else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
PartDesign::Line* p = static_cast<PartDesign::Line*>(refs[i]);
@ -325,7 +304,7 @@ void CoordinateSystem::onChanged(const App::Property *prop)
line2 = true;
}
else
return; //throw Base::Exception("Too many lines in coordinate syste references");; //too much lines selected
throw Base::Exception("Too many lines in coordinate syste references");; //too much lines selected
} else if (refs[i]->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) {
App::Line* p = static_cast<App::Line*>(refs[i]);
@ -347,17 +326,17 @@ void CoordinateSystem::onChanged(const App::Property *prop)
line2=true;
}
else
return; //throw Base::Exception("Too many lines in coordinate syste references");
throw Base::Exception("Too many lines in coordinate syste references");
}
else if (refs[i]->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
Part::Feature* feature = static_cast<Part::Feature*>(refs[i]);
const TopoDS_Shape& sh = feature->Shape.getValue();
if (sh.IsNull())
return; //throw Base::Exception("Invalid shape in reference");
throw Base::Exception("Invalid shape in reference");
// Get subshape
TopoDS_Shape subshape = feature->Shape.getShape().getSubShape(subrefs[i].c_str());
if (subshape.IsNull())
return; //throw Base::Exception("Reference has Null shape");
throw Base::Exception("Reference has Null shape");
if (subshape.ShapeType() == TopAbs_VERTEX) {
TopoDS_Vertex v = TopoDS::Vertex(subshape);
@ -367,13 +346,13 @@ void CoordinateSystem::onChanged(const App::Property *prop)
origin=true;
}
else
return; //throw Base::Exception("Too many points in coordinate system references");
throw Base::Exception("Too many points in coordinate system references");
}
else if (subshape.ShapeType() == TopAbs_EDGE) {
TopoDS_Edge e = TopoDS::Edge(subshape);
BRepAdaptor_Curve adapt(e);
if (adapt.GetType() != GeomAbs_Line)
return; //throw Base::Exception("Only straight edges are supported");
throw Base::Exception("Only straight edges are supported");
if(!line1) {
lin1 = adapt.Line();
@ -384,7 +363,7 @@ void CoordinateSystem::onChanged(const App::Property *prop)
line2=true;
}
else
return; //throw Base::Exception("Too many lines in coordinate system references");
throw Base::Exception("Too many lines in coordinate system references");
} else if (subshape.ShapeType() == TopAbs_FACE) {
TopoDS_Face f = TopoDS::Face(subshape);
@ -402,10 +381,10 @@ void CoordinateSystem::onChanged(const App::Property *prop)
plane = true;
}
else
return; //throw Base::Exception("Too many planes in coordinate system references");
throw Base::Exception("Too many planes in coordinate system references");
} else {
return; //throw Base::Exception("Only planar faces allowed");
throw Base::Exception("Only planar faces allowed");
}
}
}
@ -418,11 +397,14 @@ void CoordinateSystem::onChanged(const App::Property *prop)
if(plane) {
if(!pln.Contains(org, Precision::Confusion()))
return; //throw Base::Exception("Point must lie on plane");
throw Base::Exception("Point must lie on plane");
if(line1) {
if(!pln.Contains(lin1, Precision::Confusion(), Precision::Confusion()))
return; //throw Base::Exception("Line must lie on plane");
throw Base::Exception("Line must lie on plane");
if(line2)
throw Base::Exception("Two lines and a plain are not supportet");
ax = gp_Ax3(org, pln.Axis().Direction(), lin1.Direction());
}
@ -448,7 +430,7 @@ void CoordinateSystem::onChanged(const App::Property *prop)
if(line1) {
if(!pln.Contains(lin1, Precision::Confusion(), Precision::Confusion()))
return; //throw Base::Exception("Line must lie on plane");
throw Base::Exception("Line must lie on plane");
ax = gp_Ax3(pln.Location(), pln.Axis().Direction(), lin1.Direction());
}
@ -459,6 +441,8 @@ void CoordinateSystem::onChanged(const App::Property *prop)
else if(line1) {
if(line2) {
if(! ((lin1.Angle(lin2) - M_PI<2) < Precision::Angular()) )
throw Base::Exception("Lines must be perpendicular");
ax = gp_Ax3(lin1.Location(), lin1.Direction(), lin2.Direction());
}
else

View File

@ -159,14 +159,14 @@ void Line::onChanged(const App::Property *prop)
std::vector<App::DocumentObject*> refs = References.getValues();
std::vector<std::string> refnames = References.getSubValues();
if (refs.size() != refnames.size())
return;
throw Base::Exception("Reference Missmatch");
for (int r = 0; r < refs.size(); r++)
refTypes.insert(getRefType(refs[r], refnames[r]));
std::set<QString> hint = getHint();
if (!((hint.size() == 1) && (hint.find(QObject::tr("Done")) != hint.end())))
return; // incomplete references
throw Base::Exception("Incomplete References"); // incomplete references
// Extract the geometry of the references
Base::Vector3d* base = NULL;
@ -226,7 +226,7 @@ void Line::onChanged(const App::Property *prop)
// Create plane through line normal to s1
Handle_Geom_Plane pl = Handle_Geom_Plane::DownCast(s1);
if (pl.IsNull())
return; // Non-planar first surface
throw Base::Exception("Non-planar first surface"); // Non-planar first surface
gp_Dir normal = ldir.Crossed(pl->Axis().Direction());
double offset1 = Offset.getValue();
double offset2 = Offset2.getValue();
@ -375,7 +375,7 @@ void Line::onChanged(const App::Property *prop)
// Line from two surfaces
GeomAPI_IntSS intersectorSS(s1, s2, Precision::Confusion());
if (!intersectorSS.IsDone() || (intersectorSS.NbLines() == 0))
return;
throw Base::Exception("Intersection of surfaces failed");
if (intersectorSS.NbLines() > 1)
Base::Console().Warning("More than one intersection curve for datum line from surfaces\n");
Handle_Geom_Line l = Handle_Geom_Line::DownCast(intersectorSS.Line(1));

View File

@ -326,7 +326,7 @@ void Plane::onChanged(const App::Property *prop)
// Intersect a line through the base point of the cylinder and normal to the plane with the cylinder itself
GeomAPI_IntCS intersector(normalLine, cylinder);
if (!intersector.IsDone() || (intersector.NbPoints() == 0))
return;
throw Base::Exception("Curve - Surface intersection failed");
if (intersector.NbPoints() > 1)
Base::Console().Warning("More than one intersection point for datum plane from cylinder and plane\n");
@ -349,7 +349,7 @@ void Plane::onChanged(const App::Property *prop)
Base::Vector3d vec2 = *p3 - *p1;
normal = new Base::Vector3d(vec1 % vec2);
} else {
return;
throw Base::Exception("Unvalid references");
}
*normal = normal->Normalize();

View File

@ -310,7 +310,7 @@ void Point::onChanged(const App::Property* prop)
// Point from intersection of two curves
GeomAPI_ExtremaCurveCurve intersector(c1, c2);
if ((intersector.LowerDistance() > Precision::Confusion()) || (intersector.NbExtrema() == 0))
return; // No intersection
throw Base::Exception("Curve-Curve intersection failed"); // No intersection
// Note: We don't check for multiple intersection points
gp_Pnt p, p2;
intersector.Points(1, p, p2);
@ -330,7 +330,7 @@ void Point::onChanged(const App::Property* prop)
// Intersect again
intersector = GeomAPI_ExtremaCurveCurve(c1, c2);
if ((intersector.LowerDistance() > Precision::Confusion()) || (intersector.NbExtrema() == 0))
return; // No intersection
throw Base::Exception("Curve-Curve intersection failed"); // No intersection
// Note: We don't check for multiple intersection points
intersector.Points(1, p, p2);
}
@ -339,7 +339,7 @@ void Point::onChanged(const App::Property* prop)
} else if (!s1.IsNull()) {
GeomAPI_IntCS intersector(c1, s1);
if (!intersector.IsDone() || (intersector.NbPoints() == 0))
return;
throw Base::Exception("Curve-Surface intersection failed");
if (intersector.NbPoints() > 1)
Base::Console().Warning("More than one intersection point for datum point from curve and surface\n");

View File

@ -229,8 +229,13 @@ const QString makeRefText(std::set<QString> hint)
return result;
}
void TaskDatumParameters::updateUI()
void TaskDatumParameters::updateUI(std::string message, bool error)
{
//set text if available
if(!message.empty()) {
ui->message->setText(QString::fromStdString(message));
}
ui->checkBoxFlip->setVisible(false);
int numOffsets = static_cast<Part::Datum*>(DatumView->getObject())->offsetsAllowed();
@ -401,8 +406,16 @@ void TaskDatumParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
refs.push_back(selObj);
refnames.push_back(subname);
}
pcDatum->References.setValues(refs, refnames);
//pcDatum->getDocument()->recomputeFeature(pcDatum);
bool error = false;
std::string message("Selection accepted");
try {
pcDatum->References.setValues(refs, refnames);
}
catch(Base::Exception& e) {
error = true;
message = std::string(e.what());
}
QLineEdit* line = getLine(refSelectionMode);
if (line != NULL) {
@ -412,7 +425,7 @@ void TaskDatumParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
line->blockSignals(false);
}
updateUI();
updateUI(message, error);
}
}

View File

@ -79,7 +79,7 @@ protected:
private:
void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI();
void updateUI(std::string message = std::string(), bool isWarning = false);
void makeRefStrings(std::vector<QString>& refstrings, std::vector<std::string>& refnames);
QLineEdit* getLine(const int idx);

View File

@ -14,6 +14,16 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="message">
<property name="text">
<string>Selection accepted</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>