From db13fbb7b3bc41db73d6a257e05b6c94c0a55bd8 Mon Sep 17 00:00:00 2001 From: Sebastian Hoogen Date: Sun, 8 Mar 2015 21:05:19 +0100 Subject: [PATCH] add angularDeflection property to ViewProvider issue #1868 --- src/Mod/Part/Gui/DlgSettings3DViewPart.ui | 65 ++++++++++++++----- src/Mod/Part/Gui/DlgSettings3DViewPartImp.cpp | 2 + src/Mod/Part/Gui/ViewProvider.cpp | 10 +++ src/Mod/Part/Gui/ViewProvider.h | 1 + src/Mod/Part/Gui/ViewProviderExt.cpp | 16 ++++- src/Mod/Part/Gui/ViewProviderExt.h | 3 + .../Gui/ViewProviderTransformed.cpp | 8 ++- 7 files changed, 87 insertions(+), 18 deletions(-) diff --git a/src/Mod/Part/Gui/DlgSettings3DViewPart.ui b/src/Mod/Part/Gui/DlgSettings3DViewPart.ui index 8b8a4c652..96b2580eb 100644 --- a/src/Mod/Part/Gui/DlgSettings3DViewPart.ui +++ b/src/Mod/Part/Gui/DlgSettings3DViewPart.ui @@ -6,7 +6,7 @@ 0 0 - 525 + 539 339 @@ -53,20 +53,7 @@ 6 - - - - Defines the deviation of tessellation to the actual surface - - - <html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg 2; font-size:7.8pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Tessellation</span></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"></p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"><span style=" font-weight:400;">Defines the maximum deviation of the tessellated mesh to the surface. The smaller the value is the slower the render speed and the nicer the appearance are.</span></p></body></html> - - - Maximum deviation depending on the model bounding box - - - - + % @@ -94,6 +81,54 @@ + + + + Defines the deviation of tessellation to the actual surface + + + <html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg 2; font-size:7.8pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Tessellation</span></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"></p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"><span style=" font-weight:400;">Defines the maximum deviation of the tessellated mesh to the surface. The smaller the value is the slower the render speed and the nicer the appearance are.</span></p></body></html> + + + Maximum deviation depending on the model bounding box + + + + + + + Maximum angular deflection + + + + + + + ° + + + 2 + + + 0.0 + + + 180.000000000000000 + + + 0.5 + + + 28.5 + + + MeshAngularDeflection + + + Mod/Part + + + diff --git a/src/Mod/Part/Gui/DlgSettings3DViewPartImp.cpp b/src/Mod/Part/Gui/DlgSettings3DViewPartImp.cpp index 846775ce3..479875500 100644 --- a/src/Mod/Part/Gui/DlgSettings3DViewPartImp.cpp +++ b/src/Mod/Part/Gui/DlgSettings3DViewPartImp.cpp @@ -70,6 +70,7 @@ void DlgSettings3DViewPart::on_maxDeviation_valueChanged(double v) void DlgSettings3DViewPart::saveSettings() { ui->maxDeviation->onSave(); + ui->maxAngularDeflection->onSave(); // search for Part view providers and apply the new settings std::vector docs = App::GetApplication().getDocuments(); @@ -85,6 +86,7 @@ void DlgSettings3DViewPart::saveSettings() void DlgSettings3DViewPart::loadSettings() { ui->maxDeviation->onRestore(); + ui->maxAngularDeflection->onRestore(); } /** diff --git a/src/Mod/Part/Gui/ViewProvider.cpp b/src/Mod/Part/Gui/ViewProvider.cpp index b540442ab..421571ad5 100644 --- a/src/Mod/Part/Gui/ViewProvider.cpp +++ b/src/Mod/Part/Gui/ViewProvider.cpp @@ -422,6 +422,7 @@ bool ViewProviderPartBase::loadParameter() ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/Mod/Part"); float deviation = hGrp->GetFloat("MeshDeviation",0.2); + float angularDeflection = hGrp->GetFloat("MeshAngularDeflection",28.65); bool novertexnormals = hGrp->GetBool("NoPerVertexNormals",false); bool qualitynormals = hGrp->GetBool("QualityNormals",false); @@ -429,6 +430,9 @@ bool ViewProviderPartBase::loadParameter() this->meshDeviation = deviation; changed = true; } + if (this->angularDeflection != angularDeflection) { + this->angularDeflection = angularDeflection; + } if (this->noPerVertexNormals != novertexnormals) { this->noPerVertexNormals = novertexnormals; changed = true; @@ -472,8 +476,14 @@ void ViewProviderPartBase::updateData(const App::Property* prop) bounds.Get(xMin, yMin, zMin, xMax, yMax, zMax); Standard_Real deflection = ((xMax-xMin)+(yMax-yMin)+(zMax-zMin))/300.0 * this->meshDeviation; + Standard_Real AngDeflectionRads = this-> angularDeflection / 180.0 * M_PI; +#if OCC_VERSION_HEX >= 0x060600 + BRepMesh_IncrementalMesh(cShape,deflection,Standard_False, + AngDeflectionRads,Standard_True); +#else BRepMesh_IncrementalMesh(cShape,deflection); +#endif //BRepMesh_IncrementalMesh MESH(cShape,meshDeviation); // We must reset the location here because the transformation data // are set in the placement property diff --git a/src/Mod/Part/Gui/ViewProvider.h b/src/Mod/Part/Gui/ViewProvider.h index 56e2389fb..ad3db83fe 100644 --- a/src/Mod/Part/Gui/ViewProvider.h +++ b/src/Mod/Part/Gui/ViewProvider.h @@ -124,6 +124,7 @@ protected: private: // settings stuff float meshDeviation; + float angularDeflection; bool noPerVertexNormals; bool qualityNormals; static App::PropertyFloatConstraint::Constraints floatRange; diff --git a/src/Mod/Part/Gui/ViewProviderExt.cpp b/src/Mod/Part/Gui/ViewProviderExt.cpp index 02ad4c645..3cc46fcd1 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.cpp +++ b/src/Mod/Part/Gui/ViewProviderExt.cpp @@ -220,6 +220,7 @@ void GetNormals(const TopoDS_Face& theFace, App::PropertyFloatConstraint::Constraints ViewProviderPartExt::sizeRange = {1.0,64.0,1.0}; App::PropertyFloatConstraint::Constraints ViewProviderPartExt::tessRange = {0.0001,100.0,0.01}; +App::PropertyQuantityConstraint::Constraints ViewProviderPartExt::angDeflectionRange = {0.0,180.0,0.05}; const char* ViewProviderPartExt::LightingEnums[]= {"One side","Two side",NULL}; const char* ViewProviderPartExt::DrawStyleEnums[]= {"Solid","Dashed","Dotted","Dashdot",NULL}; @@ -250,6 +251,8 @@ ViewProviderPartExt::ViewProviderPartExt() ADD_PROPERTY(PointSize,(lwidth)); ADD_PROPERTY(Deviation,(0.5f)); Deviation.setConstraints(&tessRange); + ADD_PROPERTY(AngularDeflection,(28.65)); + AngularDeflection.setConstraints(&angDeflectionRange); ADD_PROPERTY(Lighting,(1)); Lighting.setEnums(LightingEnums); ADD_PROPERTY(DrawStyle,((long int)0)); @@ -321,6 +324,9 @@ void ViewProviderPartExt::onChanged(const App::Property* prop) if (prop == &Deviation) { VisualTouched = true; } + if (prop == &AngularDeflection) { + VisualTouched = true; + } if (prop == &LineWidth) { pcLineStyle->lineWidth = LineWidth.getValue(); } @@ -632,6 +638,7 @@ bool ViewProviderPartExt::loadParameter() ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/Mod/Part"); float deviation = hGrp->GetFloat("MeshDeviation",0.2); + float angularDeflection = hGrp->GetFloat("MeshAngularDeflection",28.65); bool novertexnormals = hGrp->GetBool("NoPerVertexNormals",false); bool qualitynormals = hGrp->GetBool("QualityNormals",false); @@ -639,6 +646,9 @@ bool ViewProviderPartExt::loadParameter() Deviation.setValue(deviation); changed = true; } + if (AngularDeflection.getValue() != angularDeflection ) { + AngularDeflection.setValue(angularDeflection); + } if (this->noPerVertexNormals != novertexnormals) { this->noPerVertexNormals = novertexnormals; changed = true; @@ -752,12 +762,14 @@ void ViewProviderPartExt::updateVisual(const TopoDS_Shape& inputShape) bounds.Get(xMin, yMin, zMin, xMax, yMax, zMax); Standard_Real deflection = ((xMax-xMin)+(yMax-yMin)+(zMax-zMin))/300.0 * Deviation.getValue(); + Standard_Real AngDeflectionRads = AngularDeflection.getValue() / 180.0 * M_PI; // create or use the mesh on the data structure #if OCC_VERSION_HEX >= 0x060600 - BRepMesh_IncrementalMesh myMesh(cShape,deflection,Standard_False,0.5,Standard_True); + BRepMesh_IncrementalMesh(cShape,deflection,Standard_False, + AngDeflectionRads,Standard_True); #else - BRepMesh_IncrementalMesh myMesh(cShape,deflection); + BRepMesh_IncrementalMesh(cShape,deflection); #endif // We must reset the location here because the transformation data // are set in the placement property diff --git a/src/Mod/Part/Gui/ViewProviderExt.h b/src/Mod/Part/Gui/ViewProviderExt.h index c9e2fd00b..2167c252e 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.h +++ b/src/Mod/Part/Gui/ViewProviderExt.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -71,6 +72,7 @@ public: App::PropertyFloatConstraint LineWidth; App::PropertyFloatConstraint PointSize; App::PropertyFloatConstraint Deviation; + App::PropertyAngle AngularDeflection; App::PropertyColor LineColor; App::PropertyColor PointColor; App::PropertyMaterial LineMaterial; @@ -143,6 +145,7 @@ private: bool qualityNormals; static App::PropertyFloatConstraint::Constraints sizeRange; static App::PropertyFloatConstraint::Constraints tessRange; + static App::PropertyQuantityConstraint::Constraints angDeflectionRange; static const char* LightingEnums[]; static const char* DrawStyleEnums[]; }; diff --git a/src/Mod/PartDesign/Gui/ViewProviderTransformed.cpp b/src/Mod/PartDesign/Gui/ViewProviderTransformed.cpp index 1e2ac6c12..473f7ea64 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderTransformed.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderTransformed.cpp @@ -247,9 +247,15 @@ void ViewProviderTransformed::recomputeFeature(void) bounds.Get(xMin, yMin, zMin, xMax, yMax, zMax); } Standard_Real deflection = ((xMax-xMin)+(yMax-yMin)+(zMax-zMin))/300.0 * Deviation.getValue(); + Standard_Real AngDeflectionRads = AngularDeflection.getValue() / 180.0 * M_PI; // create or use the mesh on the data structure - BRepMesh_IncrementalMesh myMesh(cShape,deflection); +#if OCC_VERSION_HEX >= 0x060600 + BRepMesh_IncrementalMesh(cShape,deflection,Standard_False, + AngDeflectionRads,Standard_True); +#else + BRepMesh_IncrementalMesh(cShape,deflection); +#endif // We must reset the location here because the transformation data // are set in the placement property TopLoc_Location aLoc;