]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Adding a new type of axis creation : by 3 dimensions.
authorClarisse Genrault <clarisse.genrault@cea.fr>
Tue, 21 Jun 2016 13:22:01 +0000 (15:22 +0200)
committerClarisse Genrault <clarisse.genrault@cea.fr>
Tue, 21 Jun 2016 13:22:01 +0000 (15:22 +0200)
src/ConstructionPlugin/CMakeLists.txt
src/ConstructionPlugin/ConstructionPlugin_Axis.cpp
src/ConstructionPlugin/ConstructionPlugin_Axis.h
src/ConstructionPlugin/Test/UnitTestAxis.py [new file with mode: 0644]
src/ConstructionPlugin/axis_widget.xml
src/ConstructionPlugin/icons/axis_dxyz_32x32.png [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h

index 3b149668a31bafb6644935b7d8a158653a4c1af0..0460b88de6a44e06b188f7eeeb8d86b4c959c240 100644 (file)
@@ -7,15 +7,15 @@ SET(PROJECT_HEADERS
     ConstructionPlugin.h
     ConstructionPlugin_Plugin.h
     ConstructionPlugin_Point.h
-       ConstructionPlugin_Axis.h
-       ConstructionPlugin_Plane.h
+    ConstructionPlugin_Axis.h
+    ConstructionPlugin_Plane.h
 )
 
 SET(PROJECT_SOURCES
     ConstructionPlugin_Plugin.cpp
     ConstructionPlugin_Point.cpp
-       ConstructionPlugin_Axis.cpp
-       ConstructionPlugin_Plane.cpp
+    ConstructionPlugin_Axis.cpp
+    ConstructionPlugin_Plane.cpp
 )
 
 SET(XML_RESOURCES
@@ -49,4 +49,5 @@ INCLUDE_DIRECTORIES(
 
 
 ADD_UNIT_TESTS(TestAxisCreation.py
-               TestPointName.py)
+               TestPointName.py
+               UnitTestAxis.py)
index b25cc9c2d4c0b3568fa89ddbf1f7e06e5caa1f6b..90d9dcf312998d7a6ab5e24d038b9563722c3211 100644 (file)
@@ -1,9 +1,11 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
 
 // File:        ConstructionPlugin_Axis.cpp
 // Created:     12 Dec 2014
 // Author:      Vitaly Smetannikov
 
+// Modified by CEA (delegation to Alyotech) : 29 Mar 2016 
+
 #include "ConstructionPlugin_Axis.h"
 
 #include <Config_PropManager.h>
@@ -20,6 +22,8 @@
 #include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomAlgoAPI_PointBuilder.h>
 
+#include <math.h>
+
 #ifdef _DEBUG
 #include <iostream>
 #endif
@@ -34,10 +38,14 @@ void ConstructionPlugin_Axis::initAttributes()
 {
   data()->addAttribute(ConstructionPlugin_Axis::METHOD(),
                        ModelAPI_AttributeString::typeId());
+  
+  // Attributes needed to build the axis using the "two points" method
   data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(),
                        ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(ConstructionPlugin_Axis::POINT_SECOND(),
                        ModelAPI_AttributeSelection::typeId());
+
+  // Attributes needed to build the axis using the "cylindrical face" method"
   data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(),
                        ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(ConstructionPlugin_Axis::X_DIRECTION(),
@@ -52,6 +60,14 @@ void ConstructionPlugin_Axis::initAttributes()
       ConstructionPlugin_Axis::Y_DIRECTION());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), 
       ConstructionPlugin_Axis::Z_DIRECTION());
+
+  //Attributes needed to build the axis using the "three dimensions" method
+  data()->addAttribute(ConstructionPlugin_Axis::DX(),
+                       ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(ConstructionPlugin_Axis::DY(),
+                       ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(ConstructionPlugin_Axis::DZ(),
+                       ModelAPI_AttributeDouble::typeId());
 }
 
 void ConstructionPlugin_Axis::createAxisByTwoPoints()
@@ -126,7 +142,25 @@ void ConstructionPlugin_Axis::createAxisByCylindricalFace()
     }
 }
 
+void ConstructionPlugin_Axis::createAxisByDimensions()
+{
+  // Start by getting these dimensions
+  double aDX = data()->real(DX())->value();
+  double aDY = data()->real(DY())->value();
+  double aDZ = data()->real(DZ())->value();
+
+  if (fabs(aDX) < MINIMAL_LENGTH()  && fabs(aDY) < MINIMAL_LENGTH() && fabs(aDZ) < MINIMAL_LENGTH()){
+    setError("Axis builder with dimensions  :: all dimensions are null", false);
+    return ;
+  }
 
+  // Make the axis, build the ResultConstructionPtr and write it
+  std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aDX, aDY, aDZ);
+  ResultConstructionPtr aConstr = document()->createConstruction(data());
+  aConstr->setInfinite(true);
+  aConstr->setShape(anEdge);
+  setResult(aConstr);    
+}
 
 void ConstructionPlugin_Axis::execute()
 {
@@ -138,6 +172,8 @@ void ConstructionPlugin_Axis::execute()
     createAxisByCylindricalFace();
   } else if (aMethodType == "AxisByPointAndDirection") {
     createAxisByPointAndDirection();
+  } else if (aMethodType == "AxisByDimensionsCase") {
+    createAxisByDimensions();
   }
 }
 
index 4c51a1d40f9fedbdab675eb61a8721becda16dd6..63f8e01a72106f9794a8ffc90220949840385a8b 100644 (file)
@@ -1,9 +1,11 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
 
 // File:        ConstructionPlugin_Axis.h
 // Created:     12 Dec 2014
 // Author:      Vitaly Smetannikov
 
+// Modified by CEA (delegation to Alyotech) : 29 Mar 2016 
+
 #ifndef ConstructionPlugin_Axis_H
 #define ConstructionPlugin_Axis_H
 
@@ -57,6 +59,24 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
     static const std::string CYLINDRICAL_FACE_ATTR("CylindricalFace");
     return CYLINDRICAL_FACE_ATTR;
   }
+  /// attribute name for the X dimension
+  inline static const std::string& DX()
+  {
+    static const std::string DX_ATTR("DX");
+    return DX_ATTR;
+  }
+  /// attribute name for the Y dimension
+  inline static const std::string& DY()
+  {
+    static const std::string DY_ATTR("DY");
+    return DY_ATTR;
+  }
+  /// attribute name for the Z dimension
+  inline static const std::string& DZ()
+  {
+    static const std::string DZ_ATTR("DZ");
+    return DZ_ATTR;
+  }
 
   /// attribute name for X direction
   inline static const std::string& X_DIRECTION()
@@ -101,6 +121,8 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
  protected:
   /// Creates a new axis by two defined points
   void createAxisByTwoPoints();
+  /// Creates a new axis using three dimensions
+  void createAxisByDimensions();
   /// Creates a new axis as copy of cylindrical face axis
   void createAxisByCylindricalFace();
   /// Creates a new axis by point and direction
diff --git a/src/ConstructionPlugin/Test/UnitTestAxis.py b/src/ConstructionPlugin/Test/UnitTestAxis.py
new file mode 100644 (file)
index 0000000..845dcef
--- /dev/null
@@ -0,0 +1,76 @@
+# Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+# File:        UnitTestAxis.py
+# Created:     30 Mar 2016
+# Author:      CEA (delegation to Alyotech)
+
+"""
+    UnitTestAxis.py
+    Unit Test of ConstructionPlugin_Axis class
+
+
+    static const std::string CONSTRUCTION_AXIS_KIND("Axis");
+    static const std::string METHOD_ATTR("CreationMethod");
+    static const std::string POINT_ATTR_FIRST("FirstPoint");
+    static const std::string POINT_ATTR_SECOND("SecondPoint");
+    static const std::string CYLINDRICAL_FACE_ATTR("CylindricalFace");
+    static const std::string X_ATTR("X");
+    static const std::string Y_ATTR("Y");
+    static const std::string Z_ATTR("Z");
+
+
+    data()->addAttribute(ConstructionPlugin_Axis::METHOD(), ModelAPI_AttributeString::typeId());
+  
+    data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(), ModelAPI_AttributeSelection::typeId());
+    data()->addAttribute(ConstructionPlugin_Axis::POINT_SECOND(), ModelAPI_AttributeSelection::typeId());
+
+    data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(), ModelAPI_AttributeSelection::typeId());
+
+    data()->addAttribute(ConstructionPlugin_Axis::X(), ModelAPI_AttributeDouble::typeId());
+    data()->addAttribute(ConstructionPlugin_Axis::Y(), ModelAPI_AttributeDouble::typeId());
+    data()->addAttribute(ConstructionPlugin_Axis::Z(), ModelAPI_AttributeDouble::typeId());
+
+"""
+
+
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+from ModelAPI import *
+from GeomDataAPI import *
+from GeomAlgoAPI import *
+from GeomAPI import *
+import math
+
+__updated__ = "2016-01-04"
+
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
+# Create a part for creation of a box
+aSession.startOperation()
+aPartFeature = aDocument.addFeature("Part")
+aSession.finishOperation()
+assert (len(aPartFeature.results()) == 1)
+
+aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
+aPart = aPartResult.partDoc()
+#=========================================================================
+# Creation of an Axis by coordinates
+#=========================================================================
+aSession.startOperation()
+anAxisByDimensions = aPart.addFeature("Axis")
+anAxisByDimensions.string("CreationMethod").setValue("AxisByDimensionsCase")
+anAxisByDimensions.real("DX").setValue(2.5)
+anAxisByDimensions.real("DY").setValue(3.2)
+anAxisByDimensions.real("DZ").setValue(1.4)
+anAxisByDimensions.execute()
+
+
+assert(len(anAxisByDimensions.results()) > 0)
+anAxisByDimensions = modelAPI_ResultConstruction(anAxisByDimensions.firstResult())
+assert(anAxisByDimensions is not None)
+
+aSession.finishOperation()
+#=========================================================================
+# End of test
+#=========================================================================
index 4f0711c14b24a176821edcb20e60bdc534c6f54d..f783742d6be66c94bc46aaf49c860d22c223f093 100644 (file)
@@ -1,4 +1,6 @@
-<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+<!-- Copyright (C) 2014-2016 CEA/DEN, EDF R&D -->
+
+<!--  Modified by CEA (delegation to Alyotech) : 29 Mar 2016 -->
 
 <source>
   <toolbox id="CreationMethod">
         <validator id="GeomValidators_Face" parameters="cylinder"/>
       </shape_selector>
     </box>
+    <box id="AxisByDimensionsCase" title="By three dimensions" icon="icons/Construction/axis_dxyz_32x32.png">
+      <doublevalue id="DX" label="DX " tooltip="X dimension" default="0"/>
+      <doublevalue id="DY" label="DY " tooltip="Y dimension" default="0"/>
+      <doublevalue id="DZ" label="DZ " tooltip="Z dimension" default="10"/>
+    </box>
   </toolbox>
   
 </source>
diff --git a/src/ConstructionPlugin/icons/axis_dxyz_32x32.png b/src/ConstructionPlugin/icons/axis_dxyz_32x32.png
new file mode 100644 (file)
index 0000000..24a519a
Binary files /dev/null and b/src/ConstructionPlugin/icons/axis_dxyz_32x32.png differ
index 97e62158a5adfb6f0875bf681de1a1d86af06f57..360f46bd2b850f90febbc136e831fbff247bde36 100644 (file)
@@ -36,6 +36,23 @@ std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::line(
   aRes->setImpl(new TopoDS_Shape(anEdge));
   return aRes;
 }
+std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::line(                                                            
+    double theDX, double theDY, double theDZ)
+{
+  
+  const gp_Pnt& aStart = gp_Pnt(0, 0, 0);
+  const gp_Pnt& anEnd = gp_Pnt(theDX, theDY, theDZ);
+
+  if (aStart.IsEqual(anEnd, Precision::Confusion()))
+    return std::shared_ptr<GeomAPI_Edge>();
+  if (Abs(aStart.SquareDistance(anEnd)) > 1.e+100)
+    return std::shared_ptr<GeomAPI_Edge>();
+  BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
+  std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
+  TopoDS_Edge anEdge = anEdgeBuilder.Edge();
+  aRes->setImpl(new TopoDS_Shape(anEdge));
+  return aRes;
+}
 
 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::cylinderAxis(
     std::shared_ptr<GeomAPI_Shape> theCylindricalFace)
index ffd042b4c52c2e7a6a967b69a87471a2e199e6ca..b7b97aa7ee6818e881ed2106c38d0dd3e79adc09 100644 (file)
@@ -26,6 +26,15 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder
   /// \param theEnd an end point of an edge
   static std::shared_ptr<GeomAPI_Edge> line(std::shared_ptr<GeomAPI_Pnt> theStart,
                                             std::shared_ptr<GeomAPI_Pnt> theEnd);
+
+  /// Creates linear edge by three dimensions.
+  /// \param theX the X dimension
+  /// \param theY the Y dimension
+  /// \param theZ the Z dimension
+  static std::shared_ptr<GeomAPI_Edge> line(double theDX,
+                                            double theDY,
+                                            double theDZ);
+
   /// Creates edge - axis of the given cylindrical face. The result axis edge is infinite
   static std::shared_ptr<GeomAPI_Edge> cylinderAxis(
     std::shared_ptr<GeomAPI_Shape> theCylindricalFace);