FeaturesPlugin_Extrusion.h
FeaturesPlugin_Revolution.h
FeaturesPlugin_Rotation.h
- FeaturesPlugin_Movement.h
+ FeaturesPlugin_Translation.h
FeaturesPlugin_Boolean.h
FeaturesPlugin_Group.h
FeaturesPlugin_Partition.h
FeaturesPlugin_Extrusion.cpp
FeaturesPlugin_Revolution.cpp
FeaturesPlugin_Rotation.cpp
- FeaturesPlugin_Movement.cpp
+ FeaturesPlugin_Translation.cpp
FeaturesPlugin_Boolean.cpp
FeaturesPlugin_Group.cpp
FeaturesPlugin_Partition.cpp
TestRevolutionCut.py
TestRevolutionFuse.py
TestPartition.py
- TestMovement.py
+ TestTranslation.py
TestRotation.py
TestBoolean.py
TestMultiBoolean.py
+++ /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_BodyBuilder.h>
-#include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultPart.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;
- std::list<ResultPtr> aContextes;
- 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);
- aContextes.push_back(anObjectAttr->context());
- }
-
- //Getting axis.
- 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()));
- } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
- anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
- }
- 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;
- std::list<ResultPtr>::iterator aContext = aContextes.begin();
- for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
- anObjectsIt++, aContext++) {
- std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
- bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group();
- GeomAlgoAPI_Movement 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) {
- ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
- ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
- aResultPart->setTrsf(*aContext, aMovementAlgo.transformation());
- setResult(aResultPart);
- } else {
- 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("Translation");
- 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_ExtrusionCut.h>
#include <FeaturesPlugin_ExtrusionFuse.h>
#include <FeaturesPlugin_Group.h>
-#include <FeaturesPlugin_Movement.h>
+#include <FeaturesPlugin_Translation.h>
#include <FeaturesPlugin_Partition.h>
#include <FeaturesPlugin_Placement.h>
#include <FeaturesPlugin_Revolution.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_Translation::ID()) {
+ return FeaturePtr(new FeaturesPlugin_Translation);
} else if (theFeatureID == FeaturesPlugin_Boolean::ID()) {
return FeaturePtr(new FeaturesPlugin_Boolean);
} else if (theFeatureID == FeaturesPlugin_Group::ID()) {
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: FeaturesPlugin_Translation.cpp
+// Created: 8 June 2015
+// Author: Dmitry Bobylev
+
+#include <FeaturesPlugin_Translation.h>
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_BodyBuilder.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
+
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+
+//=================================================================================================
+FeaturesPlugin_Translation::FeaturesPlugin_Translation()
+{
+}
+
+//=================================================================================================
+void FeaturesPlugin_Translation::initAttributes()
+{
+ AttributeSelectionListPtr aSelection =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
+ FeaturesPlugin_Translation::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
+ // revolution works with faces always
+ aSelection->setSelectionType("SOLID");
+
+ data()->addAttribute(FeaturesPlugin_Translation::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(FeaturesPlugin_Translation::DISTANCE_ID(), ModelAPI_AttributeDouble::typeId());
+}
+
+//=================================================================================================
+void FeaturesPlugin_Translation::execute()
+{
+ // Getting objects.
+ ListOfShape anObjects;
+ std::list<ResultPtr> aContextes;
+ AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Translation::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);
+ aContextes.push_back(anObjectAttr->context());
+ }
+
+ //Getting axis.
+ std::shared_ptr<GeomAPI_Ax1> anAxis;
+ std::shared_ptr<GeomAPI_Edge> anEdge;
+ std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
+ if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
+ anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
+ } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
+ anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
+ anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+ }
+ if(anEdge) {
+ anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction()));
+ }
+
+ // Getting distance.
+ double aDistance = real(FeaturesPlugin_Translation::DISTANCE_ID())->value();
+
+ // Moving each object.
+ int aResultIndex = 0;
+ std::list<ResultPtr>::iterator aContext = aContextes.begin();
+ for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
+ 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) {
+ ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
+ ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
+ aResultPart->setTrsf(*aContext, aMovementAlgo.transformation());
+ setResult(aResultPart);
+ } else {
+ 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_Translation::LoadNamingDS(const GeomAlgoAPI_Translation& 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_Translation.h
+// Created: 8 June 2015
+// Author: Dmitry Bobylev
+
+#ifndef FeaturesPlugin_Translation_H_
+#define FeaturesPlugin_Translation_H_
+
+#include <FeaturesPlugin.h>
+
+#include <ModelAPI_Feature.h>
+
+#include <GeomAlgoAPI_Translation.h>
+
+/** \class FeaturesPlugin_Translation
+ * \ingroup Plugins
+ * \brief Feature for movement objects along the axis.
+ */
+class FeaturesPlugin_Translation : public ModelAPI_Feature
+{
+ public:
+ /// Movement kind.
+ inline static const std::string& ID()
+ {
+ static const std::string MY_MOVEMENT_ID("Translation");
+ 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_Translation::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_Translation();
+
+private:
+ void LoadNamingDS(const GeomAlgoAPI_Translation& theMovementAlgo,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ std::shared_ptr<GeomAPI_Shape> theBaseShape);
+};
+
+#endif
+++ /dev/null
-"""
- TestMovement.py
- Unit test of FeaturesPlugin_Movement class
-
- class FeaturesPlugin_Movement : public ModelAPI_Feature
- static const std::string MY_MOVEMENT_ID("Translation");
- static const std::string MY_OBJECTS_LIST_ID("main_objects");
- static const std::string MY_AXIS_OBJECT_ID("axis_object");
- static const std::string MY_DISTANCE_ID("distance");
-
- data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
- data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
- data()->addAttribute(DISTANCE_ID(), ModelAPI_AttributeDouble::typeId());
-"""
-#=========================================================================
-# Initialization of the test
-#=========================================================================
-from ModelAPI import *
-from GeomDataAPI import *
-from GeomAlgoAPI import *
-from GeomAPI import *
-import math
-
-aSession = ModelAPI_Session.get()
-aDocument = aSession.moduleDocument()
-# Create a part for movement
-aSession.startOperation()
-aPartFeature = aDocument.addFeature("Part")
-aSession.finishOperation()
-assert (len(aPartFeature.results()) == 1)
-# Another way is:
-# aPart = aSession.activeDocument()
-aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
-aPart = aPartResult.partDoc()
-
-#=========================================================================
-# Create a sketch circle to extrude
-#=========================================================================
-aSession.startOperation()
-aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
-origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
-origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
-dirx.setValue(1, 0, 0)
-norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
-norm.setValue(0, 0, 1)
-# Create circle
-aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
-anCircleCentr.setValue(50, 50)
-aCircleRadius.setValue(20)
-aSession.finishOperation()
-#=========================================================================
-# Make extrusion on circle
-#=========================================================================
-# Build shape from sketcher results
-aCircleSketchResult = aCircleSketchFeature.firstResult()
-aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape()
-origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt()
-dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir()
-norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir()
-aCircleSketchFaces = ShapeList()
-GeomAlgoAPI_SketchBuilder.createFaces(
- origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces)
-assert (len(aCircleSketchFaces) > 0)
-assert (aCircleSketchFaces[0] is not None)
-# Create extrusion
-aSession.startOperation()
-anExtrusionFt = aPart.addFeature("Extrusion")
-assert (anExtrusionFt.getKind() == "Extrusion")
-# selection type FACE=4
-anExtrusionFt.selectionList("base").append(
- aCircleSketchResult, aCircleSketchFaces[0])
-anExtrusionFt.string("CreationMethod").setValue("BySizes")
-anExtrusionFt.real("to_size").setValue(50)
-anExtrusionFt.real("from_size").setValue(0)
-anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
-anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
-anExtrusionFt.execute()
-aSession.finishOperation()
-assert (anExtrusionFt.real("to_size").value() == 50)
-
-# Check extrusion results
-assert (len(anExtrusionFt.results()) > 0)
-anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
-assert (anExtrusionResult is not None)
-
-#=========================================================================
-# Create a sketch line to movement
-#=========================================================================
-aSession.startOperation()
-aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
-origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
-origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
-dirx.setValue(1, 0, 0)
-norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
-norm.setValue(0, 0, 1)
-
-aSketchLine = aLineSketchFeature.addFeature("SketchLine")
-aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
-aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
-aLineStartPoint.setValue(-100, -100)
-aLineEndPoint.setValue(100, -100)
-aSession.finishOperation()
-
-# Build shape from sketcher results
-aLineSketchResult = aLineSketchFeature.firstResult()
-aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
-aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
-aLineEdge = aShapeExplorer.current()
-
-#=========================================================================
-# Test movement
-#=========================================================================
-aSession.startOperation()
-aMoveFt = aPart.addFeature("Translation")
-assert (aMoveFt.getKind() == "Translation")
-aMoveFt.selectionList("main_objects").append(
- anExtrusionResult, anExtrusionResult.shape())
-aMoveFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
-aMoveFt.real("distance").setValue(100)
-aMoveFt.execute()
-aSession.finishOperation()
-assert (aMoveFt.real("distance").value() == 100)
-
-# Check movement results
-aFactory = ModelAPI_Session.get().validators()
-assert (aFactory.validate(aMoveFt))
-assert (len(aMoveFt.results()) > 0)
-aMoveResult = modelAPI_ResultBody(aMoveFt.firstResult())
-assert (aMoveResult is not None)
-
--- /dev/null
+"""
+ TestMovement.py
+ Unit test of FeaturesPlugin_Movement class
+
+ class FeaturesPlugin_Movement : public ModelAPI_Feature
+ static const std::string MY_MOVEMENT_ID("Translation");
+ static const std::string MY_OBJECTS_LIST_ID("main_objects");
+ static const std::string MY_AXIS_OBJECT_ID("axis_object");
+ static const std::string MY_DISTANCE_ID("distance");
+
+ data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
+ data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(DISTANCE_ID(), ModelAPI_AttributeDouble::typeId());
+"""
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+from ModelAPI import *
+from GeomDataAPI import *
+from GeomAlgoAPI import *
+from GeomAPI import *
+import math
+
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
+# Create a part for movement
+aSession.startOperation()
+aPartFeature = aDocument.addFeature("Part")
+aSession.finishOperation()
+assert (len(aPartFeature.results()) == 1)
+# Another way is:
+# aPart = aSession.activeDocument()
+aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
+aPart = aPartResult.partDoc()
+
+#=========================================================================
+# Create a sketch circle to extrude
+#=========================================================================
+aSession.startOperation()
+aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
+origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+# Create circle
+aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
+aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr.setValue(50, 50)
+aCircleRadius.setValue(20)
+aSession.finishOperation()
+#=========================================================================
+# Make extrusion on circle
+#=========================================================================
+# Build shape from sketcher results
+aCircleSketchResult = aCircleSketchFeature.firstResult()
+aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape()
+origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt()
+dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir()
+norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir()
+aCircleSketchFaces = ShapeList()
+GeomAlgoAPI_SketchBuilder.createFaces(
+ origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces)
+assert (len(aCircleSketchFaces) > 0)
+assert (aCircleSketchFaces[0] is not None)
+# Create extrusion
+aSession.startOperation()
+anExtrusionFt = aPart.addFeature("Extrusion")
+assert (anExtrusionFt.getKind() == "Extrusion")
+# selection type FACE=4
+anExtrusionFt.selectionList("base").append(
+ aCircleSketchResult, aCircleSketchFaces[0])
+anExtrusionFt.string("CreationMethod").setValue("BySizes")
+anExtrusionFt.real("to_size").setValue(50)
+anExtrusionFt.real("from_size").setValue(0)
+anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
+anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
+anExtrusionFt.execute()
+aSession.finishOperation()
+assert (anExtrusionFt.real("to_size").value() == 50)
+
+# Check extrusion results
+assert (len(anExtrusionFt.results()) > 0)
+anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
+assert (anExtrusionResult is not None)
+
+#=========================================================================
+# Create a sketch line to movement
+#=========================================================================
+aSession.startOperation()
+aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
+origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+
+aSketchLine = aLineSketchFeature.addFeature("SketchLine")
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
+aLineStartPoint.setValue(-100, -100)
+aLineEndPoint.setValue(100, -100)
+aSession.finishOperation()
+
+# Build shape from sketcher results
+aLineSketchResult = aLineSketchFeature.firstResult()
+aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
+aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
+aLineEdge = aShapeExplorer.current()
+
+#=========================================================================
+# Test movement
+#=========================================================================
+aSession.startOperation()
+aMoveFt = aPart.addFeature("Translation")
+assert (aMoveFt.getKind() == "Translation")
+aMoveFt.selectionList("main_objects").append(
+ anExtrusionResult, anExtrusionResult.shape())
+aMoveFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
+aMoveFt.real("distance").setValue(100)
+aMoveFt.execute()
+aSession.finishOperation()
+assert (aMoveFt.real("distance").value() == 100)
+
+# Check movement results
+aFactory = ModelAPI_Session.get().validators()
+assert (aFactory.validate(aMoveFt))
+assert (len(aMoveFt.results()) > 0)
+aMoveResult = modelAPI_ResultBody(aMoveFt.firstResult())
+assert (aMoveResult is not None)
+
return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
}
-void GeomAPI_Ax3::setNorm(const std::shared_ptr<GeomAPI_Dir>& theNorm)
+void GeomAPI_Ax3::setNormal(const std::shared_ptr<GeomAPI_Dir>& theNorm)
{
gp_Ax1 aAx1 = MY_AX3->Axis();
aAx1.SetDirection(theNorm->impl<gp_Dir>());
MY_AX3->SetAxis(aAx1);
}
-std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::norm() const
+std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::normal() const
{
gp_Dir aDir = MY_AX3->Axis().Direction();
return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(),aDir.Y(),aDir.Z()));
/// Sets Z direction vector
GEOMAPI_EXPORT
- void setNorm(const std::shared_ptr<GeomAPI_Dir>& theNorm);
+ void setNormal(const std::shared_ptr<GeomAPI_Dir>& theNorm);
/// Returns Z direction vector
GEOMAPI_EXPORT
- std::shared_ptr<GeomAPI_Dir> norm() const;
+ std::shared_ptr<GeomAPI_Dir> normal() const;
/// Converts 2d coordinates from the plane to 3d space point
/// \param theX X coordinate
std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::norm() const
{
if (hasPlane())
- return myPlane->norm();
+ return myPlane->normal();
return std::shared_ptr<GeomAPI_Dir>();
}
GeomAlgoAPI_EdgeBuilder.h
GeomAlgoAPI_PointBuilder.h
GeomAlgoAPI_SketchBuilder.h
- GeomAlgoAPI_Extrusion.h
GeomAlgoAPI_Prism.h
GeomAlgoAPI_Revolution.h
GeomAlgoAPI_Boolean.h
GeomAlgoAPI_Rotation.h
- GeomAlgoAPI_Movement.h
+ GeomAlgoAPI_Translation.h
GeomAlgoAPI_MakeShape.h
GeomAlgoAPI_MakeShapeCustom.h
GeomAlgoAPI_MakeShapeList.h
GeomAlgoAPI_EdgeBuilder.cpp
GeomAlgoAPI_PointBuilder.cpp
GeomAlgoAPI_SketchBuilder.cpp
- GeomAlgoAPI_Extrusion.cpp
GeomAlgoAPI_Prism.cpp
GeomAlgoAPI_Revolution.cpp
GeomAlgoAPI_Boolean.cpp
GeomAlgoAPI_Rotation.cpp
- GeomAlgoAPI_Movement.cpp
+ GeomAlgoAPI_Translation.cpp
GeomAlgoAPI_MakeShape.cpp
GeomAlgoAPI_MakeShapeCustom.cpp
GeomAlgoAPI_MakeShapeList.cpp
#include "GeomAlgoAPI_CompoundBuilder.h"
#include "GeomAlgoAPI_DFLoader.h"
#include "GeomAlgoAPI_EdgeBuilder.h"
- #include "GeomAlgoAPI_Extrusion.h"
#include "GeomAlgoAPI_FaceBuilder.h"
#include "GeomAlgoAPI_MakeShape.h"
#include "GeomAlgoAPI_MakeShapeCustom.h"
#include "GeomAlgoAPI_MakeShapeList.h"
- #include "GeomAlgoAPI_Movement.h"
+ #include "GeomAlgoAPI_Translation.h"
#include "GeomAlgoAPI_Placement.h"
#include "GeomAlgoAPI_PointBuilder.h"
#include "GeomAlgoAPI_Prism.h"
%include "GeomAlgoAPI_CompoundBuilder.h"
%include "GeomAlgoAPI_DFLoader.h"
%include "GeomAlgoAPI_EdgeBuilder.h"
-%include "GeomAlgoAPI_Extrusion.h"
%include "GeomAlgoAPI_FaceBuilder.h"
%include "GeomAlgoAPI_MakeShape.h"
%include "GeomAlgoAPI_MakeShapeCustom.h"
%include "GeomAlgoAPI_MakeShapeList.h"
-%include "GeomAlgoAPI_Movement.h"
+%include "GeomAlgoAPI_Translation.h"
%include "GeomAlgoAPI_Placement.h"
%include "GeomAlgoAPI_PointBuilder.h"
%include "GeomAlgoAPI_Prism.h"
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: GeomAlgoAPI_Extrusion.cpp
-// Created: 06 Jun 2014
-// Author: Artem ZHIDKOV
-
-#include <GeomAlgoAPI_Extrusion.h>
-#include <GeomAlgoAPI_MakeShape.h>
-#include <GeomAlgoAPI_DFLoader.h>
-#include <GeomAlgoAPI_MakeShape.h>
-#include <gp_Pln.hxx>
-#include <BRepPrimAPI_MakePrism.hxx>
-#include <BRepBuilderAPI_MakeShape.hxx>
-#include <Geom_Plane.hxx>
-#include <Geom_Surface.hxx>
-#include <TopExp_Explorer.hxx>
-#include <BRepCheck_Analyzer.hxx>
-#include <GProp_GProps.hxx>
-#include <BRepGProp.hxx>
-#include <TopoDS.hxx>
-#include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <Precision.hxx>
-#include <TDF_TagSource.hxx>
-#include <memory>
-#include <BRepPrimAPI_MakePrism.hxx>
-#include <TopoDS_Shape.hxx>
-
-const double tolerance = Precision::Angular();
-// Constructor
-GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion(
- std::shared_ptr<GeomAPI_Shape> theBasis, double theSize)
-: mySize(theSize), myDone(false), myShape(new GeomAPI_Shape()),
- myFirst(new GeomAPI_Shape()), myLast(new GeomAPI_Shape())
-{
- build(theBasis);
-}
-
-//============================================================================
-void GeomAlgoAPI_Extrusion::build(const std::shared_ptr<GeomAPI_Shape>& theBasis)
-{
- bool isFirstNorm = true;
- gp_Dir aShapeNormal;
- TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
- Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(
- BRep_Tool::Surface(aBasis));
- if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet
- return;
-
- const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
- gp_Vec aVec(aNormal);
- aVec = aVec * mySize;
-
- BRepPrimAPI_MakePrism* aBuilder = new BRepPrimAPI_MakePrism(aBasis, aVec);
- if(aBuilder) {
- setImpl(aBuilder);
- myDone = aBuilder->IsDone() == Standard_True;
- if (myDone) {
- TopoDS_Shape aResult;
- if(aBuilder->Shape().ShapeType() == TopAbs_COMPOUND)
- aResult = GeomAlgoAPI_DFLoader::refineResult(aBuilder->Shape());
- else
- aResult = aBuilder->Shape();
- // fill data map to keep correct orientation of sub-shapes
- for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
- std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
- aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
- myMap.bind(aCurrentShape, aCurrentShape);
- }
- myShape->setImpl(new TopoDS_Shape(aResult));
- myFirst->setImpl(new TopoDS_Shape(aBuilder->FirstShape()));
- myLast->setImpl(new TopoDS_Shape(aBuilder-> LastShape()));
- myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
- }
- }
-}
-
-//============================================================================
-const bool GeomAlgoAPI_Extrusion::isDone() const
-{return myDone;}
-
-//============================================================================
-const bool GeomAlgoAPI_Extrusion::isValid() const
-{
- BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
- return (aChecker.IsValid() == Standard_True);
-}
-
-//============================================================================
-const bool GeomAlgoAPI_Extrusion::hasVolume() const
-{
- bool hasVolume(false);
- if(isValid()) {
- const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
- GProp_GProps aGProp;
- BRepGProp::VolumeProperties(aRShape, aGProp);
- if(aGProp.Mass() > Precision::Confusion())
- hasVolume = true;
- }
- return hasVolume;
-}
-
-//============================================================================
-const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::shape () const
-{
- return myShape;
-}
-
-//============================================================================
-const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::firstShape()
-{
- return myFirst;
-}
-
-//============================================================================
-const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::lastShape()
-{
- return myLast;
-}
-
-//============================================================================
-void GeomAlgoAPI_Extrusion::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
-{
- theMap = myMap;
-}
-
-//============================================================================
-GeomAlgoAPI_MakeShape * GeomAlgoAPI_Extrusion::makeShape() const
-{
- return myMkShape;
-}
-
-//============================================================================
-GeomAlgoAPI_Extrusion::~GeomAlgoAPI_Extrusion()
-{
- if (!empty()) {
- myMap.clear();
- }
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: GeomAlgoAPI_Extrusion.h
-// Created: 22 October 2014
-// Author: Sergey Zaritchny
-
-#ifndef GeomAlgoAPI_Extrusion_H_
-#define GeomAlgoAPI_Extrusion_H_
-
-#include <GeomAlgoAPI.h>
-#include <GeomAPI_Shape.h>
-#include <GeomAPI_Dir.h>
-#include <GeomAlgoAPI_MakeShape.h>
-#include <GeomAPI_DataMapOfShapeShape.h>
-#include <memory>
-
-/**\class GeomAlgoAPI_Extrusion
- * \ingroup DataAlgo
- * \brief Allows to create the prism based on a given face and a direction
- */
-
-class GeomAlgoAPI_Extrusion : public GeomAPI_Interface
-{
- public:
-
- /* \brief Creates extrusion for the given shape along the normal for this shape
- * \param[in] theBasis face or wire to be extruded
- * \param[in] theSize the length of extrusion (if the value is less than 0, the extrusion in opposite normal)
- * \return a solid or a face/shell which is obtained from specified one
- */
- /// Constructor
- GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion (std::shared_ptr<GeomAPI_Shape> theBasis, double theSize);
-
- /// Returns True if algorithm succeed
- GEOMALGOAPI_EXPORT const bool isDone() const;
-
- /// Returns True if resulting shape is valid
- GEOMALGOAPI_EXPORT const bool isValid() const;
-
- /// Returns True if resulting shape has volume
- GEOMALGOAPI_EXPORT const bool hasVolume() const;
-
- /// Returns result of the Extrusion algorithm which may be a Solid or a Face
- GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape>& shape () const;
-
- /// Returns the first shape
- GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape>& firstShape();
-
- /// returns last shape
- GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape>& lastShape();
-
- /// Returns map of sub-shapes of the result. To be used for History keeping
- GEOMALGOAPI_EXPORT void mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const;
-
- /// Return interface for for History processing
- GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape* makeShape () const;
-
- /// Destructor
- GEOMALGOAPI_EXPORT ~GeomAlgoAPI_Extrusion();
-private:
- /// builds resulting shape
- void build(const std::shared_ptr<GeomAPI_Shape>& theBasis);
- /// fields
- double mySize;
- bool myDone;
- std::shared_ptr<GeomAPI_Shape> myShape;
- std::shared_ptr<GeomAPI_Shape> myFirst;
- std::shared_ptr<GeomAPI_Shape> myLast;
- GeomAPI_DataMapOfShapeShape myMap;
- GeomAlgoAPI_MakeShape * myMkShape;
-};
-
-#endif
+++ /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_ShapeTools.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,
- bool theSimpleTransform)
-: myDone(false)
-{
- build(theSourceShape, theAxis, theDistance, theSimpleTransform);
-}
-
-//=================================================================================================
-void GeomAlgoAPI_Movement::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
- std::shared_ptr<GeomAPI_Ax1> theAxis,
- double theDistance,
- bool theSimpleTransform)
-{
- 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);
-
- 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);
- }
- }
-
- myShape.reset(new GeomAPI_Shape());
- myShape->setImpl(new TopoDS_Shape(aResult));
-}
-
-//=================================================================================================
-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_ShapeTools::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;
-}
-
-//=================================================================================================
-std::shared_ptr<GeomAPI_Trsf> GeomAlgoAPI_Movement::transformation() const
-{
- return myTrsf;
-}
+++ /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>
-#include <GeomAPI_Trsf.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.
- * \param[in] theSimpleTransform makes just transformation of shape without changing of topology or geometry
- */
- GEOMALGOAPI_EXPORT GeomAlgoAPI_Movement(std::shared_ptr<GeomAPI_Shape> theSourceShape,
- std::shared_ptr<GeomAPI_Ax1> theAxis,
- double theDistance,
- bool theSimpleTransform = false);
-
- /// \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,
- bool theSimpleTransform);
-
-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; ///< transformation of the shape in case theSimpleTransform
-};
-
-#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_Translation.cpp
+// Created: 8 June 2015
+// Author: Dmitry Bobylev
+
+#include <GeomAlgoAPI_Translation.h>
+
+#include <GeomAlgoAPI_ShapeTools.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,
+ bool theSimpleTransform)
+: myDone(false)
+{
+ build(theSourceShape, theAxis, theDistance, theSimpleTransform);
+}
+
+//=================================================================================================
+void GeomAlgoAPI_Translation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Ax1> theAxis,
+ double theDistance,
+ bool theSimpleTransform)
+{
+ 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);
+
+ 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);
+ }
+ }
+
+ 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;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_Translation.h
+// Created: 8 June 2015
+// Author: Dmitry Bobylev
+
+#ifndef GeomAlgoAPI_Translation_H_
+#define GeomAlgoAPI_Translation_H_
+
+#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
+{
+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.
+ * \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);
+
+ /// \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,
+ bool theSimpleTransform);
+
+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; ///< transformation of the shape in case theSimpleTransform
+};
+
+#endif
std::shared_ptr<GeomAPI_Dir> aDir = thePrs->plane()->dirX();
aVec1 = gp_Vec(aDir->impl<gp_Dir>());
}
- gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl<gp_Dir>());
+ gp_Vec aShift = aVec1.Crossed(thePrs->plane()->normal()->impl<gp_Dir>());
aShift.Normalize();
aShift.Multiply(theStep * 0.8);
aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
}
std::shared_ptr<GeomAPI_Pnt> aCenter = myPlane->to3D(aCenterAttr->x(), aCenterAttr->y());
- std::shared_ptr<GeomAPI_Dir> aNormal = myPlane->norm();
+ std::shared_ptr<GeomAPI_Dir> aNormal = myPlane->normal();
GeomAPI_Circ aCircle(aCenter, aNormal, aRadius);