From 12ff6c6ac96338a0bf0edadba22a6ca79bce5947 Mon Sep 17 00:00:00 2001 From: Clarisse Genrault Date: Tue, 21 Jun 2016 15:22:01 +0200 Subject: [PATCH] Adding a new type of axis creation : by 3 dimensions. --- src/ConstructionPlugin/CMakeLists.txt | 1 + .../ConstructionPlugin_Axis.cpp | 38 ++++++++- .../ConstructionPlugin_Axis.h | 24 +++++- src/ConstructionPlugin/Test/UnitTestAxis.py | 76 ++++++++++++++++++ src/ConstructionPlugin/axis_widget.xml | 9 ++- .../icons/axis_dxyz_32x32.png | Bin 0 -> 1620 bytes src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp | 17 ++++ src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h | 9 +++ 8 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 src/ConstructionPlugin/Test/UnitTestAxis.py create mode 100644 src/ConstructionPlugin/icons/axis_dxyz_32x32.png 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 0000000000000000000000000000000000000000..24a519a929e4e9ca0d35a8aaf3e1700ba18910a5 GIT binary patch literal 1620 zcmV-a2CMmrP)s3V zK~z}7wU=#dTh$rIf9Kq5H+GUbO>vquT}rB!L7PDt@PSEXY=v(HQB~8nq9IKPBqE{m zWfTnw1QM${-ZV{`)NZheNziVzmD&QDKyA}j0`VfXr3KQ2bR>PToy3Wq*uK8^o^$rW z$Ca@Pa-!@=SC-Fx?tT8x|NNhq3k|F_o3=N!H=iXMHC(f4JJFu?kAfiXIJ-aj^DhPnkP_p06uvmx z4Gas%MF@!w{cA>8jnZ@_lfXSlc|crBd$m61z<>cEs?OE}y+(xzqg5jhKLfmp)|=-g z!gc+7?gidJ(y0TVusBU_^z`$Yf!AIJ^4EmhmD~zE1r&h-#th^8FN$n_cJ9{* zXo-{#POKF-zU0S1tO_8%Y#FUmF9D)}54;3)Rh~CzL~3HAjd+QHsW|~i9o_YZ#QIIg z@Q@ci{DbVD!`g&SoU^Ua8X0vbR{FEEBOdo-;Gk)Ek*y|X9|VS zL*Hkn5_J=B$zJ(+0Z6R86=Wp~kaFBIaM{wm1K3R%J}oA5tAO~eGo{a3viVQXRfKr~ zI0bw&?_S`>7T1;!1B|SL>&|vw_b;FWWB#^nYU+Tc+Sf2xhH)GHATUf#`pp@D_De`0 z0MJIY!I~q9<~tE$149Ln+CLy4sKH`L2-J100JQ?3zwhxGwf<@`W+2J@ zTp?z)EiPl0ZnbztAD#E~?=V_@I`qcl`|6#q*|fd!Zs-d^UPi)Ol;?J}cdjHiJ|L#` zHsZ1M7}bFa+i~0sv6gIW*IH-h-219$^K*Sh`A-3q=QUHL1VZffO3JV`?NxGF@c0O>>!j*E1n2uFeeqgADLI4)>Yk%TeeI1iuw z)0WrW?{i*teDk*b5fzjlqLlk)Pz5VbM%zdPK8fi|;6_nS6d8#kkYE(bF9I4N9h_)0 zD)0#NIgk#*i6Di83QJ2H)_~UPkD#B(XTE-A?BEOU0FQalorWS#3{|E*WGUuqBi(vhJ9&%Hw~T?B5oFT4zl+9Ff7QHpC1kwk%|wg zQk=2RdVrF3UpS%teM0%A)X+crHPr&2Ty!pg>}i^FIq9l+Cg$b0UR@iyM;Io9Ji_VQ>$!Klh6FWK>QDgYnMHh SWiJr`0000 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); -- 2.39.2