Salome HOME
Merge branch 'master' of https://codev-tuleap.cea.fr/plugins/git/salome/shaper
authormzn <mzn@opencascade.com>
Mon, 20 Aug 2018 16:57:41 +0000 (19:57 +0300)
committermzn <mzn@opencascade.com>
Mon, 20 Aug 2018 16:57:41 +0000 (19:57 +0300)
src/ConstructionAPI/ConstructionAPI_Point.cpp
src/ConstructionAPI/ConstructionAPI_Point.h
src/ConstructionPlugin/CMakeLists.txt
src/ConstructionPlugin/Test/TestPoint_VertexSelection.py [new file with mode: 0644]

index 7dcca33b67b9938706c226b5c0b2ba9cc292e9f2..f0a6ef0085f7e3709a19cff3e5cfc5fbf60ec494 100644 (file)
 
 #include "ConstructionAPI_Point.h"
 
+#include <GeomAPI_Pnt.h>
 #include <GeomAPI_Shape.h>
+#include <GeomAPI_Vertex.h>
 
+#include <ModelHighAPI_Double.h>
 #include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
@@ -114,6 +117,38 @@ ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feat
   {
     if (theIsCircularEdge) {
       setByCenterOfCircle(theObject);
+    } else if (theObject.shapeType() == "VERTEX") {
+      // This is tricky way to get vertex shape.
+      fillAttribute(theObject, mypointToProject);
+      GeomShapePtr aShape = mypointToProject->value();
+      if (!aShape.get()) {
+        ResultPtr aContext = mypointToProject->context();
+        if (!aContext.get()) {
+          fillAttribute(ModelHighAPI_Selection(), mypointToProject);
+          return;
+        }
+        aShape = aContext->shape();
+      }
+
+      if (!aShape.get()) {
+        fillAttribute(ModelHighAPI_Selection(), mypointToProject);
+        return;
+      }
+
+      GeomVertexPtr aVertex = aShape->vertex();
+      if (!aVertex.get()) {
+        fillAttribute(ModelHighAPI_Selection(), mypointToProject);
+        return;
+      }
+
+      GeomPointPtr aPnt = aVertex->point();
+      if (!aPnt.get()) {
+        fillAttribute(ModelHighAPI_Selection(), mypointToProject);
+        return;
+      }
+
+      fillAttribute(ModelHighAPI_Selection(), mypointToProject);
+      setByXYZ(aPnt->x(), aPnt->y(), aPnt->z());
     } else {
       setByCenterOfGravity(theObject);
     }
@@ -173,7 +208,7 @@ void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection&
                 mycreationMethod);
   fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE(),
                 myprojectionType);
-  fillAttribute(theVertex, mypoinToProject);
+  fillAttribute(theVertex, mypointToProject);
   fillAttribute(theEdge, myedgeForPointProjection);
 
   execute();
@@ -187,7 +222,7 @@ void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection&
                 mycreationMethod);
   fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_FACE(),
                 myprojectionType);
-  fillAttribute(theVertex, mypoinToProject);
+  fillAttribute(theVertex, mypointToProject);
   fillAttribute(theFace, myfaceForPointProjection);
 
   execute();
@@ -296,7 +331,7 @@ void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
     }
     theDumper << ", " << reverse()->value();
   } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION()) {
-    theDumper << poinToProject() << ", ";
+    theDumper << pointToProject() << ", ";
     if (projectionType()->value() == ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE()) {
       theDumper << edgeForPointProjection();
     } else {
index 32e2878d58b7a2e1344f5948c7322a330a87118d..8e59114049db4847de574a171b561466940f2d38 100644 (file)
@@ -117,7 +117,7 @@ public:
     ModelAPI_AttributeDouble, /** Ratio */,
     reverse, ConstructionPlugin_Point::REVERSE(),
     ModelAPI_AttributeBoolean, /** Reverse */,
-    poinToProject, ConstructionPlugin_Point::POINT_TO_PROJECT(),
+    pointToProject, ConstructionPlugin_Point::POINT_TO_PROJECT(),
     ModelAPI_AttributeSelection, /** Point to project*/,
     projectionType, ConstructionPlugin_Point::PROJECTION_TYPE(),
     ModelAPI_AttributeString, /** Type of the point projection */,
index a9705702fbfe2c6eea3ec2c75730ae996a306e57..442035abde5340ed14bc5f77fa52bfe3e2999429 100644 (file)
@@ -88,5 +88,6 @@ ADD_UNIT_TESTS(TestAxisCreation.py
                TestPoint_ProjectOnFace.py
                TestPoint_GeometricalPropertyCenterOfGravity.py
                TestPoint_GeometricalPropertyCenterOfCircle.py
+               TestPoint_VertexSelection.py
                TestPointName.py
                TestPlane.py)
diff --git a/src/ConstructionPlugin/Test/TestPoint_VertexSelection.py b/src/ConstructionPlugin/Test/TestPoint_VertexSelection.py
new file mode 100644 (file)
index 0000000..8180742
--- /dev/null
@@ -0,0 +1,37 @@
+## Copyright (C) 2014-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<mailto:webmaster.salome@opencascade.com>
+##
+
+from salome.shaper import model
+from GeomAPI import *
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+Point_2 = model.addPoint(Part_1_doc, model.selection("VERTEX", "Box_1_1/Front&Box_1_1/Left&Box_1_1/Top"))
+model.do()
+model.end()
+
+assert (len(Point_2.results()) > 0)
+rightPosition = GeomAPI_Vertex(10, 0, 10)
+assert(rightPosition.isEqual(Point_2.results()[0].resultSubShapePair()[0].shape()))
+
+assert(model.checkPythonDump())