#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_ResultBody.h>
#include <ModelAPI_Session.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+
+#define _ROTATED_TAG 1
+
//=================================================================================================
FeaturesPlugin_Rotation::FeaturesPlugin_Rotation()
{
{
AttributeSelectionListPtr aSelection =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
- FeaturesPlugin_Rotation::LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
+ FeaturesPlugin_Rotation::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
// revolution works with faces always
aSelection->setSelectionType("SOLID");
data()->addAttribute(FeaturesPlugin_Rotation::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
-
data()->addAttribute(FeaturesPlugin_Rotation::ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
}
//=================================================================================================
void FeaturesPlugin_Rotation::execute()
{
+ // Getting objects.
+ ListOfShape anObjects;
+ AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Rotation::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_Rotation::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 angle.
+ double anAngle = real(FeaturesPlugin_Rotation::ANGLE_ID())->value();
+
+ // Rotating each object.
+ int aResultIndex = 0;
+ for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
+ std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
+ 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;
+ }
+
+ // Setting result.
+ ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
+ LoadNamingDS(aRotationAlgo, aResultBody, aBaseShape);
+ setResult(aResultBody, aResultIndex);
+ aResultIndex++;
+ }
+
+ // Remove the rest results if there were produced in the previous pass.
+ removeResults(aResultIndex);
+}
+
+void FeaturesPlugin_Rotation::LoadNamingDS(const GeomAlgoAPI_Rotation& theRotaionAlgo,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ std::shared_ptr<GeomAPI_Shape> theBaseShape)
+{
+ // Store result.
+ theResultBody->storeModified(theBaseShape, theRotaionAlgo.shape());
+
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theRotaionAlgo.mapOfShapes();
+
+ int aRotatedTag = 1;
+ std::string aRotatedName = "Rotated";
+ theResultBody->loadAndOrientModifiedShapes(theRotaionAlgo.makeShape().get(),
+ theBaseShape, GeomAPI_Shape::FACE,
+ aRotatedTag, aRotatedName, *aSubShapes.get());
+
}
#include <ModelAPI_Feature.h>
+#include <GeomAlgoAPI_Rotation.h>
+
/** \class FeaturesPlugin_Rotation
* \ingroup Plugins
- * \brief Feature for creation of revolution from the planar face.
- * Revolution creates the lateral faces based on edges of the base face and
- * the start and end faces and/or start and end angles.
+ * \brief Feature for rotation objects around the axis.
*/
class FeaturesPlugin_Rotation : public ModelAPI_Feature
{
public:
- /// Revolution kind.
+ /// Rotation kind.
inline static const std::string& ID()
{
- static const std::string MY_REVOLUTION_ID("Rotation");
- return MY_REVOLUTION_ID;
+ static const std::string MY_ROTATION_ID("Rotation");
+ return MY_ROTATION_ID;
}
- /// Attribute name of references sketch entities list, it should contain a sketch result or
- /// a pair a sketch result to sketch face.
- inline static const std::string& LIST_ID()
+ /// Attribute name of referenced objects.
+ inline static const std::string& OBJECTS_LIST_ID()
{
- static const std::string MY_GROUP_LIST_ID("base");
- return MY_GROUP_LIST_ID;
+ static const std::string MY_OBJECTS_LIST_ID("main_objects");
+ return MY_OBJECTS_LIST_ID;
}
- /// Attribute name of an object to which the extrusion grows.
+ /// Attribute name of an axis.
inline static const std::string& AXIS_OBJECT_ID()
{
- static const std::string MY_TO_OBJECT_ID("axis_object");
- return MY_TO_OBJECT_ID;
+ static const std::string MY_AXIS_OBJECT_ID("axis_object");
+ return MY_AXIS_OBJECT_ID;
}
- /// Attribute name of revolution angle.
+ /// Attribute name of angle.
inline static const std::string& ANGLE_ID()
{
- static const std::string MY_TO_ANGLE_ID("angle");
- return MY_TO_ANGLE_ID;
+ static const std::string MY_ANGLE_ID("angle");
+ return MY_ANGLE_ID;
}
/// \return the kind of a feature.
/// Use plugin manager for features creation.
FeaturesPlugin_Rotation();
+
+private:
+ void LoadNamingDS(const GeomAlgoAPI_Rotation& theRotaionAlgo,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ std::shared_ptr<GeomAPI_Shape> theBaseShape);
};
#endif
<source>
<multi_selector id="main_objects"
- label="Main object"
+ label="Main objects"
icon=":icons/cut_shape.png"
- tooltip="Select an object solid"
+ tooltip="Select a solid objects"
type_choice="Solids"
concealment="true">
<validator id="PartSet_DifferentObjects"/>
<validator id="PartSet_DifferentObjects"/>
<validator id="GeomValidators_ShapeType" parameters="solid"/>
</multi_selector>
- <!--<shape_selector id="main_object"
- label="Main object"
- icon=":icons/cut_shape.png"
- tooltip="Select an object solid"
- shape_types="solid"
- concealment="true"
- />
- <shape_selector id="tool_object"
- label="Tool object"
- icon=":icons/cut_tool.png"
- tooltip="Select a tool solid"
- shape_types="solid"
- concealment="true" >
- <validator id="PartSet_DifferentObjects"/>
- </shape_selector>-->
<choice id="bool_type"
label="Type"
tooltip="Type of boolean operation"
<feature id="Placement" title="Placement" tooltip="Perform moving of an object to specified position" icon=":icons/placement.png">
<source path="placement_widget.xml"/>
</feature>
- <!--Modification for specification of 1.3.0
- <feature id="Rotation" title="Movement" tooltip="" icon=":icons/placement.png">
+ <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>
+ <!--Modification for specification of 1.3.0
<feature id="ExtrusionCut" title="RevolutionCut" tooltip="" icon=":icons/placement.png">
<source path="extrusioncut_widget.xml"/>
</feature>-->
<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
<source>
- <multi_selector id="base"
- label="Select a sketch face"
+ <multi_selector id="main_objects"
+ label="Main objects"
icon=":icons/cut_shape.png"
- tooltip="Select a sketch face"
- type_choice="Solids">
+ tooltip="Select a solid objects"
+ type_choice="Solids"
+ concealment="true">
</multi_selector>
<shape_selector id="axis_object"
icon=":icons/axis.png"
tooltip="Select an edge for axis"
shape_types="edge"
default="">
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
<doublevalue
id="angle"
label="Angle"
- min="0"
+ min="-360"
+ max="360"
step="1.0"
default="0"
icon=":icons/radius.png"
std::shared_ptr<GeomAPI_Ax1> theAxis,
double theAngle)
: myDone(false),
- myShape(new GeomAPI_Shape())
+ myShape(new GeomAPI_Shape()),
+ myMap(new GeomAPI_DataMapOfShapeShape()),
+ myMkShape(new GeomAlgoAPI_MakeShape())
{
build(theSourceShape, theAxis, theAngle);
}
return;
}
- setImpl(aBuilder);
myDone = aBuilder->IsDone() == Standard_True;
if(!myDone) {
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);
+ myMap->bind(aCurrentShape, aCurrentShape);
}
myShape->setImpl(new TopoDS_Shape(aResult));
- myMkShape = new GeomAlgoAPI_MakeShape(aBuilder);
+ myMkShape->setImpl(aBuilder);
}
//=================================================================================================
}
//=================================================================================================
-void GeomAlgoAPI_Rotation::mapOfShapes(GeomAPI_DataMapOfShapeShape& theMap) const
+std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Rotation::mapOfShapes() const
{
- theMap = myMap;
+ return myMap;
}
//=================================================================================================
-GeomAlgoAPI_MakeShape* GeomAlgoAPI_Rotation::makeShape() const
+std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Rotation::makeShape() const
{
return myMkShape;
}
-
-//=================================================================================================
-GeomAlgoAPI_Rotation::~GeomAlgoAPI_Rotation()
-{
- if (myImpl) {
- myMap.clear();
- }
-}
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 void mapOfShapes(GeomAPI_DataMapOfShapeShape& theMap) const;
+ GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_DataMapOfShapeShape> mapOfShapes() const;
/// \return interface for for History processing.
- GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape* makeShape() const;
-
- /// Destructor.
- GEOMALGOAPI_EXPORT virtual ~GeomAlgoAPI_Rotation();
+ GEOMALGOAPI_EXPORT std::shared_ptr<GeomAlgoAPI_MakeShape> makeShape() const;
private:
/// Builds resulting shape.
/// Fields.
bool myDone;
std::shared_ptr<GeomAPI_Shape> myShape;
- GeomAPI_DataMapOfShapeShape myMap;
- GeomAlgoAPI_MakeShape* myMkShape;
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap;
+ std::shared_ptr<GeomAlgoAPI_MakeShape> myMkShape;
};
#endif
<file>icons/activate.png</file>
<file>icons/deactivate.png</file>
<file>icons/edit.png</file>
+ <file>icons/rotation.png</file>
</qresource>
</RCC>