From: azv Date: Fri, 23 Jun 2017 12:57:29 +0000 (+0300) Subject: Revert "Merge branch 'Pre_2.8.0_development'" X-Git-Tag: V_2.7.1.1~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5a67842979db286af5bb5015fe413d8b06c6587e;p=modules%2Fshaper.git Revert "Merge branch 'Pre_2.8.0_development'" This reverts commit bf64d76b7e6021149db8e0e38c2697a9a0c44f1b, reversing changes made to cacdfa1cd62583b9f40fe6a05e1b9e63f8fe2f03. # Conflicts: # src/SketchPlugin/plugin-Sketch.xml --- diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index 325e5055d..8e191e4fd 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -56,8 +56,6 @@ SET(PROJECT_HEADERS GeomAPI_Trsf.h GeomAPI_Angle2d.h GeomAPI_Wire.h - GeomAPI_Ellipse.h - GeomAPI_Ellipse2d.h ) SET(PROJECT_SOURCES @@ -92,8 +90,6 @@ SET(PROJECT_SOURCES GeomAPI_Trsf.cpp GeomAPI_Angle2d.cpp GeomAPI_Wire.cpp - GeomAPI_Ellipse.cpp - GeomAPI_Ellipse2d.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomAPI/GeomAPI_Ax2.h b/src/GeomAPI/GeomAPI_Ax2.h index 39cd19c3f..e7658e88e 100644 --- a/src/GeomAPI/GeomAPI_Ax2.h +++ b/src/GeomAPI/GeomAPI_Ax2.h @@ -70,7 +70,4 @@ public: std::shared_ptr dir() const; }; -//! Pointer on the object -typedef std::shared_ptr GeomAx2Ptr; - #endif diff --git a/src/GeomAPI/GeomAPI_Circ.h b/src/GeomAPI/GeomAPI_Circ.h index 6f4215965..218efd9ff 100644 --- a/src/GeomAPI/GeomAPI_Circ.h +++ b/src/GeomAPI/GeomAPI_Circ.h @@ -37,8 +37,7 @@ class GeomAPI_Circ : public GeomAPI_Interface { public: - /** \brief Constructs a circle of radius Radius, where theAx2 locates - * the circle and defines its orientation in 3D space such that:\n + /** \brief Constructs a circle of radius Radius, where theAx2 locates the circle and defines its orientation in 3D space such that:\n * - the center of the circle is the origin of theAx2;\n * - the origin, "X Direction" and "Y Direction" of theAx2 define the plane of the circle;\n * - theAx2 is the local coordinate system of the circle.\n @@ -78,8 +77,5 @@ class GeomAPI_Circ : public GeomAPI_Interface double& theParameter) const; }; -//! Pointer on the object -typedef std::shared_ptr GeomCirclePtr; - #endif diff --git a/src/GeomAPI/GeomAPI_Dir.h b/src/GeomAPI/GeomAPI_Dir.h index 7e2a0bda7..9462aabed 100644 --- a/src/GeomAPI/GeomAPI_Dir.h +++ b/src/GeomAPI/GeomAPI_Dir.h @@ -78,8 +78,5 @@ class GeomAPI_Dir : public GeomAPI_Interface }; -//! Pointer on the object -typedef std::shared_ptr GeomDirPtr; - #endif diff --git a/src/GeomAPI/GeomAPI_Edge.cpp b/src/GeomAPI/GeomAPI_Edge.cpp index 9927c2ae9..c336050f9 100644 --- a/src/GeomAPI/GeomAPI_Edge.cpp +++ b/src/GeomAPI/GeomAPI_Edge.cpp @@ -24,8 +24,6 @@ #include #include #include -#include -#include #include @@ -37,11 +35,9 @@ #include #include #include -#include #include #include #include -#include #include @@ -100,16 +96,6 @@ bool GeomAPI_Edge::isArc() const return false; } -bool GeomAPI_Edge::isEllipse() const -{ - const TopoDS_Shape& aShape = const_cast(this)->impl(); - double aFirst, aLast; - Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast); - if (aCurve->IsKind(STANDARD_TYPE(Geom_Ellipse))) - return true; - return false; -} - std::shared_ptr GeomAPI_Edge::firstPoint() { const TopoDS_Shape& aShape = const_cast(this)->impl(); @@ -130,14 +116,14 @@ std::shared_ptr GeomAPI_Edge::lastPoint() return std::shared_ptr(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z())); } -std::shared_ptr GeomAPI_Edge::circle() const +std::shared_ptr GeomAPI_Edge::circle() { const TopoDS_Shape& aShape = const_cast(this)->impl(); double aFirst, aLast; Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast); - if (!aCurve.IsNull()) { + if (aCurve) { Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve); - if (!aCirc.IsNull()) { + if (aCirc) { gp_Pnt aLoc = aCirc->Location(); std::shared_ptr aCenter(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z())); gp_Dir anAxis = aCirc->Axis().Direction(); @@ -148,24 +134,7 @@ std::shared_ptr GeomAPI_Edge::circle() const return std::shared_ptr(); // not circle } -std::shared_ptr GeomAPI_Edge::ellipse() const -{ - const TopoDS_Shape& aShape = const_cast(this)->impl(); - double aFirst, aLast; - Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast); - if (!aCurve.IsNull()) { - Handle(Geom_Ellipse) aElips = Handle(Geom_Ellipse)::DownCast(aCurve); - if (!aElips.IsNull()) { - gp_Elips aGpElips = aElips->Elips(); - std::shared_ptr aEllipse(new GeomAPI_Ellipse()); - aEllipse->setImpl(new gp_Elips(aGpElips)); - return aEllipse; - } - } - return std::shared_ptr(); // not elipse -} - -std::shared_ptr GeomAPI_Edge::line() const +std::shared_ptr GeomAPI_Edge::line() { const TopoDS_Shape& aShape = const_cast(this)->impl(); double aFirst, aLast; diff --git a/src/GeomAPI/GeomAPI_Edge.h b/src/GeomAPI/GeomAPI_Edge.h index 59b36c042..44c76df82 100644 --- a/src/GeomAPI/GeomAPI_Edge.h +++ b/src/GeomAPI/GeomAPI_Edge.h @@ -27,7 +27,6 @@ class GeomAPI_Pln; class GeomAPI_Pnt; class GeomAPI_Circ; class GeomAPI_Lin; -class GeomAPI_Ellipse; /**\class GeomAPI_Edge * \ingroup DataModel @@ -57,10 +56,6 @@ public: GEOMAPI_EXPORT bool isArc() const; - /// Verifies that the edge is an arc of circle - GEOMAPI_EXPORT - bool isEllipse() const; - /// Returns the first vertex coordinates of the edge GEOMAPI_EXPORT std::shared_ptr firstPoint(); @@ -71,15 +66,11 @@ public: /// Returns a circle if edge is based on the circle curve GEOMAPI_EXPORT - std::shared_ptr circle() const; - - /// Returns an ellipse if edge is based on the ellipse curve - GEOMAPI_EXPORT - std::shared_ptr ellipse() const; + std::shared_ptr circle(); /// Returns a line if edge is based on the linear curve GEOMAPI_EXPORT - std::shared_ptr line() const; + std::shared_ptr line(); /// Returns true if the current edge is geometrically equal to the given edge GEOMAPI_EXPORT @@ -98,8 +89,5 @@ public: double length() const; }; -//! Pointer on attribute object -typedef std::shared_ptr GeomEdgePtr; - #endif diff --git a/src/GeomAPI/GeomAPI_Ellipse.cpp b/src/GeomAPI/GeomAPI_Ellipse.cpp deleted file mode 100644 index 9c0926a13..000000000 --- a/src/GeomAPI/GeomAPI_Ellipse.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: GeomAPI_Ellipse.cpp -// Created: 25 April 2017 -// Author: Vitaly Smetannikov - -#include "GeomAPI_Ellipse.h" -#include "GeomAPI_Ax2.h" -#include "GeomAPI_Pnt.h" - -#include - -#define MY_ELIPS implPtr() - -GeomAPI_Ellipse::GeomAPI_Ellipse(const std::shared_ptr& theAx2, - double theMajorRadius, double theMinorRadius) -: GeomAPI_Interface(new gp_Elips(theAx2->impl(), theMajorRadius, theMinorRadius)) -{ -} - -std::shared_ptr GeomAPI_Ellipse::center() const -{ - const gp_Pnt& aCenter = MY_ELIPS->Location(); - return std::shared_ptr(new GeomAPI_Pnt(aCenter.X(), aCenter.Y(), aCenter.Z())); -} - -GeomPointPtr GeomAPI_Ellipse::firstFocus() const -{ - const gp_Pnt& aFirst = MY_ELIPS->Focus1(); - return std::shared_ptr(new GeomAPI_Pnt(aFirst.X(), aFirst.Y(), aFirst.Z())); -} - -GeomPointPtr GeomAPI_Ellipse::secondFocus() const -{ - const gp_Pnt& aSecond = MY_ELIPS->Focus2(); - return std::shared_ptr(new GeomAPI_Pnt(aSecond.X(), aSecond.Y(), aSecond.Z())); -} - -double GeomAPI_Ellipse::minorRadius() const -{ - return MY_ELIPS->MinorRadius(); -} - -double GeomAPI_Ellipse::majorRadius() const -{ - return MY_ELIPS->MajorRadius(); -} diff --git a/src/GeomAPI/GeomAPI_Ellipse.h b/src/GeomAPI/GeomAPI_Ellipse.h deleted file mode 100644 index 02536b240..000000000 --- a/src/GeomAPI/GeomAPI_Ellipse.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: GeomAPI_Ellipse.h -// Created: 25 April 2017 -// Author: Vitaly Smetannikov - -#ifndef GeomAPI_Ellipse_H_ -#define GeomAPI_Ellipse_H_ - -#include -#include - -class GeomAPI_Pnt; -class GeomAPI_Ax2; - - -/**\class GeomAPI_Ellipse - * \ingroup DataModel - * \brief Ellipse in 3D - */ -class GeomAPI_Ellipse : public GeomAPI_Interface -{ -public: - - /// \brief Constructs an epty ellipse - GEOMAPI_EXPORT GeomAPI_Ellipse() : GeomAPI_Interface() {} - - /** \brief Constructs an ellipse with major and minor radiuses, - * where theAx2 locates the ellipse and defines its orientation in 3D space such that:\n - * - the center of the circle is the origin of theAx2;\n - * - the origin, "X Direction" and "Y Direction" of theAx2 define the plane of the circle;\n - * - theAx2 is the local coordinate system of the circle.\n - * Note: It is possible to create a circle where Radius is equal to 0.0. raised if Radius < 0. - */ - GEOMAPI_EXPORT GeomAPI_Ellipse(const std::shared_ptr& theAx2, - double theMajorRadius, double theMinorRadius); - - /// Returns center of the ellipse - GEOMAPI_EXPORT std::shared_ptr center() const; - - /// Returns first focus of the ellipse - GEOMAPI_EXPORT std::shared_ptr firstFocus() const; - - /// Returns second focus of the ellipse - GEOMAPI_EXPORT std::shared_ptr secondFocus() const; - - /// Returns minor radius of the ellipse - GEOMAPI_EXPORT double minorRadius() const; - - /// Returns major radius of the ellipse - GEOMAPI_EXPORT double majorRadius() const; - -}; - -//! Pointer on the object -typedef std::shared_ptr GeomEllipsePtr; - -#endif diff --git a/src/GeomAPI/GeomAPI_Ellipse2d.cpp b/src/GeomAPI/GeomAPI_Ellipse2d.cpp deleted file mode 100644 index d789f717f..000000000 --- a/src/GeomAPI/GeomAPI_Ellipse2d.cpp +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: GeomAPI_Ellipse2d.cpp -// Created: 26 April 2017 -// Author: Artem ZHIDKOV - -#include -#include -#include - -#include -#include -#include - -#define MY_ELLIPSE implPtr() - -static gp_Elips2d* newEllipse(const gp_Pnt2d& theCenter, - const gp_Dir2d& theXAxis, - const double theMajorRadius, - const double theMinorRadius) -{ - if (theMajorRadius < theMinorRadius - Precision::Confusion()) { - return newEllipse(theCenter, gp_Dir2d(-theXAxis.Y(), theXAxis.X()), - theMinorRadius, theMajorRadius); - } - - gp_Ax22d anAxis(theCenter, theXAxis); - return new gp_Elips2d(anAxis, theMajorRadius, theMinorRadius); -} - -static gp_Elips2d* newEllipse(const std::shared_ptr& theCenter, - const std::shared_ptr& theAxisPoint, - const std::shared_ptr& thePassingPoint) -{ - const gp_Pnt2d& aCenter = theCenter->impl(); - const gp_Pnt2d& anAxisPnt = theAxisPoint->impl(); - const gp_Pnt2d& aPassedPnt = thePassingPoint->impl(); - - gp_Dir2d aXAxis(anAxisPnt.XY() - aCenter.XY()); - double aMajorRadius = anAxisPnt.Distance(aCenter); - - gp_XY aPassedDir = aPassedPnt.XY() - aCenter.XY(); - - double X = aPassedDir.Dot(aXAxis.XY()) / aMajorRadius; - if (Abs(X) > 1.0 - Precision::Confusion()) - return 0; // ellipse cannot be created for such parameters - - double Y = aPassedDir.CrossMagnitude(aXAxis.XY()); - double aMinorRadius = Y / Sqrt(1. - X * X); - - return newEllipse(aCenter, aXAxis, aMajorRadius, aMinorRadius); -} - - -GeomAPI_Ellipse2d::GeomAPI_Ellipse2d(const std::shared_ptr& theCenter, - const std::shared_ptr& theXAxis, - const double theMajorRadius, - const double theMinorRadius) - : GeomAPI_Interface(newEllipse(theCenter->impl(), theXAxis->impl(), - theMajorRadius, theMinorRadius)) -{ -} - -GeomAPI_Ellipse2d::GeomAPI_Ellipse2d(const std::shared_ptr& theCenter, - const std::shared_ptr& theAxisPoint, - const std::shared_ptr& thePassingPoint) - : GeomAPI_Interface(newEllipse(theCenter, theAxisPoint, thePassingPoint)) -{ -} - -std::shared_ptr GeomAPI_Ellipse2d::center() const -{ - const gp_Pnt2d& aCenter = MY_ELLIPSE->Location(); - return std::shared_ptr(new GeomAPI_Pnt2d(aCenter.X(), aCenter.Y())); -} - -std::shared_ptr GeomAPI_Ellipse2d::firstFocus() const -{ - const gp_Pnt2d& aFirst = MY_ELLIPSE->Focus1(); - return std::shared_ptr(new GeomAPI_Pnt2d(aFirst.X(), aFirst.Y())); -} - -std::shared_ptr GeomAPI_Ellipse2d::secondFocus() const -{ - const gp_Pnt2d& aSecond = MY_ELLIPSE->Focus2(); - return std::shared_ptr(new GeomAPI_Pnt2d(aSecond.X(), aSecond.Y())); -} - -double GeomAPI_Ellipse2d::minorRadius() const -{ - return MY_ELLIPSE->MinorRadius(); -} - -double GeomAPI_Ellipse2d::majorRadius() const -{ - return MY_ELLIPSE->MajorRadius(); -} diff --git a/src/GeomAPI/GeomAPI_Ellipse2d.h b/src/GeomAPI/GeomAPI_Ellipse2d.h deleted file mode 100644 index ef8840d4a..000000000 --- a/src/GeomAPI/GeomAPI_Ellipse2d.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: GeomAPI_Ellipse2d.h -// Created: 26 April 2017 -// Author: Artem ZHIDKOV - -#ifndef GeomAPI_Ellipse2d_H_ -#define GeomAPI_Ellipse2d_H_ - -#include - -class GeomAPI_Pnt2d; -class GeomAPI_Dir2d; - -/**\class GeomAPI_Ellipse2d - * \ingroup DataModel - * \brief Ellipse in 2D - */ -class GeomAPI_Ellipse2d : public GeomAPI_Interface -{ -public: - /// \brief Constructs ellipse by center, X-axis and given radii - GEOMAPI_EXPORT GeomAPI_Ellipse2d(const std::shared_ptr& theCenter, - const std::shared_ptr& theXAxis, - const double theMajorRadius, - const double theMinorRadius); - - /// \brief Constructs ellipse by center and two points lying on the ellipse: - /// first of them defines an axis of the ellipse - /// and another is just placed on the ellipse. - GEOMAPI_EXPORT GeomAPI_Ellipse2d(const std::shared_ptr& theCenter, - const std::shared_ptr& theAxisPoint, - const std::shared_ptr& thePassingPoint); - - /// Returns center of the ellipse - GEOMAPI_EXPORT std::shared_ptr center() const; - - /// Returns first focus of the ellipse - GEOMAPI_EXPORT std::shared_ptr firstFocus() const; - - /// Returns second focus of the ellipse - GEOMAPI_EXPORT std::shared_ptr secondFocus() const; - - /// Returns minor radius of the ellipse - GEOMAPI_EXPORT double minorRadius() const; - - /// Returns major radius of the ellipse - GEOMAPI_EXPORT double majorRadius() const; -}; - -#endif diff --git a/src/GeomAPI/GeomAPI_Pln.h b/src/GeomAPI/GeomAPI_Pln.h index 14d886ee3..4a22b226a 100644 --- a/src/GeomAPI/GeomAPI_Pln.h +++ b/src/GeomAPI/GeomAPI_Pln.h @@ -95,8 +95,5 @@ class GeomAPI_Pln : public GeomAPI_Interface std::shared_ptr intersect(const std::shared_ptr thePlane) const; }; -//! Pointer on the object -typedef std::shared_ptr GeomPlanePtr; - #endif diff --git a/src/GeomAPI/GeomAPI_Pnt.h b/src/GeomAPI/GeomAPI_Pnt.h index 333a2350a..3af09c127 100644 --- a/src/GeomAPI/GeomAPI_Pnt.h +++ b/src/GeomAPI/GeomAPI_Pnt.h @@ -91,7 +91,4 @@ class GeomAPI_Pnt : public GeomAPI_Interface void translate(const std::shared_ptr& theDir, double theDist); }; -//! Pointer on the object -typedef std::shared_ptr GeomPointPtr; - #endif diff --git a/src/GeomAPI/GeomAPI_Vertex.h b/src/GeomAPI/GeomAPI_Vertex.h index cee8fd66b..62160593b 100644 --- a/src/GeomAPI/GeomAPI_Vertex.h +++ b/src/GeomAPI/GeomAPI_Vertex.h @@ -52,8 +52,5 @@ public: bool isEqual(const std::shared_ptr theVert) const; }; -//! Pointer on the object -typedef std::shared_ptr GeomVertexPtr; - #endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp index 2e9c9c18e..c292ee482 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp @@ -19,21 +19,20 @@ // #include - -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include +#include #include #include +#include +#include +#include +#include +#include + +#include +#include +#include +#include std::shared_ptr GeomAlgoAPI_EdgeBuilder::line( std::shared_ptr theStart, std::shared_ptr theEnd) @@ -223,23 +222,3 @@ std::shared_ptr GeomAlgoAPI_EdgeBuilder::lineCircleArc( } return aRes; } - -std::shared_ptr GeomAlgoAPI_EdgeBuilder::ellipse( - const std::shared_ptr& theCenter, - const std::shared_ptr& theNormal, - const std::shared_ptr& theMajorAxis, - const double theMajorRadius, - const double theMinorRadius) -{ - const gp_Pnt& aCenter = theCenter->impl(); - const gp_Dir& aNormal = theNormal->impl(); - const gp_Dir& aMajorAxis = theMajorAxis->impl(); - - gp_Elips anEllipse(gp_Ax2(aCenter, aNormal, aMajorAxis), theMajorRadius, theMinorRadius); - - BRepBuilderAPI_MakeEdge anEdgeBuilder(anEllipse); - std::shared_ptr aRes(new GeomAPI_Edge); - TopoDS_Edge anEdge = anEdgeBuilder.Edge(); - aRes->setImpl(new TopoDS_Shape(anEdge)); - return aRes; -} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h index 22c248d97..e063e2b29 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h @@ -72,13 +72,6 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder std::shared_ptr theStartPoint, std::shared_ptr theEndPoint, std::shared_ptr theNormal); - - /// Creates elliptic edge - static std::shared_ptr ellipse(const std::shared_ptr& theCenter, - const std::shared_ptr& theNormal, - const std::shared_ptr& theMajorAxis, - const double theMajorRadius, - const double theMinorRadius); }; #endif diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 197b6911d..7348703ee 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -36,8 +36,6 @@ #include #include #include -#include -#include #include #include @@ -56,9 +54,6 @@ #include #include #include -#include -#include -#include //#define DEB_NAMING 1 #ifdef DEB_NAMING @@ -74,13 +69,6 @@ Standard_GUID kPART_REF_ID("635eacb2-a1d6-4dec-8348-471fae17cb27"); // selection is invalid after recomputation Standard_GUID kINVALID_SELECTION("bce47fd7-80fa-4462-9d63-2f58acddd49d"); -// identifier of the selection of the center of circle on edge -Standard_GUID kCIRCLE_CENTER("d0d0e0f1-217a-4b95-8fbb-0c4132f23718"); -// identifier of the selection of the first focus point of ellipse on edge -Standard_GUID kELLIPSE_CENTER1("f70df04c-3168-4dc9-87a4-f1f840c1275d"); -// identifier of the selection of the second focus point of ellipse on edge -Standard_GUID kELLIPSE_CENTER2("1395ae73-8e02-4cf8-b204-06ff35873a32"); - // on this label is stored: // TNaming_NamedShape - selected shape // TNaming_Naming - topological selection information (for the body) @@ -98,7 +86,6 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext, } else { myTmpContext.reset(); myTmpSubShape.reset(); - myTmpCenterType = NOT_CENTER; } const std::shared_ptr& anOldShape = value(); @@ -115,9 +102,6 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext, TDF_Label aSelLab = selectionLabel(); aSelLab.ForgetAttribute(kSIMPLE_REF_ID); aSelLab.ForgetAttribute(kINVALID_SELECTION); - aSelLab.ForgetAttribute(kCIRCLE_CENTER); - aSelLab.ForgetAttribute(kELLIPSE_CENTER1); - aSelLab.ForgetAttribute(kELLIPSE_CENTER2); bool isDegeneratedEdge = false; // do not use the degenerated edge as a shape, a null context and shape is used in the case @@ -161,31 +145,6 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext, owner()->data()->sendAttributeUpdated(this); } -void Model_AttributeSelection::setValueCenter( - const ResultPtr& theContext, const std::shared_ptr& theEdge, - const CenterType theCenterType, const bool theTemporarily) -{ - setValue(theContext, theEdge, theTemporarily); - if (theTemporarily) { - myTmpCenterType = theCenterType; - } else { // store in the data structure - TDF_Label aSelLab = selectionLabel(); - switch(theCenterType) { - case CIRCLE_CENTER: - TDataStd_UAttribute::Set(aSelLab, kCIRCLE_CENTER); - break; - case ELLIPSE_FIRST_FOCUS: - TDataStd_UAttribute::Set(aSelLab, kELLIPSE_CENTER1); - break; - case ELLIPSE_SECOND_FOCUS: - TDataStd_UAttribute::Set(aSelLab, kELLIPSE_CENTER2); - break; - } - owner()->data()->sendAttributeUpdated(this); - } -} - - void Model_AttributeSelection::removeTemporaryValues() { if (myTmpContext.get() || myTmpSubShape.get()) { @@ -194,42 +153,6 @@ void Model_AttributeSelection::removeTemporaryValues() } } -// returns the center of the edge: circular or elliptical -GeomShapePtr centerByEdge(GeomShapePtr theEdge, ModelAPI_AttributeSelection::CenterType theType) -{ - if (theType != ModelAPI_AttributeSelection::NOT_CENTER && theEdge.get() != NULL) { - TopoDS_Shape aShape = theEdge->impl(); - if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE) { - TopoDS_Edge anEdge = TopoDS::Edge(aShape); - double aFirst, aLast; - Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast); - if (!aCurve.IsNull()) { - TopoDS_Vertex aVertex; - BRep_Builder aBuilder; - if (theType == ModelAPI_AttributeSelection::CIRCLE_CENTER) { - Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve); - if (!aCirc.IsNull()) { - aBuilder.MakeVertex(aVertex, aCirc->Location(), Precision::Confusion()); - } - } else { // ellipse - Handle(Geom_Ellipse) anEll = Handle(Geom_Ellipse)::DownCast(aCurve); - if (!anEll.IsNull()) { - aBuilder.MakeVertex(aVertex, - theType == ModelAPI_AttributeSelection::ELLIPSE_FIRST_FOCUS ? - anEll->Focus1() : anEll->Focus2(), Precision::Confusion()); - } - } - if (!aVertex.IsNull()) { - std::shared_ptr aResult(new GeomAPI_Vertex); - aResult->setImpl(new TopoDS_Vertex(aVertex)); - return aResult; - } - } - } - } - return theEdge; // no vertex, so, return the initial edge -} - std::shared_ptr Model_AttributeSelection::value() { GeomShapePtr aResult; @@ -238,40 +161,30 @@ std::shared_ptr Model_AttributeSelection::value() std::dynamic_pointer_cast(myTmpContext); if(aResulConstruction.get()) { // it is just reference to construction. - return centerByEdge(myTmpSubShape, myTmpCenterType); + return myTmpSubShape; } - return centerByEdge(myTmpSubShape.get() ? myTmpSubShape : myTmpContext->shape(), - myTmpCenterType); + return myTmpSubShape.get() ? myTmpSubShape : myTmpContext->shape(); } TDF_Label aSelLab = selectionLabel(); if (aSelLab.IsAttribute(kINVALID_SELECTION)) return aResult; - CenterType aType = NOT_CENTER; - if (aSelLab.IsAttribute(kCIRCLE_CENTER)) - aType = CIRCLE_CENTER; - else if (aSelLab.IsAttribute(kELLIPSE_CENTER1)) - aType = ELLIPSE_FIRST_FOCUS; - else if (aSelLab.IsAttribute(kELLIPSE_CENTER2)) - aType = ELLIPSE_SECOND_FOCUS; - - if (myRef.isInitialized()) { if (aSelLab.IsAttribute(kSIMPLE_REF_ID)) { // it is just reference to shape, not sub-shape ResultPtr aContext = context(); if (!aContext.get()) return aResult; // empty result - return centerByEdge(aContext->shape(), aType); + return aContext->shape(); } if (aSelLab.IsAttribute(kPART_REF_ID)) { ResultPartPtr aPart = std::dynamic_pointer_cast(context()); if (!aPart.get() || !aPart->isActivated()) - return aResult; // postponed naming needed + return std::shared_ptr(); // postponed naming needed Handle(TDataStd_Integer) anIndex; if (aSelLab.FindAttribute(TDataStd_Integer::GetID(), anIndex)) { if (anIndex->Get()) { // special selection attribute was created, use it - return centerByEdge(aPart->selectionValue(anIndex->Get()), aType); + return aPart->selectionValue(anIndex->Get()); } else { // face with name is already in the data model, so try to take it by name Handle(TDataStd_Name) aName; if (aSelLab.FindAttribute(TDataStd_Name::GetID(), aName)) { @@ -280,8 +193,8 @@ std::shared_ptr Model_AttributeSelection::value() if (aPartEnd != std::string::npos && aPartEnd != aSubShapeName.rfind('/')) { std::string aNameInPart = aSubShapeName.substr(aPartEnd + 1); int anIndex; - std::string aTypeStr; // to reuse already existing selection the type is not needed - return centerByEdge(aPart->shapeInPart(aNameInPart, aTypeStr, anIndex), aType); + std::string aType; // to reuse already existing selection the type is not needed + return aPart->shapeInPart(aNameInPart, aType, anIndex); } } } @@ -293,7 +206,6 @@ std::shared_ptr Model_AttributeSelection::value() TopoDS_Shape aSelShape = aSelection->Get(); aResult = std::shared_ptr(new GeomAPI_Shape); aResult->setImpl(new TopoDS_Shape(aSelShape)); - return centerByEdge(aResult, aType); } else { // for simple construction element: just shape of this construction element std::shared_ptr aConstr = std::dynamic_pointer_cast(context()); @@ -301,13 +213,13 @@ std::shared_ptr Model_AttributeSelection::value() Handle(TDataStd_Integer) anIndex; if (aSelLab.FindAttribute(TDataStd_Integer::GetID(), anIndex)) { if (anIndex->Get() == 0) // it is just reference to construction, nothing is in value - return centerByEdge(aResult, aType); - return centerByEdge(aConstr->shape(anIndex->Get(), owner()->document()), aType); + return aResult; + return aConstr->shape(anIndex->Get(), owner()->document()); } } } } - return aResult; // empty case + return aResult; } bool Model_AttributeSelection::isInvalid() diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 2d64b6f56..c75766a73 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -41,8 +41,6 @@ class Model_AttributeSelection : public ModelAPI_AttributeSelection ResultPtr myTmpContext; /// temporarily storages to avoid keeping in the data structure if not needed std::shared_ptr myTmpSubShape; - /// temporarily storages to avoid keeping in the data structure if not needed - CenterType myTmpCenterType; /// Reference to the partent attribute, if any (to split selection compounds in issue 1799) Model_AttributeSelectionList* myParent; public: @@ -55,13 +53,6 @@ public: const ResultPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily = false); - /// Same as SetValue, but it takes an edge (on circular or elliptical curve) - /// and stores the vertex of the central point (for ellipse the first or the second focus point) - MODEL_EXPORT virtual void setValueCenter( - const ResultPtr& theContext, const std::shared_ptr& theEdge, - const CenterType theCenterType, - const bool theTemporarily = false); - /// Reset temporary stored values virtual void removeTemporaryValues(); diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 0985db34b..9f039b63b 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -112,7 +112,6 @@ SET(PROJECT_SOURCES SET(PROJECT_LIBRARIES Config - GeomAPI ) SET(CMAKE_SWIG_FLAGS -threads -Wall) ADD_DEFINITIONS(-DMODELAPI_EXPORTS) diff --git a/src/ModelAPI/ModelAPI_AttributeSelection.h b/src/ModelAPI/ModelAPI_AttributeSelection.h index 44eace64f..74802c858 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelection.h +++ b/src/ModelAPI/ModelAPI_AttributeSelection.h @@ -24,8 +24,6 @@ #include "ModelAPI_Attribute.h" #include -class GeomAPI_Edge; - /**\class ModelAPI_AttributeSelection * \ingroup DataModel * \brief Attribute that contains reference to the sub-shape of some result, the selected shape. @@ -34,14 +32,6 @@ class GeomAPI_Edge; class ModelAPI_AttributeSelection : public ModelAPI_Attribute { public: - /// Type of the center of the circular of elliptical edge - enum CenterType { - NOT_CENTER, ///< this is not a center - CIRCLE_CENTER, ///< center of the circle - ELLIPSE_FIRST_FOCUS, ///< first focus point of the ellipse - ELLIPSE_SECOND_FOCUS, ///< second focus point of the ellipse - }; - /// Defines the result and its selected sub-shape /// \param theContext object where the sub-shape was selected /// \param theSubShape selected sub-shape (if null, the whole context is selected) @@ -51,13 +41,6 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute const ResultPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily = false) = 0; - /// Same as SetValue, but it takes an edge (on circular or elliptical curve) - /// and stores the vertex of the central point (for ellipse the first or the second focus point) - virtual void setValueCenter( - const ResultPtr& theContext, const std::shared_ptr& theEdge, - const CenterType theCenterType, - const bool theTemporarily = false) = 0; - /// Reset temporary stored values virtual void removeTemporaryValues() = 0; diff --git a/src/ModelAPI/ModelAPI_Events.cpp b/src/ModelAPI/ModelAPI_Events.cpp index 9368211e0..c660afca2 100644 --- a/src/ModelAPI/ModelAPI_Events.cpp +++ b/src/ModelAPI/ModelAPI_Events.cpp @@ -21,8 +21,6 @@ #include #include -#include - ModelAPI_ObjectUpdatedMessage::ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender) : Events_MessageGroup(theID, theSender) @@ -340,44 +338,3 @@ const std::set& ModelAPI_SolverFailedMessage::objects() const { return myObjects; } - - -// ===== ModelAPI_ObjectMovedMessage ===== -ModelAPI_ObjectMovedMessage::ModelAPI_ObjectMovedMessage(const void* theSender) - : Events_Message(Events_Loop::eventByName(EVENT_OBJECT_MOVED), theSender) -{ -} - -void ModelAPI_ObjectMovedMessage::setMovedObject(const ObjectPtr& theMovedObject) -{ - myMovedObject = theMovedObject; - myMovedAttribute = AttributePtr(); -} - -void ModelAPI_ObjectMovedMessage::setMovedAttribute(const AttributePtr& theMovedAttribute) -{ - myMovedAttribute = theMovedAttribute; - myMovedObject = ObjectPtr(); -} - -void ModelAPI_ObjectMovedMessage::setOriginalPosition(double theX, double theY) -{ - myOriginalPosition = std::shared_ptr(new GeomAPI_Pnt2d(theX, theY)); -} - -void ModelAPI_ObjectMovedMessage::setOriginalPosition( - const std::shared_ptr& thePoint) -{ - myOriginalPosition = thePoint; -} - -void ModelAPI_ObjectMovedMessage::setCurrentPosition(double theX, double theY) -{ - myCurrentPosition = std::shared_ptr(new GeomAPI_Pnt2d(theX, theY)); -} - -void ModelAPI_ObjectMovedMessage::setCurrentPosition( - const std::shared_ptr& thePoint) -{ - myCurrentPosition = thePoint; -} diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index a7718d1de..1d69e38a9 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -36,7 +36,6 @@ class ModelAPI_Document; class ModelAPI_ResultParameter; -class GeomAPI_Pnt2d; /// Event ID that feature is created (comes with ModelAPI_ObjectUpdatedMessage) static const char * EVENT_OBJECT_CREATED = "ObjectCreated"; @@ -468,46 +467,4 @@ private: int myDOF; }; -/// Message sent when feature or attrubute has been moved. -/// Stores the moving object/attribute, original and new positions of mouse. -class ModelAPI_ObjectMovedMessage : public Events_Message -{ - ObjectPtr myMovedObject; - AttributePtr myMovedAttribute; - - std::shared_ptr myOriginalPosition; - std::shared_ptr myCurrentPosition; - -public: - MODELAPI_EXPORT ModelAPI_ObjectMovedMessage(const void* theSender = 0); - - /// Set object which is being moved (if the message already contains attribute it will be cleared) - MODELAPI_EXPORT void setMovedObject(const ObjectPtr& theMovedObject); - /// Set attribute which is being moved (if the message already contains object it will be cleared) - MODELAPI_EXPORT void setMovedAttribute(const AttributePtr& theMovedAttribute); - - /// Return moved object - ObjectPtr movedObject() const - { return myMovedObject; } - /// Return moved attribute - AttributePtr movedAttribute() const - { return myMovedAttribute; } - - /// Set original mouse position - MODELAPI_EXPORT void setOriginalPosition(double theX, double theY); - /// Set original mouse position - MODELAPI_EXPORT void setOriginalPosition(const std::shared_ptr& thePoint); - /// Return original mouse position - const std::shared_ptr& originalPosition() const - { return myOriginalPosition; } - - /// Set current mouse position - MODELAPI_EXPORT void setCurrentPosition(double theX, double theY); - /// Set current mouse position - MODELAPI_EXPORT void setCurrentPosition(const std::shared_ptr& thePoint); - /// Return current mouse position - const std::shared_ptr& currentPosition() const - { return myCurrentPosition; } -}; - #endif diff --git a/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp b/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp index d018517e2..ad32819b3 100644 --- a/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp +++ b/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include #include "ModelHighAPI_Interface.h" @@ -82,13 +81,3 @@ bool ModelHighAPI_RefAttr::isEmpty() const { return !(myAttribute && myObject); } - -//-------------------------------------------------------------------------------------- -void ModelHighAPI_RefAttr::fillMessage( - const std::shared_ptr& theMessage) const -{ - switch (myVariantType) { - case VT_ATTRIBUTE: theMessage->setMovedAttribute(myAttribute); return; - case VT_OBJECT: theMessage->setMovedObject(myObject); return; - } -} diff --git a/src/ModelHighAPI/ModelHighAPI_RefAttr.h b/src/ModelHighAPI/ModelHighAPI_RefAttr.h index feb9edfdc..7c1bbd6e8 100644 --- a/src/ModelHighAPI/ModelHighAPI_RefAttr.h +++ b/src/ModelHighAPI/ModelHighAPI_RefAttr.h @@ -31,7 +31,6 @@ class ModelAPI_Attribute; class ModelAPI_AttributeRefAttr; class ModelAPI_AttributeRefAttrList; class ModelAPI_Object; -class ModelAPI_ObjectMovedMessage; class ModelHighAPI_Interface; //-------------------------------------------------------------------------------------- /**\class ModelHighAPI_RefAttr @@ -69,10 +68,6 @@ public: MODELHIGHAPI_EXPORT bool isEmpty() const; - /// Fill moved message by the attribute or object - MODELHIGHAPI_EXPORT - void fillMessage(const std::shared_ptr& theMessage) const; - private: enum VariantType { VT_ATTRIBUTE, VT_OBJECT } myVariantType; std::shared_ptr myAttribute; diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 5bf192c97..fcba4e0c4 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -413,7 +413,7 @@ void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) qDebug("ModuleBase_ModelWidget::moveObject"); #endif - static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED); ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent); Events_Loop::loop()->flush(anEvent); diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index e690ce0e5..0dd37b355 100755 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -105,14 +105,11 @@ void ModuleBase_ResultPrs::Compute( } void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, - const Standard_Integer theMode) + const Standard_Integer aMode) { - if (appendVertexSelection(aSelection, theMode)) - return; - - if (theMode > TopAbs_SHAPE) { + if (aMode > TopAbs_SHAPE) { // In order to avoid using custom selection modes - if (theMode == ModuleBase_ResultPrs::Sel_Result) { + if (aMode == ModuleBase_ResultPrs::Sel_Result) { AIS_Shape::ComputeSelection(aSelection, TopAbs_COMPOUND); } return; @@ -120,7 +117,7 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a // TODO: OCCT issue should be created for the COMPOUND processing // before it is fixed, the next workaround in necessary - if (theMode == AIS_Shape::SelectionMode(TopAbs_COMPOUND)) { + if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPOUND)) { const TopoDS_Shape& aShape = Shape(); TopExp_Explorer aCompExp(aShape, TopAbs_COMPOUND); // do not activate in compound mode shapes which do not contain compounds @@ -128,7 +125,7 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a return; } - if (theMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) { + if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) { // Limit selection area only by actual object (Shape) ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult); if (aCompSolid.get()) { @@ -157,7 +154,7 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a } //AIS_Shape::ComputeSelection(aSelection, 0); } - AIS_Shape::ComputeSelection(aSelection, theMode); + AIS_Shape::ComputeSelection(aSelection, aMode); if (myAdditionalSelectionPriority > 0) { for (aSelection->Init(); aSelection->More(); aSelection->Next()) { @@ -169,34 +166,6 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a } } -bool ModuleBase_ResultPrs::appendVertexSelection(const Handle(SelectMgr_Selection)& aSelection, - const Standard_Integer theMode) -{ - if (Shape().ShapeType() == TopAbs_VERTEX) { - const TopoDS_Shape& aShape = Shape(); - - int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_VERTEX); - double aDeflection = Prs3d::GetDeflection(aShape, myDrawer); - - /// The cause of this method is the last parameter of BRep owner setting into True. - /// That means that owner should behave like it comes from decomposition. (In this case, OCCT - /// visualizes it in Ring style) OCCT version is 7.0.0 with path for SHAPER module. - Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(aShape, aPriority, Standard_True); - StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection, - aDeflection, myDrawer->HLRAngle(), 9, 500); - - for (aSelection->Init(); aSelection->More(); aSelection->Next()) { - Handle(SelectMgr_EntityOwner) anOwner = - Handle(SelectMgr_EntityOwner) - ::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId()); - anOwner->Set(this); - } - return true; - } - return false; -} - -/* OBSOLETE void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection, const TopoDS_Shape& theShape) { @@ -214,7 +183,7 @@ void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection myDrawer->IsAutoTriangulation()); } catch ( Standard_Failure ) { } -}*/ +} void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, const SelectMgr_SequenceOfOwner& theOwners) diff --git a/src/ModuleBase/ModuleBase_ResultPrs.h b/src/ModuleBase/ModuleBase_ResultPrs.h index af70be9e8..6d46e4ef5 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.h +++ b/src/ModuleBase/ModuleBase_ResultPrs.h @@ -53,9 +53,9 @@ public: /// Highlight the presentation with the given color /// \param aPM a presentations manager /// \param theStyle a style of presentation - /// \param theMode a drawing mode + /// \param aMode a drawing mode virtual void HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& aPM, - const Handle(Graphic3d_HighlightStyle)& theStyle, const Standard_Integer theMode = 0) + const Handle(Graphic3d_HighlightStyle)& theStyle, const Standard_Integer aMode = 0) { Selectable()->HilightOwnerWithColor(aPM, theStyle, this); } @@ -119,22 +119,14 @@ protected: /// Redefinition of virtual function Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, - const Standard_Integer theMode) ; + const Standard_Integer aMode) ; private: - /// If the shape of this presentation is Vertex, it appends custom sensitive and owners for it. - /// Owner is a usual Brep owner with "isDecomposite" in true. It is necessary to have "Ring" - /// highlight/selected marker. - /// \param theSelection a current filled selection - /// \param theMode a selection mode - /// \return true if the owner is created - bool appendVertexSelection(const Handle(SelectMgr_Selection)& aSelection, - const Standard_Integer theMode); /// Appens sensitive and owners for wires of the given shape into selection /// \param theSelection a current filled selection /// \param theShape a shape - //void appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection, - // const TopoDS_Shape& theShape); + void appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection, + const TopoDS_Shape& theShape); /// Reference to result object ResultPtr myResult; diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 37575cf72..b04c31716 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -56,8 +56,6 @@ SET(PROJECT_HEADERS PartSet_WidgetShapeSelector.h PartSet_WidgetSketchCreator.h PartSet_WidgetSketchLabel.h - PartSet_CenterPrs.h - PartSet_ExternalPointsMgr.h ) SET(PROJECT_MOC_HEADERS @@ -76,7 +74,6 @@ SET(PROJECT_MOC_HEADERS PartSet_WidgetShapeSelector.h PartSet_WidgetSketchCreator.h PartSet_WidgetSketchLabel.h - PartSet_ExternalPointsMgr.h ) SET(PROJECT_SOURCES @@ -104,8 +101,6 @@ SET(PROJECT_SOURCES PartSet_WidgetShapeSelector.cpp PartSet_WidgetSketchCreator.cpp PartSet_WidgetSketchLabel.cpp - PartSet_CenterPrs.cpp - PartSet_ExternalPointsMgr.cpp ) SET(PROJECT_RESOURCES diff --git a/src/PartSet/PartSet_CenterPrs.cpp b/src/PartSet/PartSet_CenterPrs.cpp deleted file mode 100644 index 065c7971c..000000000 --- a/src/PartSet/PartSet_CenterPrs.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: PartSet_CenterPrs.cpp -// Created: 25 April 2017 -// Author: Vitaly SMETANNIKOV - -#include "PartSet_CenterPrs.h" - -#include - - -IMPLEMENT_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point) - -PartSet_CenterPrs::PartSet_CenterPrs(const ObjectPtr& theObject, - const GeomEdgePtr& theEdge, - const gp_Pnt& theCenter, - ModelAPI_AttributeSelection::CenterType theType) - : AIS_Point(new Geom_CartesianPoint(theCenter)), - myObject(theObject), - myEdge(theEdge), - myCenterType(theType) -{ -} \ No newline at end of file diff --git a/src/PartSet/PartSet_CenterPrs.h b/src/PartSet/PartSet_CenterPrs.h deleted file mode 100644 index 86e54b24f..000000000 --- a/src/PartSet/PartSet_CenterPrs.h +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: PartSet_CenterPrs.h -// Created: 25 April 2017 -// Author: Vitaly SMETANNIKOV - -#ifndef PartSet_CenterPrs_H -#define PartSet_CenterPrs_H - -#include -#include -#include - -#include -#include -#include - -DEFINE_STANDARD_HANDLE(PartSet_CenterPrs, AIS_Point) - -/** -* \ingroup GUI -* A presentation class for displaying of centers of external curcular objects in a sketch -*/ -class PartSet_CenterPrs: public AIS_Point -{ -public: - /// Constructor - /// \param theObject an object with circular edge - /// \param theEdge a circular edge - /// \param theCenter a center point of the circular edge - /// \param theType a type of the center - Standard_EXPORT PartSet_CenterPrs(const ObjectPtr& theObject, - const GeomEdgePtr& theEdge, - const gp_Pnt& theCenter, - ModelAPI_AttributeSelection::CenterType theType); - - /// Returns an Object which contains the circular edge - ObjectPtr object() const { return myObject; } - - /// Returns a circular edge shape - GeomEdgePtr edge() const { return myEdge; } - - /// Returns type of the center - ModelAPI_AttributeSelection::CenterType centerType() const { return myCenterType; } - - DEFINE_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point) - -private: - ObjectPtr myObject; - GeomEdgePtr myEdge; - ModelAPI_AttributeSelection::CenterType myCenterType; -}; - -#endif diff --git a/src/PartSet/PartSet_ExternalPointsMgr.cpp b/src/PartSet/PartSet_ExternalPointsMgr.cpp deleted file mode 100644 index 0f9babdae..000000000 --- a/src/PartSet/PartSet_ExternalPointsMgr.cpp +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: PartSet_ExternalPointsMgr.cpp -// Created: 26 April 2017 -// Author: Vitaly SMETANNIKOV - -#include "PartSet_ExternalPointsMgr.h" -#include "PartSet_CenterPrs.h" -#include "PartSet_Tools.h" - -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -PartSet_ExternalPointsMgr::PartSet_ExternalPointsMgr(ModuleBase_IWorkshop* theWorkshop, - const CompositeFeaturePtr& theSketch) - : QObject(theWorkshop), myWorkshop(theWorkshop), mySketch(theSketch) -{ - XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); - XGUI_Displayer* aDisplayer = aWorkshop->displayer(); - connect(aDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)), - SLOT(onDisplayObject(ObjectPtr, AISObjectPtr))); - - connect(aDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)), - SLOT(onEraseObject(ObjectPtr, AISObjectPtr))); - - updateCenterPresentations(); -} - - -PartSet_ExternalPointsMgr::~PartSet_ExternalPointsMgr() -{ - if (myPresentations.isEmpty()) - return; - XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); - if (!aWorkshop) - return; - - XGUI_Displayer* aDisplayer = aWorkshop->displayer(); - QMapIterator aIt(myPresentations); - while (aIt.hasNext()) { - aIt.next(); - ListOfAIS aAISList = aIt.value(); - foreach (AISObjectPtr aAIS, aAISList) { - aDisplayer->eraseAIS(aAIS, false); - } - } -} - - -//****************************************************** -QList> PartSet_ExternalPointsMgr::findCircularEdgesInPlane() -{ - QList> aResult; - XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); - XGUI_Displayer* aDisplayer = aWorkshop->displayer(); - QObjectPtrList aDispObjects = aDisplayer->displayedObjects(); - - std::shared_ptr aPlane = plane(); - foreach(ObjectPtr aObj, aDispObjects) { - if (myPresentations.contains(aObj)) - continue; - - // Do not process objects of the current sketch - if (isSketchObject(aObj)) - continue; - - ResultPtr aResObj = std::dynamic_pointer_cast(aObj); - if (aResObj.get()) { - GeomShapePtr aShape = aResObj->shape(); - if (aShape.get()) { - GeomAPI_ShapeExplorer aExplorer(aShape, GeomAPI_Shape::EDGE); - for(; aExplorer.more(); aExplorer.next()) { - GeomShapePtr aEdgeShape = aExplorer.current(); - GeomAPI_Edge anEdge(aEdgeShape); - if ((anEdge.isCircle() || anEdge.isArc() || anEdge.isEllipse()) && - anEdge.isInPlane(aPlane)) { - bool isContains = false; - // Check that edge is not already used. - // It is possible that the same edge will be taken from different faces - foreach(std::shared_ptr aPrs, aResult) { - GeomAPI_Edge aUsedEdge(aPrs->shape()); - if (aUsedEdge.isEqual(aEdgeShape)) { - isContains = true; - break; - } - } - if (!isContains) { - std::shared_ptr - aPrs(new ModuleBase_ViewerPrs(aResObj, aEdgeShape)); - aResult.append(aPrs); - } - } - } - } - } - } - return aResult; -} - - -void PartSet_ExternalPointsMgr::updateCenterPresentations() -{ - XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); - // Return if there is no plane defined - if (!plane().get()) { - connect(aWorkshop->selector(), SIGNAL(selectionChanged()), - SLOT(onSelectionChanged())); - return; - } - XGUI_Displayer* aDisplayer = aWorkshop->displayer(); - - QList> aEdgesPrs = findCircularEdgesInPlane(); - foreach(std::shared_ptr aPrs, aEdgesPrs) { - GeomEdgePtr aEdge(new GeomAPI_Edge(aPrs->shape())); - ListOfAIS aList; - if (aEdge->isArc() || aEdge->isCircle()) { - GeomCirclePtr aCircle = aEdge->circle(); - GeomPointPtr aCenter = aCircle->center(); - Handle(PartSet_CenterPrs) aCentPrs = - new PartSet_CenterPrs(aPrs->object(), aEdge, aCenter->impl(), - ModelAPI_AttributeSelection::CIRCLE_CENTER); - - AISObjectPtr anAIS(new GeomAPI_AISObject()); - anAIS->setImpl(new Handle(AIS_InteractiveObject)(aCentPrs)); - aList.append(anAIS); - } else if (aEdge->isEllipse()) { - GeomEllipsePtr aEllipse = aEdge->ellipse(); - GeomPointPtr aF1 = aEllipse->firstFocus(); - GeomPointPtr aF2 = aEllipse->secondFocus(); - Handle(PartSet_CenterPrs) aF1Prs = - new PartSet_CenterPrs(aPrs->object(), aEdge, aF1->impl(), - ModelAPI_AttributeSelection::ELLIPSE_FIRST_FOCUS); - Handle(PartSet_CenterPrs) aF2Prs = - new PartSet_CenterPrs(aPrs->object(), aEdge, aF2->impl(), - ModelAPI_AttributeSelection::ELLIPSE_SECOND_FOCUS); - - AISObjectPtr anAIS1(new GeomAPI_AISObject()); - anAIS1->setImpl(new Handle(AIS_InteractiveObject)(aF1Prs)); - aList.append(anAIS1); - - AISObjectPtr anAIS2(new GeomAPI_AISObject()); - anAIS2->setImpl(new Handle(AIS_InteractiveObject)(aF2Prs)); - aList.append(anAIS2); - } - if (myPresentations.contains(aPrs->object())) - myPresentations[aPrs->object()].append(aList); - else - myPresentations[aPrs->object()] = aList; - foreach(AISObjectPtr anAIS, aList) { - aDisplayer->displayAIS(anAIS, false); - aDisplayer->activateAIS(anAIS->impl(), TopAbs_VERTEX, false); - } - } -} - -std::shared_ptr PartSet_ExternalPointsMgr::plane() const -{ - return PartSet_Tools::sketchPlane(mySketch); -} - -void PartSet_ExternalPointsMgr::onDisplayObject(ObjectPtr theObj, AISObjectPtr theAIS) -{ - updateCenterPresentations(); -} - -void PartSet_ExternalPointsMgr::onEraseObject(ObjectPtr theObj, AISObjectPtr theAIS) -{ - if (myPresentations.contains(theObj)) { - XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); - XGUI_Displayer* aDisplayer = aWorkshop->displayer(); - ListOfAIS aList = myPresentations[theObj]; - foreach(AISObjectPtr aAIS, aList) { - aDisplayer->eraseAIS(aAIS, false); - } - myPresentations.remove(theObj); - aDisplayer->updateViewer(); - } -} - - -bool PartSet_ExternalPointsMgr::isSketchObject(const ObjectPtr& theRes) const -{ - FeaturePtr aFeature = ModelAPI_Feature::feature(theRes); - if (!aFeature.get()) - return false; - CompositeFeaturePtr aComp = ModelAPI_Tools::compositeOwner(aFeature); - return aComp == mySketch; -} - -void PartSet_ExternalPointsMgr::onSelectionChanged() -{ - if (plane().get()) { - XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); - disconnect(aWorkshop->selector(), SIGNAL(selectionChanged()), - this, SLOT(onSelectionChanged())); - updateCenterPresentations(); - } -} diff --git a/src/PartSet/PartSet_ExternalPointsMgr.h b/src/PartSet/PartSet_ExternalPointsMgr.h deleted file mode 100644 index 4f13f09e8..000000000 --- a/src/PartSet/PartSet_ExternalPointsMgr.h +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: PartSet_ExternalPointsMgr.h -// Created: 26 April 2017 -// Author: Vitaly SMETANNIKOV - -#ifndef PartSet_ExternalPointsMgr_H -#define PartSet_ExternalPointsMgr_H - - -#include -#include -#include -#include - -#include -#include - -class ModuleBase_ViewerPrs; -class ModuleBase_IWorkshop; - - -/** -* \ingroup Modules -* A class to manage display of presentations of center points of circular -* edges outside of a current sketcher -*/ -class PartSet_ExternalPointsMgr: public QObject -{ - Q_OBJECT -public: - PartSet_ExternalPointsMgr(ModuleBase_IWorkshop* theWorkshop, - const CompositeFeaturePtr& theSketch); - - virtual ~PartSet_ExternalPointsMgr(); - -public slots: - /** - * A slot which processes display of object - * \param theObj the displayed object - * \param theAIS its presentation - */ - void onDisplayObject(ObjectPtr theObj, AISObjectPtr theAIS); - - /** - * A slot which processes erase of object - * \param theObj the displayed object - * \param theAIS its presentation - */ - void onEraseObject(ObjectPtr theObj, AISObjectPtr theAIS); - - // Called on selection changed - void onSelectionChanged(); - -private: - /** - * Returns list of presentations which have displayed shapes with circular edges - * (circles, arcs) which are in pane of of the given sketch - * \param theSketch - the sketch - */ - QList> findCircularEdgesInPlane(); - - /// Creates presentations of centers - void updateCenterPresentations(); - - /// Returns plane of the current sketch - GeomPlanePtr plane() const; - - /** - * Checks that the given object is an object of the current sketch - * \param theRes an object to check - * \return True if the given object is a sub-object of the current sketch - */ - bool isSketchObject(const ObjectPtr& theRes) const; - -private: - /// Workshop - ModuleBase_IWorkshop* myWorkshop; - - /// Current sketch - CompositeFeaturePtr mySketch; - - /// Type for list of created AIS objects - typedef QList ListOfAIS; - - /// Map of created AIS objects - QMap myPresentations; -}; - -#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index eab2a165c..9a1ed0282 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -26,7 +26,6 @@ #include "PartSet_WidgetSketchLabel.h" #include "PartSet_WidgetEditor.h" #include "PartSet_ResultSketchPrs.h" -#include "PartSet_ExternalPointsMgr.h" #include #include @@ -153,7 +152,7 @@ PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule) : QObject(theModule), myModule(theModule), myIsEditLaunching(false), myIsDragging(false), myDragDone(false), myIsMouseOverWindow(false), myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true), - myIsPopupMenuActive(false), myExternalPointsMgr(0) + myIsPopupMenuActive(false) { ModuleBase_IWorkshop* anIWorkshop = myModule->workshop(); ModuleBase_IViewer* aViewer = anIWorkshop->viewer(); @@ -537,11 +536,8 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); Point aMousePnt; get2dPoint(theWnd, theEvent, aMousePnt); - - std::shared_ptr anOriginalPosition = std::shared_ptr( - new GeomAPI_Pnt2d(myCurrentPoint.myCurX, myCurrentPoint.myCurY)); - std::shared_ptr aCurrentPosition = std::shared_ptr( - new GeomAPI_Pnt2d(aMousePnt.myCurX, aMousePnt.myCurY)); + double dX = aMousePnt.myCurX - myCurrentPoint.myCurX; + double dY = aMousePnt.myCurY - myCurrentPoint.myCurY; ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); @@ -576,15 +572,9 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve std::dynamic_pointer_cast(aData->attribute(aAttrId)); if (aPoint.get() != NULL) { bool isImmutable = aPoint->setImmutable(true); - - std::shared_ptr aMessage = std::shared_ptr - (new ModelAPI_ObjectMovedMessage(this)); - aMessage->setMovedAttribute(aPoint); - aMessage->setOriginalPosition(anOriginalPosition); - aMessage->setCurrentPosition(aCurrentPosition); - Events_Loop::loop()->send(aMessage); - + aPoint->move(dX, dY); isModified = true; + ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent); aPoint->setImmutable(isImmutable); } } @@ -594,13 +584,9 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve std::shared_ptr aSketchFeature = std::dynamic_pointer_cast(aFeature); if (aSketchFeature) { - std::shared_ptr aMessage = std::shared_ptr - (new ModelAPI_ObjectMovedMessage(this)); - aMessage->setMovedObject(aFeature); - aMessage->setOriginalPosition(anOriginalPosition); - aMessage->setCurrentPosition(aCurrentPosition); - Events_Loop::loop()->send(aMessage); + aSketchFeature->move(dX, dY); isModified = true; + ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent); } } } @@ -608,8 +594,8 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve // were changed here if (isModified) { aCurrentOperation->onValuesChanged(); - Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver } + Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations // 5. it is necessary to save current selection in order to restore it after the features moving @@ -1013,8 +999,6 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) // plane filter if (aPln.get()) aConnector->activateModuleSelectionModes(); - - myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch); } void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) @@ -1024,11 +1008,6 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) myIsConstraintsShown[PartSet_Tools::Dimensional] = true; myIsConstraintsShown[PartSet_Tools::Expressions] = false; - if (myExternalPointsMgr) { - delete myExternalPointsMgr; - myExternalPointsMgr = 0; - } - XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); DataPtr aData = myCurrentSketch->data(); diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 92c74ef8c..5396144b3 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -50,7 +50,6 @@ class ModuleBase_ModelWidget; class ModuleBase_Operation; class XGUI_OperationMgr; class XGUI_Workshop; -class PartSet_ExternalPointsMgr; class AIS_InteractiveObject; @@ -433,8 +432,6 @@ private: bool myPreviousUpdateViewerEnabled; QMap myIsConstraintsShown; - - PartSet_ExternalPointsMgr* myExternalPointsMgr; }; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 2a5f0f08d..2b5315a8f 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -905,29 +905,3 @@ bool PartSet_Tools::isAuxiliarySketchEntity(const ObjectPtr& theObject) return isAuxiliaryFeature; } - - -ResultPtr PartSet_Tools::createFixedByExternalCenter( - const ObjectPtr& theObject, - const std::shared_ptr& theEdge, - ModelAPI_AttributeSelection::CenterType theType, - const CompositeFeaturePtr& theSketch, - bool theTemporary) -{ - FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID()); - - if (aMyFeature) { - DataPtr aData = aMyFeature->data(); - AttributeSelectionPtr anAttr = - std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); - - ResultPtr aRes = std::dynamic_pointer_cast(theObject); - if (anAttr.get() && aRes.get()) { - anAttr->setValueCenter(aRes, theEdge, theType, theTemporary); - aMyFeature->execute(); - return aMyFeature->lastResult(); - } - } - return ResultPtr(); -} diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index b7c0a22c9..69b9838d4 100755 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -31,7 +31,6 @@ #include #include #include -#include #include @@ -280,13 +279,6 @@ public: * \return boolean result */ static bool isAuxiliarySketchEntity(const ObjectPtr& theObject); - - static ResultPtr createFixedByExternalCenter(const ObjectPtr& theObject, - const std::shared_ptr& theEdge, - ModelAPI_AttributeSelection::CenterType theType, - const CompositeFeaturePtr& theSketch, - bool theTemporary = false); - }; #endif diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index c7dde30bf..36b897e5f 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -77,7 +76,6 @@ #include #include #include -#include #include #include @@ -358,23 +356,10 @@ bool PartSet_WidgetPoint2D::storeValueCustom() // myYSpin->hasVariable() ? myYSpin->text().toStdString() : ""); //aPoint->setValue(!myXSpin->hasVariable() ? myXSpin->value() : aPoint->x(), // !myYSpin->hasVariable() ? myYSpin->value() : aPoint->y()); + aPoint->setValue(myXSpin->value(), myYSpin->value()); - if (myFeature->isMacro()) { - // Moving points of macro-features has been processed directly (without solver) - aPoint->setValue(myXSpin->value(), myYSpin->value()); - moveObject(myFeature); - } else { - if (!aPoint->isInitialized()) - aPoint->setValue(0., 0.); - - std::shared_ptr aMessage( - new ModelAPI_ObjectMovedMessage(this)); - aMessage->setMovedAttribute(aPoint); - aMessage->setOriginalPosition(aPoint->pnt()); - aMessage->setCurrentPosition(myXSpin->value(), myYSpin->value()); - Events_Loop::loop()->send(aMessage); - } - + // after movement the solver will call the update event: optimization + moveObject(myFeature); aPoint->setImmutable(isImmutable); that->blockSignals(isBlocked); @@ -593,7 +578,6 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo if (!aFirstValue.get() && myPreSelected.get()) { aFirstValue = myPreSelected; } - // if we have selection and use it if (aFirstValue.get() && isValidSelectionCustom(aFirstValue) && aFirstValue->shape().get()) { /// Trihedron Axis may be selected, but shape is empty @@ -709,36 +693,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo } } } - // The selection could be a center of an external circular object - else if (aFirstValue.get() && (!aFirstValue->interactive().IsNull())) { - Handle(PartSet_CenterPrs) aAIS = - Handle(PartSet_CenterPrs)::DownCast(aFirstValue->interactive()); - if (!aAIS.IsNull()) { - gp_Pnt aPntComp = aAIS->Component()->Pnt(); - GeomVertexPtr aVertPtr(new GeomAPI_Vertex(aPntComp.X(), aPntComp.Y(), aPntComp.Z())); - TopoDS_Shape aShape = aVertPtr->impl(); - - ResultPtr aFixedObject = - PartSet_Tools::findFixedObjectByExternal(aShape, aAIS->object(), mySketch); - if (!aFixedObject.get()) - aFixedObject = PartSet_Tools::createFixedByExternalCenter(aAIS->object(), aAIS->edge(), - aAIS->centerType(), mySketch); - if (aFixedObject.get()) - setConstraintToObject(aFixedObject); - // fignal updated should be flushed in order to visualize possible created - // external objects e.g. selection of trihedron axis when input end arc point - updateObject(feature()); - - double aX, aY; - if (getPoint2d(aView, aShape, aX, aY)) { - // do not create a constraint to the point, which already used by the feature - // if the feature contains the point, focus is not switched - setPoint(aX, aY); - } - emit vertexSelected(); // it stops the reentrant operation - emit focusOutWidget(this); - } - } + // End of Bug dependent fragment else { // A case when point is taken from mouse event gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView()); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 5464d078f..190b7e2a3 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -48,8 +48,6 @@ #include #include #include -#include -#include #include #include @@ -542,9 +540,6 @@ void PartSet_WidgetSketchLabel::activateSelection(bool toActivate) QIntList aModes; std::shared_ptr aPlane = plane(); if (aPlane.get()) { - //QList> aEdges = findCircularEdgesInPlane(); - //foreach(std::shared_ptr aPrs, aEdges) { - //} myWorkshop->module()->activeSelectionModes(aModes); } else { @@ -591,7 +586,7 @@ std::shared_ptr std::shared_ptr anOrigPnt(new GeomAPI_Pnt(aCoords)); // X axis is preferable to be dirX on the sketch const double tol = Precision::Confusion(); - bool isX = fabs(fabs(anA) - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol; + bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol; std::shared_ptr aTempDir( isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0)); std::shared_ptr aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir))); @@ -624,47 +619,3 @@ void PartSet_WidgetSketchLabel::onSetPlaneView() aModule->onViewTransformed(); } } - - -//****************************************************** -QList> PartSet_WidgetSketchLabel::findCircularEdgesInPlane() -{ - QList> aResult; - XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); - XGUI_Displayer* aDisplayer = aWorkshop->displayer(); - QObjectPtrList aDispObjects = aDisplayer->displayedObjects(); - - std::shared_ptr aPlane = plane(); - foreach(ObjectPtr aObj, aDispObjects) { - ResultPtr aResObj = std::dynamic_pointer_cast(aObj); - if (aResObj.get()) { - GeomShapePtr aShape = aResObj->shape(); - if (aShape.get()) { - GeomAPI_ShapeExplorer aExplorer(aShape, GeomAPI_Shape::EDGE); - for(; aExplorer.more(); aExplorer.next()) { - GeomShapePtr aEdgeShape = aExplorer.current(); - GeomAPI_Edge anEdge(aEdgeShape); - if ((anEdge.isCircle() || anEdge.isArc() || anEdge.isEllipse()) && - anEdge.isInPlane(aPlane)) { - bool isContains = false; - // Check that edge is not used. - // It is possible that the same edge will be taken from different faces - foreach(std::shared_ptr aPrs, aResult) { - GeomAPI_Edge aUsedEdge(aPrs->shape()); - if (aUsedEdge.isEqual(aEdgeShape)) { - isContains = true; - break; - } - } - if (!isContains) { - std::shared_ptr - aPrs(new ModuleBase_ViewerPrs(aResObj, aEdgeShape)); - aResult.append(aPrs); - } - } - } - } - } - } - return aResult; -} diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 5cc4a10cf..515c0377a 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -192,13 +192,6 @@ protected: /// \param thePlane a plane std::shared_ptr setSketchPlane(std::shared_ptr thePlane); - /** - * Returns list of presentations which have displayed shapes with circular edges - * (circles, arcs) which are in pane of of the given sketch - * \param theSketch - the sketch - */ - QList> findCircularEdgesInPlane(); - private: /// class to show/hide preview planes PartSet_PreviewPlanes* myPreviewPlanes; diff --git a/src/PythonAPI/model/sketcher/__init__.py b/src/PythonAPI/model/sketcher/__init__.py index 8c0319a1e..b015b4278 100644 --- a/src/PythonAPI/model/sketcher/__init__.py +++ b/src/PythonAPI/model/sketcher/__init__.py @@ -3,4 +3,3 @@ from SketchAPI import addSketch from tools import * -from tests import * diff --git a/src/PythonAPI/model/sketcher/tests.py b/src/PythonAPI/model/sketcher/tests.py deleted file mode 100644 index ea690813d..000000000 --- a/src/PythonAPI/model/sketcher/tests.py +++ /dev/null @@ -1,93 +0,0 @@ -## Copyright (C) 2017 CEA/DEN, EDF R&D -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## See http:##www.salome-platform.org/ or -## email : webmaster.salome@opencascade.com -## - -from ModelAPI import * -from GeomDataAPI import * -import ModelHighAPI -import math -from salome.shaper.model.sketcher import tools - -TOLERANCE = 1.e-7 - -def assertPoint(thePoint, theCoords): - """ Verifies coordinates of the point - """ - aPoint = tools.toList(thePoint) - assert aPoint[0] == theCoords[0] and aPoint[1] == theCoords[1], "Wrong '{}' point {}, expected {}".format(thePoint.id(), aPoint, theCoords) - - -def assertLine(theLine, theStart, theEnd): - """ Verifies coordinates of line extremities - """ - aLine = tools.toSketchFeature(theLine) - - aStartPnt = geomDataAPI_Point2D(aLine.attribute("StartPoint")) - aEndPnt = geomDataAPI_Point2D(aLine.attribute("EndPoint")) - if len(theStart): - assertPoint(aStartPnt, theStart) - if len(theEnd): - assertPoint(aEndPnt, theEnd) - - -def assertCircle(theCircle, theCenter, theRadius): - """ Verifies attributes of circle - """ - aCircle = tools.toSketchFeature(theCircle) - - aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center")) - if len(theCenter): - assertPoint(aCenter, theCenter) - - aRadius = aCircle.real("circle_radius") - assert aRadius.value() == theRadius, "Wrong circle radius {}, expected {}".format(aRadius.value(), theRadius) - - -def assertArc(theArc, theCenter, theStart, theEnd): - """ Verifies coordinates of arc points and the consistency of the arc. - Some of points may be empty lists. - """ - anArc = tools.toSketchFeature(theArc) - - aCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point")) - aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point")) - aEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point")) - if len(theCenter): - assertPoint(aCenterPnt, theCenter) - if len(theStart): - assertPoint(aStartPnt, theStart) - if len(theEnd): - assertPoint(aEndPnt, theEnd) - - assertArcValidity(anArc) - - -def assertArcValidity(theArc): - """ Tests whether the arc is correctly defined - """ - anArc = tools.toSketchFeature(theArc) - - aCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point")) - aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point")) - aEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point")) - aRadius = anArc.real("radius") - aDistCS = tools.distancePointPoint(aCenterPnt, aStartPnt) - aDistCE = tools.distancePointPoint(aCenterPnt, aEndPnt) - assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE) - assert math.fabs(aRadius.value() - aDistCS) < TOLERANCE, "Wrong arc: radius is {}, expected {}".format(aRadius.value(), aDistCS) diff --git a/src/PythonAPI/model/sketcher/tools.py b/src/PythonAPI/model/sketcher/tools.py index e93fec49c..de3032f54 100644 --- a/src/PythonAPI/model/sketcher/tools.py +++ b/src/PythonAPI/model/sketcher/tools.py @@ -19,9 +19,7 @@ ## import ModelHighAPI -from GeomDataAPI import * -from ModelAPI import * -import math +import GeomDataAPI def addPolyline(sketch, *coords): """Add a poly-line to sketch. @@ -71,45 +69,19 @@ 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]) - -def distancePointLine(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 math.fabs(aCross / aLineLen) + 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 lastSubFeature(theSketch, theKind): """ obtains last feature of given kind from the sketch """ - aSketch = featureToCompositeFeature(toSketchFeature(theSketch)) - for anIndex in range(aSketch.numberOfSubs() - 1, -1, -1): - aSub = aSketch.subFeature(anIndex) + for anIndex in range(theSketch.numberOfSubs() - 1, -1, -1): + aSub = theSketch.subFeature(anIndex) if (aSub.getKind() == theKind): return aSub - -def toSketchFeature(theEntity): - """ Converts entity to sketch feature if possible - """ - if issubclass(type(theEntity), ModelHighAPI.ModelHighAPI_Interface): - return theEntity.feature() - else: - return theEntity - -def toList(thePoint): - if issubclass(type(thePoint), list): - return thePoint - elif issubclass(type(thePoint), GeomDataAPI_Point2D): - return [thePoint.x(), thePoint.y()] - else: - aFeature = toSketchFeature(thePoint) - aPoint = geomDataAPI_Point2D(aFeature.attribute("PointCoordinates")) - return [aPoint.x(), aPoint.y()] diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index 9b1d6c713..f75e4ae0f 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -23,6 +23,9 @@ from GeomAPI import * from GeomDataAPI import * from ModelAPI import ModelAPI_Feature import math +from salome.shaper.model import sketcher + +TOLERANCE = 1.e-7 aShapeTypes = { GeomAPI_Shape.SOLID: "GeomAPI_Shape.SOLID", @@ -174,3 +177,15 @@ def testNbSubFeatures(theComposite, theKindOfSub, theExpectedCount): if aFeature is not None and aFeature.getKind() == theKindOfSub: count += 1 assert (count == theExpectedCount), "Number of sub-features of type {}: {}, expected {}".format(theKindOfSub, count, theExpectedCount) + +def assertSketchArc(theArcFeature): + """ Tests whether the arc is correctly defined + """ + aCenterPnt = geomDataAPI_Point2D(theArcFeature.attribute("center_point")) + aStartPnt = geomDataAPI_Point2D(theArcFeature.attribute("start_point")) + aEndPnt = geomDataAPI_Point2D(theArcFeature.attribute("end_point")) + aRadius = theArcFeature.real("radius") + aDistCS = sketcher.tools.distancePointPoint(aCenterPnt, aStartPnt) + aDistCE = sketcher.tools.distancePointPoint(aCenterPnt, aEndPnt) + assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE) + assert math.fabs(aRadius.value() -aDistCS) < TOLERANCE, "Wrong arc: radius is {0}, expected {1}".format(aRadius.value(), aDistCS) diff --git a/src/SketchAPI/SketchAPI_Constraint.cpp b/src/SketchAPI/SketchAPI_Constraint.cpp index d655ff2af..b777eadde 100644 --- a/src/SketchAPI/SketchAPI_Constraint.cpp +++ b/src/SketchAPI/SketchAPI_Constraint.cpp @@ -28,8 +28,6 @@ #include #include #include -#include -#include #include #include #include @@ -84,14 +82,6 @@ static const std::string& constraintTypeToSetter(const std::string& theType) static const std::string DISTANCE_SETTER("setDistance"); return DISTANCE_SETTER; } - if (theType == SketchPlugin_ConstraintDistanceHorizontal::ID()) { - static const std::string DISTANCE_SETTER("setHorizontalDistance"); - return DISTANCE_SETTER; - } - if (theType == SketchPlugin_ConstraintDistanceVertical::ID()) { - static const std::string DISTANCE_SETTER("setVerticalDistance"); - return DISTANCE_SETTER; - } if (theType == SketchPlugin_ConstraintEqual::ID()) { static const std::string EQUAL_SETTER("setEqual"); return EQUAL_SETTER; diff --git a/src/SketchAPI/SketchAPI_Rectangle.cpp b/src/SketchAPI/SketchAPI_Rectangle.cpp index 135285e6a..6fa94f420 100644 --- a/src/SketchAPI/SketchAPI_Rectangle.cpp +++ b/src/SketchAPI/SketchAPI_Rectangle.cpp @@ -78,13 +78,3 @@ void SketchAPI_Rectangle::setByPoints( } //-------------------------------------------------------------------------------------- - -std::list > SketchAPI_Rectangle::lines() const -{ - std::list aFeatures; - std::list aList = linesList()->list(); - std::list::const_iterator anIt = aList.begin(); - for (; anIt != aList.end(); ++anIt) - aFeatures.push_back(ModelAPI_Feature::feature(*anIt)); - return SketchAPI_SketchEntity::wrap(aFeatures); -} diff --git a/src/SketchAPI/SketchAPI_Rectangle.h b/src/SketchAPI/SketchAPI_Rectangle.h index b9fe8fced..fb63cec63 100644 --- a/src/SketchAPI/SketchAPI_Rectangle.h +++ b/src/SketchAPI/SketchAPI_Rectangle.h @@ -65,9 +65,6 @@ public: SKETCHAPI_EXPORT void setByPoints(const std::shared_ptr & theStartPoint, const std::shared_ptr & theEndPoint); - - /// List of lines composing rectangle - SKETCHAPI_EXPORT std::list > lines() const; }; //! Pointer on Rectangle object diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index daefc491e..b3b26c0d0 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -25,8 +25,6 @@ #include #include #include -#include -#include #include #include #include @@ -43,7 +41,6 @@ #include #include //-------------------------------------------------------------------------------------- -#include #include #include #include @@ -66,10 +63,6 @@ #include "SketchAPI_Rotation.h" #include "SketchAPI_Translation.h" //-------------------------------------------------------------------------------------- -#include -#include -#include -//-------------------------------------------------------------------------------------- SketchAPI_Sketch::SketchAPI_Sketch( const std::shared_ptr & theFeature) : ModelHighAPI_Interface(theFeature) @@ -638,34 +631,6 @@ std::shared_ptr SketchAPI_Sketch::setDistance( return InterfacePtr(new ModelHighAPI_Interface(aFeature)); } -std::shared_ptr SketchAPI_Sketch::setHorizontalDistance( - const ModelHighAPI_RefAttr & thePoint1, - const ModelHighAPI_RefAttr & thePoint2, - const ModelHighAPI_Double & theValue) -{ - std::shared_ptr aFeature = - compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID()); - fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())); - fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B())); - fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE())); - aFeature->execute(); - return InterfacePtr(new ModelHighAPI_Interface(aFeature)); -} - -std::shared_ptr SketchAPI_Sketch::setVerticalDistance( - const ModelHighAPI_RefAttr & thePoint1, - const ModelHighAPI_RefAttr & thePoint2, - const ModelHighAPI_Double & theValue) -{ - std::shared_ptr aFeature = - compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID()); - fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())); - fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B())); - fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE())); - aFeature->execute(); - return InterfacePtr(new ModelHighAPI_Interface(aFeature)); -} - std::shared_ptr SketchAPI_Sketch::setEqual( const ModelHighAPI_RefAttr & theObject1, const ModelHighAPI_RefAttr & theObject2) @@ -810,127 +775,6 @@ std::shared_ptr SketchAPI_Sketch::setVertical( //-------------------------------------------------------------------------------------- -static std::shared_ptr pointCoordinates(const AttributePtr& thePoint) -{ - AttributePoint2DPtr aPnt = std::dynamic_pointer_cast(thePoint); - if (aPnt) - return aPnt->pnt(); - return std::shared_ptr(); -} - -static std::shared_ptr middlePointOnLine(const FeaturePtr& theFeature) -{ - AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast( - theFeature->attribute(SketchPlugin_Line::START_ID())); - AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast( - theFeature->attribute(SketchPlugin_Line::END_ID())); - - if (!aStartAttr || !aEndAttr) - return std::shared_ptr(); - - std::shared_ptr aStartPoint = aStartAttr->pnt()->xy(); - std::shared_ptr aEndPoint = aEndAttr->pnt()->xy(); - return std::shared_ptr( - new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5))); -} - -static std::shared_ptr pointOnCircle(const FeaturePtr& theFeature) -{ - AttributePoint2DPtr aCenter = std::dynamic_pointer_cast( - theFeature->attribute(SketchPlugin_Circle::CENTER_ID())); - AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID()); - - if (!aCenter || !aRadius) - return std::shared_ptr(); - - return std::shared_ptr( - new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y())); -} - -static std::shared_ptr middlePointOnArc(const FeaturePtr& theFeature) -{ - static const double PI = 3.141592653589793238463; - - AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast( - theFeature->attribute(SketchPlugin_Arc::CENTER_ID())); - AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast( - theFeature->attribute(SketchPlugin_Arc::START_ID())); - AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast( - theFeature->attribute(SketchPlugin_Arc::END_ID())); - - if (!aCenterAttr || !aStartAttr || !aEndAttr) - return std::shared_ptr(); - - std::shared_ptr aStartDir(new GeomAPI_Dir2d( - aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y())); - std::shared_ptr aEndDir(new GeomAPI_Dir2d( - aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y())); - - double anAngle = aStartDir->angle(aEndDir); - bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value(); - if (isReversed && anAngle > 0.) - anAngle -= 2.0 * PI; - else if (!isReversed && anAngle <= 0.) - anAngle += 2.0 * PI; - - double cosA = cos(anAngle); - double sinA = sin(anAngle); - - // rotate start dir to find middle point on arc - double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt()); - double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA); - double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA); - - return std::shared_ptr(new GeomAPI_Pnt2d(x, y)); -} - -static std::shared_ptr middlePoint(const ObjectPtr& theObject) -{ - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - if (aFeature) { - const std::string& aFeatureKind = aFeature->getKind(); - if (aFeatureKind == SketchPlugin_Point::ID()) - return pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID())); - else if (aFeatureKind == SketchPlugin_Line::ID()) - return middlePointOnLine(aFeature); - else if (aFeatureKind == SketchPlugin_Circle::ID()) - return pointOnCircle(aFeature); - else if (aFeatureKind == SketchPlugin_Arc::ID()) - return middlePointOnArc(aFeature); - } - // do not move other types of features - return std::shared_ptr(); -} - -void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity, - const std::shared_ptr& theTargetPoint) -{ - std::shared_ptr aMessage(new ModelAPI_ObjectMovedMessage); - theMovedEntity.fillMessage(aMessage); - - std::shared_ptr anOriginalPosition; - if (aMessage->movedAttribute()) - anOriginalPosition = pointCoordinates(aMessage->movedAttribute()); - else - anOriginalPosition = middlePoint(aMessage->movedObject()); - - if (!anOriginalPosition) - return; // something has gone wrong, do not process movement - - aMessage->setOriginalPosition(anOriginalPosition); - aMessage->setCurrentPosition(theTargetPoint); - Events_Loop::loop()->send(aMessage); -} - -void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity, - double theTargetX, double theTargetY) -{ - std::shared_ptr aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY)); - move(theMovedEntity, aTargetPoint); -} - -//-------------------------------------------------------------------------------------- - std::shared_ptr SketchAPI_Sketch::to2D(const std::shared_ptr& thePoint) { FeaturePtr aBase = feature(); diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index f17851444..b62e9c3af 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -333,20 +333,6 @@ public: const ModelHighAPI_RefAttr & thePointOrLine, const ModelHighAPI_Double & theValue); - /// Set horizontal distance - SKETCHAPI_EXPORT - std::shared_ptr setHorizontalDistance( - const ModelHighAPI_RefAttr & thePoint1, - const ModelHighAPI_RefAttr & thePoint2, - const ModelHighAPI_Double & theValue); - - /// Set vertical distance - SKETCHAPI_EXPORT - std::shared_ptr setVerticalDistance( - const ModelHighAPI_RefAttr & thePoint1, - const ModelHighAPI_RefAttr & thePoint2, - const ModelHighAPI_Double & theValue); - /// Set equal SKETCHAPI_EXPORT std::shared_ptr setEqual( @@ -421,16 +407,6 @@ public: const std::shared_ptr & theConstraint, const ModelHighAPI_Double & theValue); - /// Move point or sketch feature - SKETCHAPI_EXPORT - void move(const ModelHighAPI_RefAttr& theMovedEntity, - const std::shared_ptr& theTargetPoint); - - /// Move point or sketch feature - SKETCHAPI_EXPORT - void move(const ModelHighAPI_RefAttr& theMovedEntity, - double theTargetX, double theTargetY); - SKETCHAPI_EXPORT std::shared_ptr to2D(const std::shared_ptr& thePoint); diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index bacf4249a..82e27cd77 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -31,9 +31,8 @@ SET(PROJECT_HEADERS 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,16 +43,13 @@ SET(PROJECT_HEADERS 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 SketchPlugin_MacroArcReentrantMessage.h SketchPlugin_MacroCircle.h - SketchPlugin_MacroEllipse.h SketchPlugin_MultiRotation.h SketchPlugin_MultiTranslation.h SketchPlugin_Plugin.h @@ -76,9 +72,8 @@ SET(PROJECT_SOURCES 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,15 +84,12 @@ SET(PROJECT_SOURCES 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 SketchPlugin_MacroCircle.cpp - SketchPlugin_MacroEllipse.cpp SketchPlugin_MultiRotation.cpp SketchPlugin_MultiTranslation.cpp SketchPlugin_Plugin.cpp @@ -163,15 +155,11 @@ ADD_UNIT_TESTS(TestSketchPointLine.py TestConstraintCollinear.py TestConstraintLength.py TestConstraintDistance.py - TestConstraintDistanceHorizontal.py - TestConstraintDistanceVertical.py - TestConstraintDistanceBehavior.py TestConstraintParallel.py TestConstraintPerpendicular.py TestConstraintRadius.py TestConstraintFixed.py TestConstraintHorizontal.py - TestConstraintHorizontalValidator.py TestConstraintVertical.py TestConstraintEqual.py TestConstraintTangent.py @@ -210,10 +198,4 @@ ADD_UNIT_TESTS(TestSketchPointLine.py TestTrimCircle05.py TestTrimCircleAndArc01.py TestTrimLine01.py - TestTrimLine02.py - TestMovePoint.py - TestMoveLine.py - TestMoveCircle.py - TestMoveArc.py - TestMovementComplex.py -) + TestTrimLine02.py) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index f4a02ca41..4d299b6b0 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -178,32 +178,6 @@ double SketchPlugin_ConstraintDistance::calculateCurrentDistance() return aDistance; } -bool SketchPlugin_ConstraintDistance::areAttributesInitialized() -{ - std::shared_ptr aData = data(); - std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); - std::shared_ptr aPointA = - SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A(), aPlane); - std::shared_ptr aPointB = - SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B(), aPlane); - - if (!aPointA && !aPointB) - return false; - else if (aPointA || aPointB) { - FeaturePtr aLine; - if (!aPointA) - aLine = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); - else if (!aPointB) - aLine = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); - else // both points are initialized - return true; - - if (!aLine || aLine->getKind() != SketchPlugin_Line::ID()) - return false; - } - return true; -} - void SketchPlugin_ConstraintDistance::attributeChanged(const std::string& theID) { if (theID == SketchPlugin_Constraint::ENTITY_A() || diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index c2dc3ee40..8c96dfa29 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -85,10 +85,7 @@ class SketchPlugin_ConstraintDistance : public SketchPlugin_ConstraintBase protected: /// Returns the current distance between the feature attributes - virtual double calculateCurrentDistance(); - - /// Check the attributes related to distanced points/features are initialized - bool areAttributesInitialized(); + double calculateCurrentDistance(); private: bool myFlyoutUpdate; ///< to avoid cyclic dependencies on automatic updates of flyout point diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp deleted file mode 100644 index 4d9216477..000000000 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: SketchPlugin_ConstraintDistanceHorizontal.cpp -// Created: 2 May 2017 -// Author: Artem ZHIDKOV - -#include - -#include -#include - -#include -#include -#include - -#include - -const double tolerance = 1e-7; - - -SketchPlugin_ConstraintDistanceHorizontal::SketchPlugin_ConstraintDistanceHorizontal() - : SketchPlugin_ConstraintDistance() -{ -} - -//************************************************************************************* -void SketchPlugin_ConstraintDistanceHorizontal::initAttributes() -{ - data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); -} - -//************************************************************************************* -void SketchPlugin_ConstraintDistanceHorizontal::execute() -{ - AttributeDoublePtr anAttrValue = real(SketchPlugin_Constraint::VALUE()); - if (anAttrValue->isInitialized() || !areAttributesInitialized()) - return; - - double aDistance = calculateCurrentDistance(); - anAttrValue->setValue(aDistance); -} - -//************************************************************************************* -AISObjectPtr SketchPlugin_ConstraintDistanceHorizontal::getAISObject(AISObjectPtr thePrevious) -{ - if (!sketch()) - return thePrevious; - - AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, - sketch()->coordinatePlane(), - thePrevious); - return anAIS; -} - -//************************************************************************************* -void SketchPlugin_ConstraintDistanceHorizontal::move(double theDeltaX, double theDeltaY) -{ - std::shared_ptr aData = data(); - if (!aData->isValid()) - return; - - // Recalculate a shift of flyout point in terms of local coordinates - std::shared_ptr aDir(new GeomAPI_XY(theDeltaX, theDeltaY)); - std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); - std::shared_ptr aPointA = SketcherPrs_Tools::getFeaturePoint( - data(), SketchPlugin_Constraint::ENTITY_A(), aPlane); - std::shared_ptr aPointB = SketcherPrs_Tools::getFeaturePoint( - data(), SketchPlugin_Constraint::ENTITY_B(), aPlane); - - if (!aPointA || !aPointB) - return; - - std::shared_ptr aStartPnt = aPointA->pnt()->xy(); - std::shared_ptr aEndPnt = aPointB->pnt()->xy(); - - std::shared_ptr aLineDir(new GeomAPI_Dir2d(aEndPnt->decreased(aStartPnt))); - double dX = aDir->dot(aLineDir->xy()); - double dY = -aDir->cross(aLineDir->xy()); - - std::shared_ptr aPoint = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - myFlyoutUpdate = true; - if (aPoint->isInitialized()) { - aPoint->setValue(aPoint->x() + dX, aPoint->y() + dY); - } else { - aPoint->setValue(dX, dY); - } - myFlyoutUpdate = false; -} - -double SketchPlugin_ConstraintDistanceHorizontal::calculateCurrentDistance() -{ - std::shared_ptr aData = data(); - std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); - std::shared_ptr aPointA = - SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A(), aPlane); - std::shared_ptr aPointB = - SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B(), aPlane); - - return aPointB->x() - aPointA->x(); -} - -void SketchPlugin_ConstraintDistanceHorizontal::attributeChanged(const std::string& theID) -{ - if (theID == SketchPlugin_Constraint::ENTITY_A() || - theID == SketchPlugin_Constraint::ENTITY_B()) - { - AttributeDoublePtr aValueAttr = real(SketchPlugin_Constraint::VALUE()); - if (!aValueAttr->isInitialized() && areAttributesInitialized()) { - // only if it is not initialized, try to compute the current value - double aDistance = calculateCurrentDistance(); - aValueAttr->setValue(aDistance); - } - } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) { - myFlyoutUpdate = true; - // Recalculate flyout point in local coordinates of the distance constraint: - // the X coordinate is a length of projection of the flyout point on the - // line binding two distanced points - // or a line of projection of the distanced point onto the distanced segment - // the Y coordinate is a distance from the flyout point to the line - std::shared_ptr aFlyoutAttr = - std::dynamic_pointer_cast( - attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - std::shared_ptr aFlyoutPnt = aFlyoutAttr->pnt(); - - std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); - std::shared_ptr aPointA = SketcherPrs_Tools::getFeaturePoint( - data(), SketchPlugin_Constraint::ENTITY_A(), aPlane); - std::shared_ptr aPointB = SketcherPrs_Tools::getFeaturePoint( - data(), SketchPlugin_Constraint::ENTITY_B(), aPlane); - - std::shared_ptr aStartPnt = aPointA->pnt()->xy(); - std::shared_ptr aEndPnt = aPointB->pnt()->xy(); - - if (aEndPnt->distance(aStartPnt) < tolerance) - return; - - std::shared_ptr aLineDir(new GeomAPI_Dir2d(aEndPnt->decreased(aStartPnt))); - std::shared_ptr aFlyoutDir = aFlyoutPnt->xy()->decreased(aStartPnt); - - double X = aFlyoutDir->dot(aLineDir->xy()); - double Y = -aFlyoutDir->cross(aLineDir->xy()); - aFlyoutAttr->setValue(X, Y); - myFlyoutUpdate = false; - } -} diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.h b/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.h deleted file mode 100644 index 98ef11796..000000000 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: SketchPlugin_ConstraintDistanceHorizontal.h -// Created: 2 May 2017 -// Author: Artem ZHIDKOV - -#ifndef SketchPlugin_ConstraintDistanceHorizontal_H_ -#define SketchPlugin_ConstraintDistanceHorizontal_H_ - -#include -#include - -/** \class SketchPlugin_ConstraintDistanceHorizontal - * \ingroup Plugins - * \brief Feature for creation of a new constraint which defines a horizontal distance between two points. - * - * This constraint has three attributes: - * SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() - */ -class SketchPlugin_ConstraintDistanceHorizontal : public SketchPlugin_ConstraintDistance -{ -public: - /// Distance constraint kind - inline static const std::string& ID() - { - static const std::string MY_CONSTRAINT_DISTANCE_ID("SketchConstraintDistanceHorizontal"); - return MY_CONSTRAINT_DISTANCE_ID; - } - - /// \brief Returns the kind of a feature - SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - { - static std::string MY_KIND = SketchPlugin_ConstraintDistanceHorizontal::ID(); - return MY_KIND; - } - - /// \brief Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(); - - /// \brief Request for initialization of data model of the feature: adding all attributes - SKETCHPLUGIN_EXPORT virtual void initAttributes(); - - /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); - - /// Moves the feature - /// \param theDeltaX the delta for X coordinate is moved - /// \param theDeltaY the delta for Y coordinate is moved - SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY); - - /// Called on change of any argument-attribute of this object - /// \param theID identifier of changed attribute - SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); - - /// \brief Use plugin manager for features creation - SketchPlugin_ConstraintDistanceHorizontal(); - -protected: - /// Returns the current distance between the feature attributes - virtual double calculateCurrentDistance(); - -private: - bool myFlyoutUpdate; ///< to avoid cyclic dependencies on automatic updates of flyout point -}; - -#endif diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.cpp deleted file mode 100644 index 6691ee51b..000000000 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.cpp +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: SketchPlugin_ConstraintDistanceVertical.cpp -// Created: 10 May 2017 -// Author: Artem ZHIDKOV - -#include - -#include -#include - -#include -#include -#include - -#include - -const double tolerance = 1e-7; - - -SketchPlugin_ConstraintDistanceVertical::SketchPlugin_ConstraintDistanceVertical() - : SketchPlugin_ConstraintDistance() -{ -} - -//************************************************************************************* -void SketchPlugin_ConstraintDistanceVertical::initAttributes() -{ - data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); -} - -//************************************************************************************* -void SketchPlugin_ConstraintDistanceVertical::execute() -{ - AttributeDoublePtr anAttrValue = real(SketchPlugin_Constraint::VALUE()); - if (anAttrValue->isInitialized() || !areAttributesInitialized()) - return; - - double aDistance = calculateCurrentDistance(); - anAttrValue->setValue(aDistance); -} - -//************************************************************************************* -AISObjectPtr SketchPlugin_ConstraintDistanceVertical::getAISObject(AISObjectPtr thePrevious) -{ - if (!sketch()) - return thePrevious; - - AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, - sketch()->coordinatePlane(), - thePrevious); - return anAIS; -} - -//************************************************************************************* -void SketchPlugin_ConstraintDistanceVertical::move(double theDeltaX, double theDeltaY) -{ - std::shared_ptr aData = data(); - if (!aData->isValid()) - return; - - // Recalculate a shift of flyout point in terms of local coordinates - std::shared_ptr aDir(new GeomAPI_XY(theDeltaX, theDeltaY)); - std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); - std::shared_ptr aPointA = SketcherPrs_Tools::getFeaturePoint( - data(), SketchPlugin_Constraint::ENTITY_A(), aPlane); - std::shared_ptr aPointB = SketcherPrs_Tools::getFeaturePoint( - data(), SketchPlugin_Constraint::ENTITY_B(), aPlane); - - if (!aPointA || !aPointB) - return; - - std::shared_ptr aStartPnt = aPointA->pnt()->xy(); - std::shared_ptr aEndPnt = aPointB->pnt()->xy(); - - std::shared_ptr aLineDir(new GeomAPI_Dir2d(aEndPnt->decreased(aStartPnt))); - double dX = aDir->dot(aLineDir->xy()); - double dY = -aDir->cross(aLineDir->xy()); - - std::shared_ptr aPoint = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - myFlyoutUpdate = true; - if (aPoint->isInitialized()) { - aPoint->setValue(aPoint->x() + dX, aPoint->y() + dY); - } else { - aPoint->setValue(dX, dY); - } - myFlyoutUpdate = false; -} - -double SketchPlugin_ConstraintDistanceVertical::calculateCurrentDistance() -{ - std::shared_ptr aData = data(); - std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); - std::shared_ptr aPointA = - SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A(), aPlane); - std::shared_ptr aPointB = - SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B(), aPlane); - - return aPointB->y() - aPointA->y(); -} - -void SketchPlugin_ConstraintDistanceVertical::attributeChanged(const std::string& theID) -{ - if (theID == SketchPlugin_Constraint::ENTITY_A() || - theID == SketchPlugin_Constraint::ENTITY_B()) - { - AttributeDoublePtr aValueAttr = real(SketchPlugin_Constraint::VALUE()); - if (!aValueAttr->isInitialized() && areAttributesInitialized()) { - // only if it is not initialized, try to compute the current value - double aDistance = calculateCurrentDistance(); - aValueAttr->setValue(aDistance); - } - } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) { - myFlyoutUpdate = true; - // Recalculate flyout point in local coordinates of the distance constraint: - // the X coordinate is a length of projection of the flyout point on the - // line binding two distanced points - // or a line of projection of the distanced point onto the distanced segment - // the Y coordinate is a distance from the flyout point to the line - std::shared_ptr aFlyoutAttr = - std::dynamic_pointer_cast( - attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - std::shared_ptr aFlyoutPnt = aFlyoutAttr->pnt(); - - std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); - std::shared_ptr aPointA = SketcherPrs_Tools::getFeaturePoint( - data(), SketchPlugin_Constraint::ENTITY_A(), aPlane); - std::shared_ptr aPointB = SketcherPrs_Tools::getFeaturePoint( - data(), SketchPlugin_Constraint::ENTITY_B(), aPlane); - - std::shared_ptr aStartPnt = aPointA->pnt()->xy(); - std::shared_ptr aEndPnt = aPointB->pnt()->xy(); - - if (aEndPnt->distance(aStartPnt) < tolerance) - return; - - std::shared_ptr aLineDir(new GeomAPI_Dir2d(aEndPnt->decreased(aStartPnt))); - std::shared_ptr aFlyoutDir = aFlyoutPnt->xy()->decreased(aStartPnt); - - double X = aFlyoutDir->dot(aLineDir->xy()); - double Y = -aFlyoutDir->cross(aLineDir->xy()); - aFlyoutAttr->setValue(X, Y); - myFlyoutUpdate = false; - } -} diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.h b/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.h deleted file mode 100644 index 784770061..000000000 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: SketchPlugin_ConstraintDistanceVertical.h -// Created: 10 May 2017 -// Author: Artem ZHIDKOV - -#ifndef SketchPlugin_ConstraintDistanceVertical_H_ -#define SketchPlugin_ConstraintDistanceVertical_H_ - -#include -#include - -/** \class SketchPlugin_ConstraintDistanceVertical - * \ingroup Plugins - * \brief Feature for creation of a new constraint which defines a vertical distance between two points. - * - * This constraint has three attributes: - * SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() - */ -class SketchPlugin_ConstraintDistanceVertical : public SketchPlugin_ConstraintDistance -{ -public: - /// Distance constraint kind - inline static const std::string& ID() - { - static const std::string MY_CONSTRAINT_DISTANCE_ID("SketchConstraintDistanceVertical"); - return MY_CONSTRAINT_DISTANCE_ID; - } - - /// \brief Returns the kind of a feature - SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - { - static std::string MY_KIND = SketchPlugin_ConstraintDistanceVertical::ID(); - return MY_KIND; - } - - /// \brief Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(); - - /// \brief Request for initialization of data model of the feature: adding all attributes - SKETCHPLUGIN_EXPORT virtual void initAttributes(); - - /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); - - /// Moves the feature - /// \param theDeltaX the delta for X coordinate is moved - /// \param theDeltaY the delta for Y coordinate is moved - SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY); - - /// Called on change of any argument-attribute of this object - /// \param theID identifier of changed attribute - SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); - - /// \brief Use plugin manager for features creation - SketchPlugin_ConstraintDistanceVertical(); - -protected: - /// Returns the current distance between the feature attributes - virtual double calculateCurrentDistance(); - -private: - bool myFlyoutUpdate; ///< to avoid cyclic dependencies on automatic updates of flyout point -}; - -#endif diff --git a/src/SketchPlugin/SketchPlugin_Ellipse.cpp b/src/SketchPlugin/SketchPlugin_Ellipse.cpp deleted file mode 100644 index d9f61e165..000000000 --- a/src/SketchPlugin/SketchPlugin_Ellipse.cpp +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: SketchPlugin_Ellipse.cpp -// Created: 26 April 2017 -// Author: Artem ZHIDKOV - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -static const double tolerance = 1e-7; - - -SketchPlugin_Ellipse::SketchPlugin_Ellipse() -: SketchPlugin_SketchEntity() -{ -} - -void SketchPlugin_Ellipse::initDerivedClassAttributes() -{ - data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(FOCUS_ID(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(MAJOR_RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(MINOR_RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); - - data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID()); -} - -void SketchPlugin_Ellipse::execute() -{ - SketchPlugin_Sketch* aSketch = sketch(); - if(!aSketch) { - return; - } - - // Compute a ellipse in 3D view. - std::shared_ptr aCenterAttr = - std::dynamic_pointer_cast(data()->attribute(CENTER_ID())); - std::shared_ptr aFocusAttr = - std::dynamic_pointer_cast(data()->attribute(FOCUS_ID())); - AttributeDoublePtr aMajorRadiusAttr = real(MAJOR_RADIUS_ID()); - AttributeDoublePtr aMinorRadiusAttr = real(MINOR_RADIUS_ID()); - if (!aCenterAttr->isInitialized() || - !aFocusAttr->isInitialized() || - !aMajorRadiusAttr->isInitialized() || - !aMinorRadiusAttr->isInitialized()) { - return; - } - - double aMajorRadius = aMajorRadiusAttr->value(); - double aMinorRadius = aMinorRadiusAttr->value(); - if(aMajorRadius < tolerance || aMinorRadius < tolerance) { - return; - } - - // Make a visible point. - SketchPlugin_Sketch::createPoint2DResult(this, aSketch, CENTER_ID(), 0); - - std::shared_ptr aNDir = std::dynamic_pointer_cast( - aSketch->attribute(SketchPlugin_Sketch::NORM_ID())); - - // Make a visible ellipse. - std::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); - std::shared_ptr aFocus(aSketch->to3D(aFocusAttr->x(), aFocusAttr->y())); - std::shared_ptr aNormal = aNDir->dir(); - std::shared_ptr aMajorAxis(new GeomAPI_Dir(aFocus->x() - aCenter->x(), - aFocus->y() - aCenter->y(), aFocus->z() - aCenter->z())); - - std::shared_ptr anEllipseShape = - GeomAlgoAPI_EdgeBuilder::ellipse(aCenter, aNormal, aMajorAxis, aMajorRadius, aMinorRadius); - - std::shared_ptr aResult = document()->createConstruction(data(), 1); - aResult->setShape(anEllipseShape); - aResult->setIsInHistory(false); - setResult(aResult, 1); -} - -void SketchPlugin_Ellipse::move(double theDeltaX, double theDeltaY) -{ - std::shared_ptr aData = data(); - if(!aData->isValid()) { - return; - } - - std::shared_ptr aPoint = std::dynamic_pointer_cast( - aData->attribute(CENTER_ID())); - if(aPoint->isInitialized()) { - aPoint->move(theDeltaX, theDeltaY); - } -} - -bool SketchPlugin_Ellipse::isFixed() { - return data()->selection(EXTERNAL_ID())->context().get() != NULL; -} - -void SketchPlugin_Ellipse::attributeChanged(const std::string& theID) { - // the second condition for unability to move external segments anywhere - if (theID == EXTERNAL_ID() || isFixed()) { - std::shared_ptr aSelection = data()->selection(EXTERNAL_ID())->value(); - if (!aSelection) { - // empty shape in selection shows that the shape is equal to context - ResultPtr anExtRes = selection(EXTERNAL_ID())->context(); - if (anExtRes) - aSelection = anExtRes->shape(); - } - // update arguments due to the selection value - if (aSelection && !aSelection->isNull() && aSelection->isEdge()) { - std::shared_ptr anEdge( new GeomAPI_Edge(aSelection)); - std::shared_ptr anEllipse = anEdge->ellipse(); - - std::shared_ptr aCenterAttr = - std::dynamic_pointer_cast(attribute(CENTER_ID())); - aCenterAttr->setValue(sketch()->to2D(anEllipse->center())); - - std::shared_ptr aFocusAttr = - std::dynamic_pointer_cast(attribute(FOCUS_ID())); - aFocusAttr->setValue(sketch()->to2D(anEllipse->firstFocus())); - - real(MAJOR_RADIUS_ID())->setValue(anEllipse->majorRadius()); - real(MINOR_RADIUS_ID())->setValue(anEllipse->minorRadius()); - } - } -} diff --git a/src/SketchPlugin/SketchPlugin_Ellipse.h b/src/SketchPlugin/SketchPlugin_Ellipse.h deleted file mode 100644 index fc4b77c64..000000000 --- a/src/SketchPlugin/SketchPlugin_Ellipse.h +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: SketchPlugin_Ellipse.h -// Created: 26 April 2017 -// Author: Artem ZHIDKOV - -#ifndef SketchPlugin_Ellipse_H_ -#define SketchPlugin_Ellipse_H_ - -#include -#include - -/**\class SketchPlugin_Ellipse - * \ingroup Plugins - * \brief Feature for creation of the new ellipse in Sketch. - */ -class SketchPlugin_Ellipse: public SketchPlugin_SketchEntity -{ - public: - /// Ellipse feature kind - inline static const std::string& ID() - { - static const std::string ID("SketchEllipse"); - return ID; - } - - /// 2D point - center of the ellipse - inline static const std::string& CENTER_ID() - { - static const std::string ID("ellipse_center"); - return ID; - } - - /// 2D point - focus of the ellipse - inline static const std::string& FOCUS_ID() - { - static const std::string ID("ellipse_focus"); - return ID; - } - - /// Major radius of the ellipse - inline static const std::string& MAJOR_RADIUS_ID() - { - static const std::string ID("ellipse_major_radius"); - return ID; - } - - /// Minor radius of the ellipse - inline static const std::string& MINOR_RADIUS_ID() - { - static const std::string ID("ellipse_minor_radius"); - return ID; - } - - /// Returns the kind of a feature - SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - { - static std::string MY_KIND = SketchPlugin_Ellipse::ID(); - return MY_KIND; - } - - /// Returns true is sketch element is under the rigid constraint - SKETCHPLUGIN_EXPORT virtual bool isFixed(); - - /// Called on change of any argument-attribute of this object - SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); - - /// Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(); - - /// Moves the feature - /// \param theDeltaX the delta for X coordinate is moved - /// \param theDeltaY the delta for Y coordinate is moved - SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY); - - /// Use plugin manager for features creation - SketchPlugin_Ellipse(); - -protected: - /// \brief Initializes attributes of derived class. - virtual void initDerivedClassAttributes(); -}; - -#endif diff --git a/src/SketchPlugin/SketchPlugin_MacroCircle.cpp b/src/SketchPlugin/SketchPlugin_MacroCircle.cpp index 7c8768132..2b6829c72 100644 --- a/src/SketchPlugin/SketchPlugin_MacroCircle.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroCircle.cpp @@ -392,6 +392,7 @@ AISObjectPtr SketchPlugin_MacroCircle::getAISObject(AISObjectPtr thePrevious) } void SketchPlugin_MacroCircle::attributeChanged(const std::string& theID) { + double aRadius = 0.0; // If circle type switched reset all attributes. if(theID == CIRCLE_TYPE()) { SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_ID()); diff --git a/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp b/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp deleted file mode 100644 index 37ea7aa31..000000000 --- a/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp +++ /dev/null @@ -1,262 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: SketchPlugin_MacroEllipse.cpp -// Created: 26 April 2017 -// Author: Artem ZHIDKOV - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include -#include -#include - - -SketchPlugin_MacroEllipse::SketchPlugin_MacroEllipse() -: SketchPlugin_SketchEntity(), - myMajorRadius(0.0), - myMinorRadius(0.0) -{ -} - -void SketchPlugin_MacroEllipse::initAttributes() -{ - data()->addAttribute(CENTER_POINT_ID(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(CENTER_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); - data()->addAttribute(MAJOR_AXIS_POINT_ID(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(MAJOR_AXIS_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); - data()->addAttribute(PASSED_POINT_ID(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(PASSED_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); - - data()->addAttribute(MAJOR_RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(MINOR_RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId()); - - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_POINT_REF_ID()); - ModelAPI_Session::get()->validators()-> - registerNotObligatory(getKind(), MAJOR_AXIS_POINT_REF_ID()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PASSED_POINT_REF_ID()); -} - -void SketchPlugin_MacroEllipse::execute() -{ - FeaturePtr anEllipse = createEllipseFeature(); - constraintsForEllipse(anEllipse); - - // message to init reentrant operation - static Events_ID anId = ModelAPI_EventReentrantMessage::eventId(); - ReentrantMessagePtr aMessage(new ModelAPI_EventReentrantMessage(anId, this)); - aMessage->setCreatedFeature(anEllipse); - Events_Loop::loop()->send(aMessage); -} - -void SketchPlugin_MacroEllipse::attributeChanged(const std::string& theID) -{ - static const int NB_POINTS = 3; - std::string aPointAttrName[NB_POINTS] = { CENTER_POINT_ID(), - MAJOR_AXIS_POINT_ID(), - PASSED_POINT_ID() }; - std::string aPointRefName[NB_POINTS] = { CENTER_POINT_REF_ID(), - MAJOR_AXIS_POINT_REF_ID(), - PASSED_POINT_REF_ID() }; - - int aNbInitialized = 0; - std::shared_ptr anEllipsePoints[NB_POINTS]; - - for (int aPntIndex = 0; aPntIndex < NB_POINTS; ++aPntIndex) { - AttributePtr aPointAttr = attribute(aPointAttrName[aPntIndex]); - if (!aPointAttr->isInitialized()) - continue; - - AttributeRefAttrPtr aPointRef = refattr(aPointRefName[aPntIndex]); - // calculate ellipse parameters - std::shared_ptr aPassedPoint; - std::shared_ptr aTangentCurve; - SketchPlugin_Tools::convertRefAttrToPointOrTangentCurve( - aPointRef, aPointAttr, aTangentCurve, aPassedPoint); - - anEllipsePoints[aNbInitialized++] = aPassedPoint; - } - - std::shared_ptr anEllipse; - if (aNbInitialized == 2) { - std::shared_ptr aXDir(new GeomAPI_Dir2d( - anEllipsePoints[1]->x() - anEllipsePoints[0]->x(), - anEllipsePoints[1]->y() - anEllipsePoints[0]->y())); - double aMajorRad = anEllipsePoints[1]->distance(anEllipsePoints[0]); - anEllipse = std::shared_ptr( - new GeomAPI_Ellipse2d(anEllipsePoints[0], aXDir, aMajorRad, 0.5 * aMajorRad)); - } else if (aNbInitialized == 3) { - anEllipse = std::shared_ptr( - new GeomAPI_Ellipse2d(anEllipsePoints[0], anEllipsePoints[1], anEllipsePoints[2])); - } - - if (!anEllipse || anEllipse->implPtr() == 0) - return; - - myCenter = anEllipse->center(); - myFocus = anEllipse->firstFocus(); - myMajorRadius = anEllipse->majorRadius(); - myMinorRadius = anEllipse->minorRadius(); - - AttributeDoublePtr aMajorRadiusAttr = real(MAJOR_RADIUS_ID()); - AttributeDoublePtr aMinorRadiusAttr = real(MINOR_RADIUS_ID()); - - bool aWasBlocked = data()->blockSendAttributeUpdated(true); - // center attribute is used in processEvent() to set reference to reentrant arc - std::dynamic_pointer_cast(attribute(CENTER_POINT_ID()))->setValue(myCenter); - aMajorRadiusAttr->setValue(myMajorRadius); - aMinorRadiusAttr->setValue(myMinorRadius); - data()->blockSendAttributeUpdated(aWasBlocked, false); -} - -std::string SketchPlugin_MacroEllipse::processEvent( - const std::shared_ptr& theMessage) -{ - std::string aFilledAttributeName; - - ReentrantMessagePtr aReentrantMessage = - std::dynamic_pointer_cast(theMessage); - if (aReentrantMessage) { - FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature(); - ObjectPtr anObject = aReentrantMessage->selectedObject(); - AttributePtr anAttribute = aReentrantMessage->selectedAttribute(); - std::shared_ptr aClickedPoint = aReentrantMessage->clickedPoint(); - - if (aClickedPoint && (anObject || anAttribute)) { - aFilledAttributeName = CENTER_POINT_ID(); - std::string aReferenceAttributeName = CENTER_POINT_REF_ID(); - - // fill 2d point attribute - AttributePoint2DPtr aPointAttr = - std::dynamic_pointer_cast(attribute(aFilledAttributeName)); - aPointAttr->setValue(aClickedPoint); - - // fill reference attribute - AttributeRefAttrPtr aRefAttr = - std::dynamic_pointer_cast(attribute(aReferenceAttributeName)); - if (anAttribute) { - if (!anAttribute->owner() || !anAttribute->owner()->data()->isValid()) { - if (aCreatedFeature && anAttribute->id() == CENTER_POINT_ID()) - anAttribute = aCreatedFeature->attribute(SketchPlugin_Ellipse::CENTER_ID()); - } - aRefAttr->setAttr(anAttribute); - } - else if (anObject.get()) { - // if presentation of previous reentrant macro arc is used, the object is invalid, - // we should use result of previous feature of the message(Arc) - if (!anObject->data()->isValid()) - anObject = aCreatedFeature->lastResult(); - aRefAttr->setObject(anObject); - } - } - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - } - return aFilledAttributeName; -} - -void SketchPlugin_MacroEllipse::constraintsForEllipse(FeaturePtr theEllipseFeature) -{ - // Create constraints. - SketchPlugin_Tools::createConstraint( - this, CENTER_POINT_REF_ID(), - theEllipseFeature->attribute(SketchPlugin_Ellipse::CENTER_ID()), - ObjectPtr(), false); - SketchPlugin_Tools::createConstraint( - this, MAJOR_AXIS_POINT_REF_ID(), AttributePtr(), - theEllipseFeature->lastResult(), true); - SketchPlugin_Tools::createConstraint( - this, PASSED_POINT_REF_ID(), AttributePtr(), - theEllipseFeature->lastResult(), true); -} - -FeaturePtr SketchPlugin_MacroEllipse::createEllipseFeature() -{ - FeaturePtr aEllipseFeature = sketch()->addFeature(SketchPlugin_Ellipse::ID()); - - AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast( - aEllipseFeature->attribute(SketchPlugin_Ellipse::CENTER_ID())); - aCenterAttr->setValue(myCenter->x(), myCenter->y()); - - AttributePoint2DPtr aFocusAttr = std::dynamic_pointer_cast( - aEllipseFeature->attribute(SketchPlugin_Ellipse::FOCUS_ID())); - aFocusAttr->setValue(myFocus->x(), myFocus->y()); - - aEllipseFeature->real(SketchPlugin_Ellipse::MAJOR_RADIUS_ID())->setValue(myMajorRadius); - aEllipseFeature->real(SketchPlugin_Ellipse::MINOR_RADIUS_ID())->setValue(myMinorRadius); - - aEllipseFeature->boolean(SketchPlugin_Ellipse::AUXILIARY_ID())->setValue( - boolean(AUXILIARY_ID())->value()); - - aEllipseFeature->execute(); - return aEllipseFeature; -} - -AISObjectPtr SketchPlugin_MacroEllipse::getAISObject(AISObjectPtr thePrevious) -{ - SketchPlugin_Sketch* aSketch = sketch(); - if (!aSketch || !myCenter || myMajorRadius == 0) - return AISObjectPtr(); - - std::shared_ptr aNDir = std::dynamic_pointer_cast( - aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); - - // Compute a ellipse in 3D view. - std::shared_ptr aCenter(aSketch->to3D(myCenter->x(), myCenter->y())); - std::shared_ptr aFocus(aSketch->to3D(myFocus->x(), myFocus->y())); - std::shared_ptr aNormal = aNDir->dir(); - std::shared_ptr aMajorAxis(new GeomAPI_Dir(aFocus->x() - aCenter->x(), - aFocus->y() - aCenter->y(), aFocus->z() - aCenter->z())); - - std::shared_ptr anEllipseShape = - GeomAlgoAPI_EdgeBuilder::ellipse(aCenter, aNormal, aMajorAxis, myMajorRadius, myMinorRadius); - GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter); - if (!anEllipseShape.get() || !aCenterPointShape.get()) - return AISObjectPtr(); - - std::list > aShapes; - aShapes.push_back(anEllipseShape); - aShapes.push_back(aCenterPointShape); - - std::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes); - AISObjectPtr anAIS = thePrevious; - if (!anAIS) - anAIS.reset(new GeomAPI_AISObject()); - anAIS->createShape(aCompound); - return anAIS; -} diff --git a/src/SketchPlugin/SketchPlugin_MacroEllipse.h b/src/SketchPlugin/SketchPlugin_MacroEllipse.h deleted file mode 100644 index d31d0d55f..000000000 --- a/src/SketchPlugin/SketchPlugin_MacroEllipse.h +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: SketchPlugin_MacroEllipse.h -// Created: 26 April 2017 -// Author: Artem ZHIDKOV - -#ifndef SketchPlugin_MacroEllipse_H_ -#define SketchPlugin_MacroEllipse_H_ - -#include -#include -#include -#include - -////class GeomAPI_Circ2d; -class GeomAPI_Pnt2d; - -/**\class SketchPlugin_MacroEllipse - * \ingroup Plugins - * \brief Feature for creation of the new ellipse in Sketch. - */ -class SketchPlugin_MacroEllipse: public SketchPlugin_SketchEntity, - public GeomAPI_IPresentable, - public ModelAPI_IReentrant -{ - public: - /// Ellipse feature kind - inline static const std::string& ID() - { - static const std::string ID("SketchMacroEllipse"); - return ID; - } - - /// 2D point - center of the ellipse. - inline static const std::string& CENTER_POINT_ID() - { - static const std::string ID("center_point"); - return ID; - } - - /// Reference for center point selection. - inline static const std::string& CENTER_POINT_REF_ID() - { - static const std::string ID("center_point_ref"); - return ID; - } - - /// 2D point - major axis point of the ellipse. - inline static const std::string& MAJOR_AXIS_POINT_ID() - { - static const std::string ID("major_axis_point"); - return ID; - } - - /// Reference for major axis point selection. - inline static const std::string& MAJOR_AXIS_POINT_REF_ID() - { - static const std::string ID("major_axis_point_ref"); - return ID; - } - - /// 2D point - passed point of the ellipse - inline static const std::string& PASSED_POINT_ID() - { - static const std::string ID("passed_point"); - return ID; - } - - /// Reference for passed point selection. - inline static const std::string& PASSED_POINT_REF_ID() - { - static const std::string ID("passed_point_ref"); - return ID; - } - - /// Major radius of the ellipse - inline static const std::string& MAJOR_RADIUS_ID() - { - static const std::string ID("ellipse_major_radius"); - return ID; - } - - /// Minor radius of the ellipse - inline static const std::string& MINOR_RADIUS_ID() - { - static const std::string ID("ellipse_minor_radius"); - return ID; - } - - /// Returns the kind of a feature - SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - { - static std::string MY_KIND = SketchPlugin_MacroEllipse::ID(); - return MY_KIND; - } - - /// \brief Request for initialization of data model of the feature: adding all attributes. - SKETCHPLUGIN_EXPORT virtual void initAttributes(); - - /// Called on change of any argument-attribute of this object - SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); - - /// Returns the AIS preview - virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); - - /// Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(); - - /// Moves the feature - /// \param theDeltaX the delta for X coordinate is moved - /// \param theDeltaY the delta for Y coordinate is moved - SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) - {} - - /// Reimplemented from ModelAPI_Feature::isMacro(). - /// \returns true - SKETCHPLUGIN_EXPORT virtual bool isMacro() const - {return true;} - - SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const - {return false;} - - /// Apply information of the message to current object. It fills reference object, - /// tangent type and tangent point refence in case of tangent arc - virtual std::string processEvent(const std::shared_ptr& theMessage); - - /// Use plugin manager for features creation - SketchPlugin_MacroEllipse(); - -private: - void constraintsForEllipse(FeaturePtr theEllipseFeature); - - FeaturePtr createEllipseFeature(); - -private: - std::shared_ptr myCenter; - std::shared_ptr myFocus; - double myMajorRadius; - double myMinorRadius; -}; - -#endif diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 0a1c02678..515cc685d 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -30,8 +30,6 @@ #include #include #include -#include -#include #include #include #include @@ -52,8 +50,6 @@ #include #include #include -#include -#include #include #include @@ -130,7 +126,6 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_ArcEndPointValidator); aFactory->registerValidator("SketchPlugin_ArcEndPointIntersectionValidator", new SketchPlugin_ArcEndPointIntersectionValidator); - aFactory->registerValidator("SketchPlugin_HasNoConstraint", new SketchPlugin_HasNoConstraint); // register this plugin ModelAPI_Session::get()->registerPlugin(this); @@ -192,10 +187,6 @@ FeaturePtr SketchPlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(new SketchPlugin_ConstraintCollinear); } else if (theFeatureID == SketchPlugin_ConstraintDistance::ID()) { return FeaturePtr(new SketchPlugin_ConstraintDistance); - } else if (theFeatureID == SketchPlugin_ConstraintDistanceHorizontal::ID()) { - return FeaturePtr(new SketchPlugin_ConstraintDistanceHorizontal); - } else if (theFeatureID == SketchPlugin_ConstraintDistanceVertical::ID()) { - return FeaturePtr(new SketchPlugin_ConstraintDistanceVertical); } else if (theFeatureID == SketchPlugin_ConstraintLength::ID()) { return FeaturePtr(new SketchPlugin_ConstraintLength); } else if (theFeatureID == SketchPlugin_ConstraintParallel::ID()) { @@ -234,10 +225,6 @@ FeaturePtr SketchPlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(new SketchPlugin_MacroArc); } else if (theFeatureID == SketchPlugin_MacroCircle::ID()) { return FeaturePtr(new SketchPlugin_MacroCircle); - } else if (theFeatureID == SketchPlugin_Ellipse::ID()) { - return FeaturePtr(new SketchPlugin_Ellipse); - } else if (theFeatureID == SketchPlugin_MacroEllipse::ID()) { - return FeaturePtr(new SketchPlugin_MacroEllipse); } // feature of such kind is not found return FeaturePtr(); @@ -280,7 +267,6 @@ std::shared_ptr SketchPlugin_Plugin aMsg->setState(SketchPlugin_Line::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane); - aMsg->setState(SketchPlugin_Ellipse::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_Projection::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintCoincidence::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintCollinear::ID(), aHasSketchPlane); @@ -304,8 +290,6 @@ std::shared_ptr SketchPlugin_Plugin aMsg->setState(SketchPlugin_Trim::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_MacroArc::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_MacroCircle::ID(), aHasSketchPlane); - aMsg->setState(SketchPlugin_ConstraintDistanceHorizontal::ID(), aHasSketchPlane); - aMsg->setState(SketchPlugin_ConstraintDistanceVertical::ID(), aHasSketchPlane); // SketchRectangle is a python feature, so its ID is passed just as a string aMsg->setState("SketchRectangle", aHasSketchPlane); } diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index e16da117c..d7aaa53e9 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -1506,46 +1506,3 @@ bool SketchPlugin_ArcEndPointIntersectionValidator::isValid( return false; } - -bool SketchPlugin_HasNoConstraint::isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - Events_InfoMessage& theError) const -{ - std::set aFeatureKinds; - for (std::list::const_iterator anArgIt = theArguments.begin(); - anArgIt != theArguments.end(); anArgIt++) { - aFeatureKinds.insert(*anArgIt); - } - - if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) { - theError = "The attribute with the %1 type is not processed"; - theError.arg(theAttribute->attributeType()); - return false; - } - - AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast - (theAttribute); - bool isObject = aRefAttr->isObject(); - if (!isObject) { - theError = "It uses an empty object"; - return false; - } - ObjectPtr anObject = aRefAttr->object(); - FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); - if (!aFeature.get()) { - theError = "The feature of the checked attribute is empty"; - return false; - } - - FeaturePtr aCurrentFeature = ModelAPI_Feature::feature(aRefAttr->owner()); - - std::set aRefsList = anObject->data()->refsToMe(); - std::set::const_iterator anIt = aRefsList.begin(); - for (; anIt != aRefsList.end(); anIt++) { - FeaturePtr aRefFeature = ModelAPI_Feature::feature((*anIt)->owner()); - if (aRefFeature.get() && aCurrentFeature != aRefFeature && - aFeatureKinds.find(aRefFeature->getKind()) != aFeatureKinds.end()) - return false; // constraint is found, that means that the check is not valid - } - return true; -} diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index ccfe64328..398fd16ba 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -427,24 +427,4 @@ class SketchPlugin_ArcEndPointIntersectionValidator: public ModelAPI_AttributeVa Events_InfoMessage& theError) const; }; -/**\class SketchPlugin_HasNoConstraint - * \ingroup Validators - * \brief Validator for checking whether the feature has constraint. - * - * Checks that feature of the attribute does not have constraint with some kinds. - * The kinds of constraints should be described in parameters of the validator - * Validator processes the ModelAPI_AttributeRefAttr attribute kind - */ -class SketchPlugin_HasNoConstraint: public ModelAPI_AttributeValidator -{ - public: - //! returns true if attribute is valid - //! \param theAttribute the checked attribute - //! \param theArguments arguments of the attribute - //! \param theError error message - virtual bool isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - Events_InfoMessage& theError) const; -}; - #endif diff --git a/src/SketchPlugin/Test/TestArcBehavior.py b/src/SketchPlugin/Test/TestArcBehavior.py index 263e89a76..4c60d3696 100644 --- a/src/SketchPlugin/Test/TestArcBehavior.py +++ b/src/SketchPlugin/Test/TestArcBehavior.py @@ -163,12 +163,12 @@ for aDelta in range(0, 20): aSession.startOperation() anArcStartPoint.setValue(sx, sy+aDelta) # move start point aSession.finishOperation() - model.assertArcValidity(aSketchArc) + model.assertSketchArc(aSketchArc) for aDelta in range(20, -1, -1): aSession.startOperation() anArcStartPoint.setValue(sx, sy+aDelta) # move start point aSession.finishOperation() - model.assertArcValidity(aSketchArc) + model.assertSketchArc(aSketchArc) #========================================================================= # Test that movement of end point of arc does not break the arc #========================================================================= @@ -180,9 +180,9 @@ for aDelta in range(0, 20): aSession.startOperation() anArcEndPoint.setValue(sx+aDelta, sy) # move end point aSession.finishOperation() - model.assertArcValidity(aSketchArc) + model.assertSketchArc(aSketchArc) for aDelta in range(20, -1, -1): aSession.startOperation() anArcEndPoint.setValue(sx+aDelta, sy) # move end point aSession.finishOperation() - model.assertArcValidity(aSketchArc) + model.assertSketchArc(aSketchArc) diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py index 46ce2e4d1..b776b267b 100644 --- a/src/SketchPlugin/Test/TestConstraintDistance.py +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -51,6 +51,23 @@ from salome.shaper import model __updated__ = "2014-10-28" +def distancePointLine(point, line): + """ + subroutine to calculate distance between point and line + result of calculated distance is has 10**-5 precision + """ + aStartPoint = geomDataAPI_Point2D(line.attribute("StartPoint")) + aEndPoint = geomDataAPI_Point2D(line.attribute("EndPoint")) + # orthogonal direction + aDirX = -(aEndPoint.y() - aStartPoint.y()) + aDirY = (aEndPoint.x() - aStartPoint.x()) + aLen = math.sqrt(aDirX**2 + aDirY**2) + aDirX = aDirX / aLen + aDirY = aDirY / aLen + aVecX = point.x() - aStartPoint.x() + aVecY = point.y() - aStartPoint.y() + return round(math.fabs(aVecX * aDirX + aVecY * aDirY), 5) + aSession = ModelAPI_Session.get() aDocument = aSession.moduleDocument() #========================================================================= @@ -146,7 +163,7 @@ assert (model.dof(aSketchFeature) == 6) # Add distance between point and line #========================================================================= PT_LINE_DIST = 50. -aDist = model.distancePointLine(aSketchPointCoords, aSketchLine) +aDist = distancePointLine(aSketchPointCoords, aSketchLine) aSession.startOperation() aConstraint = aSketchFeature.addFeature("SketchConstraintDistance") aDistance = aConstraint.real("ConstraintValue") @@ -177,7 +194,7 @@ assert (model.dof(aSketchFeature) == 5) aSession.startOperation() aDistance.setValue(PT_LINE_DIST) aSession.finishOperation() -assert (math.fabs(model.distancePointLine(aSketchPointCoords, aSketchLine) - PT_LINE_DIST) < 1.e-10) +assert (math.fabs(distancePointLine(aSketchPointCoords, aSketchLine) - PT_LINE_DIST) < 1.e-10) assert (model.dof(aSketchFeature) == 5) #========================================================================= # Set distance between line boundaries diff --git a/src/SketchPlugin/Test/TestConstraintDistanceBehavior.py b/src/SketchPlugin/Test/TestConstraintDistanceBehavior.py deleted file mode 100644 index 35ab1496c..000000000 --- a/src/SketchPlugin/Test/TestConstraintDistanceBehavior.py +++ /dev/null @@ -1,102 +0,0 @@ -## Copyright (C) 2017 CEA/DEN, EDF R&D -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## See http:##www.salome-platform.org/ or -## email : webmaster.salome@opencascade.com -## - -from salome.shaper import model -from SketchAPI import * -import math - -TOLERANCE = 1.e-7 - -model.begin() -partSet = model.moduleDocument() -Part_1 = model.addPart(partSet) -Part_1_doc = Part_1.document() -DistanceParam = model.addParameter(Part_1_doc, "distance", "10.") -Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) -SketchRectangle_1 = Sketch_1.addRectangle(20., 20., 70., 50.) -[SketchLine_1, SketchLine_2, SketchLine_3, SketchLine_4] = SketchRectangle_1.lines() -firstPoint = SketchAPI_Line(SketchLine_2).startPoint() -secondPoint = SketchAPI_Line(SketchLine_3).endPoint() -model.do() - -# ============================================================================= -# Test 1. -# ============================================================================= -# horizontal distance constraint -SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(firstPoint, secondPoint, "distance") -model.do() - -# changing the parameter -for param in range(-30, 31, 2): - DistanceParam.setValue(param) - model.do() - dist = secondPoint.x() - firstPoint.x() - assert math.fabs(dist - param) < TOLERANCE, "Incorrect horizontal distance {}, expected {}".format(dist, param) - -model.testNbSubFeatures(Sketch_1, "SketchLine", 4) -model.testNbSubFeatures(Sketch_1, "SketchConstraintDistanceHorizontal", 1) - -# remove horizontal distance constraint -Part_1_doc.removeFeature(SketchConstraintDistanceHorizontal_1.feature()) -model.do() - -# ============================================================================= -# Test 2. -# ============================================================================= -# Vertical distance constraint -SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(firstPoint, secondPoint, "distance") -model.do() - -# changing the parameter -for param in range(-30, 31, 2): - DistanceParam.setValue(param) - model.do() - dist = secondPoint.y() - firstPoint.y() - assert math.fabs(dist - param) < TOLERANCE, "Incorrect vertical distance {}, expected {}".format(dist, param) - -model.testNbSubFeatures(Sketch_1, "SketchLine", 4) -model.testNbSubFeatures(Sketch_1, "SketchConstraintDistanceVertical", 1) - -# remove verticel distance constraint -Part_1_doc.removeFeature(SketchConstraintDistanceVertical_1.feature()) -model.do() - -# ============================================================================= -# Test 3. -# ============================================================================= -# distance constraint -SketchConstraintDistance_1 = Sketch_1.setDistance(firstPoint, secondPoint, "distance") -model.do() - -# changing the parameter -for param in range(-30, 31, 2): - DistanceParam.setValue(param) - model.do() - if param <= 0: - assert SketchConstraintDistance_1.feature().error() != '', "ERROR: Sketch should not be valid due to negative distance value" - else: - dist = model.distancePointPoint(firstPoint, secondPoint) - assert math.fabs(dist - math.fabs(param)) < TOLERANCE, "Incorrect distance {}, expected {}".format(dist, math.fabs(param)) - -model.testNbSubFeatures(Sketch_1, "SketchLine", 4) -model.testNbSubFeatures(Sketch_1, "SketchConstraintDistance", 1) -# leave distance constraint alive - -model.end() diff --git a/src/SketchPlugin/Test/TestConstraintDistanceHorizontal.py b/src/SketchPlugin/Test/TestConstraintDistanceHorizontal.py deleted file mode 100644 index 242787471..000000000 --- a/src/SketchPlugin/Test/TestConstraintDistanceHorizontal.py +++ /dev/null @@ -1,228 +0,0 @@ -## Copyright (C) 2017 CEA/DEN, EDF R&D -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## See http:##www.salome-platform.org/ or -## email : webmaster.salome@opencascade.com -## - -""" - TestConstraintDistanceHorizontal.py - Unit test of SketchPlugin_ConstraintDistanceHorizontal class - - SketchPlugin_ConstraintDistanceHorizontal - static const std::string MY_CONSTRAINT_DISTANCE_ID("SketchConstraintDistance"); - data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); -""" - -from GeomDataAPI import * -from ModelAPI import * -import math -from salome.shaper import model - -#========================================================================= -# Initialization of the test -#========================================================================= - -__updated__ = "2017-05-10" - - -def horizontalDistance(point1, point2): - """ - subroutine to calculate signed distance between two points - """ - return point2.x() - point1.x() - -aSession = ModelAPI_Session.get() -aDocument = aSession.moduleDocument() -#========================================================================= -# Creation of a sketch -#========================================================================= -aSession.startOperation() -aSketchCommonFeature = aDocument.addFeature("Sketch") -aSketchFeature = featureToCompositeFeature(aSketchCommonFeature) -origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) -origin.setValue(0, 0, 0) -dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) -dirx.setValue(1, 0, 0) -norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) -norm.setValue(0, 0, 1) -aSession.finishOperation() -#========================================================================= -# Create two movable and one fixed point -#========================================================================= -aSession.startOperation() -aPoint1 = aSketchFeature.addFeature("SketchPoint") -aPoint1Coords = geomDataAPI_Point2D(aPoint1.attribute("PointCoordinates")) -aPoint1Coords.setValue(50., 50.) -aSession.finishOperation() -aSession.startOperation() -aPoint2 = aSketchFeature.addFeature("SketchPoint") -aPoint2Coords = geomDataAPI_Point2D(aPoint2.attribute("PointCoordinates")) -aPoint2Coords.setValue(70., 70.) -aSession.finishOperation() -aSession.startOperation() -anOriginResult = modelAPI_Result(aDocument.objectByName("Construction", "Origin")) -anOriginShape = anOriginResult.shape() -anExtPoint = aSketchFeature.addFeature("SketchPoint") -anExtCoords = geomDataAPI_Point2D(anExtPoint.attribute("PointCoordinates")) -anExtCoords.setValue(0., 0.) -anExtPoint.selection("External").setValue(anOriginResult, anOriginShape) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 4) - -#========================================================================= -# Create a constraint to keep horizontal distance between movable points -#========================================================================= -DISTANCE1 = 25. -aSession.startOperation() -aHDist1 = aSketchFeature.addFeature("SketchConstraintDistanceHorizontal") -aDistance = aHDist1.real("ConstraintValue") -refattrA = aHDist1.refattr("ConstraintEntityA") -refattrB = aHDist1.refattr("ConstraintEntityB") -assert (not aDistance.isInitialized()) -assert (not refattrA.isInitialized()) -assert (not refattrB.isInitialized()) -refattrA.setObject(aPoint1.lastResult()) -refattrB.setObject(aPoint2.lastResult()) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 3) -# set flyout point then abort operation, after that check the Distance is correct -aSession.startOperation() -aFlyoutPoint = geomDataAPI_Point2D(aHDist1.attribute("ConstraintFlyoutValuePnt")) -aFlyoutPoint.setValue(50.0, 100.0) -aSession.abortOperation() -assert (refattrA.isInitialized()) -assert (refattrB.isInitialized()) -assert (aDistance.isInitialized()) -aSession.startOperation() -aDistance.setValue(DISTANCE1) -aSession.finishOperation() -assert math.fabs(horizontalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) -assert (model.dof(aSketchFeature) == 3) -#========================================================================= -# Change a distance value -#========================================================================= -d = DISTANCE1 + 20. -dStep = -5. -while d >= -30.: - aSession.startOperation() - DISTANCE1 = d - aDistance.setValue(DISTANCE1) - aSession.finishOperation() - assert math.fabs(horizontalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) - d += dStep -assert (model.dof(aSketchFeature) == 3) - -#========================================================================= -# Create a constraint to keep horizontal distance between fixed and movable points -#========================================================================= -DISTANCE2 = 50. -aSession.startOperation() -aHDist2 = aSketchFeature.addFeature("SketchConstraintDistanceHorizontal") -aDistance = aHDist2.real("ConstraintValue") -refattrA = aHDist2.refattr("ConstraintEntityA") -refattrB = aHDist2.refattr("ConstraintEntityB") -assert (not aDistance.isInitialized()) -assert (not refattrA.isInitialized()) -assert (not refattrB.isInitialized()) -refattrA.setObject(anExtPoint.lastResult()) -refattrB.setAttr(aPoint1Coords) -aDistance.setValue(DISTANCE2) -aSession.finishOperation() -assert math.fabs(horizontalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(anExtCoords, aPoint1Coords), DISTANCE2) -assert math.fabs(aPoint1Coords.x() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected x = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2) -assert (model.dof(aSketchFeature) == 2) -#========================================================================= -# Change a distance value (check previous constraint is applied too) -#========================================================================= -d = DISTANCE2 -dStep = -5. -while d >= -50.: - aSession.startOperation() - DISTANCE2 = d - aDistance.setValue(DISTANCE2) - aSession.finishOperation() - assert math.fabs(horizontalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(anExtCoords, aPoint1Coords), DISTANCE2) - assert math.fabs(aPoint1Coords.x() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected x = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2) - assert math.fabs(horizontalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) - d += dStep -assert (model.dof(aSketchFeature) == 2) - -#========================================================================= -# Remove first distance -#========================================================================= -aStoredCoords = [aPoint2Coords.x(), aPoint2Coords.y()] -aSession.startOperation() -aDocument.removeFeature(aHDist1) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 3) -aSession.startOperation() -DISTANCE2 = 20. -aDistance.setValue(DISTANCE2) -aSession.finishOperation() -assert math.fabs(horizontalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(anExtCoords, aPoint1Coords), DISTANCE2) -assert math.fabs(aPoint1Coords.x() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected x = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2) -assert aPoint2Coords.x() == aStoredCoords[0] and aPoint2Coords.y() == aStoredCoords[1] - -#========================================================================= -# Create line and set horizontal distance between line boundaries -#========================================================================= -aSession.startOperation() -aLine = aSketchFeature.addFeature("SketchLine") -aStartPoint = geomDataAPI_Point2D(aLine.attribute("StartPoint")) -aEndPoint = geomDataAPI_Point2D(aLine.attribute("EndPoint")) -aStartPoint.setValue(50., 0.) -aEndPoint.setValue(100., 20.) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 7) - -DISTANCE3 = 50. -aSession.startOperation() -aHDist3 = aSketchFeature.addFeature("SketchConstraintDistanceHorizontal") -aDistance = aHDist3.real("ConstraintValue") -refattrA = aHDist3.refattr("ConstraintEntityA") -refattrB = aHDist3.refattr("ConstraintEntityB") -assert (not aDistance.isInitialized()) -assert (not refattrA.isInitialized()) -assert (not refattrB.isInitialized()) -refattrA.setAttr(aStartPoint) -refattrB.setAttr(aEndPoint) -aDistance.setValue(DISTANCE3) -aSession.finishOperation() -assert math.fabs(horizontalDistance(aStartPoint, aEndPoint) - DISTANCE3) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aStartPoint, aEndPoint), DISTANCE3) -assert (model.dof(aSketchFeature) == 6) -#========================================================================= -# Change a distance value -#========================================================================= -d = DISTANCE3 -dStep = -5. -while d >= -50.: - aSession.startOperation() - DISTANCE3 = d - aDistance.setValue(DISTANCE3) - aSession.finishOperation() - assert math.fabs(horizontalDistance(aStartPoint, aEndPoint) - DISTANCE3) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aStartPoint, aEndPoint), DISTANCE3) - d += dStep -assert (model.dof(aSketchFeature) == 6) - -#========================================================================= -# End of test -#========================================================================= - -assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintDistanceVertical.py b/src/SketchPlugin/Test/TestConstraintDistanceVertical.py deleted file mode 100644 index 8910edcbf..000000000 --- a/src/SketchPlugin/Test/TestConstraintDistanceVertical.py +++ /dev/null @@ -1,228 +0,0 @@ -## Copyright (C) 2017 CEA/DEN, EDF R&D -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## See http:##www.salome-platform.org/ or -## email : webmaster.salome@opencascade.com -## - -""" - TestConstraintDistanceVertical.py - Unit test of SketchPlugin_ConstraintDistanceVertical class - - SketchPlugin_ConstraintDistanceVertical - static const std::string MY_CONSTRAINT_DISTANCE_ID("SketchConstraintDistance"); - data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); -""" - -from GeomDataAPI import * -from ModelAPI import * -import math -from salome.shaper import model - -#========================================================================= -# Initialization of the test -#========================================================================= - -__updated__ = "2017-05-10" - - -def verticalDistance(point1, point2): - """ - subroutine to calculate signed distance between two points - """ - return point2.y() - point1.y() - -aSession = ModelAPI_Session.get() -aDocument = aSession.moduleDocument() -#========================================================================= -# Creation of a sketch -#========================================================================= -aSession.startOperation() -aSketchCommonFeature = aDocument.addFeature("Sketch") -aSketchFeature = featureToCompositeFeature(aSketchCommonFeature) -origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) -origin.setValue(0, 0, 0) -dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) -dirx.setValue(1, 0, 0) -norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) -norm.setValue(0, 0, 1) -aSession.finishOperation() -#========================================================================= -# Create two movable and one fixed point -#========================================================================= -aSession.startOperation() -aPoint1 = aSketchFeature.addFeature("SketchPoint") -aPoint1Coords = geomDataAPI_Point2D(aPoint1.attribute("PointCoordinates")) -aPoint1Coords.setValue(50., 50.) -aSession.finishOperation() -aSession.startOperation() -aPoint2 = aSketchFeature.addFeature("SketchPoint") -aPoint2Coords = geomDataAPI_Point2D(aPoint2.attribute("PointCoordinates")) -aPoint2Coords.setValue(70., 70.) -aSession.finishOperation() -aSession.startOperation() -anOriginResult = modelAPI_Result(aDocument.objectByName("Construction", "Origin")) -anOriginShape = anOriginResult.shape() -anExtPoint = aSketchFeature.addFeature("SketchPoint") -anExtCoords = geomDataAPI_Point2D(anExtPoint.attribute("PointCoordinates")) -anExtCoords.setValue(0., 0.) -anExtPoint.selection("External").setValue(anOriginResult, anOriginShape) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 4) - -#========================================================================= -# Create a constraint to keep vertical distance between movable points -#========================================================================= -DISTANCE1 = 25. -aSession.startOperation() -aVDist1 = aSketchFeature.addFeature("SketchConstraintDistanceVertical") -aDistance = aVDist1.real("ConstraintValue") -refattrA = aVDist1.refattr("ConstraintEntityA") -refattrB = aVDist1.refattr("ConstraintEntityB") -assert (not aDistance.isInitialized()) -assert (not refattrA.isInitialized()) -assert (not refattrB.isInitialized()) -refattrA.setObject(aPoint1.lastResult()) -refattrB.setObject(aPoint2.lastResult()) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 3) -# set flyout point then abort operation, after that check the Distance is correct -aSession.startOperation() -aFlyoutPoint = geomDataAPI_Point2D(aVDist1.attribute("ConstraintFlyoutValuePnt")) -aFlyoutPoint.setValue(50.0, 100.0) -aSession.abortOperation() -assert (refattrA.isInitialized()) -assert (refattrB.isInitialized()) -assert (aDistance.isInitialized()) -aSession.startOperation() -aDistance.setValue(DISTANCE1) -aSession.finishOperation() -assert math.fabs(verticalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) -assert (model.dof(aSketchFeature) == 3) -#========================================================================= -# Change a distance value -#========================================================================= -d = DISTANCE1 + 20. -dStep = -5. -while d >= -30.: - aSession.startOperation() - DISTANCE1 = d - aDistance.setValue(DISTANCE1) - aSession.finishOperation() - assert math.fabs(verticalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) - d += dStep -assert (model.dof(aSketchFeature) == 3) - -#========================================================================= -# Create a constraint to keep vertical distance between fixed and movable points -#========================================================================= -DISTANCE2 = 50. -aSession.startOperation() -aVDist2 = aSketchFeature.addFeature("SketchConstraintDistanceVertical") -aDistance = aVDist2.real("ConstraintValue") -refattrA = aVDist2.refattr("ConstraintEntityA") -refattrB = aVDist2.refattr("ConstraintEntityB") -assert (not aDistance.isInitialized()) -assert (not refattrA.isInitialized()) -assert (not refattrB.isInitialized()) -refattrA.setObject(anExtPoint.lastResult()) -refattrB.setAttr(aPoint1Coords) -aDistance.setValue(DISTANCE2) -aSession.finishOperation() -assert math.fabs(verticalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(anExtCoords, aPoint1Coords), DISTANCE2) -assert math.fabs(aPoint1Coords.y() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected y = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2) -assert (model.dof(aSketchFeature) == 2) -#========================================================================= -# Change a distance value (check previous constraint is applied too) -#========================================================================= -d = DISTANCE2 -dStep = -5. -while d >= -50.: - aSession.startOperation() - DISTANCE2 = d - aDistance.setValue(DISTANCE2) - aSession.finishOperation() - assert math.fabs(verticalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(anExtCoords, aPoint1Coords), DISTANCE2) - assert math.fabs(aPoint1Coords.y() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected y = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2) - assert math.fabs(verticalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) - d += dStep -assert (model.dof(aSketchFeature) == 2) - -#========================================================================= -# Remove first distance -#========================================================================= -aStoredCoords = [aPoint2Coords.x(), aPoint2Coords.y()] -aSession.startOperation() -aDocument.removeFeature(aVDist1) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 3) -aSession.startOperation() -DISTANCE2 = 20. -aDistance.setValue(DISTANCE2) -aSession.finishOperation() -assert math.fabs(verticalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(anExtCoords, aPoint1Coords), DISTANCE2) -assert math.fabs(aPoint1Coords.y() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected y = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2) -assert aPoint2Coords.x() == aStoredCoords[0] and aPoint2Coords.y() == aStoredCoords[1] - -#========================================================================= -# Create line and set vertical distance between line boundaries -#========================================================================= -aSession.startOperation() -aLine = aSketchFeature.addFeature("SketchLine") -aStartPoint = geomDataAPI_Point2D(aLine.attribute("StartPoint")) -aEndPoint = geomDataAPI_Point2D(aLine.attribute("EndPoint")) -aStartPoint.setValue(50., 0.) -aEndPoint.setValue(100., 20.) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 7) - -DISTANCE3 = 50. -aSession.startOperation() -aVDist3 = aSketchFeature.addFeature("SketchConstraintDistanceVertical") -aDistance = aVDist3.real("ConstraintValue") -refattrA = aVDist3.refattr("ConstraintEntityA") -refattrB = aVDist3.refattr("ConstraintEntityB") -assert (not aDistance.isInitialized()) -assert (not refattrA.isInitialized()) -assert (not refattrB.isInitialized()) -refattrA.setAttr(aStartPoint) -refattrB.setAttr(aEndPoint) -aDistance.setValue(DISTANCE3) -aSession.finishOperation() -assert math.fabs(verticalDistance(aStartPoint, aEndPoint) - DISTANCE3) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aStartPoint, aEndPoint), DISTANCE3) -assert (model.dof(aSketchFeature) == 6) -#========================================================================= -# Change a distance value -#========================================================================= -d = DISTANCE3 -dStep = -5. -while d >= -50.: - aSession.startOperation() - DISTANCE3 = d - aDistance.setValue(DISTANCE3) - aSession.finishOperation() - assert math.fabs(verticalDistance(aStartPoint, aEndPoint) - DISTANCE3) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aStartPoint, aEndPoint), DISTANCE3) - d += dStep -assert (model.dof(aSketchFeature) == 6) - -#========================================================================= -# End of test -#========================================================================= - -assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintFixed.py b/src/SketchPlugin/Test/TestConstraintFixed.py index db20680aa..8b67e708c 100644 --- a/src/SketchPlugin/Test/TestConstraintFixed.py +++ b/src/SketchPlugin/Test/TestConstraintFixed.py @@ -169,141 +169,6 @@ assert ((aLineAStartPoint.x(), aLineAStartPoint.y()) == (aLineCEndPoint.x(), aLi assert ((aLineBStartPoint.x(), aLineBStartPoint.y()) == (aLineAEndPoint.x(), aLineAEndPoint.y())) assert ((aLineCStartPoint.x(), aLineCStartPoint.y()) == (aLineBEndPoint.x(), aLineBEndPoint.y())) assert (model.dof(aSketchFeature) == 6) - -#========================================================================= -# Create circle, fix it and check the circle is not moved -#========================================================================= -aCenter = [10., 10.] -aRadius = 5. -aSession.startOperation() -aCircle = aSketchFeature.addFeature("SketchCircle") -aCircleCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center")) -aCircleRadius = aCircle.real("circle_radius") -aCircleCenter.setValue(aCenter[0], aCenter[1]) -aCircleRadius.setValue(aRadius) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 9) -# fixed constraints -aSession.startOperation() -aRigidConstraint = aSketchFeature.addFeature("SketchConstraintRigid") -aRigidConstraint.refattr("ConstraintEntityA").setObject(aCircle.lastResult()) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 6) -# move center of circle -aSession.startOperation() -aCircleCenter.setValue(aCenter[0] + 1., aCenter[1] - 1.) -aSession.finishOperation() -assert (aCircleCenter.x() == aCenter[0] and aCircleCenter.y() == aCenter[1]) -assert (aCircleRadius.value() == aRadius) -assert (model.dof(aSketchFeature) == 6) -# change radius of circle -aSession.startOperation() -aCircleRadius.setValue(aRadius + 3.) -aSession.finishOperation() -assert (aCircleCenter.x() == aCenter[0] and aCircleCenter.y() == aCenter[1]) -assert (aCircleRadius.value() == aRadius) -assert (model.dof(aSketchFeature) == 6) - -#========================================================================= -# Remove Fixed constraint and check the circle can be moved -#========================================================================= -aSession.startOperation() -aDocument.removeFeature(aRigidConstraint) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 9) -# move center of circle -aCenter = [aCenter[0] + 1., aCenter[1] - 1.] -aSession.startOperation() -aCircleCenter.setValue(aCenter[0], aCenter[1]) -aSession.finishOperation() -assert (aCircleCenter.x() == aCenter[0] and aCircleCenter.y() == aCenter[1]) -assert (aCircleRadius.value() == aRadius) -assert (model.dof(aSketchFeature) == 9) -# change radius of circle -aRadius = aRadius + 3. -aSession.startOperation() -aCircleRadius.setValue(aRadius) -aSession.finishOperation() -assert (aCircleCenter.x() == aCenter[0] and aCircleCenter.y() == aCenter[1]) -assert (aCircleRadius.value() == aRadius) -assert (model.dof(aSketchFeature) == 9) - -#========================================================================= -# Create arc, fix it and check it is not moved -#========================================================================= -aCenter = [10., 10.] -aStart = [5., 10.] -aEnd = [10., 15.] -aSession.startOperation() -anArc = aSketchFeature.addFeature("SketchArc") -anArcCenter = geomDataAPI_Point2D(anArc.attribute("center_point")) -anArcStart = geomDataAPI_Point2D(anArc.attribute("start_point")) -anArcEnd = geomDataAPI_Point2D(anArc.attribute("end_point")) -anArcCenter.setValue(aCenter[0], aCenter[1]) -anArcStart.setValue(aStart[0], aStart[1]) -anArcEnd.setValue(aEnd[0], aEnd[1]) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 14) -# fixed constraints -aSession.startOperation() -aRigidConstraint = aSketchFeature.addFeature("SketchConstraintRigid") -aRigidConstraint.refattr("ConstraintEntityA").setObject(anArc.lastResult()) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 9) -# move center of arc -aSession.startOperation() -anArcCenter.setValue(aCenter[0] + 1., aCenter[1] - 1.) -aSession.finishOperation() -assert (anArcCenter.x() == aCenter[0] and anArcCenter.y() == aCenter[1]) -assert (anArcStart.x() == aStart[0] and anArcStart.y() == aStart[1]) -assert (anArcEnd.x() == aEnd[0] and anArcEnd.y() == aEnd[1]) -assert (model.dof(aSketchFeature) == 9) -# move start point of arc -aSession.startOperation() -anArcStart.setValue(aStart[0] + 1., aStart[1] - 1.) -aSession.finishOperation() -assert (anArcCenter.x() == aCenter[0] and anArcCenter.y() == aCenter[1]) -assert (anArcStart.x() == aStart[0] and anArcStart.y() == aStart[1]) -assert (anArcEnd.x() == aEnd[0] and anArcEnd.y() == aEnd[1]) -assert (model.dof(aSketchFeature) == 9) -# move end point of arc -aSession.startOperation() -anArcEnd.setValue(aEnd[0] + 1., aEnd[1] - 1.) -aSession.finishOperation() -assert (anArcCenter.x() == aCenter[0] and anArcCenter.y() == aCenter[1]) -assert (anArcStart.x() == aStart[0] and anArcStart.y() == aStart[1]) -assert (anArcEnd.x() == aEnd[0] and anArcEnd.y() == aEnd[1]) -assert (model.dof(aSketchFeature) == 9) - -#========================================================================= -# Remove Fixed constraint and check the arc can be moved -#========================================================================= -aSession.startOperation() -aDocument.removeFeature(aRigidConstraint) -aSession.finishOperation() -assert (model.dof(aSketchFeature) == 14) -# move center of arc -aCenter = [anArcCenter.x(), anArcCenter.y()] -aSession.startOperation() -anArcCenter.setValue(aCenter[0] + 1., aCenter[1] - 1.) -aSession.finishOperation() -assert (anArcCenter.x() != aCenter[0] or anArcCenter.y() != aCenter[1]) -assert (model.dof(aSketchFeature) == 14) -# move start point of arc -aStart = [anArcStart.x(), anArcStart.y()] -aSession.startOperation() -anArcStart.setValue(aStart[0] + 1., aStart[1] - 1.) -aSession.finishOperation() -assert (anArcStart.x() != aStart[0] or anArcStart.y() != aStart[1]) -assert (model.dof(aSketchFeature) == 14) -# move end point of arc -aEnd = [anArcEnd.x(), anArcEnd.y()] -aSession.startOperation() -anArcEnd.setValue(aEnd[0] + 1., aEnd[1] - 1.) -aSession.finishOperation() -assert (anArcEnd.x() != aEnd[0] or anArcEnd.y() != aEnd[1]) -assert (model.dof(aSketchFeature) == 14) - #========================================================================= # End of test #========================================================================= diff --git a/src/SketchPlugin/Test/TestConstraintHorizontalValidator.py b/src/SketchPlugin/Test/TestConstraintHorizontalValidator.py deleted file mode 100644 index 103d7db80..000000000 --- a/src/SketchPlugin/Test/TestConstraintHorizontalValidator.py +++ /dev/null @@ -1,70 +0,0 @@ -## Copyright (C) 2017 CEA/DEN, EDF R&D -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## See http:##www.salome-platform.org/ or -## email : webmaster.salome@opencascade.com -## - -""" - TestConstraintHorizontalValidator.py - It tests validation of horizontal and vertical segments in H and V constraints to avoid - selection segments that already have one of these constraint" -""" - -#========================================================================= -# of the test -#========================================================================= -from salome.shaper import model -from ModelAPI import * -import math -#========================================================================= -# Creation of a part -#========================================================================= -model.begin() -partSet = model.moduleDocument() -Part_1 = model.addPart(partSet) -Part_1_doc = Part_1.document() -#========================================================================= -# Creation of a sketch -#========================================================================= -Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ")) -SketchLine_1 = Sketch_1.addLine(20, 20, 40, 80) -SketchLine_2 = Sketch_1.addLine(40, 80, 60, 40) -SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) -SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) -SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result()) -model.do() -#========================================================================= -# Checking that sketch and constraints become invalid when to one line -# two horizontal/vertical constraints are applied in any combination -#========================================================================= -aFactory = ModelAPI_Session.get().validators() -assert(aFactory.validate(Sketch_1.feature())) -assert(Sketch_1.feature().error() != '') -#========================================================================= -# Remove duplicated Vertical constraints -#========================================================================= -Part_1_doc.removeFeature(SketchConstraintVertical_1.feature()) -assert(aFactory.validate(Sketch_1.feature())) -model.do() -#========================================================================= -# Checking that after excess constraints are removed or undone, -# sketch becomes valid. -#========================================================================= -assert(aFactory.validate(Sketch_1.feature())) -assert(Sketch_1.feature().error() == '') - -assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintTangent.py b/src/SketchPlugin/Test/TestConstraintTangent.py index 3f3ac2e7e..09649edfa 100644 --- a/src/SketchPlugin/Test/TestConstraintTangent.py +++ b/src/SketchPlugin/Test/TestConstraintTangent.py @@ -40,6 +40,23 @@ from salome.shaper import model __updated__ = "2015-03-17" +def distancePointLine(point, line): + """ + subroutine to calculate distance between point and line + result of calculated distance is has 10**-5 precision + """ + aStartPoint = geomDataAPI_Point2D(line.attribute("StartPoint")) + aEndPoint = geomDataAPI_Point2D(line.attribute("EndPoint")) + # orthogonal direction + aDirX = -(aEndPoint.y() - aStartPoint.y()) + aDirY = (aEndPoint.x() - aStartPoint.x()) + aLen = math.sqrt(aDirX**2 + aDirY**2) + aDirX = aDirX / aLen + aDirY = aDirY / aLen + aVecX = point.x() - aStartPoint.x() + aVecY = point.y() - aStartPoint.y() + return round(math.fabs(aVecX * aDirX + aVecY * aDirY), 5) + def checkArcLineTangency(theArc, theLine): """ subroutine to check that the line is tangent to arc/circle @@ -51,7 +68,7 @@ def checkArcLineTangency(theArc, theLine): aCenter = geomDataAPI_Point2D(theArc.attribute("center_point")) aStartPnt = geomDataAPI_Point2D(theArc.attribute("start_point")) aRadius = model.distancePointPoint(aStartPnt, aCenter) - aDist = model.distancePointLine(aCenter, theLine) + aDist = distancePointLine(aCenter, theLine) assert math.fabs(aDist - aRadius) < 2.e-5, "aDist = {0}, aRadius = {1}".format(aDist, aRadius) def checkArcArcTangency(theArc1, theArc2): diff --git a/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py b/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py index 0e4464774..097e636b2 100644 --- a/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py +++ b/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py @@ -52,10 +52,22 @@ def verifyLastArc(theSketch, theCenter, theStart, theEnd): subroutine to verify position of last arc in the sketch """ aLastArc = model.lastSubFeature(theSketch, "SketchArc") - model.assertArc(aLastArc, theCenter, theStart, theEnd) + aCenterPnt = geomDataAPI_Point2D(aLastArc.attribute("center_point")) + aStartPnt = geomDataAPI_Point2D(aLastArc.attribute("start_point")) + aEndPnt = geomDataAPI_Point2D(aLastArc.attribute("end_point")) + if len(theCenter): + verifyPointCoordinates(aCenterPnt, theCenter[0], theCenter[1]) + if len(theStart): + verifyPointCoordinates(aStartPnt, theStart[0], theStart[1]) + if len(theEnd): + verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1]) + model.assertSketchArc(aLastArc) + +def verifyPointCoordinates(thePoint, theX, theY): + assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.id(), thePoint.x(), thePoint.y(), theX, theY) def verifyPointOnLine(thePoint, theLine): - aDistance = model.distancePointLine(thePoint, theLine) + aDistance = distancePointLine(thePoint, theLine) assert aDistance < TOLERANCE, "Point is not on Line, distance: {0}".format(aDistance) def verifyPointOnCircle(thePoint, theCircular): @@ -70,6 +82,14 @@ def verifyPointOnCircle(thePoint, theCircular): return assert math.fabs(model.distancePointPoint(aCenterPoint, thePoint) - aRadius) < TOLERANCE +def distancePointLine(thePoint, theLine): + aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy() + aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy() + aLineDir = aLineEnd.decreased(aLineStart) + aLineLen = aLineEnd.distance(aLineStart) + aPntDir = thePoint.pnt().xy().decreased(aLineStart) + return math.fabs(aPntDir.cross(aLineDir) / aLineLen) + aSession = ModelAPI_Session.get() aDocument = aSession.moduleDocument() @@ -223,7 +243,7 @@ aEndRef.setObject(aLine.lastResult()) aEnd.setValue(aLineStart[0], aLineStart[1]) aSession.finishOperation() assert (aSketchFeature.numberOfSubs() == 8), "Number of subs {}".format(aSketchFeature.numberOfSubs()) -model.assertPoint(aPointCoord, aPointCoordinates) +verifyPointCoordinates(aPointCoord, aPointCoordinates[0], aPointCoordinates[1]) verifyLastArc(aSketchFeature, [aPrevArcStart.x(), aPrevArcStart.y()], aPointCoordinates, []) model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3) @@ -259,8 +279,11 @@ aEnd.setValue(aLineEndPoint.pnt()) aSession.finishOperation() assert (aSketchFeature.numberOfSubs() == 12), "Number of subs {}".format(aSketchFeature.numberOfSubs()) # check connected features do not change their positions -model.assertArc(aPrevArc, aPrevArcCenterXY, aPrevArcStartXY, aPrevArcEndXY) -model.assertLine(aLine, aLineStart, aLineEnd) +verifyPointCoordinates(aPrevArcCenter, aPrevArcCenterXY[0], aPrevArcCenterXY[1]) +verifyPointCoordinates(aPrevArcStart, aPrevArcStartXY[0], aPrevArcStartXY[1]) +verifyPointCoordinates(aPrevArcEnd, aPrevArcEndXY[0], aPrevArcEndXY[1]) +verifyPointCoordinates(aLineStartPoint, aLineStart[0], aLineStart[1]) +verifyPointCoordinates(aLineEndPoint, aLineEnd[0], aLineEnd[1]) # verify newly created arc anArc = model.lastSubFeature(aSketchFeature, "SketchArc") aCenter = geomDataAPI_Point2D(anArc.attribute("center_point")) diff --git a/src/SketchPlugin/Test/TestCreateArcByTangentEdge.py b/src/SketchPlugin/Test/TestCreateArcByTangentEdge.py index 448f9ea3d..6f296a03d 100644 --- a/src/SketchPlugin/Test/TestCreateArcByTangentEdge.py +++ b/src/SketchPlugin/Test/TestCreateArcByTangentEdge.py @@ -52,7 +52,19 @@ def verifyLastArc(theSketch, theCenter, theStart, theEnd): subroutine to verify position of last arc in the sketch """ aLastArc = model.lastSubFeature(theSketch, "SketchArc") - model.assertArc(aLastArc, theCenter, theStart, theEnd) + aCenterPnt = geomDataAPI_Point2D(aLastArc.attribute("center_point")) + aStartPnt = geomDataAPI_Point2D(aLastArc.attribute("start_point")) + aEndPnt = geomDataAPI_Point2D(aLastArc.attribute("end_point")) + if len(theCenter): + verifyPointCoordinates(aCenterPnt, theCenter[0], theCenter[1]) + if len(theStart): + verifyPointCoordinates(aStartPnt, theStart[0], theStart[1]) + if len(theEnd): + verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1]) + model.assertSketchArc(aLastArc) + +def verifyPointCoordinates(thePoint, theX, theY): + assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.id(), thePoint.x(), thePoint.y(), theX, theY) def verifyTangent(theFeature1, theFeature2): anArcs = [] @@ -87,11 +99,19 @@ def verifyArcLineTangent(theArc, theLine): aStart = geomDataAPI_Point2D(theArc.attribute("start_point")) aRadius = model.distancePointPoint(aStart, aCenter) - aDistCL = model.distancePointLine(aCenter, theLine) + aDistCL = distancePointLine(aCenter, theLine) assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Arc and line do not tangent" +def distancePointLine(thePoint, theLine): + aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy() + aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy() + aLineDir = aLineEnd.decreased(aLineStart) + aLineLen = aLineEnd.distance(aLineStart) + aPntDir = thePoint.pnt().xy().decreased(aLineStart) + return math.fabs(aPntDir.cross(aLineDir) / aLineLen) + def verifyPointOnLine(thePoint, theLine): - aDistance = model.distancePointLine(thePoint, theLine) + aDistance = distancePointLine(thePoint, theLine) assert aDistance < TOLERANCE, "Point is not on Line, distance: {0}".format(aDistance) diff --git a/src/SketchPlugin/Test/TestCreateArcByThreePoints.py b/src/SketchPlugin/Test/TestCreateArcByThreePoints.py index f6240ab20..0844028d9 100644 --- a/src/SketchPlugin/Test/TestCreateArcByThreePoints.py +++ b/src/SketchPlugin/Test/TestCreateArcByThreePoints.py @@ -48,10 +48,13 @@ def verifyLastArc(theSketch, theX, theY, theR): """ aLastArc = model.lastSubFeature(theSketch, "SketchArc") aCenter = geomDataAPI_Point2D(aLastArc.attribute("center_point")) - model.assertPoint(aCenter, [theX, theY]) + verifyPointCoordinates(aCenter, theX, theY) aRadius = aLastArc.real("radius") assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR) +def verifyPointCoordinates(thePoint, theX, theY): + assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY) + def verifyPointOnArc(thePoint, theArc): aCenter = geomDataAPI_Point2D(theArc.attribute("center_point")) aDistCP = model.distancePointPoint(aCenter, thePoint) @@ -75,9 +78,17 @@ def verifyTangentCircular(theDistBetweenCenters, theRadius1, theRadius2): def verifyTangentArcLine(theArc, theLine): aCenter = geomDataAPI_Point2D(theArc.attribute("center_point")) aRadius = theArc.real("radius").value() - aDistCL = model.distancePointLine(aCenter, theLine) + aDistCL = distancePointLine(aCenter, theLine) assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Circle and line are not tangent" +def distancePointLine(thePoint, theLine): + aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy() + aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy() + aLineDir = aLineEnd.decreased(aLineStart) + aLineLen = aLineEnd.distance(aLineStart) + aPntDir = thePoint.pnt().xy().decreased(aLineStart) + return math.fabs(aPntDir.cross(aLineDir) / aLineLen) + #========================================================================= # Start of test @@ -167,9 +178,9 @@ anArcPnt3.setValue(aLineStart[0], aLineStart[1]) aSession.finishOperation() assert (aSketchFeature.numberOfSubs() == 7) # check the points do not change their positions -model.assertPoint(aPrevCenter, aPrevCenterXY) -model.assertPoint(aPointCoord, aPointCoodinates) -model.assertPoint(aStartPnt, aLineStart) +verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1]) +verifyPointCoordinates(aPointCoord, aPointCoodinates[0], aPointCoodinates[1]) +verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1]) # check newly created arc passes through the points anArc = model.lastSubFeature(aSketchFeature, "SketchArc") verifyPointOnArc(aPrevCenter, anArc) @@ -198,9 +209,9 @@ anArcPnt3.setValue(20, 25) aSession.finishOperation() assert (aSketchFeature.numberOfSubs() == 9) # check the points do not change their positions -model.assertPoint(aPrevCenter, aPrevCenterXY) -model.assertPoint(aPointCoord, aPointCoodinates) -model.assertPoint(aStartPnt, aLineStart) +verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1]) +verifyPointCoordinates(aPointCoord, aPointCoodinates[0], aPointCoodinates[1]) +verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1]) # check sub-features model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3) model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 1) diff --git a/src/SketchPlugin/Test/TestCreateArcChangeType.py b/src/SketchPlugin/Test/TestCreateArcChangeType.py index 851241a02..88ad0c60e 100644 --- a/src/SketchPlugin/Test/TestCreateArcChangeType.py +++ b/src/SketchPlugin/Test/TestCreateArcChangeType.py @@ -88,7 +88,19 @@ def verifyLastArc(theSketch, theCenter, theStart, theEnd): subroutine to verify position of last arc in the sketch """ aLastArc = model.lastSubFeature(theSketch, "SketchArc") - model.assertArc(aLastArc, theCenter, theStart, theEnd) + aCenterPnt = geomDataAPI_Point2D(aLastArc.attribute("center_point")) + aStartPnt = geomDataAPI_Point2D(aLastArc.attribute("start_point")) + aEndPnt = geomDataAPI_Point2D(aLastArc.attribute("end_point")) + if len(theCenter): + verifyPointCoordinates(aCenterPnt, theCenter[0], theCenter[1]) + if len(theStart): + verifyPointCoordinates(aStartPnt, theStart[0], theStart[1]) + if len(theEnd): + verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1]) + model.assertSketchArc(aLastArc) + +def verifyPointCoordinates(thePoint, theX, theY): + assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.id(), thePoint.x(), thePoint.y(), theX, theY) #========================================================================= diff --git a/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py b/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py index 6fbb6b34a..9be701d66 100644 --- a/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py +++ b/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py @@ -47,10 +47,16 @@ def verifyLastCircle(theSketch, theX, theY, theR): subroutine to verify position of last circle in the sketch """ aLastCircle = model.lastSubFeature(theSketch, "SketchCircle") - model.assertCircle(aLastCircle, [theX, theY], theR) + aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center")) + verifyPointCoordinates(aCenter, theX, theY) + aRadius = aLastCircle.real("circle_radius") + assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR) + +def verifyPointCoordinates(thePoint, theX, theY): + assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.id(), thePoint.x(), thePoint.y(), theX, theY) def verifyPointOnLine(thePoint, theLine): - aDistance = model.distancePointLine(thePoint, theLine) + aDistance = distancePointLine(thePoint, theLine) assert aDistance < TOLERANCE, "Point is not on Line, distance: {0}".format(aDistance) def verifyTangentCircles(theCircle1, theCircle2): @@ -63,6 +69,14 @@ def verifyTangentCircles(theCircle1, theCircle2): aRDiff = math.fabs(aRadius1 - aRadius2) assert math.fabs(aRSum - aDistCC) < TOLERANCE or math.fabs(aRDiff - aDistCC) < TOLERANCE, "Circles do not tangent" +def distancePointLine(thePoint, theLine): + aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy() + aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy() + aLineDir = aLineEnd.decreased(aLineStart) + aLineLen = aLineEnd.distance(aLineStart) + aPntDir = thePoint.pnt().xy().decreased(aLineStart) + return math.fabs(aPntDir.cross(aLineDir) / aLineLen) + #========================================================================= # Start of test @@ -168,7 +182,7 @@ aPassed.setValue(aPrevCenter.pnt()) aRadius = model.distancePointPoint(aPrevCenter, aPointCoord) aSession.finishOperation() assert (aSketchFeature.numberOfSubs() == 6) -model.assertPoint(aPointCoord, aPointCoordinates) +verifyPointCoordinates(aPointCoord, aPointCoordinates[0], aPointCoordinates[1]) verifyLastCircle(aSketchFeature, aPointCoord.x(), aPointCoord.y(), aRadius) model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 2) @@ -209,13 +223,14 @@ aRadius = model.distancePointPoint(aCenter, aPassed) aSession.finishOperation() assert (aSketchFeature.numberOfSubs() == 10) # check connected features do not change their positions -model.assertPoint(aPrevCenter, aPrevCenterXY) +verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1]) assert(aPrevCircle.real("circle_radius").value() == aPrevRadius) -model.assertLine(aLine, aLineStart, aLineEnd) +verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1]) +verifyPointCoordinates(aEndPnt, aLineEnd[0], aLineEnd[1]) # verify newly created circle aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle") aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center")) -model.assertPoint(aCenter, anExpectedCenter) +verifyPointCoordinates(aCenter, anExpectedCenter[0], anExpectedCenter[1]) verifyPointOnLine(aCenter, aLine) verifyTangentCircles(aCircle, aPrevCircle) model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3) diff --git a/src/SketchPlugin/Test/TestCreateCircleByThreePoints.py b/src/SketchPlugin/Test/TestCreateCircleByThreePoints.py index 558f2f86f..321e37ab9 100644 --- a/src/SketchPlugin/Test/TestCreateCircleByThreePoints.py +++ b/src/SketchPlugin/Test/TestCreateCircleByThreePoints.py @@ -47,7 +47,13 @@ def verifyLastCircle(theSketch, theX, theY, theR): subroutine to verify position of last circle in the sketch """ aLastCircle = model.lastSubFeature(theSketch, "SketchCircle") - model.assertCircle(aLastCircle, [theX, theY], theR) + aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center")) + verifyPointCoordinates(aCenter, theX, theY) + aRadius = aLastCircle.real("circle_radius") + assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR) + +def verifyPointCoordinates(thePoint, theX, theY): + assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY) def verifyPointOnCircle(thePoint, theCircle): aCircleCenter = geomDataAPI_Point2D(theCircle.attribute("circle_center")) @@ -80,9 +86,17 @@ def verifyTangentCircular(theDistBetweenCenters, theRadius1, theRadius2): def verifyTangentCircleLine(theCircle, theLine): aCenter = geomDataAPI_Point2D(theCircle.attribute("circle_center")) aRadius = theCircle.real("circle_radius").value() - aDistCL = model.distancePointLine(aCenter, theLine) + aDistCL = distancePointLine(aCenter, theLine) assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Circle and line are not tangent" +def distancePointLine(thePoint, theLine): + aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy() + aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy() + aLineDir = aLineEnd.decreased(aLineStart) + aLineLen = aLineEnd.distance(aLineStart) + aPntDir = thePoint.pnt().xy().decreased(aLineStart) + return math.fabs(aPntDir.cross(aLineDir) / aLineLen) + #========================================================================= # Start of test @@ -172,9 +186,9 @@ aCirclePnt3.setValue(aLineStart[0], aLineStart[1]) aSession.finishOperation() assert (aSketchFeature.numberOfSubs() == 7) # check the points do not change their positions -model.assertPoint(aPrevCenter, aPrevCenterXY) -model.assertPoint(aPointCoord, aPointCoordinates) -model.assertPoint(aStartPnt, aLineStart) +verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1]) +verifyPointCoordinates(aPointCoord, aPointCoordinates[0], aPointCoordinates[1]) +verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1]) # check newly created circle passes through the points aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle") verifyPointOnCircle(aPrevCenter, aCircle) @@ -221,10 +235,13 @@ aCirclePnt3.setValue(anArcCenter[0] + anArcRadius, anArcCenter[1]) aSession.finishOperation() assert (aSketchFeature.numberOfSubs() == 12) # check the tangent entities do not change their positions -model.assertPoint(aPrevCenter, aPrevCenterXY) +verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1]) assert (aPrevCircle.real("circle_radius").value() == aPrevCircleRadius) -model.assertLine(aLine, aLineStart, aLineEnd) -model.assertArc(anArc, anArcCenter, anArcStart, anArcEnd) +verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1]) +verifyPointCoordinates(aEndPnt, aLineEnd[0], aLineEnd[1]) +verifyPointCoordinates(anArcCenterPnt, anArcCenter[0], anArcCenter[1]) +verifyPointCoordinates(anArcStartPnt, anArcStart[0], anArcStart[1]) +verifyPointCoordinates(anArcEndPnt, anArcEnd[0], anArcEnd[1]) # check newly created circle passes through the points aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle") verifyTangentCircles(aCircle, aPrevCircle) diff --git a/src/SketchPlugin/Test/TestCreateCircleChangeType.py b/src/SketchPlugin/Test/TestCreateCircleChangeType.py index 5a4677d67..882e686d8 100644 --- a/src/SketchPlugin/Test/TestCreateCircleChangeType.py +++ b/src/SketchPlugin/Test/TestCreateCircleChangeType.py @@ -72,7 +72,13 @@ def verifyLastCircle(theSketch, theX, theY, theR): subroutine to verify position of last circle in the sketch """ aLastCircle = model.lastSubFeature(theSketch, "SketchCircle") - model.assertCircle(aLastCircle, [theX, theY], theR) + aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center")) + verifyPointCoordinates(aCenter, theX, theY) + aRadius = aLastCircle.real("circle_radius") + assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR) + +def verifyPointCoordinates(thePoint, theX, theY): + assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY) #========================================================================= diff --git a/src/SketchPlugin/Test/TestFillet.py b/src/SketchPlugin/Test/TestFillet.py index a8b1f08b3..3e0f6617c 100644 --- a/src/SketchPlugin/Test/TestFillet.py +++ b/src/SketchPlugin/Test/TestFillet.py @@ -125,7 +125,7 @@ def checkSmoothness(theSketch): def checkArcLineSmoothness(theArc, theLine): aCenter = geomDataAPI_Point2D(theArc.attribute("center_point")) - aDistance = model.distancePointLine(aCenter, theLine) + aDistance = distancePointLine(aCenter, theLine) aRadius = arcRadius(theArc) assert(math.fabs(aRadius - aDistance) < TOLERANCE) @@ -162,6 +162,16 @@ def arcRadius(theArc): aStart = geomDataAPI_Point2D(theArc.attribute("start_point")) return model.distancePointPoint(aCenter, aStart) +def distancePointLine(thePoint, theLine): + aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")) + aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")) + aLength = model.distancePointPoint(aLineStart, aLineEnd) + + aDir1x, aDir1y = aLineEnd.x() - aLineStart.x(), aLineEnd.y() - aLineStart.y() + aDir2x, aDir2y = thePoint.x() - aLineStart.x(), thePoint.y() - aLineStart.y() + aCross = aDir1x * aDir2y - aDir1y * aDir2x + return math.fabs(aCross) / aLength + #========================================================================= # Initialization of the test diff --git a/src/SketchPlugin/Test/TestFilletInteracting.py b/src/SketchPlugin/Test/TestFilletInteracting.py index 60783ed52..04160ace6 100644 --- a/src/SketchPlugin/Test/TestFilletInteracting.py +++ b/src/SketchPlugin/Test/TestFilletInteracting.py @@ -35,7 +35,7 @@ __updated__ = "2017-03-06" def isArcLineSmooth(theArc, theLine, theTolerance): aCenter = geomDataAPI_Point2D(theArc.attribute("center_point")) - aDistance = model.distancePointLine(aCenter, theLine) + aDistance = distancePointLine(aCenter, theLine) aRadius = arcRadius(theArc) return math.fabs(aRadius - aDistance) < theTolerance @@ -54,6 +54,15 @@ def arcRadius(theArc): aStart = geomDataAPI_Point2D(theArc.attribute("start_point")) return model.distancePointPoint(aCenter, aStart) +def distancePointLine(thePoint, theLine): + aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")) + aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")) + aLength = model.distancePointPoint(aLineStart, aLineEnd) + aDir1x, aDir1y = aLineEnd.x() - aLineStart.x(), aLineEnd.y() - aLineStart.y() + aDir2x, aDir2y = thePoint.x() - aLineStart.x(), thePoint.y() - aLineStart.y() + aCross = aDir1x * aDir2y - aDir1y * aDir2x + return math.fabs(aCross) / aLength + class TestFilletInteracting(unittest.TestCase): diff --git a/src/SketchPlugin/Test/TestMoveArc.py b/src/SketchPlugin/Test/TestMoveArc.py deleted file mode 100644 index 4419d85e1..000000000 --- a/src/SketchPlugin/Test/TestMoveArc.py +++ /dev/null @@ -1,349 +0,0 @@ -## Copyright (C) 2017 CEA/DEN, EDF R&D -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## See http:##www.salome-platform.org/ or -## email : webmaster.salome@opencascade.com -## - -""" - Test movement of the sketch arc of circle -""" - -import unittest -from GeomDataAPI import geomDataAPI_Point2D -from salome.shaper import model - -__updated__ = "2017-05-11" - -class TestMoveArc(unittest.TestCase): - def setUp(self): - model.begin() - self.myDocument = model.moduleDocument() - self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY")) - self.myCenter = [50., 50.] - self.myStart = [70., 50.] - self.myEnd = [50., 70.] - self.myArc = self.mySketch.addArc(self.myCenter[0], self.myCenter[1], self.myStart[0], self.myStart[1], self.myEnd[0], self.myEnd[1], False) - self.myDOF = 5 - model.do() - self.checkDOF() - - def tearDown(self): - model.assertArcValidity(self.myArc) - self.checkDOF() - model.end() - assert(model.checkPythonDump()) - - def checkDOF(self): - self.assertEqual(model.dof(self.mySketch), self.myDOF) - - def checkPointCoordinates(self, thePoint, theCoordinates): - self.assertAlmostEqual(thePoint.x(), theCoordinates[0]) - self.assertAlmostEqual(thePoint.y(), theCoordinates[1]) - - def checkPointOnArc(self, theCoordinates): - distPC = model.distancePointPoint(self.myArc.center(), theCoordinates) - radius = model.distancePointPoint(self.myArc.center(), self.myArc.startPoint()) - self.assertAlmostEqual(distPC, radius) - - def checkArcRadius(self): - radius = model.distancePointPoint(self.myArc.center(), self.myArc.startPoint()) - self.assertAlmostEqual(radius, self.myRadius) - - def fixArcRadius(self): - self.myRadius = 20. - self.mySketch.setRadius(self.myArc.results()[1], self.myRadius) - self.myDOF -= 1 - model.do() - self.checkDOF() - - def fixPoint(self, thePoint): - self.mySketch.setFixed(thePoint) - self.myDOF -= 2 - model.do() - self.checkDOF() - - def fixArc(self): - self.mySketch.setFixed(self.myArc.results()[1]) - self.myDOF -= 5 - model.do() - self.checkDOF() - - - def test_move_center_of_free_arc(self): - """ Test 1. Movement of center of a free arc - """ - newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.] - self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), newPosition) - - def test_move_start_of_free_arc(self): - """ Test 2. Movement of start point of a free arc - """ - newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.] - self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - self.checkPointCoordinates(self.myArc.startPoint(), newPosition) - - def test_move_end_of_free_arc(self): - """ Test 3. Movement of end point of a free arc - """ - newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.] - self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - self.checkPointCoordinates(self.myArc.endPoint(), newPosition) - - def test_move_free_arc(self): - """ Test 4. Movement of a free arc dragging the edge - """ - newPosition = [100., 80.] - self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.checkPointOnArc(newPosition) - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - - def test_move_center_of_arc_fixed_center(self): - """ Test 5. Movement of center of the arc with fixed center (nothing should be changed) - """ - self.fixPoint(self.myArc.center()) - - newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.] - self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - - def test_move_start_of_arc_fixed_center(self): - """ Test 6. Movement of start point of the arc with fixed center - """ - self.fixPoint(self.myArc.center()) - - newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.] - self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - self.checkPointCoordinates(self.myArc.startPoint(), newPosition) - - def test_move_end_of_arc_fixed_center(self): - """ Test 7. Movement of end point of the arc with fixed center - """ - self.fixPoint(self.myArc.center()) - - newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.] - self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - self.checkPointCoordinates(self.myArc.endPoint(), newPosition) - - def test_move_arc_fixed_center(self): - """ Test 8. Movement of the arc with fixed center dragging the edge - """ - self.fixPoint(self.myArc.center()) - - newPosition = [100., 80.] - self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.checkPointOnArc(newPosition) - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - - def test_move_center_of_arc_fixed_start(self): - """ Test 9. Movement of center of the arc with fixed start point - """ - self.fixPoint(self.myArc.startPoint()) - - newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.] - self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), newPosition) - self.checkPointCoordinates(self.myArc.startPoint(), self.myStart) - - def test_move_start_of_arc_fixed_start(self): - """ Test 10. Movement of start point of the arc with fixed start point (nothing should be changed) - """ - self.fixPoint(self.myArc.startPoint()) - - newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.] - self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - self.checkPointCoordinates(self.myArc.startPoint(), self.myStart) - self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd) - - def test_move_end_of_arc_fixed_start(self): - """ Test 11. Movement of end point of the arc with fixed start point - """ - self.fixPoint(self.myArc.startPoint()) - - newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.] - self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.startPoint(), self.myStart) - self.assertNotEqual(self.myArc.center().x(), self.myCenter[0]) - self.assertNotEqual(self.myArc.center().y(), self.myCenter[1]) - - def test_move_arc_fixed_start(self): - """ Test 12. Movement of the arc with fixed start point dragging the edge - """ - self.fixPoint(self.myArc.startPoint()) - - newPosition = [100., 80.] - self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.startPoint(), self.myStart) - self.assertNotEqual(self.myArc.center().x(), self.myCenter[0]) - self.assertNotEqual(self.myArc.center().y(), self.myCenter[1]) - - def test_move_center_of_arc_fixed_end(self): - """ Test 13. Movement of center of the arc with fixed end point - """ - self.fixPoint(self.myArc.endPoint()) - - newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.] - self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), newPosition) - self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd) - - def test_move_start_of_arc_fixed_end(self): - """ Test 14. Movement of start point of the arc with fixed end point - """ - self.fixPoint(self.myArc.endPoint()) - - newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.] - self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd) - self.assertNotEqual(self.myArc.center().x(), self.myCenter[0]) - self.assertNotEqual(self.myArc.center().y(), self.myCenter[1]) - - def test_move_end_of_arc_fixed_end(self): - """ Test 15. Movement of end point of the arc with fixed end point (nothing should be changed) - """ - self.fixPoint(self.myArc.endPoint()) - - newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.] - self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - self.checkPointCoordinates(self.myArc.startPoint(), self.myStart) - self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd) - - def test_move_arc_fixed_end(self): - """ Test 16. Movement of the arc with fixed end point dragging the edge - """ - self.fixPoint(self.myArc.endPoint()) - - newPosition = [100., 80.] - self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd) - self.assertNotEqual(self.myArc.center().x(), self.myCenter[0]) - self.assertNotEqual(self.myArc.center().y(), self.myCenter[1]) - - def test_move_center_of_arc_fixed_radius(self): - """ Test 17. Movement of center of the arc with fixed radius - """ - self.fixArcRadius() - - newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.] - self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), newPosition) - self.checkArcRadius() - - def test_move_start_of_arc_fixed_radius(self): - """ Test 18. Movement of start point of the arc with fixed radius - """ - self.fixArcRadius() - - newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.] - self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkArcRadius() - - def test_move_end_of_arc_fixed_radius(self): - """ Test 19. Movement of end point of the arc with fixed radius - """ - self.fixArcRadius() - - newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.] - self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkArcRadius() - - def test_move_arc_fixed_radius(self): - """ Test 20. Movement of the arc with fixed radius dragging the edge - """ - self.fixArcRadius() - - newPosition = [100., 80.] - self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.checkArcRadius() - - def test_move_center_of_fixed_arc(self): - """ Test 21. Movement of center of fully fixed arc (nothing should be changed) - """ - self.fixArc() - - newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.] - self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - self.checkPointCoordinates(self.myArc.startPoint(), self.myStart) - self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd) - - def test_move_start_of_fixed_arc(self): - """ Test 22. Movement of start point of fully fixed arc (nothing should be changed) - """ - self.fixArc() - - newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.] - self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - self.checkPointCoordinates(self.myArc.startPoint(), self.myStart) - self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd) - - def test_move_end_of_fixed_arc(self): - """ Test 23. Movement of end point of fully fixed arc (nothing should be changed) - """ - self.fixArc() - - newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.] - self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - self.checkPointCoordinates(self.myArc.startPoint(), self.myStart) - self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd) - - def test_move_fixed_arc(self): - """ Test 24. Movement of fully fixed arc (nothing should be changed) - """ - self.fixArc() - - newPosition = [100., 80.] - self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myArc.center(), self.myCenter) - self.checkPointCoordinates(self.myArc.startPoint(), self.myStart) - self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd) - - -if __name__ == '__main__': - unittest.main() diff --git a/src/SketchPlugin/Test/TestMoveCircle.py b/src/SketchPlugin/Test/TestMoveCircle.py deleted file mode 100644 index 54a9b580e..000000000 --- a/src/SketchPlugin/Test/TestMoveCircle.py +++ /dev/null @@ -1,149 +0,0 @@ -## Copyright (C) 2017 CEA/DEN, EDF R&D -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## See http:##www.salome-platform.org/ or -## email : webmaster.salome@opencascade.com -## - -""" - Test movement of the sketch circle -""" - -import unittest -from GeomDataAPI import geomDataAPI_Point2D -from salome.shaper import model - -__updated__ = "2017-05-11" - -class TestMoveCircle(unittest.TestCase): - def setUp(self): - model.begin() - self.myDocument = model.moduleDocument() - self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY")) - self.myCenter = [70., 50.] - self.myRadius = 20. - self.myCircle = self.mySketch.addCircle(self.myCenter[0], self.myCenter[1], self.myRadius) - self.myDOF = 3 - model.do() - self.checkDOF() - - def tearDown(self): - self.checkDOF() - model.end() - assert(model.checkPythonDump()) - - def checkDOF(self): - self.assertEqual(model.dof(self.mySketch), self.myDOF) - - def checkPointCoordinates(self, thePoint, theCoordinates): - self.assertAlmostEqual(thePoint.x(), theCoordinates[0]) - self.assertAlmostEqual(thePoint.y(), theCoordinates[1]) - - def checkPointOnCircle(self, theCoordinates): - self.assertAlmostEqual(model.distancePointPoint(self.myCircle.center(), theCoordinates), self.myCircle.radius().value()) - - def fixCircleRadius(self): - self.mySketch.setRadius(self.myCircle.results()[1], self.myRadius) - self.myDOF -= 1 - model.do() - self.checkDOF() - - def fixCircleCenter(self): - self.mySketch.setFixed(self.myCircle.center()) - self.myDOF -= 2 - model.do() - self.checkDOF() - - - def test_move_center_free_circle(self): - """ Test 1. Movement of central point of a free circle - """ - newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.] - self.mySketch.move(self.myCircle.center(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myCircle.center(), newPosition) - self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius) - - def test_move_free_circle(self): - """ Test 2. Movement of a free circle dragging the edge - """ - newPosition = [120., 90.] - self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myCircle.center(), self.myCenter) - self.checkPointOnCircle(newPosition) - self.assertNotEqual(self.myCircle.radius().value(), self.myRadius) - - def test_move_center_circle_fixed_radius(self): - """ Test 3. Movement of central point of a circle with fixed radius - """ - self.fixCircleRadius() - - newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.] - self.mySketch.move(self.myCircle.center(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myCircle.center(), newPosition) - self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius) - - def test_move_circle_fixed_radius(self): - """ Test 4. Movement of a circle with fixed radius - """ - self.fixCircleRadius() - - newPosition = [120., 90.] - self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius) - self.assertNotEqual(self.myCircle.center().x(), self.myCenter[0]) - self.assertNotEqual(self.myCircle.center().y(), self.myCenter[1]) - - def test_move_center_circle_fixed_center(self): - """ Test 5. Movement of central point of a circle with fixed center (nothing should be changed) - """ - self.fixCircleCenter() - - newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.] - self.mySketch.move(self.myCircle.center(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myCircle.center(), self.myCenter) - self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius) - - def test_move_circle_fixed_center(self): - """ Test 6. Movement of a circle with fixed center - """ - self.fixCircleCenter() - - newPosition = [120., 90.] - self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.checkPointOnCircle(newPosition) - self.assertNotEqual(self.myCircle.radius().value(), self.myRadius) - - def test_move_fixed_circle(self): - """ Test 7. Trying to move fully fixed circle - """ - self.fixCircleCenter() - self.fixCircleRadius() - - newPosition = [120., 90.] - self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myCircle.center(), self.myCenter) - self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius) - - -if __name__ == '__main__': - unittest.main() diff --git a/src/SketchPlugin/Test/TestMoveLine.py b/src/SketchPlugin/Test/TestMoveLine.py deleted file mode 100644 index 3d4efa1dc..000000000 --- a/src/SketchPlugin/Test/TestMoveLine.py +++ /dev/null @@ -1,136 +0,0 @@ -## Copyright (C) 2017 CEA/DEN, EDF R&D -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## See http:##www.salome-platform.org/ or -## email : webmaster.salome@opencascade.com -## - -""" - Test movement of the sketch line -""" - -import unittest -from GeomDataAPI import geomDataAPI_Point2D -from salome.shaper import model - -__updated__ = "2017-05-11" - -class TestMoveLine(unittest.TestCase): - def setUp(self): - model.begin() - self.myDocument = model.moduleDocument() - self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY")) - self.myStart = [70., 50.] - self.myEnd = [100., 20.] - self.myLine = self.mySketch.addLine(self.myStart[0], self.myStart[1], self.myEnd[0], self.myEnd[1]) - self.myDOF = 4 - model.do() - self.checkDOF() - - def tearDown(self): - self.checkDOF() - model.end() - assert(model.checkPythonDump()) - - def checkDOF(self): - self.assertEqual(model.dof(self.mySketch), self.myDOF) - - def checkPointCoordinates(self, thePoint, theCoordinates): - self.assertAlmostEqual(thePoint.x(), theCoordinates[0]) - self.assertAlmostEqual(thePoint.y(), theCoordinates[1]) - - def checkPointOnLine(self, theCoordinates): - self.assertAlmostEqual(model.distancePointLine(theCoordinates, self.myLine), 0.) - - def test_move_start_of_free_line(self): - """ Test 1. Movement of start point of a free line - """ - newPosition = [self.myStart[0] + 20., self.myStart[1] + 10.] - self.mySketch.move(self.myLine.startPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myLine.startPoint(), newPosition) - self.checkPointCoordinates(self.myLine.endPoint(), self.myEnd) - - def test_move_end_of_free_line(self): - """ Test 2. Movement of end point of a free line - """ - newPosition = [self.myEnd[0] + 20., self.myEnd[1] + 10.] - self.mySketch.move(self.myLine.endPoint(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myLine.startPoint(), self.myStart) - self.checkPointCoordinates(self.myLine.endPoint(), newPosition) - - def test_move_free_line(self): - """ Test 3. Movement of free line - """ - diff = [self.myEnd[0] - self.myStart[0], self.myEnd[1] - self.myStart[1]] - - newPosition = [100., 100.] - self.mySketch.move(self.myLine.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.checkPointOnLine(newPosition) - - # additionally check the line keeps geometry (relative positions of extremities) - startPoint = self.myLine.startPoint() - endPoint = [startPoint.x() + diff[0], startPoint.y() + diff[1]] - self.checkPointCoordinates(self.myLine.endPoint(), endPoint) - - def test_move_line_start_fixed(self): - """ Test 4. Movement of a line, which start point is fixed - """ - fixed = self.mySketch.setFixed(self.myLine.startPoint()) - self.myDOF -= 2 - model.do() - self.checkDOF() - - newPosition = [100., 100.] - self.mySketch.move(self.myLine.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myLine.startPoint(), self.myStart) - self.assertNotEqual(self.myLine.endPoint().x(), self.myEnd[0]) - self.assertNotEqual(self.myLine.endPoint().y(), self.myEnd[1]) - - def test_move_line_end_fixed(self): - """ Test 5. Movement of a line, which end point is fixed - """ - fixed = self.mySketch.setFixed(self.myLine.endPoint()) - self.myDOF -= 2 - model.do() - self.checkDOF() - - newPosition = [100., 100.] - self.mySketch.move(self.myLine.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.assertNotEqual(self.myLine.startPoint().x(), self.myStart[0]) - self.assertNotEqual(self.myLine.startPoint().y(), self.myStart[1]) - self.checkPointCoordinates(self.myLine.endPoint(), self.myEnd) - - def test_move_line_fully_fixed(self): - """ Test 6. Movement of fully fixed line (should not change its coordinates) - """ - fixed = self.mySketch.setFixed(self.myLine.defaultResult()) - self.myDOF -= 4 - model.do() - - newPosition = [100., 100.] - self.mySketch.move(self.myLine.defaultResult(), newPosition[0], newPosition[1]) - model.do() - self.checkPointCoordinates(self.myLine.startPoint(), self.myStart) - self.checkPointCoordinates(self.myLine.endPoint(), self.myEnd) - - -if __name__ == '__main__': - unittest.main() diff --git a/src/SketchPlugin/Test/TestMovePoint.py b/src/SketchPlugin/Test/TestMovePoint.py deleted file mode 100644 index 60b0a43b6..000000000 --- a/src/SketchPlugin/Test/TestMovePoint.py +++ /dev/null @@ -1,108 +0,0 @@ -## Copyright (C) 2017 CEA/DEN, EDF R&D -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## See http:##www.salome-platform.org/ or -## email : webmaster.salome@opencascade.com -## - -""" - Test movement of the sketch point -""" - -import unittest -from GeomDataAPI import geomDataAPI_Point2D -from salome.shaper import model - -__updated__ = "2017-05-11" - -class TestMovePoint(unittest.TestCase): - def setUp(self): - model.begin() - self.myDocument = model.moduleDocument() - self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY")) - self.myOrigin = self.mySketch.addPoint(model.selection("VERTEX", "Origin")) - self.myPoint = self.mySketch.addPoint(70, 50) - self.myPointCoordinates = geomDataAPI_Point2D(self.myPoint.coordinates()) - self.myDOF = 2 - model.do() - self.checkDOF() - - def tearDown(self): - self.checkDOF() - model.end() - assert(model.checkPythonDump()) - - def checkDOF(self): - self.assertEqual(model.dof(self.mySketch), self.myDOF) - - def test_move_free_point(self): - """ Test 1. Movement of free point - """ - newPosition = [100., 100.] - self.mySketch.move(self.myPoint, newPosition[0], newPosition[1]) - model.do() - self.assertAlmostEqual(self.myPointCoordinates.x(), newPosition[0]) - self.assertAlmostEqual(self.myPointCoordinates.y(), newPosition[1]) - - def test_move_fixed_x(self): - """ Test 2. Movement of partially fixed point (fixed x coordinate) - """ - DISTANCE = 50. - horizDistance = self.mySketch.setHorizontalDistance(self.myOrigin.result(), self.myPoint.coordinates(), DISTANCE) - self.myDOF -= 1 - model.do() - self.checkDOF() - - newPosition = [100., 100.] - self.mySketch.move(self.myPoint, newPosition[0], newPosition[1]) - model.do() - self.assertAlmostEqual(self.myPointCoordinates.x(), DISTANCE) - self.assertAlmostEqual(self.myPointCoordinates.y(), newPosition[1]) - - def test_move_fixed_y(self): - """ Test 3. Movement of partially fixed point (fixed y coordinate) - """ - DISTANCE = 50. - vertDistance = self.mySketch.setVerticalDistance(self.myOrigin.result(), self.myPoint.coordinates(), DISTANCE) - self.myDOF -= 1 - model.do() - self.checkDOF() - - newPosition = [100., 100.] - self.mySketch.move(self.myPoint, newPosition[0], newPosition[1]) - model.do() - self.assertAlmostEqual(self.myPointCoordinates.x(), newPosition[0]) - self.assertAlmostEqual(self.myPointCoordinates.y(), DISTANCE) - - def test_move_fully_fixed(self): - """ Test 4. Movement of fully fixed point (should not be changed) - """ - coord = [self.myPointCoordinates.x(), self.myPointCoordinates.y()] - - fixed = self.mySketch.setFixed(self.myPoint.result()) - self.myDOF -= 2 - model.do() - self.checkDOF() - - newPosition = [100., 100.] - self.mySketch.move(self.myPoint, newPosition[0], newPosition[1]) - model.do() - self.assertAlmostEqual(self.myPointCoordinates.x(), coord[0]) - self.assertAlmostEqual(self.myPointCoordinates.y(), coord[1]) - - -if __name__ == '__main__': - unittest.main() diff --git a/src/SketchPlugin/Test/TestMovementComplex.py b/src/SketchPlugin/Test/TestMovementComplex.py deleted file mode 100644 index 6fe6afe90..000000000 --- a/src/SketchPlugin/Test/TestMovementComplex.py +++ /dev/null @@ -1,384 +0,0 @@ -## Copyright (C) 2017 CEA/DEN, EDF R&D -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## See http:##www.salome-platform.org/ or -## email : webmaster.salome@opencascade.com -## - -""" - Test moving the entities in the complex sketch by the example of a clamp -""" - -from salome.shaper import model -from SketchAPI import * -from GeomAPI import * -import math - -TOLERANCE = 1.e-7 - -model.begin() -partSet = model.moduleDocument() -Part_1 = model.addPart(partSet) -Part_1_doc = Part_1.document() - -# Create sketch representing main part of clamp -Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) -SketchLine_1 = Sketch_1.addLine(20, 165, 175, 165) -SketchLine_2 = Sketch_1.addLine(175, 165, 175, 120) -SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) -SketchLine_3 = Sketch_1.addLine(175, 120, 80, 20) -SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) -SketchLine_4 = Sketch_1.addLine(80, 20, 20, 20) -SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) -SketchLine_5 = Sketch_1.addLine(20, 20, 20, 165) -SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) -SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_5.endPoint()) -SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 155) -SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) -SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_2.result(), SketchLine_1.result()) -SketchConstraintParallel_1 = Sketch_1.setParallel(SketchLine_1.result(), SketchLine_4.result()) -SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_5.result()) -SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), 45) -SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_4.startPoint(), SketchLine_1.result(), 145) -SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchLine_4.startPoint(), SketchLine_3.startPoint(), 95) -SketchPoint_1 = Sketch_1.addPoint(model.selection("VERTEX", "PartSet/Origin")) -SketchConstraintDistanceHorizontal_2 = Sketch_1.setHorizontalDistance(SketchPoint_1.coordinates(), SketchLine_5.endPoint(), 20) -SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchPoint_1.coordinates(), SketchLine_5.endPoint(), 165) -model.do() - -# ============================================================================= -# Test 1. Create fillet and move fillet arc -# ============================================================================= -Sketch_1.setFillet(SketchLine_5.startPoint()) -SketchArc_1 = SketchAPI_Arc(model.lastSubFeature(Sketch_1, "SketchArc")) -model.do() -anArcCenter = [SketchArc_1.center().x(), SketchArc_1.center().y()] -anArcStart = [SketchArc_1.startPoint().x(), SketchArc_1.startPoint().y()] -anArcEnd = [SketchArc_1.endPoint().x(), SketchArc_1.endPoint().y()] -# move arc dragging center -delta = [1., 1.] -for i in range(1, 10): - anArcCenter = [anArcCenter[0] + delta[0], anArcCenter[1] + delta[1]] - Sketch_1.move(SketchArc_1.center(), anArcCenter[0], anArcCenter[1]) - model.do() - model.assertArcValidity(SketchArc_1) - model.assertPoint(SketchArc_1.center(), anArcCenter) - assert(SketchArc_1.startPoint().x() == anArcStart[0]) - assert(SketchArc_1.endPoint().y() == anArcEnd[1]) - if i == 5: - delta = [-1., -1.] -# move arc dragging start point -delta = [1., 1.] -aPosition = anArcStart -for i in range(1, 10): - aPosition = [aPosition[0] + delta[0], aPosition[1] + delta[1]] - Sketch_1.move(SketchArc_1.startPoint(), aPosition[0], aPosition[1]) - model.do() - model.assertArcValidity(SketchArc_1) - assert(SketchArc_1.startPoint().x() == anArcStart[0]) - assert(SketchArc_1.endPoint().y() == anArcEnd[1]) - if i == 5: - delta = [-1., -1.] -# move arc dragging end point -delta = [1., 1.] -aPosition = anArcEnd -for i in range(1, 10): - aPosition = [aPosition[0] + delta[0], aPosition[1] + delta[1]] - Sketch_1.move(SketchArc_1.endPoint(), aPosition[0], aPosition[1]) - model.do() - model.assertArcValidity(SketchArc_1) - assert(SketchArc_1.startPoint().x() == anArcStart[0]) - assert(SketchArc_1.endPoint().y() == anArcEnd[1]) - if i == 5: - delta = [-1., -1.] - -# ============================================================================= -# Test 2. Create circle and move it near its potential position -# ============================================================================= -aCircleCenter = [0, 0] -aCircleRadius = 5 -SketchCircle_1 = Sketch_1.addCircle(aCircleCenter[0], aCircleCenter[1], aCircleRadius) -model.do() -# move center -delta = [3., 2.] -for i in range(1, 15): - aCircleCenter = [aCircleCenter[0] + delta[0], aCircleCenter[1] + delta[1]] - Sketch_1.move(SketchCircle_1.center(), aCircleCenter[0], aCircleCenter[1]) - model.do() - model.assertPoint(SketchCircle_1.center(), aCircleCenter) - assert(SketchCircle_1.radius().value() == aCircleRadius) -# move circle by dragging edge -aPosition = [aCircleCenter[0] + aCircleRadius, aCircleCenter[1]] -delta = [1., 1.] -for i in range(1, 10): - aPosition = [aPosition[0] + delta[0], aPosition[1] + delta[1]] - Sketch_1.move(SketchCircle_1.defaultResult(), aPosition[0], aPosition[1]) - model.do() - model.assertPoint(SketchCircle_1.center(), aCircleCenter) - assert(math.fabs(SketchCircle_1.radius().value() - model.distancePointPoint(aPosition, aCircleCenter)) < TOLERANCE) - -# ============================================================================= -# Test 3. Constrain center of circle and move it again -# ============================================================================= -SketchConstraintDistanceHorizontal_3 = Sketch_1.setHorizontalDistance(SketchCircle_1.center(), SketchArc_1.startPoint(), -30) -model.do() -# move center -delta = [1., 1.] -aCircleCenter = [SketchCircle_1.center().x(), SketchCircle_1.center().y()] -aPosition = aCircleCenter -for i in range(1, 10): - aPosition = [aPosition[0] + delta[0], aPosition[1] + delta[1]] - Sketch_1.move(SketchCircle_1.center(), aPosition[0], aPosition[1]) - model.do() - assert(SketchCircle_1.center().x() == aCircleCenter[0]) - if i == 5: - delta = [-1., -1.] -# move circle by dragging edge -aCircleCenter = [SketchCircle_1.center().x(), SketchCircle_1.center().y()] -aPosition = [aCircleCenter[0] + aCircleRadius, aCircleCenter[1]] -delta = [1., 1.] -for i in range(1, 10): - aPosition = [aPosition[0] + delta[0], aPosition[1] + delta[1]] - Sketch_1.move(SketchCircle_1.defaultResult(), aPosition[0], aPosition[1]) - model.do() - model.assertPoint(SketchCircle_1.center(), aCircleCenter) - assert(math.fabs(SketchCircle_1.radius().value() - model.distancePointPoint(aPosition, aCircleCenter)) < TOLERANCE) -# set radius of the circle -aCircleRadius = 17.5 -SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], aCircleRadius) -model.do() -# move center -delta = [1., 1.] -aCircleCenter = [SketchCircle_1.center().x(), SketchCircle_1.center().y()] -aPosition = aCircleCenter -for i in range(1, 10): - aPosition = [aPosition[0] + delta[0], aPosition[1] + delta[1]] - Sketch_1.move(SketchCircle_1.center(), aPosition[0], aPosition[1]) - model.do() - assert(SketchCircle_1.center().x() == aCircleCenter[0]) - assert(SketchCircle_1.radius().value() == aCircleRadius) - if i == 5: - delta = [-1., -1.] -# move circle by dragging edge -aCircleCenter = [SketchCircle_1.center().x(), SketchCircle_1.center().y()] -aPosition = [aCircleCenter[0] + aCircleRadius, aCircleCenter[1]] -delta = [1., 1.] -for i in range(1, 10): - aPosition = [aPosition[0] + delta[0], aPosition[1] + delta[1]] - Sketch_1.move(SketchCircle_1.defaultResult(), aPosition[0], aPosition[1]) - model.do() - assert(SketchCircle_1.center().x() == aCircleCenter[0]) - assert(SketchCircle_1.radius().value() == aCircleRadius) - -# ============================================================================= -# Test 4. Set centers of circle and arc coincident and move circle -# ============================================================================= -SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchArc_1.center()) -model.do() -assert(model.dof(Sketch_1) == 0) -# move circle -aCircleCenter = [SketchCircle_1.center().x(), SketchCircle_1.center().y()] -aPosition = [aCircleCenter[0], aCircleCenter[1] + aCircleRadius] -delta = [0., 1.] -for i in range(1, 10): - aPosition = [aPosition[0] + delta[0], aPosition[1] + delta[1]] - Sketch_1.move(SketchCircle_1.defaultResult(), aPosition[0], aPosition[1]) - model.do() - model.assertPoint(SketchCircle_1.center(), aCircleCenter) - assert(SketchCircle_1.radius().value() == aCircleRadius) -assert(model.dof(Sketch_1) == 0) - -# Extrude main part of clamp -Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2r-SketchLine_3r-SketchLine_4r-SketchLine_5r-SketchArc_1_2f-SketchCircle_1_2r")], model.selection(), 10, 0) -model.do() - - -# Create sketch representing orthogonal part of clamp -Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ")) -SketchRectangle_1 = Sketch_2.addRectangle(20, 0, 100, 50) -[SketchLine_6, SketchLine_7, SketchLine_8, SketchLine_9] = SketchRectangle_1.lines() -SketchProjection_1 = Sketch_2.addProjection(model.selection("EDGE", "Sketch_1/Edge-SketchLine_1")) -SketchLine_10 = SketchProjection_1.createdFeature() -SketchConstraintCoincidence_7 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_7).startPoint(), SketchAPI_Line(SketchLine_10).startPoint()) -SketchConstraintEqual_1 = Sketch_2.setEqual(SketchLine_8.result(), SketchLine_10.result()) -SketchConstraintLength_3 = Sketch_2.setLength(SketchLine_7.result(), 80) -model.do() -assert(model.dof(Sketch_2) == 0) - -# Create auxiliary lines for further holes -SketchLine_11 = Sketch_2.addLine(20, 10, 175, 10) -SketchLine_11.setAuxiliary(True) -SketchConstraintCoincidence_8 = Sketch_2.setCoincident(SketchLine_11.startPoint(), SketchLine_7.result()) -SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchLine_11.endPoint(), SketchLine_9.result()) -SketchConstraintParallel_2 = Sketch_2.setParallel(SketchLine_11.result(), SketchLine_8.result()) -SketchLine_12 = Sketch_2.addLine(150, 0, 150, 80) -SketchLine_12.setAuxiliary(True) -SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchLine_12.startPoint(), SketchLine_6.result()) -SketchConstraintCoincidence_11 = Sketch_2.setCoincident(SketchLine_12.endPoint(), SketchLine_8.result()) -SketchConstraintPerpendicular_2 = Sketch_2.setPerpendicular(SketchLine_11.result(), SketchLine_12.result()) -model.do() -assert(model.dof(Sketch_2) == 2) - -# ============================================================================= -# Test 5. Create circular hole and move it -# ============================================================================= -SketchCircle_2 = Sketch_2.addCircle(50, 10, 10) -SketchConstraintCoincidence_12 = Sketch_2.setCoincident(SketchCircle_2.center(), SketchLine_11.result()) -model.do() -# move center -delta = [2., 1.] -aCircleCenter = [SketchCircle_2.center().x(), SketchCircle_2.center().y()] -aCircleRadius = SketchCircle_2.radius().value() -for i in range(1, 10): - aCircleCenter = [aCircleCenter[0] + delta[0], aCircleCenter[1] + delta[1]] - Sketch_2.move(SketchCircle_2.center(), aCircleCenter[0], aCircleCenter[1]) - model.do() - model.assertPoint(SketchCircle_2.center(), aCircleCenter) - assert(aCircleRadius == SketchCircle_2.radius().value()) -# move circle by dragging edge -aCircleCenter = [SketchCircle_2.center().x(), SketchCircle_2.center().y()] -aPosition = [aCircleCenter[0] + aCircleRadius, aCircleCenter[1]] -delta = [0., 1.] -for i in range(1, 10): - aPosition = [aPosition[0] + delta[0], aPosition[1] + delta[1]] - Sketch_1.move(SketchCircle_2.defaultResult(), aPosition[0], aPosition[1]) - model.do() - model.assertPoint(SketchCircle_2.center(), aCircleCenter) - assert(math.fabs(SketchCircle_2.radius().value() - model.distancePointPoint(aPosition, aCircleCenter)) < TOLERANCE) - -SketchConstraintDistanceHorizontal_4 = Sketch_2.setHorizontalDistance(SketchLine_11.startPoint(), SketchCircle_2.center(), 21.5) -model.do() -assert(model.dof(Sketch_2) == 3) - -# ============================================================================= -# Test 6. Create oval hole and move it -# ============================================================================= -anArcRadius = 5 -anArcCenter = [SketchLine_11.endPoint().x() + anArcRadius, SketchCircle_2.center().y()] -SketchArc_2 = Sketch_2.addArc(anArcCenter[0], anArcCenter[1], anArcCenter[0], anArcCenter[1] + anArcRadius, anArcCenter[0], anArcCenter[1] - anArcRadius, True) -SketchConstraintCoincidence_13 = Sketch_2.setCoincident(SketchArc_2.center(), SketchLine_11.result()) -SketchLine_13 = Sketch_2.addLine(anArcCenter[0], anArcCenter[1] + anArcRadius, SketchLine_12.startPoint().x(), anArcCenter[1] + anArcRadius) -SketchConstraintCoincidence_14 = Sketch_2.setCoincident(SketchArc_2.startPoint(), SketchLine_13.startPoint()) -SketchConstraintCoincidence_15 = Sketch_2.setCoincident(SketchLine_13.endPoint(), SketchLine_12.result()) -SketchConstraintPerpendicular_3 = Sketch_2.setPerpendicular(SketchLine_13.result(), SketchLine_12.result()) -SketchLine_14 = Sketch_2.addLine(anArcCenter[0], anArcCenter[1] - anArcRadius, SketchLine_12.startPoint().x(), anArcCenter[1] - anArcRadius) -SketchConstraintCoincidence_16 = Sketch_2.setCoincident(SketchArc_2.endPoint(), SketchLine_14.startPoint()) -SketchConstraintCoincidence_17 = Sketch_2.setCoincident(SketchLine_14.endPoint(), SketchLine_12.result()) -SketchConstraintPerpendicular_4 = Sketch_2.setPerpendicular(SketchLine_14.result(), SketchLine_12.result()) -SketchConstraintTangent_1 = Sketch_2.setTangent(SketchArc_2.results()[1], SketchLine_13.result()) -SketchConstraintTangent_2 = Sketch_2.setTangent(SketchArc_2.results()[1], SketchLine_14.result()) -model.do() -assert(model.dof(Sketch_2) == 5) -# move center of arc -delta = [-2., 1.] -anArcCenter = [SketchArc_2.center().x(), SketchArc_2.center().y()] -for i in range(1, 10): - anArcCenter = [anArcCenter[0] + delta[0], anArcCenter[1] + delta[1]] - Sketch_2.move(SketchArc_2.center(), anArcCenter[0], anArcCenter[1]) - model.do() - model.assertArc(SketchArc_2, anArcCenter, [], []) - -# Complete the oval hole -SketchConstraintMirror_1_objects = [SketchLine_13.result(), SketchArc_2.results()[1], SketchLine_14.result()] -SketchConstraintMirror_1 = Sketch_2.addMirror(SketchLine_12.result(), SketchConstraintMirror_1_objects) -[SketchLine_15, SketchArc_3, SketchLine_16] = SketchConstraintMirror_1.mirrored() -model.do() - -# ============================================================================= -# Test 7. Set arc and circle equal radii and move arc -# ============================================================================= -SketchConstraintEqual_2 = Sketch_2.setEqual(SketchCircle_2.results()[1], SketchArc_2.results()[1]) -model.do() -# move center of arc -delta = [-1., -1.] -anArcCenter = [SketchArc_2.center().x(), SketchArc_2.center().y()] -aCircleCenter = [SketchCircle_2.center().x(), SketchCircle_2.center().y()] -for i in range(1, 10): - anArcCenter = [anArcCenter[0] + delta[0], anArcCenter[1] + delta[1]] - Sketch_2.move(SketchArc_2.center(), anArcCenter[0], anArcCenter[1]) - model.do() - model.assertArc(SketchArc_2, anArcCenter, [], []) - model.assertPoint(SketchCircle_2.center(), [aCircleCenter[0], anArcCenter[1]]) - anArcRadius = model.distancePointPoint(SketchArc_2.center(), SketchArc_2.startPoint()) - assert(math.fabs(SketchCircle_2.radius().value() - anArcRadius) < TOLERANCE) -# move arc by dragging edge -aCircleCenter = [SketchCircle_2.center().x(), SketchCircle_2.center().y()] -anArcCenter = [SketchArc_2.center().x(), SketchArc_2.center().y()] -aPosition = [anArcCenter[0] + anArcRadius, anArcCenter[1]] -delta = [1., 1.] -for i in range(1, 10): - aPosition = [aPosition[0] + delta[0], aPosition[1] + delta[1]] - Sketch_2.move(SketchArc_2.defaultResult(), aPosition[0], aPosition[1]) - model.do() - model.assertArc(SketchArc_2, anArcCenter, [], []) - model.assertPoint(SketchCircle_2.center(), aCircleCenter) - anArcRadius = model.distancePointPoint(SketchArc_2.center(), SketchArc_2.startPoint()) - assert(math.fabs(SketchCircle_2.radius().value() - anArcRadius) < TOLERANCE) - if i == 5: - delta = [-1., -1.] - -# Fix all DOF in Sketch_2 -SketchConstraintDistance_2 = Sketch_2.setDistance(SketchArc_2.center(), SketchLine_9.result(), 21.5) -SketchConstraintLength_4 = Sketch_2.setLength(SketchLine_13.result(), 3.5) -SketchConstraintRadius_2 = Sketch_2.setRadius(SketchCircle_2.results()[1], 6.5) -SketchConstraintDistance_3 = Sketch_2.setDistance(SketchCircle_2.center(), SketchLine_8.result(), 30) -model.do() - -Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_6r-SketchLine_7r-SketchLine_8r-SketchLine_9r-SketchCircle_2_2r-SketchArc_2_2r-SketchLine_13r-SketchLine_14f-SketchLine_15f-SketchArc_3_2r-SketchLine_16r")], model.selection(), -165, 155) -Boolean_1 = model.addFuse(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], [model.selection("SOLID", "Extrusion_2_1")]) - -Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "Boolean_1_1/Modified_8")) -SketchLine_17 = Sketch_3.addLine(145, 0, 165, 0) -SketchPoint_2 = Sketch_3.addPoint(model.selection("VERTEX", "Boolean_1_1/Modified_7&Boolean_1_1/Modified_6&Boolean_1_1/Modified_2")) -SketchConstraintCoincidence_23 = Sketch_3.setCoincident(SketchLine_17.endPoint(), SketchPoint_2.result()) -SketchLine_18 = Sketch_3.addLine(165, 0, 165, -20) -SketchLine_19 = Sketch_3.addLine(165, -20, 145, -20) -SketchLine_20 = Sketch_3.addLine(145, -20, 145, 0) -SketchConstraintCoincidence_24 = Sketch_3.setCoincident(SketchLine_20.endPoint(), SketchLine_17.startPoint()) -SketchConstraintCoincidence_25 = Sketch_3.setCoincident(SketchLine_17.endPoint(), SketchLine_18.startPoint()) -SketchConstraintCoincidence_26 = Sketch_3.setCoincident(SketchLine_18.endPoint(), SketchLine_19.startPoint()) -SketchConstraintCoincidence_27 = Sketch_3.setCoincident(SketchLine_19.endPoint(), SketchLine_20.startPoint()) -SketchConstraintHorizontal_4 = Sketch_3.setHorizontal(SketchLine_17.result()) -SketchConstraintVertical_4 = Sketch_3.setVertical(SketchLine_18.result()) -SketchConstraintHorizontal_5 = Sketch_3.setHorizontal(SketchLine_19.result()) -SketchConstraintVertical_5 = Sketch_3.setVertical(SketchLine_20.result()) -SketchArc_4 = Sketch_3.addArc(145, -20, 165, -20, 145, 0, False) -SketchConstraintCoincidence_28 = Sketch_3.setCoincident(SketchLine_19.endPoint(), SketchArc_4.center()) -SketchConstraintCoincidence_29 = Sketch_3.setCoincident(SketchLine_18.endPoint(), SketchArc_4.startPoint()) -SketchConstraintCoincidence_30 = Sketch_3.setCoincident(SketchArc_4.endPoint(), SketchLine_20.endPoint()) -SketchConstraintRadius_3 = Sketch_3.setRadius(SketchArc_4.results()[1], 20) -SketchArc_5 = Sketch_3.addArc(145, -20, 155, -20, 145, -10, False) -SketchConstraintCoincidence_31 = Sketch_3.setCoincident(SketchLine_19.endPoint(), SketchArc_5.center()) -SketchConstraintCoincidence_32 = Sketch_3.setCoincident(SketchLine_20.result(), SketchArc_5.endPoint()) -SketchConstraintCoincidence_33 = Sketch_3.setCoincident(SketchArc_5.startPoint(), SketchLine_19.result()) -SketchLine_21 = Sketch_3.addLine(model.selection("EDGE", "Boolean_1_1/Modified_12&Boolean_1_1/Modified_11")) -SketchConstraintTangent_5 = Sketch_3.setTangent(SketchArc_5.results()[1], SketchLine_21.result()) -model.do() - -ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_3/Face-SketchLine_17r-SketchLine_18r-SketchArc_4_2r")], model.selection(), model.selection("FACE", "Boolean_1_1/Modified_5"), 0, model.selection(), 0, [model.selection("SOLID", "Boolean_1_1")]) -ExtrusionFuse_1 = model.addExtrusionFuse(Part_1_doc, [model.selection("FACE", "Sketch_3/Face-SketchLine_19r-SketchLine_20r-SketchArc_4_2f-SketchArc_5_2r")], model.selection(), model.selection("FACE", "ExtrusionCut_1_1/Modfied_7"), 0, model.selection(), 0, [model.selection("SOLID", "ExtrusionCut_1_1")]) -model.do() - -model.end() - -model.testNbResults(ExtrusionFuse_1, 1) -model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.SOLID, [1]) -model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.FACE, [30]) -model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.EDGE, [140]) -model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.VERTEX, [280]) -model.testResultsVolumes(ExtrusionFuse_1, [260653.824775497108930721879005432]) - -assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/icons/distance_h.png b/src/SketchPlugin/icons/distance_h.png deleted file mode 100644 index b88db2102..000000000 Binary files a/src/SketchPlugin/icons/distance_h.png and /dev/null differ diff --git a/src/SketchPlugin/icons/distance_v.png b/src/SketchPlugin/icons/distance_v.png deleted file mode 100644 index 027a384d5..000000000 Binary files a/src/SketchPlugin/icons/distance_v.png and /dev/null differ diff --git a/src/SketchPlugin/icons/ellipse.png b/src/SketchPlugin/icons/ellipse.png deleted file mode 100644 index 6f311635d..000000000 Binary files a/src/SketchPlugin/icons/ellipse.png and /dev/null differ diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index b6c74bff6..d5b54374a 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -28,7 +28,7 @@ email : webmaster.salome@opencascade.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -792,7 +636,6 @@ email : webmaster.salome@opencascade.com - diff --git a/src/SketchSolver/CMakeLists.txt b/src/SketchSolver/CMakeLists.txt index 5dab71a4f..50c4fab20 100644 --- a/src/SketchSolver/CMakeLists.txt +++ b/src/SketchSolver/CMakeLists.txt @@ -55,7 +55,6 @@ SET(SKETCHSOLVER_CONSTRAINT_HEADERS SketchSolver_ConstraintMulti.h SketchSolver_ConstraintMultiRotation.h SketchSolver_ConstraintMultiTranslation.h - SketchSolver_ConstraintMovement.h ) SET(SKETCHSOLVER_SOURCES @@ -79,7 +78,6 @@ SET(SKETCHSOLVER_CONSTRAINT_SOURCES SketchSolver_ConstraintMulti.cpp SketchSolver_ConstraintMultiRotation.cpp SketchSolver_ConstraintMultiTranslation.cpp - SketchSolver_ConstraintMovement.cpp ) SET(SKETCHSOLVER_LIBRARIES diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Defs.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Defs.h index 0f31d2e2c..981769fc2 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Defs.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Defs.h @@ -40,7 +40,6 @@ typedef int ConstraintID; // Predefined values for identifiers const ConstraintID CID_UNKNOWN = 0; const ConstraintID CID_MOVEMENT = -1; -const ConstraintID CID_FICTIVE = 1024; /// Types of entities enum SketchSolver_EntityType { @@ -64,8 +63,6 @@ enum SketchSolver_ConstraintType { CONSTRAINT_DISTANCE, // base distance if we don't know the measured objects yet CONSTRAINT_PT_PT_DISTANCE, CONSTRAINT_PT_LINE_DISTANCE, - CONSTRAINT_HORIZONTAL_DISTANCE, - CONSTRAINT_VERTICAL_DISTANCE, CONSTRAINT_RADIUS, CONSTRAINT_ANGLE, CONSTRAINT_FIXED, diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp index 9c4cad57d..38b60f7fe 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp @@ -27,8 +27,7 @@ PlaneGCSSolver_Solver::PlaneGCSSolver_Solver() myDiagnoseBeforeSolve(false), myInitilized(false), myConfCollected(false), - myDOF(0), - myFictiveConstraint(0) + myDOF(0) { } @@ -44,8 +43,6 @@ void PlaneGCSSolver_Solver::clear() myConstraints.clear(); myConflictingIDs.clear(); myDOF = 0; - - removeFictiveConstraint(); } void PlaneGCSSolver_Solver::addConstraint(GCSConstraintPtr theConstraint) @@ -112,7 +109,6 @@ void PlaneGCSSolver_Solver::removeParameters(const GCS::SET_pD& theParams) void PlaneGCSSolver_Solver::initialize() { Events_LongOp::start(this); - addFictiveConstraintIfNecessary(); if (myDiagnoseBeforeSolve) diagnose(); myEquationSystem->declareUnknowns(myParameters); @@ -138,8 +134,6 @@ PlaneGCSSolver_Solver::SolveStatus PlaneGCSSolver_Solver::solve() if (myInitilized) { aResult = (GCS::SolveStatus)myEquationSystem->solve(); } else { - addFictiveConstraintIfNecessary(); - if (myDiagnoseBeforeSolve) diagnose(); aResult = (GCS::SolveStatus)myEquationSystem->solve(myParameters); @@ -163,7 +157,6 @@ PlaneGCSSolver_Solver::SolveStatus PlaneGCSSolver_Solver::solve() aStatus = STATUS_OK; } - removeFictiveConstraint(); myInitilized = false; return aStatus; } @@ -205,34 +198,3 @@ void PlaneGCSSolver_Solver::diagnose() myDOF = myEquationSystem->diagnose(); myDiagnoseBeforeSolve = false; } - -void PlaneGCSSolver_Solver::addFictiveConstraintIfNecessary() -{ - if (!myConstraints.empty() && - myConstraints.find(CID_MOVEMENT) == myConstraints.end()) - return; - - if (myFictiveConstraint) - return; // no need several fictive constraints - - double* aParam = createParameter(); - double* aFictiveParameter = new double(0.0); - - myFictiveConstraint = new GCS::ConstraintEqual(aFictiveParameter, aParam); - myFictiveConstraint->setTag(CID_FICTIVE); - myEquationSystem->addConstraint(myFictiveConstraint); -} - -void PlaneGCSSolver_Solver::removeFictiveConstraint() -{ - if (myFictiveConstraint) { - myEquationSystem->removeConstraint(myFictiveConstraint); - myParameters.pop_back(); - - GCS::VEC_pD aParams = myFictiveConstraint->params(); - for (GCS::VEC_pD::iterator anIt = aParams.begin(); anIt != aParams.end(); ++ anIt) - delete *anIt; - delete myFictiveConstraint; - myFictiveConstraint = 0; - } -} diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h index 572f2df25..2e49798a1 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h @@ -81,11 +81,6 @@ public: private: void collectConflicting(); - /// \brief Add fictive constraint if the sketch contains temporary constraints only - void addFictiveConstraintIfNecessary(); - /// \brief Remove previously added fictive constraint - void removeFictiveConstraint(); - private: typedef std::map > ConstraintMap; @@ -101,8 +96,6 @@ private: bool myConfCollected; int myDOF; ///< degrees of freedom - - GCS::Constraint* myFictiveConstraint; }; typedef std::shared_ptr SolverPtr; diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp index 161220521..56567d292 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp @@ -66,9 +66,12 @@ void PlaneGCSSolver_Storage::addConstraint( constraintsToSolver(theSolverConstraint, mySketchSolver); } -void PlaneGCSSolver_Storage::addMovementConstraint( +void PlaneGCSSolver_Storage::addTemporaryConstraint( const ConstraintWrapperPtr& theSolverConstraint) { + if (myConstraintMap.empty()) + return; // no need to process temporary constraints if there is no active constraint + // before adding movement constraint to solver, re-check its DOF if (mySketchSolver->dof() == 0) mySketchSolver->diagnose(); diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h index 48526b9c7..28eaed091 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h @@ -44,10 +44,10 @@ public: virtual void addConstraint(ConstraintPtr theConstraint, ConstraintWrapperPtr theSolverConstraint); - /// \brief Add a movement constraint which will be destroyed + /// \brief Add list of temporary constraints which will be destroyed /// after the next solving of the set of constraints. /// \param theSolverConstraint [in] solver's constraint - virtual void addMovementConstraint(const ConstraintWrapperPtr& theSolverConstraint); + virtual void addTemporaryConstraint(const ConstraintWrapperPtr& theSolverConstraint); /// \brief Convert feature to the form applicable for specific solver and map it diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp index a4e461ada..51460d9af 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp @@ -42,8 +42,6 @@ #include #include #include -#include -#include #include #include #include @@ -78,11 +76,6 @@ static ConstraintWrapperPtr createConstraintDistancePointLine(std::shared_ptr theValue, std::shared_ptr thePoint, std::shared_ptr theEntity); -static ConstraintWrapperPtr - createConstraintHVDistance(const SketchSolver_ConstraintType& theType, - std::shared_ptr theValue, - std::shared_ptr thePoint1, - std::shared_ptr thePoint2); static ConstraintWrapperPtr createConstraintRadius(std::shared_ptr theValue, std::shared_ptr theEntity); @@ -125,9 +118,7 @@ SolverConstraintPtr PlaneGCSSolver_Tools::createConstraint(ConstraintPtr theCons return SolverConstraintPtr(new SketchSolver_ConstraintCoincidence(theConstraint)); } else if (theConstraint->getKind() == SketchPlugin_ConstraintCollinear::ID()) { return SolverConstraintPtr(new SketchSolver_ConstraintCollinear(theConstraint)); - } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID() || - theConstraint->getKind() == SketchPlugin_ConstraintDistanceHorizontal::ID() || - theConstraint->getKind() == SketchPlugin_ConstraintDistanceVertical::ID()) { + } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) { return SolverConstraintPtr(new SketchSolver_ConstraintDistance(theConstraint)); } else if (theConstraint->getKind() == SketchPlugin_ConstraintEqual::ID()) { return SolverConstraintPtr(new SketchSolver_ConstraintEqual(theConstraint)); @@ -152,18 +143,11 @@ SolverConstraintPtr PlaneGCSSolver_Tools::createConstraint(ConstraintPtr theCons return SolverConstraintPtr(new SketchSolver_Constraint(theConstraint)); } -std::shared_ptr PlaneGCSSolver_Tools::createMovementConstraint( +std::shared_ptr PlaneGCSSolver_Tools::createMovementConstraint( FeaturePtr theMovedFeature) { - return std::shared_ptr( - new SketchSolver_ConstraintMovement(theMovedFeature)); -} - -std::shared_ptr PlaneGCSSolver_Tools::createMovementConstraint( - AttributePtr theMovedAttribute) -{ - return std::shared_ptr( - new SketchSolver_ConstraintMovement(theMovedAttribute)); + return std::shared_ptr( + new SketchSolver_ConstraintFixed(theMovedFeature)); } @@ -202,10 +186,6 @@ ConstraintWrapperPtr PlaneGCSSolver_Tools::createConstraint( aPoint1, GCS_EDGE_WRAPPER(theEntity1)); break; - case CONSTRAINT_HORIZONTAL_DISTANCE: - case CONSTRAINT_VERTICAL_DISTANCE: - aResult = createConstraintHVDistance(theType, GCS_SCALAR_WRAPPER(theValue), aPoint1, aPoint2); - break; case CONSTRAINT_RADIUS: aResult = createConstraintRadius(GCS_SCALAR_WRAPPER(theValue), GCS_EDGE_WRAPPER(theEntity1)); @@ -399,32 +379,6 @@ ConstraintWrapperPtr createConstraintDistancePointLine( return aResult; } -ConstraintWrapperPtr createConstraintHVDistance( - const SketchSolver_ConstraintType& theType, - std::shared_ptr theValue, - std::shared_ptr thePoint1, - std::shared_ptr thePoint2) -{ - GCSPointPtr aPoint1 = thePoint1->point(); - GCSPointPtr aPoint2 = thePoint2->point(); - - double *aParam1, *aParam2; - if (theType == CONSTRAINT_HORIZONTAL_DISTANCE) { - aParam1 = aPoint1->x; - aParam2 = aPoint2->x; - } else if (theType == CONSTRAINT_VERTICAL_DISTANCE) { - aParam1 = aPoint1->y; - aParam2 = aPoint2->y; - } - - GCSConstraintPtr aNewConstr(new GCS::ConstraintDifference(aParam1, aParam2, theValue->scalar())); - - std::shared_ptr aResult( - new PlaneGCSSolver_ConstraintWrapper(aNewConstr, theType)); - aResult->setValueParameter(theValue); - return aResult; -} - ConstraintWrapperPtr createConstraintRadius( std::shared_ptr theValue, std::shared_ptr theEntity) diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.h index 69cc96680..e06acb159 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.h @@ -22,7 +22,7 @@ #define PlaneGCSSolver_Tools_H_ #include -#include +#include #include #include @@ -39,11 +39,8 @@ namespace PlaneGCSSolver_Tools SolverConstraintPtr createConstraint(ConstraintPtr theConstraint); /// \brief Creates temporary constraint to fix the feature after movement - std::shared_ptr + std::shared_ptr createMovementConstraint(FeaturePtr theMovedFeature); - /// \brief Creates temporary constraint to fix the attribute after movement - std::shared_ptr - createMovementConstraint(AttributePtr theMovedAttribute); /// \brief Creates new constraint using given parameters /// \param theConstraint [in] original constraint diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 4a78cc548..f0e6365cc 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -134,10 +134,6 @@ void SketchSolver_Constraint::process() ConstraintWrapperPtr aNewConstraint = PlaneGCSSolver_Tools::createConstraint( myBaseConstraint, aConstrType, aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]); - if (!aNewConstraint) { - myErrorMsg = SketchSolver_Error::WRONG_CONSTRAINT_TYPE(); - return; - } myStorage->addConstraint(myBaseConstraint, aNewConstraint); adjustConstraint(); diff --git a/src/SketchSolver/SketchSolver_ConstraintDistance.cpp b/src/SketchSolver/SketchSolver_ConstraintDistance.cpp index 901053c6d..3a6a0fa48 100644 --- a/src/SketchSolver/SketchSolver_ConstraintDistance.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintDistance.cpp @@ -22,9 +22,6 @@ #include #include -#include -#include - #include #include #include @@ -43,14 +40,9 @@ void SketchSolver_ConstraintDistance::getAttributes( return; } - if (theAttributes[1]) { - if (myBaseConstraint->getKind() == SketchPlugin_ConstraintDistanceHorizontal::ID()) - myType = CONSTRAINT_HORIZONTAL_DISTANCE; - else if (myBaseConstraint->getKind() == SketchPlugin_ConstraintDistanceVertical::ID()) - myType = CONSTRAINT_VERTICAL_DISTANCE; - else - myType = CONSTRAINT_PT_PT_DISTANCE; - } else if (theAttributes[2] && theAttributes[2]->type() == ENTITY_LINE) + if (theAttributes[1]) + myType = CONSTRAINT_PT_PT_DISTANCE; + else if (theAttributes[2] && theAttributes[2]->type() == ENTITY_LINE) myType = CONSTRAINT_PT_LINE_DISTANCE; else theAttributes.clear(); diff --git a/src/SketchSolver/SketchSolver_ConstraintFixed.cpp b/src/SketchSolver/SketchSolver_ConstraintFixed.cpp index 677ef229d..5cf488270 100644 --- a/src/SketchSolver/SketchSolver_ConstraintFixed.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintFixed.cpp @@ -30,7 +30,13 @@ #include #include -/// \brief Get list of parameters of current entity +#include + +// Verify the points are equal +static bool isEqual(const GCS::Point& thePoint1, const GCS::Point& thePoint2); +// Verify the entities are equal +static bool isEqual(const EntityWrapperPtr& theEntity1, const EntityWrapperPtr& theEntity2); +// Convert entity to the list of parameters static GCS::VEC_pD toParameters(const EntityWrapperPtr& theEntity); @@ -40,30 +46,42 @@ SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(ConstraintPtr theCons myType = CONSTRAINT_FIXED; } +SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(FeaturePtr theFeature) + : SketchSolver_Constraint(), + myBaseFeature(theFeature) +{ + myType = CONSTRAINT_FIXED; +} + void SketchSolver_ConstraintFixed::blockEvents(bool isBlocked) { - SketchSolver_Constraint::blockEvents(isBlocked); + if (myBaseFeature) + myBaseFeature->data()->blockSendAttributeUpdated(isBlocked); + if (myBaseConstraint) + SketchSolver_Constraint::blockEvents(isBlocked); } void SketchSolver_ConstraintFixed::process() { cleanErrorMsg(); - if (!myBaseConstraint || !myStorage) { + if ((!myBaseConstraint && !myBaseFeature) || !myStorage) { // Not enough parameters are assigned return; } - EntityWrapperPtr aBaseEntity = entityToFix(); - if (!aBaseEntity) + EntityWrapperPtr aBaseEntity; + getAttributes(aBaseEntity, myFixedEntity); + if (!aBaseEntity) { + moveFeature(); // remove myFixed entity myErrorMsg = SketchSolver_Error::ALREADY_FIXED(); + } if (!myErrorMsg.empty()) return; - ConstraintWrapperPtr aConstraint = fixFeature(aBaseEntity); - myStorage->addConstraint(myBaseConstraint, aConstraint); + fixFeature(aBaseEntity); } -ConstraintWrapperPtr SketchSolver_ConstraintFixed::fixFeature(EntityWrapperPtr theFeature) +void SketchSolver_ConstraintFixed::fixFeature(EntityWrapperPtr theFeature) { GCS::VEC_pD aParameters = toParameters(theFeature); @@ -77,28 +95,93 @@ ConstraintWrapperPtr SketchSolver_ConstraintFixed::fixFeature(EntityWrapperPtr t GCSConstraintPtr(new GCS::ConstraintEqual(&myFixedValues[i], *anIt))); } - return ConstraintWrapperPtr( + myConstraint = ConstraintWrapperPtr( new PlaneGCSSolver_ConstraintWrapper(aConstraints, getType())); + + if (myBaseConstraint) + myStorage->addConstraint(myBaseConstraint, myConstraint); + else + myStorage->addTemporaryConstraint(myConstraint); +} + +void SketchSolver_ConstraintFixed::getAttributes(EntityWrapperPtr& theBaseEntity, + EntityWrapperPtr& theFixedEntity) +{ + if (myBaseFeature) { + // if the feature is copy, do not move it + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(myBaseFeature); + if (aSketchFeature && aSketchFeature->isCopy()) { + myStorage->setNeedToResolve(true); + return; + } + + bool fixFullFeature = false; + theBaseEntity = EntityWrapperPtr(); + theFixedEntity = EntityWrapperPtr(); + + // The feature is fixed. + PlaneGCSSolver_FeatureBuilder aBuilder; + std::list aBaseAttr = myBaseFeature->data()->attributes(std::string()); + std::list::const_iterator anIt = aBaseAttr.begin(); + for (; anIt != aBaseAttr.end(); ++anIt) { + EntityWrapperPtr anEntity = aBuilder.createAttribute(*anIt); + EntityWrapperPtr aBaseEntity = myStorage->entity(*anIt); + if (!anEntity || !aBaseEntity) + continue; + + if (!fixFullFeature && anEntity->type() == ENTITY_POINT && + !isEqual(anEntity, aBaseEntity)) { + if (theFixedEntity) + fixFullFeature = true; + theFixedEntity = anEntity; + theBaseEntity = aBaseEntity; + } + } + + if (fixFullFeature) { + theFixedEntity = aBuilder.createFeature(myBaseFeature); + theBaseEntity = myStorage->entity(myBaseFeature); + if (isEqual(theBaseEntity, theFixedEntity)) + theBaseEntity = EntityWrapperPtr(); // do not want to fix already fixed entity + } + + } else if (myBaseConstraint) { + // Constraint Fixed is added by user. + // Get the attribute of constraint (it should be alone in the list of constraints). + EntityWrapperPtr aValue; + std::vector anAttributes; + SketchSolver_Constraint::getAttributes(aValue, anAttributes); + std::vector::const_iterator anIt = anAttributes.begin(); + for (; anIt != anAttributes.end(); ++anIt) + if (*anIt) + theBaseEntity = *anIt; + } else + myErrorMsg = SketchSolver_Error::NOT_INITIALIZED(); } -EntityWrapperPtr SketchSolver_ConstraintFixed::entityToFix() +void SketchSolver_ConstraintFixed::moveFeature() { - // Constraint Fixed is added by user. - // Get the attribute of constraint (it should be alone in the list of constraints). - EntityWrapperPtr aValue; - std::vector anAttributes; - SketchSolver_Constraint::getAttributes(aValue, anAttributes); - std::vector::const_iterator anIt = anAttributes.begin(); - for (; anIt != anAttributes.end(); ++anIt) - if (*anIt) - return *anIt; - return EntityWrapperPtr(); + if (!myFixedEntity) + return; + + GCS::VEC_pD aFixedParams = toParameters(myFixedEntity); + for (int i = 0; i < aFixedParams.size() && i < myFixedValues.size(); ++i) + myFixedValues[i] = *(aFixedParams[i]); + + // Remove fixed entity due to its parameters already copied into the constraint + PlaneGCSSolver_EntityDestroyer aDestroyer; + aDestroyer.remove(myFixedEntity); + std::dynamic_pointer_cast(myStorage)->removeParameters( + aDestroyer.parametersToRemove()); + + myFixedEntity = EntityWrapperPtr(); } -// ================== Auxiliary functions ================== +// ==================== Auxiliary functions =============================== GCS::VEC_pD toParameters(const EntityWrapperPtr& theEntity) { GCS::VEC_pD aParameters; @@ -148,3 +231,23 @@ GCS::VEC_pD toParameters(const EntityWrapperPtr& theEntity) return aParameters; } + +bool isEqual(const GCS::Point& thePoint1, const GCS::Point& thePoint2) +{ + return fabs((*thePoint1.x) - (*thePoint2.x)) <= tolerance && + fabs((*thePoint1.y) - (*thePoint2.y)) <= tolerance; +} + +bool isEqual(const EntityWrapperPtr& theEntity1, const EntityWrapperPtr& theEntity2) +{ + GCS::VEC_pD aParamList1 = toParameters(theEntity1); + GCS::VEC_pD aParamList2 = toParameters(theEntity2); + + GCS::VEC_pD::const_iterator anIt1 = aParamList1.begin(); + GCS::VEC_pD::const_iterator anIt2 = aParamList2.begin(); + for (; anIt1 != aParamList1.end() && anIt2 != aParamList2.end(); ++anIt1, ++anIt2) + if (fabs((**anIt1) - (**anIt2)) > tolerance) + return false; + + return anIt1 == aParamList1.end() && anIt2 == aParamList2.end(); +} diff --git a/src/SketchSolver/SketchSolver_ConstraintFixed.h b/src/SketchSolver/SketchSolver_ConstraintFixed.h index 1d005c1b5..7d437fb55 100644 --- a/src/SketchSolver/SketchSolver_ConstraintFixed.h +++ b/src/SketchSolver/SketchSolver_ConstraintFixed.h @@ -26,36 +26,45 @@ /** \class SketchSolver_ConstraintFixed * \ingroup Plugins * \brief Stores data of the Fixed constraint + * + * Fixed constraint may have NULL basic SketchPlugin constraint, + * because the Fixed constraint may be temporary for correct moving of objects. */ class SketchSolver_ConstraintFixed : public SketchSolver_Constraint { public: /// Creates constraint to manage the given constraint from plugin SketchSolver_ConstraintFixed(ConstraintPtr theConstraint); + /// Creates temporary constraint based on feature (useful while the feature is being moved) + SketchSolver_ConstraintFixed(FeaturePtr theFeature); /// \brief Block or unblock events from this constraint virtual void blockEvents(bool isBlocked); + /// \brief Set coordinates of fixed feature to the values where it has been dragged. + /// Useful when the feature is being moved. + void moveFeature(); + protected: /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints virtual void process(); /// \brief Generate list of attributes of constraint in order useful for constraints - /// \param[out] theValue numerical characteristic of constraint (e.g. distance) - /// \param[out] theAttributes list of attributes to be filled - virtual void getAttributes(EntityWrapperPtr& , std::vector& ) - {} - - /// \brief Obtain entity to be fixed - EntityWrapperPtr entityToFix(); + /// \param[out] theBaseEntity the entity which coordinates should be fixed + /// \param[out] theFixedEntity the entity containing fixed values + virtual void getAttributes(EntityWrapperPtr& theBaseEntity, + EntityWrapperPtr& theFixedEntity); - /// \brief Create Fixed constraint for the feature basing on its type + /// \brief Fixed feature basing on its type /// \param theFeature [in] feature, converted to solver specific format - /// \return Fixed constraint - ConstraintWrapperPtr fixFeature(EntityWrapperPtr theFeature); + virtual void fixFeature(EntityWrapperPtr theFeature); -protected: +private: + FeaturePtr myBaseFeature; ///< fixed feature (when it is set, myBaseConstraint should be NULL) + + ConstraintWrapperPtr myConstraint; std::vector myFixedValues; + EntityWrapperPtr myFixedEntity; }; #endif diff --git a/src/SketchSolver/SketchSolver_ConstraintMovement.cpp b/src/SketchSolver/SketchSolver_ConstraintMovement.cpp deleted file mode 100644 index 94c6d7af1..000000000 --- a/src/SketchSolver/SketchSolver_ConstraintMovement.cpp +++ /dev/null @@ -1,219 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include - -#include - - -SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(FeaturePtr theFeature) - : SketchSolver_ConstraintFixed(ConstraintPtr()), - myMovedFeature(theFeature), - mySimpleMove(true) -{ -} - -SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(AttributePtr thePoint) - : SketchSolver_ConstraintFixed(ConstraintPtr()), - myDraggedPoint(thePoint), - mySimpleMove(true) -{ - myMovedFeature = ModelAPI_Feature::feature(thePoint->owner()); -} - -void SketchSolver_ConstraintMovement::blockEvents(bool isBlocked) -{ - if (myMovedFeature) - myMovedFeature->data()->blockSendAttributeUpdated(isBlocked); -} - -void SketchSolver_ConstraintMovement::process() -{ - cleanErrorMsg(); - if (!myMovedFeature || !myStorage) { - // Not enough parameters are initialized - return; - } - - mySolverConstraint = initMovement(); - if (!myErrorMsg.empty() || !mySolverConstraint) { - // Nothing to move, clear the feature to avoid changing its group - // after removing the Movement constraint. - myMovedFeature = FeaturePtr(); - return; - } - myStorage->addMovementConstraint(mySolverConstraint); -} - - -static bool isSimpleMove(FeaturePtr theMovedFeature, AttributePtr theDraggedPoint) -{ - bool isSimple = true; - if (theMovedFeature->getKind() == SketchPlugin_Circle::ID()) - isSimple = (theDraggedPoint.get() != 0); - else if (theMovedFeature->getKind() == SketchPlugin_Arc::ID()) { - isSimple = (theDraggedPoint.get() != 0 && - theDraggedPoint->id() == SketchPlugin_Arc::CENTER_ID()); - } - return isSimple; -} - -ConstraintWrapperPtr SketchSolver_ConstraintMovement::initMovement() -{ - ConstraintWrapperPtr aConstraint; - - // if the feature is copy, do not move it - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(myMovedFeature); - if (!aSketchFeature || aSketchFeature->isCopy()) { - myStorage->setNeedToResolve(true); - return aConstraint; - } - - EntityWrapperPtr anEntity = - myDraggedPoint ? myStorage->entity(myDraggedPoint) : myStorage->entity(myMovedFeature); - if (!anEntity) { - myStorage->update(myMovedFeature, true); - anEntity = - myDraggedPoint ? myStorage->entity(myDraggedPoint) : myStorage->entity(myMovedFeature); - if (!anEntity) - return aConstraint; - } - - mySimpleMove = isSimpleMove(myMovedFeature, myDraggedPoint); - - if (mySimpleMove) - aConstraint = fixFeature(anEntity); - else { - if (myDraggedPoint) // start or end point of arc has been moved - aConstraint = fixArcExtremity(anEntity); - else // arc or circle has been moved - aConstraint = fixPointOnCircle(anEntity); - } - - return aConstraint; -} - -ConstraintWrapperPtr SketchSolver_ConstraintMovement::fixArcExtremity( - const EntityWrapperPtr& theArcExtremity) -{ - static const int nbParams = 4; - myFixedValues.reserve(nbParams); // moved point and center of arc - - EdgeWrapperPtr aCircularEntity = std::dynamic_pointer_cast( - myStorage->entity(myMovedFeature)); - std::shared_ptr anArc = - std::dynamic_pointer_cast(aCircularEntity->entity()); - - PointWrapperPtr aPoint = - std::dynamic_pointer_cast(theArcExtremity); - - double* aParams[nbParams] = { aPoint->point()->x, aPoint->point()->y, - anArc->center.x, anArc->center.y }; - - std::list aConstraints; - for (int i = 0; i < nbParams; ++i) { - myFixedValues.push_back(*aParams[i]); - GCSConstraintPtr aNewConstraint(new GCS::ConstraintEqual(&myFixedValues[i], aParams[i])); - aNewConstraint->rescale(0.01); - aConstraints.push_back(aNewConstraint); - } - - return ConstraintWrapperPtr( - new PlaneGCSSolver_ConstraintWrapper(aConstraints, getType())); -} - -ConstraintWrapperPtr SketchSolver_ConstraintMovement::fixPointOnCircle( - const EntityWrapperPtr& theCircular) -{ - static const double scale = 0.01; - static const int nbParams = 4; - myFixedValues.reserve(nbParams); // moved point and center of arc/circle - - EdgeWrapperPtr aCircularEntity = - std::dynamic_pointer_cast(theCircular); - std::shared_ptr aCircular = - std::dynamic_pointer_cast(aCircularEntity->entity()); - - // initialize fixed values - myFixedValues.push_back(*aCircular->center.x + *aCircular->rad); - myFixedValues.push_back(*aCircular->center.y); - myFixedValues.push_back(*aCircular->center.x); - myFixedValues.push_back(*aCircular->center.y); - - // create a moved point - GCS::Point aPointOnCircle; - aPointOnCircle.x = &myFixedValues[0]; - aPointOnCircle.y = &myFixedValues[1]; - - std::list aConstraints; - // point-on-circle - GCSConstraintPtr aNewConstraint( - new GCS::ConstraintP2PDistance(aPointOnCircle, aCircular->center, aCircular->rad)); - aNewConstraint->rescale(scale); - aConstraints.push_back(aNewConstraint); - // fixed center (x) - aNewConstraint = GCSConstraintPtr( - new GCS::ConstraintEqual(&myFixedValues[2], aCircular->center.x)); - aNewConstraint->rescale(scale); - aConstraints.push_back(aNewConstraint); - // fixed center (y) - aNewConstraint = GCSConstraintPtr( - new GCS::ConstraintEqual(&myFixedValues[3], aCircular->center.y)); - aNewConstraint->rescale(scale); - aConstraints.push_back(aNewConstraint); - - return ConstraintWrapperPtr( - new PlaneGCSSolver_ConstraintWrapper(aConstraints, getType())); -} - - -void SketchSolver_ConstraintMovement::startPoint( - const std::shared_ptr& theStartPoint) -{ - myStartPoint = theStartPoint; - if (!mySimpleMove) { - myFixedValues[0] = myStartPoint->x(); - myFixedValues[1] = myStartPoint->y(); - } -} - -void SketchSolver_ConstraintMovement::moveTo( - const std::shared_ptr& theDestinationPoint) -{ - double aDelta[2] = { theDestinationPoint->x() - myStartPoint->x(), - theDestinationPoint->y() - myStartPoint->y() }; - - int aMaxSize = mySimpleMove ? (int)myFixedValues.size() : 2; - for (int i = 0; i < aMaxSize; ++i) - myFixedValues[i] += aDelta[i % 2]; -} diff --git a/src/SketchSolver/SketchSolver_ConstraintMovement.h b/src/SketchSolver/SketchSolver_ConstraintMovement.h deleted file mode 100644 index 8614f309a..000000000 --- a/src/SketchSolver/SketchSolver_ConstraintMovement.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -// File: SketchSolver_ConstraintMovement.h -// Created: 15 Jun 2015 -// Author: Artem ZHIDKOV - -#ifndef SketchSolver_ConstraintMovement_H_ -#define SketchSolver_ConstraintMovement_H_ - -#include - -class GeomAPI_Pnt2d; - -/** \class SketchSolver_ConstraintMovement - * \ingroup Plugins - * \brief Stores data to the Fixed constraint for the moved feature only - */ -class SketchSolver_ConstraintMovement : public SketchSolver_ConstraintFixed -{ -public: - /// Creates movement constraint based on feature - SketchSolver_ConstraintMovement(FeaturePtr theFeature); - - /// Creates movement constraint based on point - SketchSolver_ConstraintMovement(AttributePtr thePoint); - - /// \brief Set coordinates of the start point of the movement - void startPoint(const std::shared_ptr& theStartPoint); - - /// \brief Set coordinates of fixed feature to the values where it has been dragged. - /// Useful when the feature is being moved. - void moveTo(const std::shared_ptr& theDestinationPoint); - - /// \brief Block or unblock events from this constraint - virtual void blockEvents(bool isBlocked); - - /// \brief Returns moved feature - FeaturePtr movedFeature() const - { return myMovedFeature; } - -protected: - /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints - virtual void process(); - - /// \brief Create Fixed constraint for the feature basing on its type and moved point - /// \return Fixed constraint - ConstraintWrapperPtr initMovement(); - - /// \brief Create constraint to fix moved arc extremity - ConstraintWrapperPtr fixArcExtremity(const EntityWrapperPtr& theArcExtremity); - - /// \brief Creat constraint to fix moved point on circle/arc - ConstraintWrapperPtr fixPointOnCircle(const EntityWrapperPtr& theCircular); - -private: - FeaturePtr myMovedFeature; ///< fixed feature (if set, myBaseConstraint should be NULL) - AttributePtr myDraggedPoint; ///< one of the feature points which has been moved - std::shared_ptr myStartPoint; ///< start point of the movement - - bool mySimpleMove; ///< simple move, thus all parameters should be increased by movement delta -}; - -#endif diff --git a/src/SketchSolver/SketchSolver_Error.h b/src/SketchSolver/SketchSolver_Error.h index 3093e7bc9..4b4347f36 100644 --- a/src/SketchSolver/SketchSolver_Error.h +++ b/src/SketchSolver/SketchSolver_Error.h @@ -103,12 +103,6 @@ class SketchSolver_Error static const std::string MY_ERROR_VALUE("Caution: SolveSpace crash! Constraints are wrong"); return MY_ERROR_VALUE; } - /// Constraint has wrong type - inline static const std::string& WRONG_CONSTRAINT_TYPE() - { - static const std::string MY_ERROR_VALUE("Unsupported type of constraint"); - return MY_ERROR_VALUE; - } }; #endif diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 93bbfa69d..f437103ac 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -70,7 +70,7 @@ static void sendMessage(const char* theMessageName, // ======================================================== -// ========= SketchSolver_Group =============== +// ========= SketchSolver_Group =============== // ======================================================== SketchSolver_Group::SketchSolver_Group(const CompositeFeaturePtr& theWorkplane) @@ -129,56 +129,32 @@ bool SketchSolver_Group::updateFeature(FeaturePtr theFeature) return myStorage->update(theFeature); } -template -static SolverConstraintPtr move(StoragePtr theStorage, - SolverPtr theSketchSolver, - int theSketchDOF, - bool theEventsBlocked, - Type theFeatureOrPoint, - const std::shared_ptr& theFrom, - const std::shared_ptr& theTo) +bool SketchSolver_Group::moveFeature(FeaturePtr theFeature) { - bool isEntityExists = (theStorage->entity(theFeatureOrPoint).get() != 0); - if (theSketchDOF == 0 && isEntityExists) { + bool isFeatureExists = (myStorage->entity(theFeature).get() != 0); + if (myDOF == 0 && isFeatureExists) { // avoid moving elements of fully constrained sketch - theStorage->refresh(); - return SolverConstraintPtr(); + myStorage->refresh(); + return true; } // Create temporary Fixed constraint - std::shared_ptr aConstraint = - PlaneGCSSolver_Tools::createMovementConstraint(theFeatureOrPoint); - if (aConstraint) { - SolverConstraintPtr(aConstraint)->process(theStorage, theEventsBlocked); - if (aConstraint->error().empty()) { - aConstraint->startPoint(theFrom); - theSketchSolver->initialize(); - aConstraint->moveTo(theTo); - theStorage->setNeedToResolve(true); - } else - theStorage->notify(aConstraint->movedFeature()); + std::shared_ptr aConstraint = + PlaneGCSSolver_Tools::createMovementConstraint(theFeature); + if (!aConstraint) + return false; + SolverConstraintPtr(aConstraint)->process(myStorage, myIsEventsBlocked); + if (aConstraint->error().empty()) { + setTemporary(aConstraint); + if (!myStorage->isEmpty()) + myStorage->setNeedToResolve(true); + + mySketchSolver->initialize(); + aConstraint->moveFeature(); } - return aConstraint; -} - -bool SketchSolver_Group::moveFeature(FeaturePtr theFeature, - const std::shared_ptr& theFrom, - const std::shared_ptr& theTo) -{ - SolverConstraintPtr aConstraint = - move(myStorage, mySketchSolver, myDOF, myIsEventsBlocked, theFeature, theFrom, theTo); - setTemporary(aConstraint); - return true; -} - -bool SketchSolver_Group::movePoint(AttributePtr theAttribute, - const std::shared_ptr& theFrom, - const std::shared_ptr& theTo) -{ - SolverConstraintPtr aConstraint = - move(myStorage, mySketchSolver, myDOF, myIsEventsBlocked, theAttribute, theFrom, theTo); - setTemporary(aConstraint); + // notify all observers that theFeature has been changed + myStorage->notify(theFeature); return true; } @@ -396,8 +372,7 @@ void SketchSolver_Group::removeConstraint(ConstraintPtr theConstraint) // ============================================================================ void SketchSolver_Group::setTemporary(SolverConstraintPtr theConstraint) { - if (theConstraint) - myTempConstraints.insert(theConstraint); + myTempConstraints.insert(theConstraint); } // ============================================================================ diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index 4a65bf258..9a78d9a2c 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -31,8 +31,6 @@ #include #include -class GeomAPI_Pnt2d; - typedef std::map ConstraintConstraintMap; /** \class SketchSolver_Group @@ -74,25 +72,11 @@ class SketchSolver_Group bool updateFeature(FeaturePtr theFeature); /** \brief Updates the data corresponding the specified feature moved in GUI. - * Special kind of Fixed constraints is created. + * Additional Fixed constraints are created. * \param[in] theFeature the feature to be updated - * \param[in] theFrom start point of the movement - * \param[in] theTo final point of the movement - * \return \c true, if the feature is really moved - */ - bool moveFeature(FeaturePtr theFeature, - const std::shared_ptr& theFrom, - const std::shared_ptr& theTo); - /** \brief Updates the data corresponding the specified point moved in GUI. - * Special kind of Fixed constraints is created. - * \param[in] thePoint the attribute to be updated - * \param[in] theFrom start point of the movement - * \param[in] theTo final point of the movement - * \return \c true, if the attribute is really moved + * \return \c true, if the feature is moved */ - bool movePoint(AttributePtr thePoint, - const std::shared_ptr& theFrom, - const std::shared_ptr& theTo); + bool moveFeature(FeaturePtr theFeature); /// Returns the current workplane inline const CompositeFeaturePtr& getWorkplane() const diff --git a/src/SketchSolver/SketchSolver_Manager.cpp b/src/SketchSolver/SketchSolver_Manager.cpp index d253916c9..e20ef48c1 100644 --- a/src/SketchSolver/SketchSolver_Manager.cpp +++ b/src/SketchSolver/SketchSolver_Manager.cpp @@ -22,12 +22,10 @@ #include "SketchSolver_Error.h" #include -#include #include #include #include #include -#include #include /// Global constraint manager object @@ -68,6 +66,8 @@ SketchSolver_Manager::SketchSolver_Manager() Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED)); Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_MOVED)); + ////Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED)); + ////Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_REPAIRED)); Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_PREPARED)); } @@ -106,13 +106,20 @@ void SketchSolver_Manager::processEvent( myIsComputed = true; if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED) - || theMessage->eventID() == anUpdateEvent) { + || theMessage->eventID() == anUpdateEvent + || theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED)) { std::shared_ptr anUpdateMsg = std::dynamic_pointer_cast(theMessage); std::set aFeatures = anUpdateMsg->objects(); isUpdateFlushed = stopSendUpdate(); + isMovedEvt = theMessage->eventID() + == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED); + + // Shows that the message has at least one feature applicable for solver + bool hasProperFeature = false; + // update sketch features only std::set::iterator aFeatIter; for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { @@ -121,28 +128,11 @@ void SketchSolver_Manager::processEvent( if (!aFeature || aFeature->isMacro()) continue; - updateFeature(aFeature); + hasProperFeature = updateFeature(aFeature, isMovedEvt) || hasProperFeature; } - } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED)) { - std::shared_ptr aMoveMsg = - std::dynamic_pointer_cast(theMessage); - - ObjectPtr aMovedObject = aMoveMsg->movedObject(); - std::shared_ptr aMovedPoint = - std::dynamic_pointer_cast(aMoveMsg->movedAttribute()); - - const std::shared_ptr& aFrom = aMoveMsg->originalPosition(); - const std::shared_ptr& aTo = aMoveMsg->currentPosition(); - - if (aMovedObject) { - FeaturePtr aMovedFeature = ModelAPI_Feature::feature(aMovedObject); - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(aMovedFeature); - if (aSketchFeature && !aSketchFeature->isMacro()) - needToResolve = moveFeature(aSketchFeature, aFrom, aTo); - } else if (aMovedPoint) - needToResolve = moveAttribute(aMovedPoint, aFrom, aTo); + if (isMovedEvt && hasProperFeature) + needToResolve = true; } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { std::shared_ptr aDeleteMsg = @@ -189,10 +179,11 @@ void SketchSolver_Manager::processEvent( } // ============================================================================ -// Function: updateFeature -// Purpose: create/update constraint or feature in appropriate group +// Function: changeConstraintOrEntity +// 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. @@ -208,52 +199,13 @@ bool SketchSolver_Manager::updateFeature(const std::shared_ptrchangeConstraint(aConstraint); + else if (theMoved) + isOk = aGroup->moveFeature(theFeature); else isOk = aGroup->updateFeature(theFeature); return isOk; } -// ============================================================================ -// Function: moveFeature -// Purpose: move given feature in appropriate group -// ============================================================================ -bool SketchSolver_Manager::moveFeature( - const std::shared_ptr& theMovedFeature, - const std::shared_ptr& theFrom, - const std::shared_ptr& theTo) -{ - SketchGroupPtr aGroup = findGroup(theMovedFeature); - if (!aGroup) - return false; - - aGroup->blockEvents(true); - return aGroup->moveFeature(theMovedFeature, theFrom, theTo); -} - -// ============================================================================ -// Function: moveAttribute -// Purpose: move given attribute in appropriate group -// ============================================================================ -bool SketchSolver_Manager::moveAttribute( - const std::shared_ptr& theMovedAttribute, - const std::shared_ptr& theFrom, - const std::shared_ptr& theTo) -{ - FeaturePtr anOwner = ModelAPI_Feature::feature(theMovedAttribute->owner()); - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(anOwner); - SketchGroupPtr aGroup; - if (aSketchFeature) - aGroup = findGroup(aSketchFeature); - if (!aGroup) { - theMovedAttribute->setValue(theTo); - return false; - } - - aGroup->blockEvents(true); - return aGroup->movePoint(theMovedAttribute, theFrom, theTo); -} - // ============================================================================ // Function: findGroup // Purpose: search groups of entities interacting with given feature diff --git a/src/SketchSolver/SketchSolver_Manager.h b/src/SketchSolver/SketchSolver_Manager.h index 105cc0e97..45c1a4284 100644 --- a/src/SketchSolver/SketchSolver_Manager.h +++ b/src/SketchSolver/SketchSolver_Manager.h @@ -24,14 +24,11 @@ #include #include +#include #include #include -class GeomAPI_Pnt2d; -class GeomDataAPI_Point2D; -class SketchPlugin_Constraint; - /** \class SketchSolver_Manager * \ingroup Plugins * \brief Listens the changes of SketchPlugin features and transforms the Constraint @@ -64,29 +61,10 @@ 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); - - /** \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); + bool updateFeature(std::shared_ptr theFeature, bool theMoved = false); /** \brief Removes a constraint from the manager * \param[in] theConstraint constraint to be removed diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index 801770348..f4f6e7254 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -57,10 +57,10 @@ public: virtual void addConstraint(ConstraintPtr theConstraint, ConstraintWrapperPtr theSolverConstraint); - /// \brief Add a movement constraint which will be destroyed + /// \brief Add list of temporary constraints which will be destroyed /// after the next solving of the set of constraints. /// \param theSolverConstraint [in] solver's constraint - virtual void addMovementConstraint(const ConstraintWrapperPtr& theSolverConstraint) = 0; + virtual void addTemporaryConstraint(const ConstraintWrapperPtr& theSolverConstraint) = 0; /// \brief Change mapping feature from SketchPlugin and /// the entity applicable for corresponding solver. diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp index 5e5c60465..6a64f6eba 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp @@ -25,8 +25,6 @@ #include #include #include -#include -#include #include #include #include @@ -185,9 +183,7 @@ bool SketcherPrs_LengthDimension::readyToDisplay(ModelAPI_Feature* theConstraint thePnt2 = thePlane->to3D(aEndPoint->x(), aEndPoint->y())->impl(); return true; - } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID() || - theConstraint->getKind() == SketchPlugin_ConstraintDistanceHorizontal::ID() || - theConstraint->getKind() == SketchPlugin_ConstraintDistanceVertical::ID()) { + } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) { // The constraint is distance std::shared_ptr aPoint_A = SketcherPrs_Tools::getFeaturePoint( aData, SketchPlugin_Constraint::ENTITY_A(), thePlane); diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 47c1be475..e22a952e2 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -702,7 +702,7 @@ QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName) void XGUI_ContextMenuMgr::onRename() { QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects(); - if (!myWorkshop->operationMgr()->abortAllOperations()) + if (!myWorkshop->abortAllOperations()) return; // restore selection in case if dialog box was shown myWorkshop->objectBrowser()->setObjectsSelected(anObjects); diff --git a/src/XGUI/XGUI_MenuMgr.cpp b/src/XGUI/XGUI_MenuMgr.cpp index 73d0447b0..fdb129faa 100755 --- a/src/XGUI/XGUI_MenuMgr.cpp +++ b/src/XGUI/XGUI_MenuMgr.cpp @@ -99,8 +99,7 @@ void XGUI_MenuMgr::addFeature(const std::shared_ptr& theM } if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) { QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll); - QObject::connect(anAction, SIGNAL(triggered()), - anOperationMgr, SLOT(onAbortAllOperations())); + QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations())); aNestedActList << anAction; } } @@ -210,8 +209,7 @@ QAction* XGUI_MenuMgr::buildAction(const std::shared_ptr& } if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) { QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll); - QObject::connect(anAction, SIGNAL(triggered()), - anOperationMgr, SLOT(onAbortAllOperations())); + QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations())); aNestedActList << anAction; } anAction = aSalomeConnector->addFeatureOfNested(theWchName.c_str(), aFeatureInfo, diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 02186143c..a0a879c7a 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -211,12 +211,7 @@ bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation) return isStarted; } -void XGUI_OperationMgr::onAbortAllOperations() -{ - abortAllOperations(); -} - -bool XGUI_OperationMgr::abortAllOperations(const XGUI_MessageKind& theMessageKind) +bool XGUI_OperationMgr::abortAllOperations() { bool aResult = true; if(!hasOperation()) @@ -224,29 +219,18 @@ bool XGUI_OperationMgr::abortAllOperations(const XGUI_MessageKind& theMessageKin if (operationsCount() == 1) { ModuleBase_Operation* aCurrentOperation = currentOperation(); - if (canStopOperation(aCurrentOperation, theMessageKind)) { + if (canStopOperation(aCurrentOperation)) { abortOperation(aCurrentOperation); } else aResult = false; } else { - if (theMessageKind == XGUI_AbortOperationMessage) { - aResult = QMessageBox::question(qApp->activeWindow(), - tr("Abort operation"), - tr("All active operations will be aborted."), - QMessageBox::Ok | QMessageBox::Cancel, - QMessageBox::Cancel) == QMessageBox::Ok; - } - else if (theMessageKind == XGUI_InformationMessage) { - QString aMessage = tr("Please validate all your active operations before saving."); - QMessageBox::question(qApp->activeWindow(), - tr("Validate operation"), - aMessage, - QMessageBox::Ok, - QMessageBox::Ok); - aResult = false; // do not perform abort - } + aResult = QMessageBox::question(qApp->activeWindow(), + tr("Abort operation"), + tr("All active operations will be aborted."), + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Cancel) == QMessageBox::Ok; while(aResult && hasOperation()) { abortOperation(currentOperation()); } @@ -260,7 +244,7 @@ bool XGUI_OperationMgr::commitAllOperations() while (hasOperation()) { ModuleBase_Operation* anOperation = currentOperation(); if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) { - anOperationProcessed = commitOperation(); + anOperationProcessed = onCommitOperation(); } else { abortOperation(anOperation); anOperationProcessed = true; @@ -314,35 +298,33 @@ void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperati onValidateOperation(); } -bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation, - const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind) +bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation) { //in case of nested (sketch) operation no confirmation needed if (isGrantedOperation(theOperation->id())) return true; if (theOperation && theOperation->isModified()) { - if (theMessageKind == XGUI_AbortOperationMessage) { - QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id()); - int anAnswer = QMessageBox::question(qApp->activeWindow(), - tr("Abort operation"), - aMessage, - QMessageBox::Ok | QMessageBox::Cancel, - QMessageBox::Cancel); - return anAnswer == QMessageBox::Ok; - } - else if (theMessageKind == XGUI_InformationMessage) { - QString aMessage = tr("Please validate your %1 before saving.").arg(theOperation->id()); - QMessageBox::question(qApp->activeWindow(), - tr("Validate operation"), - aMessage, - QMessageBox::Ok, - QMessageBox::Ok); - return false; - } + QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id()); + int anAnswer = QMessageBox::question(qApp->activeWindow(), + tr("Abort operation"), + aMessage, + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Cancel); + return anAnswer == QMessageBox::Ok; } return true; } +bool XGUI_OperationMgr::commitOperation() +{ + //if (hasOperation() && currentOperation()->isValid()) { + // onCommitOperation(); + // return true; + //} + //return false; + return onCommitOperation(); +} + void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation) { theOperation->resume(); @@ -440,7 +422,7 @@ void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation) } } -bool XGUI_OperationMgr::commitOperation() +bool XGUI_OperationMgr::onCommitOperation() { bool isCommitted = false; ModuleBase_Operation* anOperation = currentOperation(); diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index 00d941981..56286cc1f 100755 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -48,15 +48,7 @@ class XGUI_ShortCutListener; class XGUI_EXPORT XGUI_OperationMgr : public QObject { Q_OBJECT -public: - /// Enumeration of kind of message that is used when trying to stop the active operation - enum XGUI_MessageKind - { - XGUI_AbortOperationMessage, //< warns and give possibility to abort current operation - XGUI_InformationMessage //< ask to apply the current operation before performing something - }; - -public: + public: /// Constructor /// \param theParent the parent /// \param theWorkshop a reference to workshop @@ -95,9 +87,7 @@ public: /// Returns true if the operation can be aborted. If the operation is modified, /// the warning message box is shown. /// \param theOperation an operation which is checked on stop - /// \param theMessageKind a kind of message in warning message box - bool canStopOperation(ModuleBase_Operation* theOperation, - const XGUI_MessageKind& theMessageKind = XGUI_AbortOperationMessage); + bool canStopOperation(ModuleBase_Operation* theOperation); /// Find and return operation by its Id. ModuleBase_Operation* findOperation(const QString& theId) const; @@ -134,7 +124,8 @@ public: /// \param theOperation an aborted operation void abortOperation(ModuleBase_Operation* theOperation); - bool abortAllOperations(const XGUI_MessageKind& theMessageKind = XGUI_AbortOperationMessage); + /// Slot that commits the current operation. + bool onCommitOperation(); public slots: /// Slot that aborts the current operation. @@ -144,10 +135,7 @@ public slots: /// Commit all operations bool commitAllOperations(); /// Abort all operations - void onAbortAllOperations(); - -protected slots: - + bool abortAllOperations(); signals: /// Signal about an operation is stopped. It is emitted after the stop() of operation is done. diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 32d60c780..0c5fcd7cf 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -169,9 +169,7 @@ bool canRename(const ObjectPtr& theObject, const QString& theName) XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop) { XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); - if (aConnector) - return aConnector->workshop(); - return 0; + return aConnector->workshop(); } } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index b08c24cd7..ec7da2e25 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -508,7 +508,7 @@ void XGUI_Workshop::onAcceptActionClicked() (anOperationMgr->currentOperation()); if (aFOperation) { //if (errorMgr()->canProcessClick(anAction, aFOperation->feature())) - myOperationMgr->commitOperation(); + myOperationMgr->onCommitOperation(); } } } @@ -776,6 +776,12 @@ void XGUI_Workshop::saveDocument(const QString& theName, std::list& QApplication::restoreOverrideCursor(); } +//****************************************************** +bool XGUI_Workshop::abortAllOperations() +{ + return myOperationMgr->abortAllOperations(); +} + //****************************************************** void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation) { @@ -791,7 +797,7 @@ void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation) //****************************************************** void XGUI_Workshop::onOpen() { - if(!myOperationMgr->abortAllOperations()) + if(!abortAllOperations()) return; //save current file before close if modified SessionPtr aSession = ModelAPI_Session::get(); @@ -921,7 +927,7 @@ void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState) //****************************************************** bool XGUI_Workshop::onSave() { - if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage)) + if(!abortAllOperations()) return false; if (myCurrentDir.isEmpty()) { return onSaveAs(); @@ -938,7 +944,7 @@ bool XGUI_Workshop::onSave() //****************************************************** bool XGUI_Workshop::onSaveAs() { - if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage)) + if(!abortAllOperations()) return false; QFileDialog dialog(desktop()); dialog.setWindowTitle(tr("Select directory to save files...")); @@ -1466,7 +1472,7 @@ void XGUI_Workshop::deleteObjects() } QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); - if (!myOperationMgr->abortAllOperations()) + if (!abortAllOperations()) return; bool hasResult = false; @@ -1533,7 +1539,7 @@ void addRefsToFeature(const FeaturePtr& theFeature, //************************************************************** void XGUI_Workshop::cleanHistory() { - if (!myOperationMgr->abortAllOperations()) + if (!abortAllOperations()) return; QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); @@ -1659,7 +1665,7 @@ void XGUI_Workshop::cleanHistory() //************************************************************** void XGUI_Workshop::moveObjects() { - if (!myOperationMgr->abortAllOperations()) + if (!abortAllOperations()) return; SessionPtr aMgr = ModelAPI_Session::get(); @@ -1900,7 +1906,7 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) if (aColor.size() != 3) return; - if (!myOperationMgr->abortAllOperations()) + if (!abortAllOperations()) return; // 2. show the dialog to change the value XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop()); @@ -1990,7 +1996,7 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects) if (aDeflection < 0) return; - if (!myOperationMgr->abortAllOperations()) + if (!abortAllOperations()) return; // 2. show the dialog to change the value XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop()); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index e275f8408..0f0c350fd 100755 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -265,11 +265,20 @@ Q_OBJECT */ void saveDocument(const QString& theName, std::list& theFileNames); + /** + * If there is an active (uncommitted) operation shows a prompt to abort it + * and performs abortion if user agreed. Returns true if + * - operation aborted successfully + * - there is no active operation + */ + bool abortAllOperations(); + /// Updates workshop state according to the started operation, e.g. visualizes the property panel /// and connect to it. /// \param theOpertion a started operation void operationStarted(ModuleBase_Operation* theOperation); + //! Delete features. Delete the referenced features. There can be a question with a list of //! referenced objects. //! \param theFeatures a list of objects to be deleted