From: lucasjerome Date: Fri, 2 Apr 2021 09:15:12 +0000 (+0200) Subject: Add angular precision for V and H contraints in degrees (4°) X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FCEA_2020%2FLot3_Polyline;p=modules%2Fshaper.git Add angular precision for V and H contraints in degrees (4°) --- diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index 69e900fdc..9411724c8 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -61,7 +61,7 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin() Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_thickness", "Thickness", Config_Prop::IntSpin, SKETCH_WIDTH); Config_PropManager::registerProp(SKETCH_TAB_NAME, "angular_tolerance", "Angular tolerance", - Config_Prop::DblSpin, "0.04"); + Config_Prop::DblSpin, "4.0"); Config_PropManager::registerProp(SKETCH_TAB_NAME, "spline_weight", "Default spline weight", Config_Prop::DblSpin, "1.0"); Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane", diff --git a/src/PartSet/PartSet_SketcherReentrantMgr.cpp b/src/PartSet/PartSet_SketcherReentrantMgr.cpp index 90dee037a..0269ca821 100644 --- a/src/PartSet/PartSet_SketcherReentrantMgr.cpp +++ b/src/PartSet/PartSet_SketcherReentrantMgr.cpp @@ -867,7 +867,7 @@ void PartSet_SketcherReentrantMgr::addConstraints(const FeaturePtr& theFeature) if (aVertAngle > M_PI/2.) aVertAngle = M_PI - aVertAngle; - double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance"); + double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance")* M_PI/180.0; CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch(); FeaturePtr aFeature; if (aHorAngle < aTolerance) { diff --git a/src/SketchPlugin/SketchPlugin_Polyline.cpp b/src/SketchPlugin/SketchPlugin_Polyline.cpp index a8fd95c38..176eb29ea 100644 --- a/src/SketchPlugin/SketchPlugin_Polyline.cpp +++ b/src/SketchPlugin/SketchPlugin_Polyline.cpp @@ -40,6 +40,9 @@ #include #include +#include "GeomAPI_Lin2d.h" +#include "GeomAPI_Dir2d.h" + #include SketchPlugin_Polyline::SketchPlugin_Polyline() @@ -72,28 +75,29 @@ void SketchPlugin_Polyline::createLineFeature() if (aPointsArray->isInitialized() && aPointsArray->size() > 1) { + static GeomDir2dPtr myHorDir(new GeomAPI_Dir2d(1, 0)); + static GeomDir2dPtr myVertDir(new GeomAPI_Dir2d(0, 1)); + FeaturePtr aLastline; FeaturePtr aFirstline; // collect points for (int anIndex = 1; anIndex < aPointsArray->size(); ++anIndex) { - FeaturePtr aLine = sketch()->addFeature(SketchPlugin_Line::ID()); + FeaturePtr aLineFtr = sketch()->addFeature(SketchPlugin_Line::ID()); if (anIndex ==1) { - aFirstline = aLine; + aFirstline = aLineFtr; } - std::shared_ptr aStartA = - std::dynamic_pointer_cast( - aLine->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aStartA = std::dynamic_pointer_cast( + aLineFtr->attribute(SketchPlugin_Line::START_ID())); aStartA->setValue(aPointsArray->pnt(anIndex-1)); - std::shared_ptr aEndA = - std::dynamic_pointer_cast( - aLine->attribute(SketchPlugin_Line::END_ID())); + std::shared_ptr aEndA = std::dynamic_pointer_cast( + aLineFtr->attribute(SketchPlugin_Line::END_ID())); aEndA->setValue(aPointsArray->pnt(anIndex)); - aLine->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue( + aLineFtr->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue( boolean(AUXILIARY_ID())->value()); if (aLastline) { @@ -102,7 +106,7 @@ void SketchPlugin_Polyline::createLineFeature() std::shared_ptr aSPoint = std::dynamic_pointer_cast( aSFData->attribute(SketchPlugin_Line::END_ID())); - std::shared_ptr aNFData = aLine->data(); + std::shared_ptr aNFData = aLineFtr->data(); std::shared_ptr aNPoint = std::dynamic_pointer_cast( aNFData->attribute(SketchPlugin_Line::START_ID())); @@ -110,16 +114,30 @@ void SketchPlugin_Polyline::createLineFeature() SketchPlugin_ConstraintCoincidence::createCoincidenceFeature(sketch(), aSPoint, aNPoint); } - aLine->execute(); - - if (fabs(aPointsArray->pnt(anIndex-1)->x() - aPointsArray->pnt(anIndex)->x()) < 1.0) { - SketchPlugin_ConstraintVertical::createVerticalFeature(sketch(),aLine->firstResult()); - } else if (fabs(aPointsArray->pnt(anIndex-1)->y() - aPointsArray->pnt(anIndex)->y()) < 1.0) { - SketchPlugin_ConstraintHorizontal::createHorizontalFeature(sketch(),aLine->firstResult()); + aLineFtr->execute(); + + GeomLine2dPtr aLine(new GeomAPI_Lin2d(aPointsArray->pnt(anIndex-1), + aPointsArray->pnt(anIndex))); + GeomDir2dPtr aDir = aLine->direction(); + double aHorAngle = fabs(myHorDir->angle(aDir)); + double aVertAngle = fabs(myVertDir->angle(aDir)); + if (aHorAngle > M_PI/2.) + aHorAngle = M_PI - aHorAngle; + if (aVertAngle > M_PI/2.) + aVertAngle = M_PI - aVertAngle; + double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, + "angular_tolerance") * M_PI/180.0; + + if (aHorAngle < aTolerance) { + SketchPlugin_ConstraintHorizontal::createHorizontalFeature(sketch(), + aLineFtr->firstResult()); + } else if (aVertAngle < aTolerance) { + SketchPlugin_ConstraintVertical::createVerticalFeature(sketch(), + aLineFtr->firstResult()); } - - aLastline = aLine; + aLastline = aLineFtr; } + // Initialize new line with first point equal to end of previous std::shared_ptr aSFData = aLastline->data(); std::shared_ptr aSPoint = std::dynamic_pointer_cast(