FeaturesPlugin_ExtrusionCut.h
FeaturesPlugin_Revolution.h
FeaturesPlugin_Rotation.h
+ FeaturesPlugin_Movement.h
FeaturesPlugin_Boolean.h
FeaturesPlugin_Group.h
FeaturesPlugin_Placement.h
FeaturesPlugin_ExtrusionCut.cpp
FeaturesPlugin_Revolution.cpp
FeaturesPlugin_Rotation.cpp
+ FeaturesPlugin_Movement.cpp
FeaturesPlugin_Boolean.cpp
FeaturesPlugin_Group.cpp
FeaturesPlugin_Placement.cpp
extrusioncut_widget.xml
revolution_widget.xml
rotation_widget.xml
+ movement_widget.xml
boolean_widget.xml
group_widget.xml
placement_widget.xml
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: FeaturesPlugin_Movement.cpp
+// Created: 8 June 2015
+// Author: Dmitry Bobylev
+
+#include <FeaturesPlugin_Movement.h>
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_Session.h>
+
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+
+//=================================================================================================
+FeaturesPlugin_Movement::FeaturesPlugin_Movement()
+{
+}
+
+//=================================================================================================
+void FeaturesPlugin_Movement::initAttributes()
+{
+ AttributeSelectionListPtr aSelection =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(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<ModelAPI_AttributeSelection> anObjectAttr = anObjectsSelList->value(anObjectsIndex);
+ std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
+ if(!anObject.get()) {
+ return;
+ }
+ anObjects.push_back(anObject);
+ }
+
+ //Getting axe.
+ std::shared_ptr<GeomAPI_Ax1> anAxis;
+ std::shared_ptr<GeomAPI_Edge> anEdge;
+ std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_Movement::AXIS_OBJECT_ID());
+ if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
+ anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
+ }
+ if(anEdge) {
+ anAxis = std::shared_ptr<GeomAPI_Ax1>(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<GeomAPI_Shape> 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<ModelAPI_ResultBody> theResultBody,
+ std::shared_ptr<GeomAPI_Shape> theBaseShape)
+{
+ // Store result.
+ theResultBody->storeModified(theBaseShape, theMovementAlgo.shape());
+
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theMovementAlgo.mapOfShapes();
+
+ int aMovedTag = 1;
+ std::string aMovedName = "Moved";
+ theResultBody->loadAndOrientModifiedShapes(theMovementAlgo.makeShape().get(),
+ theBaseShape, GeomAPI_Shape::FACE,
+ aMovedTag, aMovedName, *aSubShapes.get());
+
+}
--- /dev/null
+// 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 <FeaturesPlugin.h>
+
+#include <ModelAPI_Feature.h>
+
+#include <GeomAlgoAPI_Movement.h>
+
+/** \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<ModelAPI_ResultBody> theResultBody,
+ std::shared_ptr<GeomAPI_Shape> theBaseShape);
+};
+
+#endif
#include <FeaturesPlugin_Extrusion.h>
#include <FeaturesPlugin_ExtrusionCut.h>
#include <FeaturesPlugin_Group.h>
+#include <FeaturesPlugin_Movement.h>
#include <FeaturesPlugin_Placement.h>
#include <FeaturesPlugin_Revolution.h>
#include <FeaturesPlugin_Rotation.h>
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()) {
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
-#define _ROTATED_TAG 1
-
//=================================================================================================
FeaturesPlugin_Rotation::FeaturesPlugin_Rotation()
{
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+ <multi_selector id="main_objects"
+ label="Main objects"
+ icon=":icons/cut_shape.png"
+ tooltip="Select a solid objects"
+ type_choice="Solids"
+ concealment="true">
+ </multi_selector>
+ <shape_selector id="axis_object"
+ icon=":icons/axis.png"
+ label="Axis"
+ tooltip="Select an edge for axis"
+ shape_types="edge"
+ default="">
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
+ </shape_selector>
+ <doublevalue
+ id="distance"
+ label="Distance"
+ step="1.0"
+ default="0"
+ icon=":icons/radius.png"
+ tooltip="Distance">
+ </doublevalue>
+</source>
\ No newline at end of file
<feature id="Rotation" title="Rotation" tooltip="Perform rotation of an objects around the axis to specified angle" icon=":icons/rotation.png">
<source path="rotation_widget.xml"/>
</feature>
+ <feature id="Movement" title="Movement" tooltip="Perform movement of an objects along the axis to specified distance" icon=":icons/movement.png">
+ <source path="movement_widget.xml"/>
+ </feature>
<feature id="ExtrusionCut" title="ExtrusionCut" tooltip="" icon=":icons/extrusion_cut.png">
<source path="extrusioncut_widget.xml"/>
</feature>
GeomAlgoAPI_Revolution.h
GeomAlgoAPI_Boolean.h
GeomAlgoAPI_Rotation.h
+ GeomAlgoAPI_Movement.h
GeomAlgoAPI_MakeShape.h
GeomAlgoAPI_MakeShapeList.h
GeomAlgoAPI_ShapeProps.h
GeomAlgoAPI_Revolution.cpp
GeomAlgoAPI_Boolean.cpp
GeomAlgoAPI_Rotation.cpp
+ GeomAlgoAPI_Movement.cpp
GeomAlgoAPI_MakeShape.cpp
GeomAlgoAPI_MakeShapeList.cpp
GeomAlgoAPI_ShapeProps.cpp
#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"
%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"
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_Movement.cpp
+// Created: 8 June 2015
+// Author: Dmitry Bobylev
+
+#include <GeomAlgoAPI_Movement.h>
+
+#include <GeomAlgoAPI_ShapeProps.h>
+
+#include <BRepBuilderAPI_Transform.hxx>
+#include <BRepCheck_Analyzer.hxx>
+#include <gp_Ax1.hxx>
+#include <Precision.hxx>
+#include <TopExp_Explorer.hxx>
+
+//=================================================================================================
+GeomAlgoAPI_Movement::GeomAlgoAPI_Movement(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Ax1> 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<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Ax1> theAxis,
+ double theDistance)
+{
+ if(!theSourceShape || !theAxis) {
+ return;
+ }
+
+ const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
+ const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
+
+ 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<GeomAPI_Shape> 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<TopoDS_Shape>());
+ 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<GeomAPI_Shape>& GeomAlgoAPI_Movement::shape() const
+{
+ return myShape;
+}
+
+//=================================================================================================
+std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Movement::mapOfShapes() const
+{
+ return myMap;
+}
+
+//=================================================================================================
+std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Movement::makeShape() const
+{
+ return myMkShape;
+}
--- /dev/null
+// 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 <GeomAlgoAPI.h>
+#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAPI_Ax1.h>
+#include <GeomAPI_DataMapOfShapeShape.h>
+#include <GeomAPI_Shape.h>
+
+/** \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<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;
+
+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;
+};
+
+#endif
/// \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<GeomAPI_Shape>& shape() const;
/// \return map of sub-shapes of the result. To be used for History keeping.
<file>icons/deactivate.png</file>
<file>icons/edit.png</file>
<file>icons/rotation.png</file>
+ <file>icons/movement.png</file>
<file>icons/extrusion_cut.png</file>
</qresource>
</RCC>