From: azv Date: Thu, 21 Sep 2017 07:06:06 +0000 (+0300) Subject: Merge remote-tracking branch 'remotes/origin/master' into Dev_2.8.0 X-Git-Tag: V_2.9.0~23^2~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b3695c3af5289903f1c0fa01bbb7c40203c5e544;p=modules%2Fshaper.git Merge remote-tracking branch 'remotes/origin/master' into Dev_2.8.0 # Conflicts: # CMakeCommon/FindTInspector.cmake # env.sh # src/GeomAPI/GeomAPI_Edge.cpp # src/Model/Model_AttributeSelection.cpp # src/ModelAPI/ModelAPI_Events.cpp # src/PythonAPI/model/sketcher/tools.py # src/SketchAPI/SketchAPI_Sketch.cpp # src/SketchPlugin/CMakeLists.txt # src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp # src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.h # src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.cpp # src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.h # src/SketchPlugin/SketchPlugin_Ellipse.cpp # src/SketchPlugin/SketchPlugin_Ellipse.h # src/SketchPlugin/SketchPlugin_MacroEllipse.h # src/SketchSolver/SketchSolver_ConstraintDistance.cpp # src/SketchSolver/SketchSolver_ConstraintMovement.cpp # src/SketchSolver/SketchSolver_Manager.cpp # src/XGUI/XGUI_Workshop.cpp --- b3695c3af5289903f1c0fa01bbb7c40203c5e544 diff --cc src/GeomAPI/GeomAPI_Edge.h index 59b36c042,f4fd1add6..ce0f7b559 --- a/src/GeomAPI/GeomAPI_Edge.h +++ b/src/GeomAPI/GeomAPI_Edge.h @@@ -96,10 -87,15 +96,18 @@@ public /// Returns edge length. GEOMAPI_EXPORT double length() const; + + /// Returns true if the edge is closed (like full circle) + GEOMAPI_EXPORT + bool isClosed() const; + + /// Returns true if the edge is degenerated (has no 3D curve) + GEOMAPI_EXPORT + bool isDegenerated() const; }; +//! Pointer on attribute object +typedef std::shared_ptr GeomEdgePtr; + #endif diff --cc src/Model/Model_AttributeSelection.cpp index 63614449c,f26270a9f..15d910ede --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@@ -760,68 -633,47 +758,68 @@@ void Model_AttributeSelection::selectSu { if(theSubShapeName.empty() || theType.empty()) return; - // check this is Part-name: 2 delimiters in the name - std::size_t aPartEnd = theSubShapeName.find('/'); - if (aPartEnd != std::string::npos && aPartEnd != theSubShapeName.rfind('/')) { - std::string aPartName = theSubShapeName.substr(0, aPartEnd); - ObjectPtr aFound = owner()->document()->objectByName(ModelAPI_ResultPart::group(), aPartName); - if (aFound.get()) { // found such part, so asking it for the name - ResultPartPtr aPart = std::dynamic_pointer_cast(aFound); - std::string aNameInPart = theSubShapeName.substr(aPartEnd + 1); - int anIndex; - std::shared_ptr aSelected = aPart->shapeInPart(aNameInPart, theType, anIndex); - if (aSelected.get()) { - setValue(aPart, aSelected); - TDataStd_Integer::Set(selectionLabel(), anIndex); - return; + std::string aSubShapeName = theSubShapeName; + CenterType aCenterType = theType[0] == 'v' || theType[0] == 'V' ? // only for vertex-type + centerTypeByName(aSubShapeName) : NOT_CENTER; + std::string aType = aCenterType == NOT_CENTER ? theType : "EDGE"; // search for edge now + + // first iteration is selection by name without center prefix, second - in case of problem, + // try with initial name + for(int aUseCenter = 1; aUseCenter >= 0; aUseCenter--) { + if (aUseCenter == 0 && aCenterType != NOT_CENTER) { + aSubShapeName = theSubShapeName; + aCenterType = NOT_CENTER; + aType = theType; + } else if (aUseCenter != 1) continue; + + // check this is Part-name: 2 delimiters in the name + std::size_t aPartEnd = aSubShapeName.find('/'); + if (aPartEnd != std::string::npos && aPartEnd != aSubShapeName.rfind('/')) { + std::string aPartName = aSubShapeName.substr(0, aPartEnd); + ObjectPtr aFound = owner()->document()->objectByName(ModelAPI_ResultPart::group(), aPartName); + if (aFound.get()) { // found such part, so asking it for the name + ResultPartPtr aPart = std::dynamic_pointer_cast(aFound); + std::string aNameInPart = aSubShapeName.substr(aPartEnd + 1); + int anIndex; + std::shared_ptr aSelected = aPart->shapeInPart(aNameInPart, aType, anIndex); + if (aSelected.get()) { + if (aCenterType != NOT_CENTER) { + if (!aSelected->isEdge()) + continue; + std::shared_ptr aSelectedEdge(new GeomAPI_Edge(aSelected)); + setValueCenter(aPart, aSelectedEdge, aCenterType); + } else + setValue(aPart, aSelected); + TDataStd_Integer::Set(selectionLabel(), anIndex); + return; + } } } - } - Model_SelectionNaming aSelNaming(selectionLabel()); - std::shared_ptr aDoc = - std::dynamic_pointer_cast(owner()->document()); - std::shared_ptr aShapeToBeSelected; - ResultPtr aCont; - if (aSelNaming.selectSubShape(theType, theSubShapeName, aDoc, aShapeToBeSelected, aCont)) { - // try to find the last context to find the up to date shape - if (aCont->shape().get() && !aCont->shape()->isNull() && - aCont->groupName() == ModelAPI_ResultBody::group() && aDoc == owner()->document()) { - const TopoDS_Shape aConShape = aCont->shape()->impl(); - if (!aConShape.IsNull()) { - Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aConShape, selectionLabel()); - if (!aNS.IsNull()) { - aNS = TNaming_Tool::CurrentNamedShape(aNS); + Model_SelectionNaming aSelNaming(selectionLabel()); + std::shared_ptr aDoc = + std::dynamic_pointer_cast(owner()->document()); + std::shared_ptr aShapeToBeSelected; + ResultPtr aCont; + if (aSelNaming.selectSubShape(aType, aSubShapeName, aDoc, aShapeToBeSelected, aCont)) { + // try to find the last context to find the up to date shape + if (aCont->shape().get() && !aCont->shape()->isNull() && + aCont->groupName() == ModelAPI_ResultBody::group() && aDoc == owner()->document()) { + const TopoDS_Shape aConShape = aCont->shape()->impl(); + if (!aConShape.IsNull()) { + Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aConShape, selectionLabel()); - if (!aNS.IsNull()) { + if (!aNS.IsNull() && scope().Contains(aNS->Label())) { // scope check is for 2228 - TDF_Label aLab = aNS->Label(); - while(aLab.Depth() != 7 && aLab.Depth() > 5) - aLab = aLab.Father(); - ObjectPtr anObj = aDoc->objects()->object(aLab); - if (anObj.get()) { - ResultPtr aRes = std::dynamic_pointer_cast(anObj); - if (aRes) - aCont = aRes; + aNS = TNaming_Tool::CurrentNamedShape(aNS); + if (!aNS.IsNull()) { + TDF_Label aLab = aNS->Label(); + while(aLab.Depth() != 7 && aLab.Depth() > 5) + aLab = aLab.Father(); + ObjectPtr anObj = aDoc->objects()->object(aLab); + if (anObj.get()) { + ResultPtr aRes = std::dynamic_pointer_cast(anObj); + if (aRes) + aCont = aRes; + } } } } diff --cc src/PythonAPI/model/sketcher/tools.py index f3dcdb37a,de3032f54..5c1903a06 --- a/src/PythonAPI/model/sketcher/tools.py +++ b/src/PythonAPI/model/sketcher/tools.py @@@ -71,24 -69,14 +69,28 @@@ def dof(sketch) return int(filter(str.isdigit, aSketch.string("SolverDOF").value())) def distancePointPoint(thePoint1, thePoint2): - aPnt1 = toList(thePoint1) - aPnt2 = toList(thePoint2) - return math.hypot(aPnt1[0] - aPnt2[0], aPnt1[1] - aPnt2[1]) + aGeomPnt1 = thePoint1 + aGeomPnt2 = thePoint2 + if issubclass(type(thePoint1), GeomDataAPI.GeomDataAPI_Point2D): + aGeomPnt1 = thePoint1.pnt() + if issubclass(type(thePoint2), GeomDataAPI.GeomDataAPI_Point2D): + aGeomPnt2 = thePoint2.pnt() + return aGeomPnt1.distance(aGeomPnt2) +def signedDistancePointLine(thePoint, theLine): + aPoint = toList(thePoint) + aLine = toSketchFeature(theLine) + + aLineStart = geomDataAPI_Point2D(aLine.attribute("StartPoint")).pnt().xy() + aLineEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint")).pnt().xy() + aLineDir = aLineEnd.decreased(aLineStart) + aLineLen = aLineEnd.distance(aLineStart) + aCross = (aPoint[0] - aLineStart.x()) * aLineDir.y() - (aPoint[1] - aLineStart.y()) * aLineDir.x() + return aCross / aLineLen + +def distancePointLine(thePoint, theLine): + return math.fabs(signedDistancePointLine(thePoint, theLine)) + def lastSubFeature(theSketch, theKind): """ obtains last feature of given kind from the sketch diff --cc src/SketchPlugin/CMakeLists.txt index e5b9bc0ca,ba06dbe55..7c89b5e5c --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@@ -31,9 -31,8 +31,10 @@@ SET(PROJECT_HEADER SketchPlugin_ConstraintCoincidence.h SketchPlugin_ConstraintCollinear.h SketchPlugin_ConstraintDistance.h + SketchPlugin_ConstraintDistanceHorizontal.h + SketchPlugin_ConstraintDistanceVertical.h SketchPlugin_ConstraintEqual.h + SketchPlugin_Fillet.h SketchPlugin_ConstraintHorizontal.h SketchPlugin_ConstraintLength.h SketchPlugin_ConstraintMiddle.h @@@ -44,10 -43,8 +45,9 @@@ SketchPlugin_ConstraintRigid.h SketchPlugin_ConstraintTangent.h SketchPlugin_ConstraintVertical.h + SketchPlugin_Ellipse.h SketchPlugin_ExternalValidator.h SketchPlugin_Feature.h - SketchPlugin_Fillet.h SketchPlugin_IntersectionPoint.h SketchPlugin_Line.h SketchPlugin_MacroArc.h @@@ -76,9 -72,8 +76,10 @@@ SET(PROJECT_SOURCE SketchPlugin_ConstraintCoincidence.cpp SketchPlugin_ConstraintCollinear.cpp SketchPlugin_ConstraintDistance.cpp + SketchPlugin_ConstraintDistanceHorizontal.cpp + SketchPlugin_ConstraintDistanceVertical.cpp SketchPlugin_ConstraintEqual.cpp + SketchPlugin_Fillet.cpp SketchPlugin_ConstraintHorizontal.cpp SketchPlugin_ConstraintLength.cpp SketchPlugin_ConstraintMiddle.cpp @@@ -89,10 -84,8 +90,9 @@@ SketchPlugin_ConstraintRigid.cpp SketchPlugin_ConstraintTangent.cpp SketchPlugin_ConstraintVertical.cpp + SketchPlugin_Ellipse.cpp SketchPlugin_ExternalValidator.cpp SketchPlugin_Feature.cpp - SketchPlugin_Fillet.cpp SketchPlugin_IntersectionPoint.cpp SketchPlugin_Line.cpp SketchPlugin_MacroArc.cpp @@@ -212,21 -199,6 +212,23 @@@ ADD_UNIT_TESTS(TestSketchPointLine.p TestTrimCircleAndArc01.py TestTrimLine01.py TestTrimLine02.py + Test2229.py + Test2239.py + TestDistanceSignedVsUnsigned01.py + TestDistanceSignedVsUnsigned02.py + TestDistanceSignedVsUnsigned03.py + TestDistanceSignedVsUnsigned04.py + TestDistanceSignedVsUnsigned05.py + TestSignedDistancePointPoint.py + TestSignedDistancePointLine.py ) + +if(${SKETCHER_CHANGE_RADIUS_WHEN_MOVE}) + ADD_UNIT_TESTS( + TestMovePoint.py + TestMoveLine.py + TestMoveCircle.py + TestMoveArc.py + TestMovementComplex.py + ) +endif() diff --cc src/SketchSolver/SketchSolver_Manager.cpp index 506c8e46d,70161208f..4921a4d03 --- a/src/SketchSolver/SketchSolver_Manager.cpp +++ b/src/SketchSolver/SketchSolver_Manager.cpp @@@ -189,10 -196,11 +196,11 @@@ void SketchSolver_Manager::processEvent } // ============================================================================ -// Function: changeConstraintOrEntity +// Function: updateFeature - // Purpose: create/update constraint or feature in appropriate group + // Purpose: create/update the constraint or the feature and place it into appropriate group // ============================================================================ - bool SketchSolver_Manager::updateFeature(const std::shared_ptr& theFeature) + bool SketchSolver_Manager::updateFeature(std::shared_ptr theFeature, + bool theMoved) { // Check feature validity and find a group to place it. // If the feature is not valid, the returned group will be empty. diff --cc src/SketchSolver/SketchSolver_Manager.h index 105cc0e97,45c1a4284..d3509c707 --- a/src/SketchSolver/SketchSolver_Manager.h +++ b/src/SketchSolver/SketchSolver_Manager.h @@@ -64,30 -61,11 +64,31 @@@ protected /** \brief Adds or updates a constraint or an entity in the suitable group * \param[in] theFeature sketch feature to be changed + * \param[in] theMoved \c true if the feature has been moved in the viewer * \return \c true if the feature changed successfully */ - bool updateFeature(const std::shared_ptr& theFeature); + bool updateFeature(std::shared_ptr theFeature, bool theMoved = false); + /** \brief Move feature + * \param[in] theMovedFeature dragged sketch feature + * \param[in] theFromPoint original position of the feature + * \param[in] theToPoint prefereble position of the feature (current position of the mouse) + * \return \c true if the feature has been changed successfully + */ + bool moveFeature(const std::shared_ptr& theMovedFeature, + const std::shared_ptr& theFromPoint, + const std::shared_ptr& theToPoint); + + /** \brief Move feature using its moved attribute + * \param[in] theMovedAttribute dragged point attribute of sketch feature + * \param[in] theFromPoint original position of the moved point + * \param[in] theToPoint prefereble position (current position of the mouse) + * \return \c true if the attribute owner has been changed successfully + */ + bool moveAttribute(const std::shared_ptr& theMovedAttribute, + const std::shared_ptr& theFromPoint, + const std::shared_ptr& theToPoint); + /** \brief Removes a constraint from the manager * \param[in] theConstraint constraint to be removed * \return \c true if the constraint removed successfully