anObjectsIt++, aContext++) {
std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group();
- GeomAlgoAPI_Rotation aRotationAlgo(aBaseShape, anAxis, anAngle, isPart);
-
- // Checking that the algorithm worked properly.
- if(!aRotationAlgo.isDone()) {
- static const std::string aFeatureError = "Rotation algorithm failed";
- setError(aFeatureError);
- break;
- }
- if(aRotationAlgo.shape()->isNull()) {
- static const std::string aShapeError = "Resulting shape is Null";
- setError(aShapeError);
- break;
- }
- if(!aRotationAlgo.isValid()) {
- std::string aFeatureError = "Warning: resulting shape is not valid";
- setError(aFeatureError);
- break;
- }
// Setting result.
if (isPart) {
+ std::shared_ptr<GeomAPI_Trsf> aTrsf(new GeomAPI_Trsf());
+ aTrsf->setRotation(anAxis, anAngle);
ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
- aResultPart->setTrsf(*aContext, aRotationAlgo.transformation());
+ aResultPart->setTrsf(*aContext, aTrsf);
setResult(aResultPart);
} else {
+ GeomAlgoAPI_Rotation aRotationAlgo(aBaseShape, anAxis, anAngle);
+
+ // Checking that the algorithm worked properly.
+ if(!aRotationAlgo.isDone()) {
+ static const std::string aFeatureError = "Rotation algorithm failed";
+ setError(aFeatureError);
+ break;
+ }
+ if(aRotationAlgo.shape()->isNull()) {
+ static const std::string aShapeError = "Resulting shape is Null";
+ setError(aShapeError);
+ break;
+ }
+ if(!aRotationAlgo.isValid()) {
+ std::string aFeatureError = "Warning: resulting shape is not valid";
+ setError(aFeatureError);
+ break;
+ }
+
ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
LoadNamingDS(aRotationAlgo, aResultBody, aBaseShape);
setResult(aResultBody, aResultIndex);
anObjectsIt++, aContext++) {
std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group();
- GeomAlgoAPI_Translation aMovementAlgo(aBaseShape, anAxis, aDistance, isPart);
-
- // Checking that the algorithm worked properly.
- if(!aMovementAlgo.isDone()) {
- static const std::string aFeatureError = "Movement algorithm failed";
- setError(aFeatureError);
- break;
- }
- if(aMovementAlgo.shape()->isNull()) {
- static const std::string aShapeError = "Resulting shape is Null";
- setError(aShapeError);
- break;
- }
- if(!aMovementAlgo.isValid()) {
- std::string aFeatureError = "Warning: resulting shape is not valid";
- setError(aFeatureError);
- break;
- }
// Setting result.
if (isPart) {
+ std::shared_ptr<GeomAPI_Trsf> aTrsf(new GeomAPI_Trsf());
+ aTrsf->setTranslation(anAxis, aDistance);
ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
- aResultPart->setTrsf(*aContext, aMovementAlgo.transformation());
+ aResultPart->setTrsf(*aContext, aTrsf);
setResult(aResultPart);
} else {
+ GeomAlgoAPI_Translation aMovementAlgo(aBaseShape, anAxis, aDistance);
+
+ // Checking that the algorithm worked properly.
+ if(!aMovementAlgo.isDone()) {
+ static const std::string aFeatureError = "Movement algorithm failed";
+ setError(aFeatureError);
+ break;
+ }
+ if(aMovementAlgo.shape()->isNull()) {
+ static const std::string aShapeError = "Resulting shape is Null";
+ setError(aShapeError);
+ break;
+ }
+ if(!aMovementAlgo.isValid()) {
+ std::string aFeatureError = "Warning: resulting shape is not valid";
+ setError(aFeatureError);
+ break;
+ }
+
ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
LoadNamingDS(aMovementAlgo, aResultBody, aBaseShape);
setResult(aResultBody, aResultIndex);
#include<GeomAPI_Trsf.h>
+#include <GeomAPI_Ax1.h>
+
+#include <gp_Ax1.hxx>
#include<gp_Trsf.hxx>
+#define MY_TRSF implPtr<gp_Trsf>()
+
+//=================================================================================================
GeomAPI_Trsf::GeomAPI_Trsf()
- : GeomAPI_Interface()
+: GeomAPI_Interface(new gp_Trsf())
{
}
+//=================================================================================================
GeomAPI_Trsf::GeomAPI_Trsf(void* theTrsf)
- : GeomAPI_Interface(theTrsf)
+: GeomAPI_Interface(theTrsf)
+{
+}
+
+//=================================================================================================
+void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
+ const double theDistance)
+{
+ MY_TRSF->SetTranslation(gp_Vec(theAxis->impl<gp_Ax1>().Direction()) * theDistance);
+}
+
+//=================================================================================================
+void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
+ const double theAngle)
{
+ MY_TRSF->SetRotation(theAxis->impl<gp_Ax1>(), theAngle / 180.0 * M_PI);
}
#include <GeomAPI_Interface.h>
#include <memory>
+class GeomAPI_Ax1;
+
/**\class GeomAPI_Trsf
* \ingroup DataModel
* \brief Keep the transformation matrix coefficients
GEOMAPI_EXPORT GeomAPI_Trsf();
/// Takes the pointer to existing transformation
GEOMAPI_EXPORT GeomAPI_Trsf(void* theTrsf);
+
+ /** \brief Sets a translation transformation.
+ * \param[in] theAxis translation axis.
+ * \param[in] theDistance translation distance.
+ */
+ GEOMAPI_EXPORT void setTranslation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
+ const double theDistance);
+
+ /** \brief Sets a rotation transformation.
+ * \param[in] theAxis rotation axis.
+ * \param[in] theAngle rotation angle(in degree).
+ */
+ GEOMAPI_EXPORT void setRotation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
+ const double theAngle);
};
#endif
//=================================================================================================
GeomAlgoAPI_Rotation::GeomAlgoAPI_Rotation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> theAxis,
- double theAngle,
- bool theSimpleTransform)
+ double theAngle)
: myDone(false)
{
- build(theSourceShape, theAxis, theAngle, theSimpleTransform);
+ build(theSourceShape, theAxis, theAngle);
}
//=================================================================================================
void GeomAlgoAPI_Rotation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> theAxis,
- double theAngle,
- bool theSimpleTransform)
+ double theAngle)
{
if(!theSourceShape || !theAxis) {
return;
return;
}
- gp_Trsf aTrsf;
- aTrsf.SetRotation(anAxis, theAngle / 180.0 * M_PI);
+ gp_Trsf* aTrsf = new gp_Trsf();
+ aTrsf->SetRotation(anAxis, theAngle / 180.0 * M_PI);
+ myTrsf.reset(new GeomAPI_Trsf(aTrsf));
- TopoDS_Shape aResult;
// Transform the shape with copying it.
- if (theSimpleTransform) {
- TopLoc_Location aDelta(aTrsf);
- aResult = aSourceShape.Moved(aDelta);
- //myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation())));
- myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf)));
- myDone = true; // is OK for sure
- } else {
- BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
- if(!aBuilder) {
- return;
- }
- myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
-
- myDone = aBuilder->IsDone() == Standard_True;
-
- if(!myDone) {
- return;
- }
-
- aResult = aBuilder->Shape();
- // Fill data map to keep correct orientation of sub-shapes.
- myMap.reset(new GeomAPI_DataMapOfShapeShape());
- for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
- std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
- aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
- myMap->bind(aCurrentShape, aCurrentShape);
- }
+ BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
+ if(!aBuilder) {
+ return;
+ }
+ myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
+
+ myDone = aBuilder->IsDone() == Standard_True;
+
+ if(!myDone) {
+ return;
+ }
+
+ TopoDS_Shape aResult = aBuilder->Shape();
+ // Fill data map to keep correct orientation of sub-shapes.
+ myMap.reset(new GeomAPI_DataMapOfShapeShape());
+ for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
+ std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
+ aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
+ myMap->bind(aCurrentShape, aCurrentShape);
}
myShape.reset(new GeomAPI_Shape());
* \param[in] theSourceShape a shape to be rotated.
* \param[in] theAxis rotation axis.
* \param[in] theAngle rotation angle(in degree).
- * \param[in] theSimpleTransform makes just transformation of shape without changing of topology or geometry
*/
GEOMALGOAPI_EXPORT GeomAlgoAPI_Rotation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> theAxis,
- double theAngle,
- bool theSimpleTransform = false);
+ double theAngle);
/// \return true if algorithm succeed.
GEOMALGOAPI_EXPORT const bool isDone() const
/// Builds resulting shape.
void build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> theAxis,
- double theAngle,
- bool theSimpleTransform);
+ double theAngle);
private:
/// Fields.
//=================================================================================================
GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
- std::shared_ptr<GeomAPI_Ax1> theAxis,
- double theDistance,
- bool theSimpleTransform)
+ std::shared_ptr<GeomAPI_Ax1> theAxis,
+ double theDistance)
: myDone(false)
{
- build(theSourceShape, theAxis, theDistance, theSimpleTransform);
+ build(theSourceShape, theAxis, theDistance);
}
//=================================================================================================
void GeomAlgoAPI_Translation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
- std::shared_ptr<GeomAPI_Ax1> theAxis,
- double theDistance,
- bool theSimpleTransform)
+ std::shared_ptr<GeomAPI_Ax1> theAxis,
+ double theDistance)
{
if(!theSourceShape || !theAxis) {
return;
return;
}
- gp_Trsf aTrsf;
- aTrsf.SetTranslation(gp_Vec(anAxis.Direction()) * theDistance);
+ gp_Trsf* aTrsf = new gp_Trsf();
+ aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * theDistance);
+ myTrsf.reset(new GeomAPI_Trsf(aTrsf));
- TopoDS_Shape aResult;
// Transform the shape with copying it.
- if (theSimpleTransform) {
- TopLoc_Location aDelta(aTrsf);
- aResult = aSourceShape.Moved(aDelta);
- // store the accumulated information about the result and this delta
- //myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation())));
- myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf)));
- myDone = true; // is OK for sure
- } else {
- BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
- if(!aBuilder) {
- return;
- }
- myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
-
- myDone = aBuilder->IsDone() == Standard_True;
-
- if(!myDone) {
- return;
- }
-
- aResult = aBuilder->Shape();
- // Fill data map to keep correct orientation of sub-shapes.
- myMap.reset(new GeomAPI_DataMapOfShapeShape());
- for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
- std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
- aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
- myMap->bind(aCurrentShape, aCurrentShape);
- }
+ BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
+ if(!aBuilder) {
+ return;
+ }
+ myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
+
+ myDone = aBuilder->IsDone() == Standard_True;
+
+ if(!myDone) {
+ return;
+ }
+
+ TopoDS_Shape aResult = aBuilder->Shape();
+ // Fill data map to keep correct orientation of sub-shapes.
+ myMap.reset(new GeomAPI_DataMapOfShapeShape());
+ for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
+ std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
+ aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
+ myMap->bind(aCurrentShape, aCurrentShape);
}
myShape.reset(new GeomAPI_Shape());
* \param[in] theSourceShape a shape to be moved.
* \param[in] theAxis movement axis.
* \param[in] theDistance movement distance.
- * \param[in] theSimpleTransform makes just transformation of shape without changing of topology or geometry
*/
GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
- std::shared_ptr<GeomAPI_Ax1> theAxis,
- double theDistance,
- bool theSimpleTransform = false);
+ std::shared_ptr<GeomAPI_Ax1> theAxis,
+ double theDistance);
/// \return true if algorithm succeed.
GEOMALGOAPI_EXPORT const bool isDone() const
/// Builds resulting shape.
void build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> theAxis,
- double theDistance,
- bool theSimpleTransform);
+ double theDistance);
private:
/// Fields.
std::shared_ptr<GeomAPI_Shape> myShape;
std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap;
std::shared_ptr<GeomAlgoAPI_MakeShape> myMkShape;
- std::shared_ptr<GeomAPI_Trsf> myTrsf; ///< transformation of the shape in case theSimpleTransform
+ std::shared_ptr<GeomAPI_Trsf> myTrsf;
};
#endif