From 04c0ae5f6d7372e07cc1264036ae5a87116a1c45 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 28 Jul 2016 15:05:55 +0300 Subject: [PATCH] Issue #1660 Ability to change the deflection coefficient --- src/GeomAPI/GeomAPI_AISObject.cpp | 13 +++++--- src/ModelAPI/ModelAPI_ResultBody.h | 6 ++++ src/ModelAPI/ModelAPI_ResultConstruction.h | 6 ++++ src/ModuleBase/ModuleBase_ResultPrs.cpp | 2 +- src/ModuleBase/ModuleBase_Tools.cpp | 25 ++++++++++---- src/ModuleBase/ModuleBase_Tools.h | 6 ++-- src/PartSet/PartSet_ResultSketchPrs.cpp | 10 ++++-- src/XGUI/XGUI_CustomPrs.cpp | 38 ++++++++++++++++++++-- src/XGUI/XGUI_Displayer.cpp | 6 ++-- src/XGUI/XGUI_Workshop.cpp | 7 ++-- 10 files changed, 94 insertions(+), 25 deletions(-) diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 74c1e1344..8510cdca3 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -379,13 +379,16 @@ bool GeomAPI_AISObject::setDeflection(const double theDeflection) bool isModified = false; Handle(AIS_InteractiveObject) anAIS = impl(); if (!anAIS.IsNull()) { - Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes(); - if (fabs(aDrawer->DeviationCoefficient() - theDeflection) > Precision::Confusion()) { - aDrawer->SetDeviationCoefficient(theDeflection); - isModified = true; + Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS); + if (!anAISShape.IsNull()) { + Standard_Real aCoefficient, aPreviousCoefficient; + anAISShape->OwnDeviationCoefficient(aCoefficient, aPreviousCoefficient); + if (fabs(aCoefficient-theDeflection) > Precision::Confusion()) { + isModified = true; + anAISShape->SetOwnDeviationCoefficient(theDeflection); + } } } - return isModified; } diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index 119978c6f..6847000c4 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -44,6 +44,12 @@ public: return RESULT_BODY_COLOR; } + /// default deflection for a result body + inline static const std::string DEFAULT_DEFLECTION() + { + return "0.001"; + } + /// Iternal enumeration for storage the information of connected topology flag enum ConnectedTopologyFlag { ConnectionNotComputed, ///< not yet computed diff --git a/src/ModelAPI/ModelAPI_ResultConstruction.h b/src/ModelAPI/ModelAPI_ResultConstruction.h index 41d74975c..4704bc43b 100644 --- a/src/ModelAPI/ModelAPI_ResultConstruction.h +++ b/src/ModelAPI/ModelAPI_ResultConstruction.h @@ -40,6 +40,12 @@ class ModelAPI_ResultConstruction : public ModelAPI_Result return RESULT_CONSTRUCTION_COLOR; } + /// default deflection for a result construction + inline static const std::string DEFAULT_DEFLECTION() + { + return "0.0001"; + } + /// Sets the result virtual void setShape(std::shared_ptr theShape) = 0; diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index 09c65829a..49e1dc691 100755 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -81,7 +81,7 @@ void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t Set(myOriginalShape); } // change deviation coefficient to provide more precise circle - ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes()); + //ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes()); AIS_Shape::Compute(thePresentationManager, thePresentation, theMode); if (!aReadyToDisplay) { diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 305d2dfd1..6ca02d6ac 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -582,7 +582,7 @@ void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFe } } -bool setDefaultDeviationCoefficient(std::shared_ptr theGeomShape) +/*bool setDefaultDeviationCoefficient(std::shared_ptr theGeomShape) { if (!theGeomShape.get()) return false; @@ -591,9 +591,9 @@ bool setDefaultDeviationCoefficient(std::shared_ptr theGeomShape) GeomAPI_ShapeExplorer anExp(theGeomShape, GeomAPI_Shape::FACE); bool anEmpty = anExp.empty(); return !anExp.more(); -} +}*/ -void setDefaultDeviationCoefficient(const std::shared_ptr& theResult, +/*void setDefaultDeviationCoefficient(const std::shared_ptr& theResult, const Handle(Prs3d_Drawer)& theDrawer) { if (!theResult.get()) @@ -611,7 +611,7 @@ void setDefaultDeviationCoefficient(const std::shared_ptr& theR if (aUseDeviation) theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT); } - +*/ void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape, const Handle(Prs3d_Drawer)& theDrawer) { @@ -620,8 +620,21 @@ void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape, std::shared_ptr aGeomShape(new GeomAPI_Shape()); aGeomShape->setImpl(new TopoDS_Shape(theShape)); - if (setDefaultDeviationCoefficient(aGeomShape)) - theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT); + + // if the shape could not be exploded on faces, it contains only wires, edges, and vertices + // correction of deviation for them should not influence to the application performance + GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE); + bool isConstruction = !anExp.more(); + + double aDeflection; + if (isConstruction) + aDeflection = Config_PropManager::real("Visualization", "construction_deflection", + ModelAPI_ResultConstruction::DEFAULT_DEFLECTION()); + else + aDeflection = Config_PropManager::real("Visualization", "body_deflection", + ModelAPI_ResultBody::DEFAULT_DEFLECTION()); + + theDrawer->SetDeviationCoefficient(aDeflection); } Quantity_Color color(const std::string& theSection, diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 244afca4c..3e250f5c3 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -164,9 +164,9 @@ MODULEBASE_EXPORT void checkObjects(const QObjectPtrList& theObjects, bool& hasR /// It provides 1.e-4 for results of construction type /// \param theResult a result object to define the deviation coeffient /// \param theDrawer a drawer -MODULEBASE_EXPORT void setDefaultDeviationCoefficient( - const std::shared_ptr& theResult, - const Handle(Prs3d_Drawer)& theDrawer); +//MODULEBASE_EXPORT void setDefaultDeviationCoefficient( +// const std::shared_ptr& theResult, +// const Handle(Prs3d_Drawer)& theDrawer); /// Sets the default coeffient into the driver calculated accordingly the shape type. /// It provides 1.e-4 for a shape withe Edge shape type diff --git a/src/PartSet/PartSet_ResultSketchPrs.cpp b/src/PartSet/PartSet_ResultSketchPrs.cpp index ccf60f8ae..dba8a45ac 100755 --- a/src/PartSet/PartSet_ResultSketchPrs.cpp +++ b/src/PartSet/PartSet_ResultSketchPrs.cpp @@ -91,7 +91,7 @@ void PartSet_ResultSketchPrs::Compute(const Handle(PrsMgr_PresentationManager3d) setAuxiliaryPresentationStyle(false); // change deviation coefficient to provide more precise circle - ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes()); + //ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes()); AIS_Shape::Compute(thePresentationManager, thePresentation, theMode); if (!myAuxiliaryCompound.IsNull()) { @@ -136,6 +136,7 @@ void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection) return; bool aShapeIsChanged = false; + double aPrevDeviation = Attributes()->DeviationCoefficient(); if (aMode == SketcherPrs_Tools::Sel_Sketch_Face || aMode == SketcherPrs_Tools::Sel_Sketch_Wire) { aMode = (aMode == SketcherPrs_Tools::Sel_Sketch_Face) ? AIS_Shape::SelectionMode(TopAbs_FACE) @@ -163,6 +164,9 @@ void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection) debugInfo(aComp, TopAbs_FACE); // 2 #endif Set(aComp); + double aBodyDefDeflection = Config_PropManager::real("Visualization", "body_deflection", + ModelAPI_ResultBody::DEFAULT_DEFLECTION()); + Attributes()->SetDeviationCoefficient(aBodyDefDeflection); aShapeIsChanged = true; } else @@ -178,8 +182,10 @@ void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection) AIS_Shape::ComputeSelection(aSelection, aMode); - if (aShapeIsChanged) + if (aShapeIsChanged) { + Attributes()->SetDeviationCoefficient(aPrevDeviation); Set(myOriginalShape); + } } void PartSet_ResultSketchPrs::appendShapeSelection(const Handle(SelectMgr_Selection)& theSelection, diff --git a/src/XGUI/XGUI_CustomPrs.cpp b/src/XGUI/XGUI_CustomPrs.cpp index 373eb2fe6..fc9b7fb08 100644 --- a/src/XGUI/XGUI_CustomPrs.cpp +++ b/src/XGUI/XGUI_CustomPrs.cpp @@ -13,6 +13,11 @@ #include #include #include +#include +#include + +#include + #include #include @@ -27,8 +32,11 @@ double getDeflection(const ResultPtr& theResult) if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::DEFLECTION_ID()).get() != NULL) { AttributeDoublePtr aDoubleAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID()); - if (aDoubleAttr.get() && aDoubleAttr->isInitialized()) - aDeflection = aDoubleAttr->value(); + if (aDoubleAttr.get() && aDoubleAttr->isInitialized()) { + double aValue = aDoubleAttr->value(); + if (aValue > 0) /// zero value should not be used as a deflection(previous studies) + aDeflection = aDoubleAttr->value(); + } } return aDeflection; } @@ -70,7 +78,31 @@ void XGUI_CustomPrs::getDefaultColor(ObjectPtr theObject, const bool isEmptyColo double XGUI_CustomPrs::getDefaultDeflection(const ObjectPtr& theObject) { - return Config_PropManager::real("Visualization", "result_deflection", "0.001"); + double aDeflection = -1; + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) { + bool isConstruction = false; + + std::string aResultGroup = aResult->groupName(); + if (aResultGroup == ModelAPI_ResultConstruction::group()) + isConstruction = true; + else if (aResultGroup == ModelAPI_ResultBody::group()) { + GeomShapePtr aGeomShape = aResult->shape(); + if (aGeomShape.get()) { + // if the shape could not be exploded on faces, it contains only wires, edges, and vertices + // correction of deviation for them should not influence to the application performance + GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE); + isConstruction = !anExp.more(); + } + } + if (isConstruction) + aDeflection = Config_PropManager::real("Visualization", "construction_deflection", + ModelAPI_ResultConstruction::DEFAULT_DEFLECTION()); + else + aDeflection = Config_PropManager::real("Visualization", "body_deflection", + ModelAPI_ResultBody::DEFAULT_DEFLECTION()); + } + return aDeflection; } XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop) diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 87dfcee80..24e7b9eb6 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -154,15 +154,15 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer) anAIS = aPrs->getAISObject(anAIS); if (anAIS.get()) { // correct deviation coefficient for - Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl(); + /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl(); if (!anAISPrs.IsNull()) { Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs); if (!aShapePrs.IsNull()) { TopoDS_Shape aShape = aShapePrs->Shape(); if (!aShape.IsNull()) - ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes()); + //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes()); } - } + }*/ } } else { ResultPtr aResult = std::dynamic_pointer_cast(theObject); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 6fe42a610..800e59028 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -208,8 +208,11 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) Config_PropManager::registerProp("Visualization", "result_part_color", "Part color", Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR()); - Config_PropManager::registerProp("Visualization", "result_deflection", "Result deflection", - Config_Prop::Double, "0.001"); + Config_PropManager::registerProp("Visualization", "body_deflection", "Body deflection coefficient", + Config_Prop::Double, ModelAPI_ResultBody::DEFAULT_DEFLECTION());//"0.001"); + + Config_PropManager::registerProp("Visualization", "construction_deflection", "Construction deflection coefficient", + Config_Prop::Double, ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());//"0.0001"); if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true)) myViewerSelMode.append(TopAbs_FACE); -- 2.30.2