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
ADD_UNIT_TESTS(TestAxisCreation.py
- TestPointName.py)
+ TestPointName.py
+ UnitTestAxis.py)
-// 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>
#include <GeomAlgoAPI_EdgeBuilder.h>
#include <GeomAlgoAPI_PointBuilder.h>
+#include <math.h>
+
#ifdef _DEBUG
#include <iostream>
#endif
{
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(),
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()
}
}
+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()
{
createAxisByCylindricalFace();
} else if (aMethodType == "AxisByPointAndDirection") {
createAxisByPointAndDirection();
+ } else if (aMethodType == "AxisByDimensionsCase") {
+ createAxisByDimensions();
}
}
-// 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
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()
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
--- /dev/null
+# 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
+#=========================================================================
-<!-- 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>
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)
/// \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);