From: Clarisse Genrault Date: Tue, 21 Jun 2016 13:22:01 +0000 (+0200) Subject: Adding a new type of axis creation : by 3 dimensions. X-Git-Tag: V_2.5.0~232 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=12ff6c6ac96338a0bf0edadba22a6ca79bce5947;p=modules%2Fshaper.git Adding a new type of axis creation : by 3 dimensions. --- diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index f31b6e820..c0fb68719 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -58,5 +58,6 @@ INCLUDE_DIRECTORIES( ADD_UNIT_TESTS(TestAxisCreation.py + UnitTestAxis.py TestPointName.py TestPoint.py) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index b25cc9c2d..90d9dcf31 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -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 @@ -20,6 +22,8 @@ #include #include +#include + #ifdef _DEBUG #include #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 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(); } } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.h b/src/ConstructionPlugin/ConstructionPlugin_Axis.h index 4c51a1d40..63f8e01a7 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.h @@ -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 index 000000000..845dcef37 --- /dev/null +++ b/src/ConstructionPlugin/Test/UnitTestAxis.py @@ -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 +#========================================================================= diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml index c67dff3e1..654420e6b 100644 --- a/src/ConstructionPlugin/axis_widget.xml +++ b/src/ConstructionPlugin/axis_widget.xml @@ -1,4 +1,6 @@ - + + + @@ -30,6 +32,11 @@ + + + + + diff --git a/src/ConstructionPlugin/icons/axis_dxyz_32x32.png b/src/ConstructionPlugin/icons/axis_dxyz_32x32.png new file mode 100644 index 000000000..24a519a92 Binary files /dev/null and b/src/ConstructionPlugin/icons/axis_dxyz_32x32.png differ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp index 97e62158a..360f46bd2 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp @@ -36,6 +36,23 @@ std::shared_ptr GeomAlgoAPI_EdgeBuilder::line( aRes->setImpl(new TopoDS_Shape(anEdge)); return aRes; } +std::shared_ptr 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(); + if (Abs(aStart.SquareDistance(anEnd)) > 1.e+100) + return std::shared_ptr(); + BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd); + std::shared_ptr aRes(new GeomAPI_Edge); + TopoDS_Edge anEdge = anEdgeBuilder.Edge(); + aRes->setImpl(new TopoDS_Shape(anEdge)); + return aRes; +} std::shared_ptr GeomAlgoAPI_EdgeBuilder::cylinderAxis( std::shared_ptr theCylindricalFace) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h index ffd042b4c..b7b97aa7e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h @@ -26,6 +26,15 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder /// \param theEnd an end point of an edge static std::shared_ptr line(std::shared_ptr theStart, std::shared_ptr 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 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 cylinderAxis( std::shared_ptr theCylindricalFace);