From: dbv Date: Mon, 8 Jun 2015 11:26:01 +0000 (+0300) Subject: Feature #535: 5.02. Body placement by translation along a direction X-Git-Tag: V_1.3.0~267 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a67c27ec9c9f0be2c0e40e5c2c487945e0d75b52;p=modules%2Fshaper.git Feature #535: 5.02. Body placement by translation along a direction --- diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index b16c2b7ca..6447870d7 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -10,6 +10,7 @@ SET(PROJECT_HEADERS FeaturesPlugin_ExtrusionCut.h FeaturesPlugin_Revolution.h FeaturesPlugin_Rotation.h + FeaturesPlugin_Movement.h FeaturesPlugin_Boolean.h FeaturesPlugin_Group.h FeaturesPlugin_Placement.h @@ -21,6 +22,7 @@ SET(PROJECT_SOURCES FeaturesPlugin_ExtrusionCut.cpp FeaturesPlugin_Revolution.cpp FeaturesPlugin_Rotation.cpp + FeaturesPlugin_Movement.cpp FeaturesPlugin_Boolean.cpp FeaturesPlugin_Group.cpp FeaturesPlugin_Placement.cpp @@ -32,6 +34,7 @@ SET(XML_RESOURCES extrusioncut_widget.xml revolution_widget.xml rotation_widget.xml + movement_widget.xml boolean_widget.xml group_widget.xml placement_widget.xml diff --git a/src/FeaturesPlugin/FeaturesPlugin_Movement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Movement.cpp new file mode 100644 index 000000000..5842ffd59 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_Movement.cpp @@ -0,0 +1,116 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesPlugin_Movement.cpp +// Created: 8 June 2015 +// Author: Dmitry Bobylev + +#include + +#include +#include +#include +#include + +#include +#include + +//================================================================================================= +FeaturesPlugin_Movement::FeaturesPlugin_Movement() +{ +} + +//================================================================================================= +void FeaturesPlugin_Movement::initAttributes() +{ + AttributeSelectionListPtr aSelection = + std::dynamic_pointer_cast(data()->addAttribute( + FeaturesPlugin_Movement::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); + // revolution works with faces always + aSelection->setSelectionType("SOLID"); + + data()->addAttribute(FeaturesPlugin_Movement::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(FeaturesPlugin_Movement::DISTANCE_ID(), ModelAPI_AttributeDouble::typeId()); +} + +//================================================================================================= +void FeaturesPlugin_Movement::execute() +{ + // Getting objects. + ListOfShape anObjects; + AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Movement::OBJECTS_LIST_ID()); + if (anObjectsSelList->size() == 0) { + return; + } + for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { + std::shared_ptr anObjectAttr = anObjectsSelList->value(anObjectsIndex); + std::shared_ptr anObject = anObjectAttr->value(); + if(!anObject.get()) { + return; + } + anObjects.push_back(anObject); + } + + //Getting axe. + std::shared_ptr anAxis; + std::shared_ptr anEdge; + std::shared_ptr anObjRef = selection(FeaturesPlugin_Movement::AXIS_OBJECT_ID()); + if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->value())); + } + if(anEdge) { + anAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction())); + } + + // Getting distance. + double aDistance = real(FeaturesPlugin_Movement::DISTANCE_ID())->value(); + + // Moving each object. + int aResultIndex = 0; + for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) { + std::shared_ptr aBaseShape = *anObjectsIt; + GeomAlgoAPI_Movement 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; + } + + // Setting result. + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + LoadNamingDS(aMovementAlgo, aResultBody, aBaseShape); + setResult(aResultBody, aResultIndex); + aResultIndex++; + } + + // Remove the rest results if there were produced in the previous pass. + removeResults(aResultIndex); +} + +void FeaturesPlugin_Movement::LoadNamingDS(const GeomAlgoAPI_Movement& theMovementAlgo, + std::shared_ptr theResultBody, + std::shared_ptr theBaseShape) +{ + // Store result. + theResultBody->storeModified(theBaseShape, theMovementAlgo.shape()); + + std::shared_ptr aSubShapes = theMovementAlgo.mapOfShapes(); + + int aMovedTag = 1; + std::string aMovedName = "Moved"; + theResultBody->loadAndOrientModifiedShapes(theMovementAlgo.makeShape().get(), + theBaseShape, GeomAPI_Shape::FACE, + aMovedTag, aMovedName, *aSubShapes.get()); + +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_Movement.h b/src/FeaturesPlugin/FeaturesPlugin_Movement.h new file mode 100644 index 000000000..84384ae6a --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_Movement.h @@ -0,0 +1,73 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesPlugin_Movement.h +// Created: 8 June 2015 +// Author: Dmitry Bobylev + +#ifndef FeaturesPlugin_Movement_H_ +#define FeaturesPlugin_Movement_H_ + +#include + +#include + +#include + +/** \class FeaturesPlugin_Movement + * \ingroup Plugins + * \brief Feature for movement objects along the axis. + */ +class FeaturesPlugin_Movement : public ModelAPI_Feature +{ + public: + /// Movement kind. + inline static const std::string& ID() + { + static const std::string MY_MOVEMENT_ID("Movement"); + return MY_MOVEMENT_ID; + } + + /// Attribute name of referenced objects. + inline static const std::string& OBJECTS_LIST_ID() + { + static const std::string MY_OBJECTS_LIST_ID("main_objects"); + return MY_OBJECTS_LIST_ID; + } + + /// Attribute name of an axis. + inline static const std::string& AXIS_OBJECT_ID() + { + static const std::string MY_AXIS_OBJECT_ID("axis_object"); + return MY_AXIS_OBJECT_ID; + } + + /// Attribute name of distance. + inline static const std::string& DISTANCE_ID() + { + static const std::string MY_DISTANCE_ID("distance"); + return MY_DISTANCE_ID; + } + + /// \return the kind of a feature. + FEATURESPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = FeaturesPlugin_Movement::ID(); + return MY_KIND; + } + + /// Creates a new part document if needed. + FEATURESPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes. + FEATURESPLUGIN_EXPORT virtual void initAttributes(); + + /// Use plugin manager for features creation. + FeaturesPlugin_Movement(); + +private: + void LoadNamingDS(const GeomAlgoAPI_Movement& theMovementAlgo, + std::shared_ptr theResultBody, + std::shared_ptr theBaseShape); +}; + +#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index 100dddf3e..844d77f82 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,8 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(string theFeatureID) return FeaturePtr(new FeaturesPlugin_Revolution); } else if (theFeatureID == FeaturesPlugin_Rotation::ID()) { return FeaturePtr(new FeaturesPlugin_Rotation); + } else if (theFeatureID == FeaturesPlugin_Movement::ID()) { + return FeaturePtr(new FeaturesPlugin_Movement); } else if (theFeatureID == FeaturesPlugin_Boolean::ID()) { return FeaturePtr(new FeaturesPlugin_Boolean); } else if (theFeatureID == FeaturesPlugin_Group::ID()) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp index 154e5cfa4..cbff4e0ca 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp @@ -14,8 +14,6 @@ #include #include -#define _ROTATED_TAG 1 - //================================================================================================= FeaturesPlugin_Rotation::FeaturesPlugin_Rotation() { diff --git a/src/FeaturesPlugin/movement_widget.xml b/src/FeaturesPlugin/movement_widget.xml new file mode 100644 index 000000000..96c16cf3a --- /dev/null +++ b/src/FeaturesPlugin/movement_widget.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index ea5b8a78d..a6af70516 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -18,6 +18,9 @@ + + + diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index 75870d350..3bc403732 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -18,6 +18,7 @@ SET(PROJECT_HEADERS GeomAlgoAPI_Revolution.h GeomAlgoAPI_Boolean.h GeomAlgoAPI_Rotation.h + GeomAlgoAPI_Movement.h GeomAlgoAPI_MakeShape.h GeomAlgoAPI_MakeShapeList.h GeomAlgoAPI_ShapeProps.h @@ -43,6 +44,7 @@ SET(PROJECT_SOURCES GeomAlgoAPI_Revolution.cpp GeomAlgoAPI_Boolean.cpp GeomAlgoAPI_Rotation.cpp + GeomAlgoAPI_Movement.cpp GeomAlgoAPI_MakeShape.cpp GeomAlgoAPI_MakeShapeList.cpp GeomAlgoAPI_ShapeProps.cpp diff --git a/src/GeomAlgoAPI/GeomAlgoAPI.i b/src/GeomAlgoAPI/GeomAlgoAPI.i index 3778f6034..c86c9a7a5 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI.i +++ b/src/GeomAlgoAPI/GeomAlgoAPI.i @@ -10,6 +10,7 @@ #include "GeomAlgoAPI_FaceBuilder.h" #include "GeomAlgoAPI_MakeShape.h" #include "GeomAlgoAPI_MakeShapeList.h" + #include "GeomAlgoAPI_Movement.h" #include "GeomAlgoAPI_PointBuilder.h" #include "GeomAlgoAPI_Prism.h" #include "GeomAlgoAPI_Revolution.h" @@ -40,6 +41,7 @@ %include "GeomAlgoAPI_FaceBuilder.h" %include "GeomAlgoAPI_MakeShape.h" %include "GeomAlgoAPI_MakeShapeList.h" +%include "GeomAlgoAPI_Movement.h" %include "GeomAlgoAPI_PointBuilder.h" %include "GeomAlgoAPI_Prism.h" %include "GeomAlgoAPI_Revolution.h" diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Movement.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Movement.cpp new file mode 100644 index 000000000..cb043a4ef --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Movement.cpp @@ -0,0 +1,105 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAlgoAPI_Movement.cpp +// Created: 8 June 2015 +// Author: Dmitry Bobylev + +#include + +#include + +#include +#include +#include +#include +#include + +//================================================================================================= +GeomAlgoAPI_Movement::GeomAlgoAPI_Movement(std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + double theDistance) +: myDone(false), + myShape(new GeomAPI_Shape()), + myMap(new GeomAPI_DataMapOfShapeShape()), + myMkShape(new GeomAlgoAPI_MakeShape()) +{ + build(theSourceShape, theAxis, theDistance); +} + +//================================================================================================= +void GeomAlgoAPI_Movement::build(std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + double theDistance) +{ + if(!theSourceShape || !theAxis) { + return; + } + + const TopoDS_Shape& aSourceShape = theSourceShape->impl(); + const gp_Ax1& anAxis = theAxis->impl(); + + if(aSourceShape.IsNull()) { + return; + } + + gp_Trsf aTrsf; + aTrsf.SetTranslation(gp_Vec(anAxis.Direction()) * theDistance); + + // Transform the shape with copying it. + BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true); + if(!aBuilder) { + return; + } + + myDone = aBuilder->IsDone() == Standard_True; + + if(!myDone) { + return; + } + + TopoDS_Shape aResult = aBuilder->Shape(); + // Fill data map to keep correct orientation of sub-shapes. + for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) { + std::shared_ptr aCurrentShape(new GeomAPI_Shape()); + aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current())); + myMap->bind(aCurrentShape, aCurrentShape); + } + + myShape->setImpl(new TopoDS_Shape(aResult)); + myMkShape->setImpl(aBuilder); +} + +//================================================================================================= +const bool GeomAlgoAPI_Movement::isValid() const +{ + BRepCheck_Analyzer aChecker(myShape->impl()); + return (aChecker.IsValid() == Standard_True); +} + +//================================================================================================= +const bool GeomAlgoAPI_Movement::hasVolume() const +{ + bool hasVolume(false); + if(isValid() && (GeomAlgoAPI_ShapeProps::volume(myShape) > Precision::Confusion())) { + hasVolume = true; + } + return hasVolume; +} + +//================================================================================================= +const std::shared_ptr& GeomAlgoAPI_Movement::shape() const +{ + return myShape; +} + +//================================================================================================= +std::shared_ptr GeomAlgoAPI_Movement::mapOfShapes() const +{ + return myMap; +} + +//================================================================================================= +std::shared_ptr GeomAlgoAPI_Movement::makeShape() const +{ + return myMkShape; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Movement.h b/src/GeomAlgoAPI/GeomAlgoAPI_Movement.h new file mode 100644 index 000000000..2068ec844 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Movement.h @@ -0,0 +1,65 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAlgoAPI_Movement.h +// Created: 8 June 2015 +// Author: Dmitry Bobylev + +#ifndef GeomAlgoAPI_Movement_H_ +#define GeomAlgoAPI_Movement_H_ + +#include +#include +#include +#include +#include + +/** \class GeomAlgoAPI_Movement + * \ingroup DataAlgo + * \brief Creates a copy of the object by moving it along the axis. + */ +class GeomAlgoAPI_Movement : public GeomAPI_Interface +{ +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. + */ + GEOMALGOAPI_EXPORT GeomAlgoAPI_Movement(std::shared_ptr theSourceShape, + std::shared_ptr 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& shape() const; + + /// \return map of sub-shapes of the result. To be used for History keeping. + GEOMALGOAPI_EXPORT std::shared_ptr mapOfShapes() const; + + /// \return interface for for History processing. + GEOMALGOAPI_EXPORT std::shared_ptr makeShape() const; + +private: + /// Builds resulting shape. + void build(std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + double theDistance); + +private: + /// Fields. + bool myDone; + std::shared_ptr myShape; + std::shared_ptr myMap; + std::shared_ptr myMkShape; +}; + +#endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.h b/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.h index 079fe75aa..c3a81d54e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.h @@ -39,7 +39,7 @@ public: /// \return true if resulting shape has volume. GEOMALGOAPI_EXPORT const bool hasVolume() const; - /// \return result of the Placement algorithm which may be a Solid or a Face. + /// \return result of the rotation algorithm. GEOMALGOAPI_EXPORT const std::shared_ptr& shape() const; /// \return map of sub-shapes of the result. To be used for History keeping. diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 9ef7e3b44..c87d1f990 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -54,6 +54,7 @@ icons/deactivate.png icons/edit.png icons/rotation.png + icons/movement.png icons/extrusion_cut.png diff --git a/src/PartSet/icons/movement.png b/src/PartSet/icons/movement.png new file mode 100644 index 000000000..bec1385f2 Binary files /dev/null and b/src/PartSet/icons/movement.png differ