From 8a502374084b1bd206a86ef4c42797fb994d8b55 Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 8 May 2015 18:10:20 +0300 Subject: [PATCH] Feature #527: 4.04. Extrusion and Revolution from and up to planar face or plane 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. --- CMakeCommon/FindCAS.cmake | 2 +- .../FeaturesPlugin_Extrusion.cpp | 120 +++++++---- src/FeaturesPlugin/FeaturesPlugin_Extrusion.h | 18 +- src/FeaturesPlugin/Test/TestBoolean.py | 4 +- src/FeaturesPlugin/Test/TestExtrusion.py | 192 +++++++++++++++--- src/FeaturesPlugin/Test/TestGroup.py | 4 +- src/FeaturesPlugin/Test/TestMultiBoolean.py | 8 +- src/FeaturesPlugin/extrusion_widget.xml | 19 +- src/GeomAlgoAPI/CMakeLists.txt | 4 + src/GeomAlgoAPI/GeomAlgoAPI.i | 4 + src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp | 12 ++ src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h | 4 + src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp | 144 +++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_Prism.h | 75 +++++++ src/GeomAlgoAPI/GeomAlgoAPI_ShapeProps.cpp | 20 ++ src/GeomAlgoAPI/GeomAlgoAPI_ShapeProps.h | 26 +++ 16 files changed, 564 insertions(+), 92 deletions(-) create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_Prism.h create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_ShapeProps.cpp create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_ShapeProps.h diff --git a/CMakeCommon/FindCAS.cmake b/CMakeCommon/FindCAS.cmake index b610c2915..3abac49ee 100644 --- a/CMakeCommon/FindCAS.cmake +++ b/CMakeCommon/FindCAS.cmake @@ -152,7 +152,7 @@ SET(CAS_KERNEL ${CAS_TKernel} ${CAS_TKMath}) 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}) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 9a0b37766..f8a6bfc55 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -6,6 +6,7 @@ #include "FeaturesPlugin_Extrusion.h" #include +#include #include #include #include @@ -16,7 +17,11 @@ #include #include #include +#include +#include #include +#include +#include using namespace std; #define _LATERAL_TAG 1 @@ -36,20 +41,39 @@ void FeaturesPlugin_Extrusion::initAttributes() // 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 aFromShape(new GeomAPI_Shape); + std::shared_ptr aToShape(new GeomAPI_Shape); + + // Getting bounding planes. + std::shared_ptr anObjRef = selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID()); + if (anObjRef) { + aFromShape = std::dynamic_pointer_cast(anObjRef->value()); + } + anObjRef = selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID()); + if (anObjRef) { + aToShape = std::dynamic_pointer_cast(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++) { @@ -61,9 +85,6 @@ void FeaturesPlugin_Extrusion::execute() setError(aContextError); break; } - double aSize = real(FeaturesPlugin_Extrusion::TO_SIZE_ID())->value(); - if (boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value()) - aSize = -aSize; std::shared_ptr aValueFace = aFaceRef->value(); int aFacesNum = -1; // this mean that "aFace" is used @@ -81,32 +102,66 @@ void FeaturesPlugin_Extrusion::execute() for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) { ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - std::shared_ptr aFace; + std::shared_ptr aBaseShape; if (aFacesNum == -1) { - aFace = aValueFace; + aBaseShape = aValueFace; } else { - aFace = std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); + aBaseShape = std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); } - GeomAlgoAPI_Extrusion aFeature(aFace, aSize); + + // If bounding faces was not set creating them. + std::shared_ptr aBaseFace(new GeomAPI_Face(aBaseShape)); + std::shared_ptr aBasePlane = aBaseFace->getPlane(); + std::shared_ptr aBaseDir = aBasePlane->direction(); + std::shared_ptr 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 aFromFace(new GeomAPI_Face(aFromShape)); + std::shared_ptr aFromPlane = aFromFace->getPlane(); + std::shared_ptr aFromLoc = aFromPlane->location(); + std::shared_ptr aFromDir = aFromPlane->direction(); + + std::shared_ptr aToFace(new GeomAPI_Face(aToShape)); + std::shared_ptr aToPlane = aToFace->getPlane(); + std::shared_ptr aToLoc = aToPlane->location(); + std::shared_ptr aToDir = aToPlane->direction(); + + bool aSign = aFromLoc->xyz()->dot(aBaseDir->xyz()) > aToLoc->xyz()->dot(aBaseDir->xyz()); + + std::shared_ptr aFromPnt(new GeomAPI_Pnt(aFromLoc->xyz()->added(aBaseDir->xyz()->multiplied(aSign ? aFromSize : -aFromSize)))); + aFromShape = GeomAlgoAPI_FaceBuilder::plane(aFromPnt, aFromDir); + + std::shared_ptr 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++; @@ -120,18 +175,16 @@ void FeaturesPlugin_Extrusion::execute() } //============================================================================ -void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, - std::shared_ptr theResultBody, - std::shared_ptr theBasis, - std::shared_ptr theContext) -{ - - +void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Prism& theFeature, + std::shared_ptr theResultBody, + std::shared_ptr theBasis, + std::shared_ptr 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); @@ -142,26 +195,23 @@ void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, //Insert bottom face std::string aBotName = "BottomFace"; - std::shared_ptr aBottomFace = theFeature.firstShape(); - if (!aBottomFace->isNull()) { - if (aSubShapes->isBound(aBottomFace)) { - aBottomFace = aSubShapes->find(aBottomFace); - } + std::shared_ptr 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 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); } - } //============================================================================ diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h index f3e788049..42c0dc1d6 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h @@ -11,6 +11,7 @@ #include #include #include +#include #include /**\class FeaturesPlugin_Extrusion @@ -18,8 +19,9 @@ * \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 { @@ -72,12 +74,6 @@ 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() @@ -96,9 +92,9 @@ class FeaturesPlugin_Extrusion : public ModelAPI_Feature FeaturesPlugin_Extrusion(); private: /// Load Naming data structure of the feature to the document - void LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, std::shared_ptr theResultBody, - std::shared_ptr theBasis, - std::shared_ptr theContext); + void LoadNamingDS(GeomAlgoAPI_Prism& theFeature, std::shared_ptr theResultBody, + std::shared_ptr theBasis, + std::shared_ptr theContext); /// Set an empty shape to the result of extrusion void clearResult(); diff --git a/src/FeaturesPlugin/Test/TestBoolean.py b/src/FeaturesPlugin/Test/TestBoolean.py index 767e51e15..657a504d2 100644 --- a/src/FeaturesPlugin/Test/TestBoolean.py +++ b/src/FeaturesPlugin/Test/TestBoolean.py @@ -92,8 +92,8 @@ for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]: 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() diff --git a/src/FeaturesPlugin/Test/TestExtrusion.py b/src/FeaturesPlugin/Test/TestExtrusion.py index bf5a2c082..b74979c8b 100644 --- a/src/FeaturesPlugin/Test/TestExtrusion.py +++ b/src/FeaturesPlugin/Test/TestExtrusion.py @@ -4,13 +4,17 @@ 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 @@ -19,6 +23,7 @@ from ModelAPI import * from GeomDataAPI import * from GeomAlgoAPI import * from GeomAPI import * +import math __updated__ = "2014-12-16" @@ -37,15 +42,15 @@ aPart = aPartResult.partDoc() # 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) @@ -55,34 +60,169 @@ aSession.finishOperation() # 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 #========================================================================= diff --git a/src/FeaturesPlugin/Test/TestGroup.py b/src/FeaturesPlugin/Test/TestGroup.py index 4fda808d6..2307a16a5 100644 --- a/src/FeaturesPlugin/Test/TestGroup.py +++ b/src/FeaturesPlugin/Test/TestGroup.py @@ -65,8 +65,8 @@ GeomAlgoAPI_SketchBuilder.createFaces( 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()) diff --git a/src/FeaturesPlugin/Test/TestMultiBoolean.py b/src/FeaturesPlugin/Test/TestMultiBoolean.py index 8ff8dabb1..eb15549c1 100644 --- a/src/FeaturesPlugin/Test/TestMultiBoolean.py +++ b/src/FeaturesPlugin/Test/TestMultiBoolean.py @@ -90,8 +90,8 @@ for i in xrange(0, N * N): 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]) @@ -151,8 +151,8 @@ GeomAlgoAPI_SketchBuilder.createFaces( 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]) diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 8144d2db6..d68dbe414 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -8,12 +8,12 @@ type_choice="Faces"> - + - + - - --> +