Added new method in GeomAlgoAPI_FaceBuilder for building plane from origin and axis
Added new GeomAlgoAPI_Prism class for building extrusion from base face between bounding planes
FeaturePlugin_Extrusion now uses GeomAlgoAPI_Prism instead of GeomAlgoAPI_Extrusion
Added new GeomAlgoAPI_ShapeProps class for computing different shape props. Currently it have only one method to compute shape volume.
Updated tests according to changes in extrusion.
SET(CAS_OCAF ${CAS_TKernel} ${CAS_TKMath} ${CAS_TKCDF} ${CAS_TKLCAF})
SET(CAS_VIEWER ${CAS_TKService} ${CAS_TKV3d} ${CAS_TKG3d} ${CAS_TKGeomBase} ${CAS_TKBRep})
SET(CAS_OCAFVIS ${CAS_TKCAF} ${CAS_TKBRep} ${CAS_TKG2d})
-SET(CAS_MODELER ${CAS_TKG3d} ${CAS_TKGeomBase} ${CAS_TKGeomAlgo} ${CAS_TKBRep} ${CAS_TKTopAlgo} ${CAS_TKG2d})
+SET(CAS_MODELER ${CAS_TKG3d} ${CAS_TKGeomBase} ${CAS_TKGeomAlgo} ${CAS_TKBRep} ${CAS_TKTopAlgo} ${CAS_TKG2d} ${CAS_TKFeat})
# TODO(mpv, vsv) Give a proper name for the following variable
SET(CAS_SHAPE ${CAS_TKShHealing} ${CAS_TKMesh} ${CAS_TKHLR})
#include "FeaturesPlugin_Extrusion.h"
#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_AttributeReference.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_XYZ.h>
#include <GeomAlgoAPI_Extrusion.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomAlgoAPI_Prism.h>
using namespace std;
#define _LATERAL_TAG 1
// extrusion works with faces always
aSelection->setSelectionType("FACE");
- data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::typeId());
data()->addAttribute(FeaturesPlugin_Extrusion::TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
- //data()->addAttribute(FeaturesPlugin_Extrusion::FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(FeaturesPlugin_Extrusion::FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
//data()->addAttribute(FeaturesPlugin_Extrusion::AXIS_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
- //data()->addAttribute(FeaturesPlugin_Extrusion::FROM_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
- //data()->addAttribute(FeaturesPlugin_Extrusion::TO_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
+ data()->addAttribute(FeaturesPlugin_Extrusion::FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(FeaturesPlugin_Extrusion::TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FeaturesPlugin_Extrusion::TO_OBJECT_ID());
}
void FeaturesPlugin_Extrusion::execute()
{
AttributeSelectionListPtr aFaceRefs = selectionList(FeaturesPlugin_Extrusion::LIST_ID());
+ std::shared_ptr<GeomAPI_Shape> aFromShape(new GeomAPI_Shape);
+ std::shared_ptr<GeomAPI_Shape> aToShape(new GeomAPI_Shape);
+
+ // Getting bounding planes.
+ std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
+ if (anObjRef) {
+ aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+ }
+ anObjRef = selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
+ if (anObjRef) {
+ aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+ }
+
+ // Getting sizes.
+ double aFromSize = real(FeaturesPlugin_Extrusion::FROM_SIZE_ID())->value();
+ double aToSize = real(FeaturesPlugin_Extrusion::TO_SIZE_ID())->value();
+
// for each selected face generate a result
int anIndex = 0, aResultIndex = 0;
for(; anIndex < aFaceRefs->size(); anIndex++) {
setError(aContextError);
break;
}
- double aSize = real(FeaturesPlugin_Extrusion::TO_SIZE_ID())->value();
- if (boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
- aSize = -aSize;
std::shared_ptr<GeomAPI_Shape> aValueFace = aFaceRef->value();
int aFacesNum = -1; // this mean that "aFace" is used
for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) {
ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
- std::shared_ptr<GeomAPI_Shape> aFace;
+ std::shared_ptr<GeomAPI_Shape> aBaseShape;
if (aFacesNum == -1) {
- aFace = aValueFace;
+ aBaseShape = aValueFace;
} else {
- aFace = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
+ aBaseShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
}
- GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
+
+ // If bounding faces was not set creating them.
+ std::shared_ptr<GeomAPI_Face> aBaseFace(new GeomAPI_Face(aBaseShape));
+ std::shared_ptr<GeomAPI_Pln> aBasePlane = aBaseFace->getPlane();
+ std::shared_ptr<GeomAPI_Dir> aBaseDir = aBasePlane->direction();
+ std::shared_ptr<GeomAPI_Pnt> aBaseLoc = aBasePlane->location();
+
+ if(!aFromShape) {
+ aFromShape = GeomAlgoAPI_FaceBuilder::plane(aBaseLoc, aBaseDir);
+ }
+ if(!aToShape) {
+ aToShape = GeomAlgoAPI_FaceBuilder::plane(aBaseLoc, aBaseDir);
+ }
+
+ // Moving bounding faces according to "from" and "to" sizes.
+ std::shared_ptr<GeomAPI_Face> aFromFace(new GeomAPI_Face(aFromShape));
+ std::shared_ptr<GeomAPI_Pln> aFromPlane = aFromFace->getPlane();
+ std::shared_ptr<GeomAPI_Pnt> aFromLoc = aFromPlane->location();
+ std::shared_ptr<GeomAPI_Dir> aFromDir = aFromPlane->direction();
+
+ std::shared_ptr<GeomAPI_Face> aToFace(new GeomAPI_Face(aToShape));
+ std::shared_ptr<GeomAPI_Pln> aToPlane = aToFace->getPlane();
+ std::shared_ptr<GeomAPI_Pnt> aToLoc = aToPlane->location();
+ std::shared_ptr<GeomAPI_Dir> aToDir = aToPlane->direction();
+
+ bool aSign = aFromLoc->xyz()->dot(aBaseDir->xyz()) > aToLoc->xyz()->dot(aBaseDir->xyz());
+
+ std::shared_ptr<GeomAPI_Pnt> aFromPnt(new GeomAPI_Pnt(aFromLoc->xyz()->added(aBaseDir->xyz()->multiplied(aSign ? aFromSize : -aFromSize))));
+ aFromShape = GeomAlgoAPI_FaceBuilder::plane(aFromPnt, aFromDir);
+
+ std::shared_ptr<GeomAPI_Pnt> aToPnt(new GeomAPI_Pnt(aToLoc->xyz()->added(aBaseDir->xyz()->multiplied(aSign ? -aToSize : aToSize))));
+ aToShape = GeomAlgoAPI_FaceBuilder::plane(aToPnt, aToDir);
+
+ //GeomAlgoAPI_Extrusion aFeature(aFace, aFromSize);
+ GeomAlgoAPI_Prism aFeature(aBaseShape, aFromShape, aToShape);
if(!aFeature.isDone()) {
- static const std::string aFeatureError = "Extrusion algorithm failed";
+ static const std::string aFeatureError = "Extrusion algorithm failed";
setError(aFeatureError);
break;
}
// Check if shape is valid
- if (aFeature.shape()->isNull()) {
- static const std::string aShapeError = "Resulting shape is Null";
+ if(aFeature.shape()->isNull()) {
+ static const std::string aShapeError = "Resulting shape is Null";
setError(aShapeError);
break;
}
if(!aFeature.isValid()) {
- std::string aFeatureError = "Warning: resulting shape is not valid";
+ std::string aFeatureError = "Warning: resulting shape is not valid";
setError(aFeatureError);
break;
- }
+ }
//LoadNamingDS
- LoadNamingDS(aFeature, aResultBody, aFace, aContext);
+ LoadNamingDS(aFeature, aResultBody, aBaseShape, aContext);
setResult(aResultBody, aResultIndex);
aResultIndex++;
}
//============================================================================
-void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature,
- std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- std::shared_ptr<GeomAPI_Shape> theBasis,
- std::shared_ptr<GeomAPI_Shape> theContext)
-{
-
-
+void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Prism& theFeature,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ std::shared_ptr<GeomAPI_Shape> theBasis,
+ std::shared_ptr<GeomAPI_Shape> theContext)
+{
//load result
if(theBasis->isEqual(theContext))
theResultBody->store(theFeature.shape());
else
- theResultBody->storeGenerated(theContext, theFeature.shape());
+ theResultBody->storeGenerated(theContext, theFeature.shape());
GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
theFeature.mapOfShapes(*aSubShapes);
//Insert bottom face
std::string aBotName = "BottomFace";
- std::shared_ptr<GeomAPI_Shape> aBottomFace = theFeature.firstShape();
- if (!aBottomFace->isNull()) {
- if (aSubShapes->isBound(aBottomFace)) {
- aBottomFace = aSubShapes->find(aBottomFace);
- }
+ std::shared_ptr<GeomAPI_Shape> aBottomFace = theFeature.firstShape();
+ if(!aBottomFace->isNull()) {
+ if(aSubShapes->isBound(aBottomFace)) {
+ aBottomFace = aSubShapes->find(aBottomFace);
+ }
theResultBody->generated(aBottomFace, aBotName, _FIRST_TAG);
}
-
-
//Insert top face
std::string aTopName = "TopFace";
std::shared_ptr<GeomAPI_Shape> aTopFace = theFeature.lastShape();
if (!aTopFace->isNull()) {
- if (aSubShapes->isBound(aTopFace)) {
- aTopFace = aSubShapes->find(aTopFace);
+ if (aSubShapes->isBound(aTopFace)) {
+ aTopFace = aSubShapes->find(aTopFace);
}
theResultBody->generated(aTopFace, aTopName, _LAST_TAG);
}
-
}
//============================================================================
#include <ModelAPI_Feature.h>
#include <ModelAPI_ResultBody.h>
#include <GeomAlgoAPI_Extrusion.h>
+#include <GeomAlgoAPI_Prism.h>
#include <GeomAPI_Shape.h>
/**\class FeaturesPlugin_Extrusion
* \brief Feature for creation of extrusion from the planar face.
*
* Extrusion creates the lateral faces based on edges of the base face and
- * the top face equal to the base face. Direction of extrusion is taken from the face
- * plane, but can be corrected by the "reverse" flag.
+ * the top and bottom faces equal to the base face or this faces can be projection on the
+ * bounding planes if they were set. Direction of extrusion is taken from the face
+ * plane or if the bounding faces were set then it will be from the bottom to the top plane.
*/
class FeaturesPlugin_Extrusion : public ModelAPI_Feature
{
static const std::string MY_FROM_OBJECT_ID("from_object");
return MY_FROM_OBJECT_ID;
}
- /// attribute name of reverse direction
- inline static const std::string& REVERSE_ID()
- {
- static const std::string MY_REVERSE_ID("reverse");
- return MY_REVERSE_ID;
- }
/// Returns the kind of a feature
FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
FeaturesPlugin_Extrusion();
private:
/// Load Naming data structure of the feature to the document
- void LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- std::shared_ptr<GeomAPI_Shape> theBasis,
- std::shared_ptr<GeomAPI_Shape> theContext);
+ void LoadNamingDS(GeomAlgoAPI_Prism& theFeature, std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ std::shared_ptr<GeomAPI_Shape> theBasis,
+ std::shared_ptr<GeomAPI_Shape> theContext);
/// Set an empty shape to the result of extrusion
void clearResult();
anExtrusionFt = aPart.addFeature("Extrusion")
anExtrusionFt.selectionList("base").append(
aSketchResult, aSketchFaces[0])
- anExtrusionFt.real("size").setValue(50)
- anExtrusionFt.boolean("reverse").setValue(False)
+ anExtrusionFt.real("from_size").setValue(0)
+ anExtrusionFt.real("to_size").setValue(50)
anExtrusionFt.execute()
extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
aSession.finishOperation()
class FeaturesPlugin_Extrusion : public ModelAPI_Feature
static const std::string MY_EXTRUSION_ID("Extrusion");
- static const std::string MY_FACE_ID("base");
- static const std::string MY_SIZE_ID("size");
- static const std::string MY_REVERSE_ID("reverse");
-
- data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::typeId());
- data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::typeId());
+ static const std::string LIST_ID("base");
+ static const std::string MY_TO_SIZE_ID("to_size");
+ static const std::string MY_FROM_SIZE_ID("from_size");
+ static const std::string MY_TO_OBJECT_ID("to_object");
+ static const std::string MY_FROM_OBJECT_ID("from_object");
+
+ data()->addAttribute(FeaturesPlugin_Extrusion::LIST_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(FeaturesPlugin_Extrusion::FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(FeaturesPlugin_Extrusion::TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(FeaturesPlugin_Extrusion::FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(FeaturesPlugin_Extrusion::TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
"""
#=========================================================================
# Initialization of the test
from GeomDataAPI import *
from GeomAlgoAPI import *
from GeomAPI import *
+import math
__updated__ = "2014-12-16"
# Create a sketch circle to extrude
#=========================================================================
aSession.startOperation()
-aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
-origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
+aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
+origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
+dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
dirx.setValue(1, 0, 0)
-norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
+norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
# Create circle
-aSketchCircle = aSketchFeature.addFeature("SketchCircle")
+aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
aCircleRadius = aSketchCircle.real("CircleRadius")
anCircleCentr.setValue(50., 50)
# Make extrusion on circle
#=========================================================================
# Build shape from sketcher results
-aSketchResult = aSketchFeature.firstResult()
-aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
-origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")).pnt()
-dirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX")).dir()
-norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")).dir()
-aSketchFaces = ShapeList()
+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, aSketchEdges, aSketchFaces)
-assert (len(aSketchFaces) > 0)
-assert (aSketchFaces[0] is not None)
+ 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(
- aSketchResult, aSketchFaces[0])
-anExtrusionFt.real("size").setValue(50)
-anExtrusionFt.boolean("reverse").setValue(False)
+ aCircleSketchResult, aCircleSketchFaces[0])
+anExtrusionFt.real("from_size").setValue(0)
+anExtrusionFt.real("to_size").setValue(50)
anExtrusionFt.execute()
aSession.finishOperation()
-assert (anExtrusionFt.real("size").value() == 50.0)
-assert (anExtrusionFt.boolean("reverse").value() == False)
+assert (anExtrusionFt.real("to_size").value() == 50.0)
# Check extrusion results
assert (len(anExtrusionFt.results()) > 0)
anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
assert (anExtrusionResult is not None)
+
+#=========================================================================
+# Test extrusion between bounding planes
+#=========================================================================
+# Create from plane
+aSession.startOperation()
+aFromPlaneFeature = aPart.addFeature("Plane")
+aFromPlaneFeature.string("CreationMethod").setValue("PlaneByGeneralEquation")
+aFromPlaneFeature.real("A").setValue(0.)
+aFromPlaneFeature.real("B").setValue(0.)
+aFromPlaneFeature.real("C").setValue(1.)
+aFromPlaneFeature.real("D").setValue(30.)
+aSession.finishOperation()
+
+# Create to plane
+aSession.startOperation()
+aToPlaneFeature = aPart.addFeature("Plane")
+aToPlaneFeature.string("CreationMethod").setValue("PlaneByGeneralEquation")
+aToPlaneFeature.real("A").setValue(0.)
+aToPlaneFeature.real("B").setValue(0.)
+aToPlaneFeature.real("C").setValue(1.)
+aToPlaneFeature.real("D").setValue(-30.)
+aSession.finishOperation()
+
+# Create extrusion
+aSession.startOperation()
+anExtrusionFt = aPart.addFeature("Extrusion")
+assert (anExtrusionFt.getKind() == "Extrusion")
+# selection type FACE=4
+anExtrusionFt.selectionList("base").append(
+ aCircleSketchResult, aCircleSketchFaces[0])
+aFromResult = aFromPlaneFeature.firstResult()
+aFromShape = modelAPI_ResultConstruction(aFromResult).shape()
+anExtrusionFt.selection("from_object").setValue(aFromResult, aFromShape)
+anExtrusionFt.real("from_size").setValue(10)
+aToResult = aToPlaneFeature.firstResult()
+aToShape = modelAPI_ResultConstruction(aToResult).shape()
+anExtrusionFt.selection("to_object").setValue(aToResult, aToShape)
+anExtrusionFt.real("to_size").setValue(10)
+anExtrusionFt.execute()
+aSession.finishOperation()
+
+# Check extrusion results
+assert (len(anExtrusionFt.results()) > 0)
+anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
+assert (anExtrusionResult is not None)
+
+# Check extrusion volume
+aRefVolume = 100530.96491487337
+aResVolume = GeomAlgoAPI_ShapeProps_volume(anExtrusionResult.shape())
+assert (math.fabs(aResVolume - aRefVolume) < 10 ** -5)
+
+#=========================================================================
+# Test extrusion between bounding faces from other sketch result
+#=========================================================================
+aSession.startOperation()
+aClampSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
+origin = geomDataAPI_Point(aClampSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aClampSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+norm = geomDataAPI_Dir(aClampSketchFeature.attribute("Norm"))
+norm.setValue(0, 1, 0)
+# Create clamp
+aSketchLineA = aClampSketchFeature.addFeature("SketchLine")
+aSketchLineB = aClampSketchFeature.addFeature("SketchLine")
+aSketchLineC = aClampSketchFeature.addFeature("SketchLine")
+aSketchLineD = aClampSketchFeature.addFeature("SketchLine")
+aSketchLineE = aClampSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
+aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
+aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
+aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
+aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
+aLineDStartPoint = geomDataAPI_Point2D(aSketchLineD.attribute("StartPoint"))
+aLineDEndPoint = geomDataAPI_Point2D(aSketchLineD.attribute("EndPoint"))
+aLineEStartPoint = geomDataAPI_Point2D(aSketchLineE.attribute("StartPoint"))
+aLineEEndPoint = geomDataAPI_Point2D(aSketchLineE.attribute("EndPoint"))
+aLineAStartPoint.setValue(0., -50.)
+aLineAEndPoint.setValue(0., 50.)
+aLineBStartPoint.setValue(0., 50.)
+aLineBEndPoint.setValue(100., 50.)
+aLineCStartPoint.setValue(100., 50.)
+aLineCEndPoint.setValue(10., 0.)
+aLineDStartPoint.setValue(10., 0.)
+aLineDEndPoint.setValue(100., -50.)
+aLineEStartPoint.setValue(100., -50.)
+aLineEEndPoint.setValue(0., -50.)
+aSession.finishOperation()
+
+# Extrude clamp
+aClampSketchResult = aClampSketchFeature.firstResult()
+aClampSketchEdges = modelAPI_ResultConstruction(aClampSketchResult).shape()
+origin = geomDataAPI_Point(aClampSketchFeature.attribute("Origin")).pnt()
+dirX = geomDataAPI_Dir(aClampSketchFeature.attribute("DirX")).dir()
+norm = geomDataAPI_Dir(aClampSketchFeature.attribute("Norm")).dir()
+aClampSketchFaces = ShapeList()
+GeomAlgoAPI_SketchBuilder.createFaces(
+ origin, dirX, norm, aClampSketchEdges, aClampSketchFaces)
+aSession.startOperation()
+aClampExtrusionFt = aPart.addFeature("Extrusion")
+assert (aClampExtrusionFt.getKind() == "Extrusion")
+# selection type FACE=4
+aClampExtrusionFt.selectionList("base").append(
+ aClampSketchResult, aClampSketchFaces[0])
+aClampExtrusionFt.real("from_size").setValue(0)
+aClampExtrusionFt.real("to_size").setValue(70)
+aClampExtrusionFt.execute()
+aSession.finishOperation()
+
+# Check extrusion results
+assert (len(aClampExtrusionFt.results()) > 0)
+anExtrusionResult = modelAPI_ResultBody(aClampExtrusionFt.firstResult())
+assert (anExtrusionResult is not None)
+
+# Extrude circle
+aSession.startOperation()
+anExtrusionFt = aPart.addFeature("Extrusion")
+assert (anExtrusionFt.getKind() == "Extrusion")
+# selection type FACE=4
+anExtrusionFt.selectionList("base").append(
+ aCircleSketchResult, aCircleSketchFaces[0])
+aClampResult = aClampExtrusionFt.firstResult()
+anExtrusionFt.selection("from_object").selectSubShape("face", "Extrusion_3/LateralFace_1")
+anExtrusionFt.real("from_size").setValue(0)
+anExtrusionFt.selection("to_object").selectSubShape("face", "Extrusion_3/LateralFace_2")
+anExtrusionFt.real("to_size").setValue(0)
+anExtrusionFt.execute()
+aSession.finishOperation()
+
+# Check extrusion results
+assert (len(anExtrusionFt.results()) > 0)
+anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
+assert (anExtrusionResult is not None)
+
#=========================================================================
# End of test
#=========================================================================
anExtrusionFt = aPart.addFeature("Extrusion")
anExtrusionFt.selectionList("base").append(
aSketchResult, aSketchFaces[0])
-anExtrusionFt.real("size").setValue(50)
-anExtrusionFt.boolean("reverse").setValue(False)
+anExtrusionFt.real("from_size").setValue(50)
+anExtrusionFt.real("to_size").setValue(50)
anExtrusionFt.execute()
aSession.finishOperation()
anExtrusionBody = modelAPI_ResultBody(anExtrusionFt.firstResult())
anExtrusionFt.selectionList("base").append(
aSketchResult, aSketchFaces[0])
- anExtrusionFt.real("size").setValue(10)
- anExtrusionFt.boolean("reverse").setValue(False)
+ anExtrusionFt.real("from_size").setValue(0)
+ anExtrusionFt.real("to_size").setValue(10)
# v1.0.2 from master
# anExtrusionFt.selection("extrusion_face").setValue(
# aSketchResult, aSketchFaces[0])
aBox = aPart.addFeature("Extrusion")
aBox.selectionList("base").append(
aSketchResult, aSketchFaces[0])
-aBox.real("size").setValue(10)
-aBox.boolean("reverse").setValue(False)
+aBox.real("from_size").setValue(0)
+aBox.real("to_size").setValue(10)
# v 1.0.2 from master
# aBox.selection("extrusion_face").setValue(
# aSketchResult, aSketchFaces[0])
type_choice="Faces">
<validator id="PartSet_SketchEntityValidator" parameters="Sketch"/>
</multi_selector>
- <!--<groupbox title="From">
+ <groupbox title="From">
<shape_selector id="from_object"
icon=":icons/plane.png"
label="Plane face"
tooltip="Select a planar face"
- shape_types="face" obligatory="false">
+ shape_types="face">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
<doublevalue
step="1.0"
default="0"
icon=":icons/dimension_down.png"
- tooltip="Height"
- obligatory="false">
+ tooltip="Height">
<validator id="GeomValidators_Positive"/>
</doublevalue>
- </groupbox>-->
+ </groupbox>
<groupbox title="To">
- <!-- <shape_selector id="to_object"
+ <shape_selector id="to_object"
icon=":icons/plane_inverted.png"
label="Plane face"
tooltip="Select a planar face"
- shape_types="face"
- obligatory="false">
+ shape_types="face">
<validator id="GeomValidators_Face" parameters="plane"/>
- </shape_selector>-->
+ </shape_selector>
<doublevalue
id="to_size"
label="Size"
tooltip="Height">
<validator id="GeomValidators_Positive"/>
</doublevalue>
- <boolvalue id="reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
- </groupbox>-->
+ </groupbox>
<!--XML definition of the revolution:-->
<!-- <multi_selector id="base"
label="Select a sketch face"
GeomAlgoAPI_PointBuilder.h
GeomAlgoAPI_SketchBuilder.h
GeomAlgoAPI_Extrusion.h
+ GeomAlgoAPI_Prism.h
GeomAlgoAPI_Boolean.h
GeomAlgoAPI_MakeShape.h
+ GeomAlgoAPI_ShapeProps.h
GeomAlgoAPI_DFLoader.h
GeomAlgoAPI_Placement.h
GeomAlgoAPI_BREPImport.h
GeomAlgoAPI_PointBuilder.cpp
GeomAlgoAPI_SketchBuilder.cpp
GeomAlgoAPI_Extrusion.cpp
+ GeomAlgoAPI_Prism.cpp
GeomAlgoAPI_Boolean.cpp
GeomAlgoAPI_MakeShape.cpp
+ GeomAlgoAPI_ShapeProps.cpp
GeomAlgoAPI_DFLoader.cpp
GeomAlgoAPI_Placement.cpp
GeomAlgoAPI_BREPImport.cpp
#include "GeomAlgoAPI_FaceBuilder.h"
#include "GeomAlgoAPI_MakeShape.h"
#include "GeomAlgoAPI_PointBuilder.h"
+ #include "GeomAlgoAPI_Prism.h"
+ #include "GeomAlgoAPI_ShapeProps.h"
#include "GeomAlgoAPI_SketchBuilder.h"
#include <memory>
%include "GeomAlgoAPI_FaceBuilder.h"
%include "GeomAlgoAPI_MakeShape.h"
%include "GeomAlgoAPI_PointBuilder.h"
+%include "GeomAlgoAPI_Prism.h"
+%include "GeomAlgoAPI_ShapeProps.h"
%include "GeomAlgoAPI_SketchBuilder.h"
%template(ShapeList) std::list<std::shared_ptr<GeomAPI_Shape> >;
\ No newline at end of file
return aRes;
}
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::plane(std::shared_ptr<GeomAPI_Pnt> theCenter,
+ std::shared_ptr<GeomAPI_Dir> theNormal)
+{
+ const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
+ const gp_Dir& aDir = theNormal->impl<gp_Dir>();
+ gp_Pln aPlane(aCenter, aDir);
+ BRepBuilderAPI_MakeFace aFaceBuilder(aPlane);
+ std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+ aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
+ return aRes;
+}
+
std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
std::shared_ptr<GeomAPI_Shape> theFace)
{
static std::shared_ptr<GeomAPI_Shape> square(std::shared_ptr<GeomAPI_Pln> thePlane,
const double theSize);
+ /// Creates the plane by given point of the center and normal to the plane.
+ static std::shared_ptr<GeomAPI_Shape> plane(std::shared_ptr<GeomAPI_Pnt> theCenter,
+ std::shared_ptr<GeomAPI_Dir> theNormal);
+
/// Returns the plane of the planar face. If it is not planar, returns empty ptr.
static std::shared_ptr<GeomAPI_Pln> plane(std::shared_ptr<GeomAPI_Shape> theFace);
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_Prism.h
+// Created: 5 May 2015
+// Author: Dmitry Bobylev
+
+#include <GeomAlgoAPI_Prism.h>
+
+#include <GeomAlgoAPI_DFLoader.h>
+
+#include <BRep_Tool.hxx>
+#include <BRepCheck_Analyzer.hxx>
+#include <BRepFeat_MakePrism.hxx>
+#include <BRepGProp.hxx>
+#include <Geom_CylindricalSurface.hxx>
+#include <Geom_Plane.hxx>
+#include <Geom_RectangularTrimmedSurface.hxx>
+#include <gp_Cylinder.hxx>
+#include <gp_Pln.hxx>
+#include <GProp_GProps.hxx>
+#include <LocOpe_FindEdgesInFace.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS.hxx>
+
+GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr<GeomAPI_Shape> theBasis,
+ std::shared_ptr<GeomAPI_Shape> theFromShape,
+ std::shared_ptr<GeomAPI_Shape> theToShape)
+: myFromShape(theFromShape),
+ myToShape(theToShape),
+ myShape(new GeomAPI_Shape()),
+ myFirst(new GeomAPI_Shape()),myLast(new GeomAPI_Shape())
+{
+ build(theBasis);
+}
+
+//============================================================================
+void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis)
+{
+ 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();
+ BRepFeat_MakePrism* aBuilder = new BRepFeat_MakePrism(aBasis, aBasis, aBasis, aNormal, 2, Standard_True);
+
+ if(aBuilder) {
+ setImpl(aBuilder);
+ TopoDS_Shape aFromShape = myFromShape->impl<TopoDS_Shape>();
+ TopoDS_Shape aToShape = myToShape->impl<TopoDS_Shape>();
+ aBuilder->Perform(myFromShape->impl<TopoDS_Shape>(), myToShape->impl<TopoDS_Shape>());
+ myDone = aBuilder->IsDone();
+ if (myDone) {
+ TopoDS_Shape aResult;
+ if(aBuilder->Shape().ShapeType() == TopAbs_COMPOUND) {
+ aResult = GeomAlgoAPI_DFLoader::refineResult(aBuilder->Shape());
+ }
+ else {
+ aResult = aBuilder->Shape();
+ }
+ TopExp_Explorer anExp(aResult, TopAbs_SOLID);
+ if(!anExp.More()) {
+ return;
+ }
+ // 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->Modified(aFromShape).First()));
+ myLast->setImpl(new TopoDS_Shape(aBuilder->Modified(aToShape).First()));
+ myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
+ }
+ }
+}
+
+//============================================================================
+const bool GeomAlgoAPI_Prism::isDone() const
+{
+ return myDone;
+}
+
+//============================================================================
+const bool GeomAlgoAPI_Prism::isValid() const
+{
+ BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
+ return (aChecker.IsValid() == Standard_True);
+}
+
+//============================================================================
+const bool GeomAlgoAPI_Prism::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_Prism::shape () const
+{
+ return myShape;
+}
+
+//============================================================================
+const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::firstShape()
+{
+ return myFirst;
+}
+
+//============================================================================
+const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::lastShape()
+{
+ return myLast;
+}
+
+//============================================================================
+void GeomAlgoAPI_Prism::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
+{
+ theMap = myMap;
+}
+
+//============================================================================
+GeomAlgoAPI_MakeShape* GeomAlgoAPI_Prism::makeShape() const
+{
+ return myMkShape;
+}
+
+//============================================================================
+GeomAlgoAPI_Prism::~GeomAlgoAPI_Prism()
+{
+ if (myImpl) {
+ myMap.clear();
+ }
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_Prism.h
+// Created: 5 May 2015
+// Author: Dmitry Bobylev
+
+#ifndef GeomAlgoAPI_Prism_H_
+#define GeomAlgoAPI_Prism_H_
+
+#include <GeomAlgoAPI.h>
+#include <GeomAPI_Shape.h>
+#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAPI_DataMapOfShapeShape.h>
+#include <memory>
+
+/**\class GeomAlgoAPI_Prism
+ * \ingroup DataAlgo
+ * \brief Allows to create the prism based on a given face and bounding planes
+ */
+
+class GeomAlgoAPI_Prism : 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] theFromShape bottom bounding shape
+ * \param[in] theToShape top bounding shape
+ * \return a solid or a face/shell which is obtained from specified one
+ */
+ /// Constructor
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(std::shared_ptr<GeomAPI_Shape> theBasis,
+ std::shared_ptr<GeomAPI_Shape> theFromShape,
+ std::shared_ptr<GeomAPI_Shape> theToShape);
+
+ /// 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 Prism 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_Prism();
+private:
+ /// builds resulting shape
+ void build(const std::shared_ptr<GeomAPI_Shape>& theBasis);
+ /// fields
+ std::shared_ptr<GeomAPI_Shape> myFromShape;
+ std::shared_ptr<GeomAPI_Shape> myToShape;
+ 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_ShapeProps.cpp
+// Created: 8 May 2015
+// Author: Dmitry Bobylev
+
+#include <GeomAlgoAPI_ShapeProps.h>
+
+#include <BRepGProp.hxx>
+#include <GProp_GProps.hxx>
+#include <TopoDS_Shape.hxx>
+
+
+double GeomAlgoAPI_ShapeProps::volume(std::shared_ptr<GeomAPI_Shape> theShape)
+{
+ GProp_GProps aGProps;
+ TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+ BRepGProp::VolumeProperties(aShape, aGProps);
+ return aGProps.Mass();
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_ShapeProps.h
+// Created: 8 May 2015
+// Author: Dmitry Bobylev
+
+#ifndef GeomAlgoAPI_ShapeProps_H_
+#define GeomAlgoAPI_ShapeProps_H_
+
+/**\class GeomAlgoAPI_ShapeProps
+ * \ingroup DataAlgo
+ * \brief Allows to compute different shape props
+ */
+
+#include <GeomAlgoAPI.h>
+#include <GeomAPI_Shape.h>
+
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_ShapeProps
+{
+public:
+ /// Returns the total volume of the solids of the current shape
+ static double volume(std::shared_ptr<GeomAPI_Shape> theShape);
+};
+
+#endif
+