aResultPart->setTrsf(*aContext, aTrsf);
setResult(aResultPart);
} else {
- GeomAlgoAPI_Translation aMovementAlgo(aBaseShape, anAxis, aDistance);
+ GeomAlgoAPI_Translation aTranslationAlgo(aBaseShape, anAxis, aDistance);
// Checking that the algorithm worked properly.
- if(!aMovementAlgo.isDone()) {
- static const std::string aFeatureError = "Movement algorithm failed";
+ if(!aTranslationAlgo.isDone()) {
+ static const std::string aFeatureError = "Translation algorithm failed";
setError(aFeatureError);
break;
}
- if(aMovementAlgo.shape()->isNull()) {
+ if(aTranslationAlgo.shape()->isNull()) {
static const std::string aShapeError = "Resulting shape is Null";
setError(aShapeError);
break;
}
- if(!aMovementAlgo.isValid()) {
+ if(!aTranslationAlgo.isValid()) {
std::string aFeatureError = "Warning: resulting shape is not valid";
setError(aFeatureError);
break;
}
ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
- LoadNamingDS(aMovementAlgo, aResultBody, aBaseShape);
+ loadNamingDS(aTranslationAlgo, aResultBody, aBaseShape);
setResult(aResultBody, aResultIndex);
}
aResultIndex++;
removeResults(aResultIndex);
}
-void FeaturesPlugin_Translation::LoadNamingDS(const GeomAlgoAPI_Translation& theMovementAlgo,
- std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- std::shared_ptr<GeomAPI_Shape> theBaseShape)
+void FeaturesPlugin_Translation::loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ std::shared_ptr<GeomAPI_Shape> theBaseShape)
{
// Store result.
- theResultBody->storeModified(theBaseShape, theMovementAlgo.shape());
+ theResultBody->storeModified(theBaseShape, theTranslationAlgo.shape());
- std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theMovementAlgo.mapOfShapes();
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theTranslationAlgo.mapOfSubShapes();
- int aMovedTag = 1;
- std::string aMovedName = "Moved";
- theResultBody->loadAndOrientModifiedShapes(theMovementAlgo.makeShape().get(),
- theBaseShape, GeomAPI_Shape::FACE,
- aMovedTag, aMovedName, *aSubShapes.get());
+ int aTranslatedTag = 1;
+ std::string aTranslatedName = "Translated";
+ theResultBody->loadAndOrientModifiedShapes(&theTranslationAlgo,
+ theBaseShape, GeomAPI_Shape::FACE,
+ aTranslatedTag, aTranslatedName, *aSubShapes.get());
}
#include <GeomAlgoAPI_Translation.h>
-/** \class FeaturesPlugin_Translation
- * \ingroup Plugins
- * \brief Feature for movement objects along the axis.
- */
+/// \class FeaturesPlugin_Translation
+/// \ingroup Plugins
+/// \brief Feature for translation objects along the axis.
class FeaturesPlugin_Translation : public ModelAPI_Feature
{
public:
- /// Movement kind.
+ /// Translation kind.
inline static const std::string& ID()
{
- static const std::string MY_MOVEMENT_ID("Translation");
- return MY_MOVEMENT_ID;
+ static const std::string MY_TRANSLATION_ID("Translation");
+ return MY_TRANSLATION_ID;
}
/// Attribute name of referenced objects.
FeaturesPlugin_Translation();
private:
- void LoadNamingDS(const GeomAlgoAPI_Translation& theMovementAlgo,
+ void loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo,
std::shared_ptr<ModelAPI_ResultBody> theResultBody,
std::shared_ptr<GeomAPI_Shape> theBaseShape);
};
// Created: 8 June 2015
// Author: Dmitry Bobylev
-#include <GeomAlgoAPI_Translation.h>
-
-#include <GeomAlgoAPI_ShapeTools.h>
+#include "GeomAlgoAPI_Translation.h"
#include <BRepBuilderAPI_Transform.hxx>
-#include <BRepCheck_Analyzer.hxx>
#include <gp_Ax1.hxx>
-#include <Precision.hxx>
-#include <TopExp_Explorer.hxx>
//=================================================================================================
GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> theAxis,
double theDistance)
-: myDone(false)
{
build(theSourceShape, theAxis, theDistance);
}
gp_Trsf* aTrsf = new gp_Trsf();
aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * theDistance);
- myTrsf.reset(new GeomAPI_Trsf(aTrsf));
// Transform the shape with copying it.
BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
if(!aBuilder) {
return;
}
- myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
-
- myDone = aBuilder->IsDone() == Standard_True;
+ this->setImpl(aBuilder);
+ this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
- if(!myDone) {
+ if(aBuilder->IsDone() != Standard_True) {
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());
- myShape->setImpl(new TopoDS_Shape(aResult));
-}
-
-//=================================================================================================
-const bool GeomAlgoAPI_Translation::isValid() const
-{
- BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
- return (aChecker.IsValid() == Standard_True);
-}
-
-//=================================================================================================
-const bool GeomAlgoAPI_Translation::hasVolume() const
-{
- bool hasVolume(false);
- if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) {
- hasVolume = true;
- }
- return hasVolume;
-}
-//=================================================================================================
-const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Translation::shape() const
-{
- return myShape;
-}
-
-//=================================================================================================
-std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Translation::mapOfShapes() const
-{
- return myMap;
-}
-
-//=================================================================================================
-std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Translation::makeShape() const
-{
- return myMkShape;
-}
-
-//=================================================================================================
-std::shared_ptr<GeomAPI_Trsf> GeomAlgoAPI_Translation::transformation() const
-{
- return myTrsf;
+ std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(aResult));
+ this->setShape(aShape);
+ this->setDone(true);
}
#include <GeomAlgoAPI.h>
#include <GeomAlgoAPI_MakeShape.h>
+
#include <GeomAPI_Ax1.h>
-#include <GeomAPI_DataMapOfShapeShape.h>
#include <GeomAPI_Shape.h>
-#include <GeomAPI_Trsf.h>
-/** \class GeomAlgoAPI_Translation
- * \ingroup DataAlgo
- * \brief Creates a copy of the object by moving it along the axis.
- */
-class GeomAlgoAPI_Translation : public GeomAPI_Interface
+/// \class GeomAlgoAPI_Translation
+/// \ingroup DataAlgo
+/// \brief Creates a copy of the object by moving it along the axis.
+class GeomAlgoAPI_Translation : public GeomAlgoAPI_MakeShape
{
public:
- /** \brief Creates an object which is obtained from current object by moving it along the axis.
- * \param[in] theSourceShape a shape to be moved.
- * \param[in] theAxis movement axis.
- * \param[in] theDistance movement distance.
- */
+ /// \brief Creates an object which is obtained from current object by moving it along the axis.
+ /// \param[in] theSourceShape a shape to be moved.
+ /// \param[in] theAxis movement axis.
+ /// \param[in] theDistance movement distance.
GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> theAxis,
double theDistance);
- /// \return true if algorithm succeed.
- GEOMALGOAPI_EXPORT const bool isDone() const
- { return myDone; }
-
- /// \return true if resulting shape is valid.
- GEOMALGOAPI_EXPORT const bool isValid() const;
-
- /// \return true if resulting shape has volume.
- GEOMALGOAPI_EXPORT const bool hasVolume() const;
-
- /// \return result of the movement algorithm.
- GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape>& shape() const;
-
- /// \return map of sub-shapes of the result. To be used for History keeping.
- GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_DataMapOfShapeShape> mapOfShapes() const;
-
- /// \return interface for for History processing.
- GEOMALGOAPI_EXPORT std::shared_ptr<GeomAlgoAPI_MakeShape> makeShape() const;
-
- /// Returns the simple transformation
- GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Trsf> transformation() const;
-
private:
/// Builds resulting shape.
void build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> theAxis,
double theDistance);
-
-private:
- /// Fields.
- bool myDone;
- std::shared_ptr<GeomAPI_Shape> myShape;
- std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap;
- std::shared_ptr<GeomAlgoAPI_MakeShape> myMkShape;
- std::shared_ptr<GeomAPI_Trsf> myTrsf;
};
#endif