Skip to content

Commit

Permalink
Sketcher: [skip ci] add function to sketch validation panel to remove…
Browse files Browse the repository at this point in the history
… degenerated geometry
  • Loading branch information
wwmayer committed Aug 13, 2020
1 parent 023f779 commit 1c432fd
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 35 deletions.
46 changes: 46 additions & 0 deletions src/Mod/Sketcher/App/SketchAnalysis.cpp
Expand Up @@ -822,3 +822,49 @@ std::vector<Base::Vector3d> SketchAnalysis::getOpenVertices(void) const

return points;
}

int SketchAnalysis::detectDegeneratedGeometries(double tolerance)
{
int countDegenerated = 0;
const std::vector<Part::Geometry *>& geom = sketch->getInternalGeometry();
for (std::size_t i=0; i<geom.size(); i++) {
Part::Geometry* g = geom[i];

if (g->Construction)
continue;

if (g->getTypeId().isDerivedFrom(Part::GeomCurve::getClassTypeId())) {
Part::GeomCurve* curve = static_cast<Part::GeomCurve*>(g);
double len = curve->length(curve->getFirstParameter(), curve->getLastParameter());
if (len < tolerance)
countDegenerated++;
}
}

return countDegenerated;
}

int SketchAnalysis::removeDegeneratedGeometries(double tolerance)
{
std::set<int> delInternalGeometries;
const std::vector<Part::Geometry *>& geom = sketch->getInternalGeometry();
for (std::size_t i=0; i<geom.size(); i++) {
Part::Geometry* g = geom[i];

if (g->Construction)
continue;

if (g->getTypeId().isDerivedFrom(Part::GeomCurve::getClassTypeId())) {
Part::GeomCurve* curve = static_cast<Part::GeomCurve*>(g);
double len = curve->length(curve->getFirstParameter(), curve->getLastParameter());
if (len < tolerance)
delInternalGeometries.insert(static_cast<int>(i));
}
}

for (auto it = delInternalGeometries.rbegin(); it != delInternalGeometries.rend(); ++it) {
sketch->delGeometry(*it);
}

return static_cast<int>(delInternalGeometries.size());
}
5 changes: 5 additions & 0 deletions src/Mod/Sketcher/App/SketchAnalysis.h
Expand Up @@ -104,6 +104,11 @@ class SketcherExport SketchAnalysis
/// Equality constraints simple routine Make step (see constructor)
void makeMissingEquality(bool onebyone = true);

/// Detect degenerated geometries
int detectDegeneratedGeometries(double tolerance);
/// Remove degenerated geometries
int removeDegeneratedGeometries(double tolerance);

// Complex routines (see constructor)

/// Fully automated multi-constraint autoconstraining
Expand Down
37 changes: 36 additions & 1 deletion src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp
Expand Up @@ -234,7 +234,7 @@ void SketcherValidation::on_findReversed_clicked()
ui->swapReversed->setEnabled(false);
}
} else {
QMessageBox::warning(this, tr("Reversed external geometry"),
QMessageBox::information(this, tr("Reversed external geometry"),
tr("No reversed external-geometry arcs were found."));
}
}
Expand Down Expand Up @@ -350,6 +350,41 @@ void SketcherValidation::hidePoints()
}
}

void SketcherValidation::on_findDegenerated_clicked()
{
double prec = Precision::Confusion();
int count = sketchAnalyser.detectDegeneratedGeometries(prec);

if (count == 0) {
QMessageBox::information(this, tr("No degenerated geometry"),
tr("No degenerated geometry found"));
ui->fixDegenerated->setEnabled(false);
}
else {
QMessageBox::warning(this, tr("Degenerated geometry"),
tr("%1 degenerated geometry found").arg(count));
ui->fixDegenerated->setEnabled(true);
}
}

void SketcherValidation::on_fixDegenerated_clicked()
{
// undo command open
App::Document* doc = sketch->getDocument();
doc->openTransaction("Remove degenerated geometry");

double prec = Precision::Confusion();
sketchAnalyser.removeDegeneratedGeometries(prec);

ui->fixButton->setEnabled(false);
hidePoints();

// finish the transaction and update
Gui::WaitCursor wc;
doc->commitTransaction();
doc->recompute();
}

// -----------------------------------------------

TaskSketcherValidation::TaskSketcherValidation(Sketcher::SketchObject* Obj)
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Sketcher/Gui/TaskSketcherValidation.h
Expand Up @@ -58,6 +58,8 @@ private Q_SLOTS:
void on_orientLockEnable_clicked();
void on_orientLockDisable_clicked();
void on_delConstrExtr_clicked();
void on_findDegenerated_clicked();
void on_fixDegenerated_clicked();

private:
void showPoints(const std::vector<Base::Vector3d>&);
Expand Down
91 changes: 57 additions & 34 deletions src/Mod/Sketcher/Gui/TaskSketcherValidation.ui
Expand Up @@ -14,80 +14,103 @@
<string>Sketcher validation</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_2">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Invalid constraints</string>
<string>Missing coincidences</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Tolerance:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="fixConstraint">
<widget class="QComboBox" name="comboBoxTolerance"/>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxIgnoreConstruction">
<property name="text">
<string>Fix</string>
<string>Ignore construction geometry</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="findConstraint">
<item row="2" column="0">
<widget class="QPushButton" name="findButton">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QPushButton" name="delConstrExtr">
<item row="2" column="1">
<widget class="QPushButton" name="fixButton">
<property name="text">
<string>Delete constraints to external geom.</string>
<string>Fix</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="highlightButton">
<property name="text">
<string>Highlight open vertexes</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Missing coincidences</string>
<string>Invalid constraints</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<widget class="QPushButton" name="findConstraint">
<property name="text">
<string>Tolerance:</string>
<string>Find</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="fixButton">
<item row="0" column="1">
<widget class="QPushButton" name="fixConstraint">
<property name="text">
<string>Fix</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBoxTolerance"/>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="findButton">
<item row="1" column="0" colspan="2">
<widget class="QPushButton" name="delConstrExtr">
<property name="text">
<string>Find</string>
<string>Delete constraints to external geom.</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="highlightButton">
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Degenerated geometry</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QPushButton" name="findDegenerated">
<property name="text">
<string>Highlight open vertexes</string>
<string>Find</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxIgnoreConstruction">
<item row="0" column="1">
<widget class="QPushButton" name="fixDegenerated">
<property name="text">
<string>Ignore construction geometry</string>
</property>
<property name="checked">
<bool>true</bool>
<string>Fix</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 1c432fd

Please sign in to comment.