#include <TopoDS_Iterator.hxx>
#include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_ShapeExplorer.h>
#include <Events_Error.h>
#include <Config_PropManager.h>
#include <string>
const double tolerance = 1e-7;
+const double DEFAULT_DEVIATION_COEFFICIENT = 1.e-4;
//#define DEBUG_ACTIVATE_WINDOW
//#define DEBUG_SET_FOCUS
}
}
+bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
+{
+ if (!theGeomShape.get())
+ return false;
+ // 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(theGeomShape, GeomAPI_Shape::FACE);
+ bool anEmpty = anExp.empty();
+ return !anExp.more();
+}
+
void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theResult,
const Handle(Prs3d_Drawer)& theDrawer)
{
if (!theResult.get())
return;
-
- if (theResult->groupName() == ModelAPI_ResultConstruction::group())
- theDrawer->SetDeviationCoefficient(1.e-4);
+ bool aUseDeviation = false;
+
+ std::string aResultGroup = theResult->groupName();
+ if (aResultGroup == ModelAPI_ResultConstruction::group())
+ aUseDeviation = true;
+ else if (aResultGroup == ModelAPI_ResultBody::group()) {
+ GeomShapePtr aGeomShape = theResult->shape();
+ if (aGeomShape.get())
+ aUseDeviation = setDefaultDeviationCoefficient(aGeomShape);
+ }
+ if (aUseDeviation)
+ theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
}
void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
{
if (theShape.IsNull())
return;
- TopAbs_ShapeEnum aType = theShape.ShapeType();
- if ((aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
- theDrawer->SetDeviationCoefficient(1.e-4);
+
+ std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
+ aGeomShape->setImpl(new TopoDS_Shape(theShape));
+ if (setDefaultDeviationCoefficient(aGeomShape))
+ theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
}
Quantity_Color color(const std::string& theSection,
bool isShading = false;
if (aPrs.get() != NULL) {
anAIS = aPrs->getAISObject(anAIS);
+ if (anAIS.get()) {
+ // correct deviation coefficient for
+ Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
+ 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());
+ }
+ }
+ }
} else {
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (aResult.get() != NULL) {