#include <GeomAlgoAPI_Boolean.h>
#include <GeomAlgoAPI_MakeShapeList.h>
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
#define FACE 4
#define _MODIFY_TAG 1
return;
}
- if(GeomAlgoAPI_ShapeProps::volume(aBoolAlgo.shape()) > 1.e-7) {
+ if(GeomAlgoAPI_ShapeTools::volume(aBoolAlgo.shape()) > 1.e-7) {
std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
LoadNamingDS(aResultBody, anObject, aTools, aBoolAlgo);
setResult(aResultBody, aResultIndex);
#include <GeomAlgoAPI_Prism.h>
#include <GeomAlgoAPI_Revolution.h>
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
//=================================================================================================
void FeaturesPlugin_CompositeBoolean::initAttributes()
return;
}
- if(GeomAlgoAPI_ShapeProps::volume(aBoolAlgo.shape()) > 1.e-7) {
+ if(GeomAlgoAPI_ShapeTools::volume(aBoolAlgo.shape()) > 1.e-7) {
std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
loadNamingDS(aResultBody, anObject, aSketchFacesList, theSolidsAlgos, aBooleanTools, aBoolAlgo);
setResult(aResultBody, aResultIndex);
aSubShapes = aPrismAlgo->mapOfShapes();
aResultBuilder->loadAndOrientGeneratedShapes(aPrismAlgo->makeShape().get(), *aFaceIter, GeomAPI_Shape::EDGE, aGenTag,
aLatName, *aSubShapes.get());
- aFromFace = aPrismAlgo->firstShape();
- aToFace = aPrismAlgo->lastShape();
+ //TODO:fix
+ //aFromFace = aPrismAlgo->firstShape();
+ //aToFace = aPrismAlgo->lastShape();
} else if(std::dynamic_pointer_cast<GeomAlgoAPI_Revolution>(*aSolidsAlgosIter)) {
std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo = std::dynamic_pointer_cast<GeomAlgoAPI_Revolution>(*aSolidsAlgosIter);
aSubShapes = aRevolAlgo->mapOfShapes();
#include <ModelAPI_AttributeReference.h>
#include <GeomAlgoAPI_Prism.h>
-
-#define _LATERAL_TAG 1
-#define _FIRST_TAG 2
-#define _LAST_TAG 3
-#define EDGE 6
-
-//#define DEBUG_COMPSOLID
-//#define DEBUG_COMPSOLID_SHAPE
+#include <GeomAlgoAPI_ShapeTools.h>
//=================================================================================================
FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
//=================================================================================================
void FeaturesPlugin_Extrusion::execute()
{
- AttributeSelectionListPtr aFaceRefs = selectionList(LIST_ID());
+ // Getting faces.
+ ListOfShape aFacesList;
+ AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID());
+ for(int anIndex = 0; anIndex < aFacesSelectionList->size(); anIndex++) {
+ std::shared_ptr<ModelAPI_AttributeSelection> aFaceSel = aFacesSelectionList->value(anIndex);
+ ResultPtr aContext = aFaceSel->context();
+ std::shared_ptr<GeomAPI_Shape> aContextShape = aContext->shape();
+ if(!aContextShape.get()) {
+ static const std::string aContextError = "The selection context is bad";
+ setError(aContextError);
+ break;
+ }
+
+ std::shared_ptr<GeomAPI_Shape> aFaceShape = aFaceSel->value();
+ int aFacesNum = -1; // this mean that "aFace" is used
+ ResultConstructionPtr aConstruction =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+ if(!aFaceShape.get()) { // this may be the whole sketch result selected, check and get faces
+ if (aConstruction.get()) {
+ aFacesNum = aConstruction->facesNum();
+ } else {
+ static const std::string aFaceError = "Can not find basis for extrusion";
+ setError(aFaceError);
+ break;
+ }
+ }
+ for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) {
+ std::shared_ptr<GeomAPI_Shape> aBaseShape;
+ if (aFacesNum == -1) {
+ aFacesList.push_back(aFaceShape);
+ break;
+ } else {
+ aFaceShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
+ aFacesList.push_back(aFaceShape);
+ }
+ }
+ }
// Getting sizes.
double aToSize = 0.0;
}
}
- // for each selected face generate a result
+ // Searching faces with common edges.
+ ListOfShape aShells;
+ ListOfShape aFreeFaces;
+ GeomAlgoAPI_ShapeTools::combineFacesToShells(aFacesList, aShells, aFreeFaces);
+ aShells.merge(aFreeFaces);
+
+ // Generating result for each shell and face.
int anIndex = 0, aResultIndex = 0;
-#ifdef DEBUG_COMPSOLID
- ResultCompSolidPtr aCompSolidResult = document()->createCompSolid(data(), aResultIndex);
- setResult(aCompSolidResult, aResultIndex);
- aResultIndex++;
-#endif
-#ifdef DEBUG_COMPSOLID_SHAPE
- bool aFirstShapeInCompsolid = aFaceRefs->size() > 0;
- if (aFirstShapeInCompsolid)
- aResultIndex--;
-#endif
- for(; anIndex < aFaceRefs->size(); anIndex++) {
- std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = aFaceRefs->value(anIndex);
- ResultPtr aContextRes = aFaceRef->context();
- std::shared_ptr<GeomAPI_Shape> aContext = aContextRes->shape();
- if (!aContext.get()) {
- static const std::string aContextError = "The selection context is bad";
- setError(aContextError);
+ for(ListOfShape::const_iterator anIter = aShells.cbegin(); anIter != aShells.cend(); anIter++) {
+ std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIter;
+
+ GeomAlgoAPI_Prism aPrismAlgo(aBaseShape, aToShape, aToSize, aFromShape, aFromSize);
+ if(!aPrismAlgo.isDone()) {
+ static const std::string aPrismAlgoError = "Extrusion algorithm failed";
+ setError(aPrismAlgoError);
+ aResultIndex = 0;
break;
}
- std::shared_ptr<GeomAPI_Shape> aValueFace = aFaceRef->value();
- int aFacesNum = -1; // this mean that "aFace" is used
- ResultConstructionPtr aConstruction =
- std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes);
- if (!aValueFace.get()) { // this may be the whole sketch result selected, check and get faces
- if (aConstruction.get()) {
- aFacesNum = aConstruction->facesNum();
- } else {
- static const std::string aFaceError = "Can not find basis for extrusion";
- setError(aFaceError);
- break;
- }
+ // Check if shape is valid
+ if(!aPrismAlgo.shape().get() || aPrismAlgo.shape()->isNull()) {
+ static const std::string aShapeError = "Resulting shape is Null";
+ setError(aShapeError);
+ aResultIndex = 0;
+ break;
}
- for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) {
- ResultBodyPtr aResultBody;
-
-#ifdef DEBUG_COMPSOLID_SHAPE
- if (aFirstShapeInCompsolid && anIndex == 0)
- aResultBody = aCompSolidResult;
- else {
-#endif
-
-#ifdef DEBUG_COMPSOLID
- aResultBody = aCompSolidResult->addResult(aResultIndex);
-#else
- aResultBody = document()->createBody(data(), aResultIndex);
-#endif
-
-#ifdef DEBUG_COMPSOLID_SHAPE
- }
-#endif
- std::shared_ptr<GeomAPI_Shape> aBaseShape;
- if (aFacesNum == -1) {
- aBaseShape = aValueFace;
- } else {
- aBaseShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
- }
-
- GeomAlgoAPI_Prism aFeature(aBaseShape, aToShape, aToSize, aFromShape, aFromSize);
- if(!aFeature.isDone()) {
- static const std::string aFeatureError = "Extrusion algorithm failed";
- setError(aFeatureError);
- break;
- }
-
- // Check if shape is valid
- if(!aFeature.shape().get() || 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";
- setError(aFeatureError);
- break;
- }
- //LoadNamingDS
- LoadNamingDS(aFeature, aResultBody, aBaseShape, aContext);
- setResult(aResultBody, aResultIndex);
- aResultIndex++;
-
- if (aFacesNum == -1)
- break;
+ if(!aPrismAlgo.isValid()) {
+ std::string aPrismAlgoError = "Warning: resulting shape is not valid";
+ setError(aPrismAlgoError);
+ aResultIndex = 0;
+ break;
}
+
+ ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
+ loadNamingDS(aPrismAlgo, aResultBody, aBaseShape);
+ setResult(aResultBody, aResultIndex);
+ aResultIndex++;
}
- // remove the rest results if there were produced in the previous pass
+
removeResults(aResultIndex);
}
//=================================================================================================
-void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Prism& theFeature,
+void FeaturesPlugin_Extrusion::loadNamingDS(GeomAlgoAPI_Prism& thePrismAlgo,
std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- std::shared_ptr<GeomAPI_Shape> theBasis,
- std::shared_ptr<GeomAPI_Shape> theContext)
+ std::shared_ptr<GeomAPI_Shape> theBasis)
{
//load result
ModelAPI_BodyBuilder* aResultBuilder = theResultBody->getBodyBuilder();
- if(theBasis->isEqual(theContext))
- aResultBuilder->store(theFeature.shape());
- else
- aResultBuilder->storeGenerated(theBasis, theFeature.shape());
+ if(thePrismAlgo.shape()->shapeType() == GeomAPI_Shape::COMPSOLID) {
+ int a = 1;
+ }
+ aResultBuilder->storeGenerated(theBasis, thePrismAlgo.shape());
- std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theFeature.mapOfShapes();
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = thePrismAlgo.mapOfShapes();
//Insert lateral face : Face from Edge
std::string aLatName = "LateralFace";
- aResultBuilder->loadAndOrientGeneratedShapes(theFeature.makeShape().get(), theBasis, EDGE,_LATERAL_TAG, aLatName, *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);
+ const int aLatTag = 1;
+ aResultBuilder->loadAndOrientGeneratedShapes(thePrismAlgo.makeShape().get(), theBasis, GeomAPI_Shape::EDGE, aLatTag, aLatName, *aSubShapes);
+
+ //Insert to faces
+ std::string aToName = "ToFace";
+ const int aToTag = 2;
+ const ListOfShape& aToFaces = thePrismAlgo.toFaces();
+ for(ListOfShape::const_iterator anIt = aToFaces.cbegin(); anIt != aToFaces.cend(); anIt++) {
+ std::shared_ptr<GeomAPI_Shape> aToFace = *anIt;
+ if(aSubShapes->isBound(aToFace)) {
+ aToFace = aSubShapes->find(aToFace);
}
- aResultBuilder->generated(aBottomFace, aBotName, _FIRST_TAG);
+ aResultBuilder->generated(aToFace, aToName, aToTag);
}
- //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);
+ //Insert from faces
+ std::string aFromName = "FromFace";
+ const int aFromTag = 3;
+ const ListOfShape& aFromFaces = thePrismAlgo.fromFaces();
+ for(ListOfShape::const_iterator anIt = aFromFaces.cbegin(); anIt != aFromFaces.cend(); anIt++) {
+ std::shared_ptr<GeomAPI_Shape> aFromFace = *anIt;
+ if(aSubShapes->isBound(aFromFace)) {
+ aFromFace = aSubShapes->find(aFromFace);
}
- aResultBuilder->generated(aTopFace, aTopName, _LAST_TAG);
+ aResultBuilder->generated(aFromFace, aFromName, aFromTag);
}
}
FeaturesPlugin_Extrusion();
private:
/// Load Naming data structure of the feature to the document
- void LoadNamingDS(GeomAlgoAPI_Prism& theFeature, std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- std::shared_ptr<GeomAPI_Shape> theBasis,
- std::shared_ptr<GeomAPI_Shape> theContext);
+ void loadNamingDS(GeomAlgoAPI_Prism& thePrismAlgo,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ std::shared_ptr<GeomAPI_Shape> theBasis);
};
#endif
# Check extrusion volume
aRefVolume = 100530.96491487337
-aResVolume = GeomAlgoAPI_ShapeProps_volume(anExtrusionResult.shape())
+aResVolume = GeomAlgoAPI_ShapeTools_volume(anExtrusionResult.shape())
assert (math.fabs(aResVolume - aRefVolume) < 10 ** -5)
#=========================================================================
<doublevalue
id="to_size"
label="Size"
- min="0"
step="1.0"
default="10"
icon=":icons/dimension_up.png"
<doublevalue
id="from_size"
label="Size"
- min="0"
step="1.0"
default="0"
icon=":icons/dimension_down.png"
<doublevalue
id="to_offset"
label="Offset"
- min="0"
step="1.0"
default="0"
icon=":icons/dimension_up.png"
<doublevalue
id="from_offset"
label="Offset"
- min="0"
step="1.0"
default="0"
icon=":icons/dimension_down.png"
return !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID;
}
+GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeType() const
+{
+ const TopoDS_Shape& aShape = impl<TopoDS_Shape>();
+ return (ShapeType)aShape.ShapeType();
+}
+
bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
double& theXmax, double& theYmax, double& theZmax) const
{
GEOMAPI_EXPORT
virtual bool isSolid() const;
+ /// Returns the shape type
+ GEOMAPI_EXPORT
+ virtual ShapeType shapeType() const;
+
/// Computes boundary dimensions of the shape
/// Returns False if it is not possible
GEOMAPI_EXPORT
GeomAlgoAPI_Movement.h
GeomAlgoAPI_MakeShape.h
GeomAlgoAPI_MakeShapeList.h
- GeomAlgoAPI_ShapeProps.h
GeomAlgoAPI_DFLoader.h
GeomAlgoAPI_Placement.h
GeomAlgoAPI_BREPImport.h
GeomAlgoAPI_STEPExport.h
GeomAlgoAPI_IGESExport.h
GeomAlgoAPI_Transform.h
+ GeomAlgoAPI_ShapeTools.h
)
SET(PROJECT_SOURCES
GeomAlgoAPI_Movement.cpp
GeomAlgoAPI_MakeShape.cpp
GeomAlgoAPI_MakeShapeList.cpp
- GeomAlgoAPI_ShapeProps.cpp
GeomAlgoAPI_DFLoader.cpp
GeomAlgoAPI_Placement.cpp
GeomAlgoAPI_BREPImport.cpp
GeomAlgoAPI_STEPExport.cpp
GeomAlgoAPI_IGESExport.cpp
GeomAlgoAPI_Transform.cpp
+ GeomAlgoAPI_ShapeTools.cpp
)
SET(PROJECT_LIBRARIES
${CAS_TKSTEPBase}
${CAS_TKIGES}
${CAS_TKTopAlgo}
- ${CAS_TKXSBase}
+ ${CAS_TKXSBase}
+ ${CAS_TKOffset}
)
ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
#include "GeomAlgoAPI_Prism.h"
#include "GeomAlgoAPI_Revolution.h"
#include "GeomAlgoAPI_Rotation.h"
- #include "GeomAlgoAPI_ShapeProps.h"
+ #include "GeomAlgoAPI_ShapeTools.h"
#include "GeomAlgoAPI_SketchBuilder.h"
#include "GeomAlgoAPI_BREPExport.h"
#include "GeomAlgoAPI_IGESExport.h"
%include "GeomAlgoAPI_Prism.h"
%include "GeomAlgoAPI_Revolution.h"
%include "GeomAlgoAPI_Rotation.h"
-%include "GeomAlgoAPI_ShapeProps.h"
+%include "GeomAlgoAPI_ShapeTools.h"
%include "GeomAlgoAPI_SketchBuilder.h"
%include "GeomAlgoAPI_BREPExport.h"
%include "GeomAlgoAPI_IGESExport.h"
#include <GeomAlgoAPI_MakeShape.h>
#include <BRepBuilderAPI_MakeShape.hxx>
+#include <BRepOffsetAPI_MakePipe.hxx>
+#include <TopExp_Explorer.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
+
GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape)
: GeomAPI_Interface(theMkShape),myShape(new GeomAPI_Shape())
{
myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
}
+GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape, const std::shared_ptr<GeomAPI_Shape> theWire)
+: GeomAPI_Interface(theMkShape),
+ myShape(new GeomAPI_Shape()),
+ myWire(theWire)
+{
+ myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
+}
+
GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
: GeomAPI_Interface(),myShape(new GeomAPI_Shape())
{}
void GeomAlgoAPI_MakeShape::generated(
const std::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
{
- BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
- if(aBuilder) {
- const TopTools_ListOfShape& aList = aBuilder->Generated(theShape->impl<TopoDS_Shape>());
- TopTools_ListIteratorOfListOfShape it(aList);
- for(;it.More();it.Next()) {
- std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
- aShape->setImpl(new TopoDS_Shape(it.Value()));
- theHistory.push_back(aShape);
+ if(!myWire.get()) {
+ BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
+ if(aBuilder) {
+ const TopTools_ListOfShape& aList = aBuilder->Generated(theShape->impl<TopoDS_Shape>());
+ TopTools_ListIteratorOfListOfShape it(aList);
+ for(;it.More();it.Next()) {
+ std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(it.Value()));
+ theHistory.push_back(aShape);
+ }
+ }
+ } else { // Pipe builder
+ BRepOffsetAPI_MakePipe* aPipeBuilder = implPtr<BRepOffsetAPI_MakePipe>();
+ if(aPipeBuilder) {
+ TopExp_Explorer aShapeExplorer(myWire->impl<TopoDS_Wire>(), TopAbs_EDGE);
+ for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+ const TopoDS_Shape& aGeneratedShape = aPipeBuilder->Generated(aShapeExplorer.Current(), theShape->impl<TopoDS_Shape>());
+ std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(aGeneratedShape));
+ theHistory.push_back(aShape);
+ }
}
}
}
/// Constructor by the already stored builder in the interface
GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape(void* theBuilder);
+ /// Constructor by the builder and wire. Used for pipe builder.
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape(void* theBuilder, const std::shared_ptr<GeomAPI_Shape> theWire);
+
/// Returns a shape built by the shape construction algorithm
GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape> shape() const;
protected:
/// The resulting shape
- std::shared_ptr<GeomAPI_Shape> myShape;
+ std::shared_ptr<GeomAPI_Shape> myShape;
+ std::shared_ptr<GeomAPI_Shape> myWire;
};
typedef std::list<std::shared_ptr<GeomAlgoAPI_MakeShape> > ListOfMakeShape;
aResultShapes.Add(theShape->impl<TopoDS_Shape>());
for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
- BRepBuilderAPI_MakeShape* aBuilder = (*aBuilderIt)->implPtr<BRepBuilderAPI_MakeShape>();
+ std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
NCollection_Map<TopoDS_Shape> aTempShapes;
bool hasResults = false;
for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(anAlgoShapes); aShapeIt.More(); aShapeIt.Next()) {
- const TopoDS_Shape& aShape = aShapeIt.Value();
- const TopTools_ListOfShape& aGeneratedList = aBuilder->Generated(aShape);
- for(TopTools_ListIteratorOfListOfShape anIt(aGeneratedList); anIt.More(); anIt.Next()) {
- aTempShapes.Add(anIt.Value());
- aResultShapes.Add(anIt.Value());
+ std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
+ aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
+ ListOfShape aGeneratedShapes;
+ aMakeShape->generated(aShape, aGeneratedShapes);
+ for(ListOfShape::const_iterator anIt = aGeneratedShapes.cbegin(); anIt != aGeneratedShapes.cend(); anIt++) {
+ aTempShapes.Add((*anIt)->impl<TopoDS_Shape>());
+ aResultShapes.Add((*anIt)->impl<TopoDS_Shape>());
hasResults = true;
}
- const TopTools_ListOfShape& aModifiedList = aBuilder->Modified(aShape);
- for(TopTools_ListIteratorOfListOfShape anIt(aModifiedList); anIt.More(); anIt.Next()) {
- aTempShapes.Add(anIt.Value());
- aResultShapes.Add(anIt.Value());
+ ListOfShape aModifiedShapes;
+ aMakeShape->modified(aShape, aModifiedShapes);
+ for(ListOfShape::const_iterator anIt = aModifiedShapes.cbegin(); anIt != aModifiedShapes.cend(); anIt++) {
+ aTempShapes.Add((*anIt)->impl<TopoDS_Shape>());
+ aResultShapes.Add((*anIt)->impl<TopoDS_Shape>());
hasResults = true;
}
if(hasResults) {
- aResultShapes.Remove(aShape);
+ aResultShapes.Remove(aShape->impl<TopoDS_Shape>());
}
}
anAlgoShapes.Unite(aTempShapes);
#include <GeomAlgoAPI_Movement.h>
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepCheck_Analyzer.hxx>
const bool GeomAlgoAPI_Movement::hasVolume() const
{
bool hasVolume(false);
- if(isValid() && (GeomAlgoAPI_ShapeProps::volume(myShape) > Precision::Confusion())) {
+ if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) {
hasVolume = true;
}
return hasVolume;
#include <GeomAPI_Face.h>
#include <GeomAPI_Pln.h>
#include <GeomAPI_Pnt.h>
+#include <GeomAPI_ShapeExplorer.h>
#include <GeomAPI_XYZ.h>
#include <GeomAlgoAPI_DFLoader.h>
#include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomAlgoAPI_MakeShapeList.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+#include <Bnd_Box.hxx>
+#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
+#include <BRepAlgoAPI_Cut.hxx>
+#include <BRepBndLib.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeShape.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepCheck_Analyzer.hxx>
-#include <BRepFeat_MakePrism.hxx>
+#include <BRepExtrema_ExtCF.hxx>
#include <BRepGProp.hxx>
+#include <BRepOffsetAPI_MakePipe.hxx>
+#include <BRepTools.hxx>
#include <Geom_Plane.hxx>
#include <gp_Pln.hxx>
#include <GProp_GProps.hxx>
+#include <TCollection_AsciiString.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Shell.hxx>
+#include <TopoDS_Solid.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
//=================================================================================================
GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr<GeomAPI_Shape> theBasis,
{
if(!theBasis ||
(((!theFromShape && !theToShape) || (theFromShape && theToShape && theFromShape->isEqual(theToShape)))
- && (theFromSize == 0.0 && theToSize == 0.0))) {
+ && (theFromSize == -theToSize))) {
return;
}
// If bounding faces was not set creating them.
- std::shared_ptr<GeomAPI_Face> aBaseFace(new GeomAPI_Face(theBasis));
+ std::shared_ptr<GeomAPI_Face> aBaseFace;
+ if(theBasis->shapeType() == GeomAPI_Shape::SHELL) {
+ GeomAPI_ShapeExplorer anExp(theBasis, GeomAPI_Shape::FACE);
+ if(anExp.more()) {
+ std::shared_ptr<GeomAPI_Shape> aFaceOnShell = anExp.current();
+ aBaseFace = std::shared_ptr<GeomAPI_Face>(new GeomAPI_Face(aFaceOnShell));
+ }
+ } else {
+ aBaseFace = std::shared_ptr<GeomAPI_Face>(new GeomAPI_Face(theBasis));
+ }
+ if(!aBaseFace.get()) {
+ return;
+ }
std::shared_ptr<GeomAPI_Pln> aBasePln = aBaseFace->getPlane();
std::shared_ptr<GeomAPI_Dir> aBaseDir = aBasePln->direction();
std::shared_ptr<GeomAPI_Pnt> aBaseLoc = aBasePln->location();
aSign ? -theToSize : theToSize))));
aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
- 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
+ // Getting bounding box for base shape.
+ const TopoDS_Shape& aBasisShape = theBasis->impl<TopoDS_Shape>();
+ Bnd_Box aBndBox;
+ BRepBndLib::Add(aBasisShape, aBndBox);
+ Standard_Real aXArr[2] = {aBndBox.CornerMin().X(), aBndBox.CornerMax().X()};
+ Standard_Real aYArr[2] = {aBndBox.CornerMin().Y(), aBndBox.CornerMax().Y()};
+ Standard_Real aZArr[2] = {aBndBox.CornerMin().Z(), aBndBox.CornerMax().Z()};
+ gp_Pnt aPoints[8];
+ int aNum = 0;
+ for(int i = 0; i < 2; i++) {
+ for(int j = 0; j < 2; j++) {
+ for(int k = 0; k < 2; k++) {
+ aPoints[aNum] = gp_Pnt(aXArr[i], aYArr[j], aZArr[k]);
+ aNum++;
+ }
+ }
+ }
+
+ // Project points to bounding planes. Search max distance to them.
+ const TopoDS_Shape& aBndToShape = aBoundingToShape->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aBndFromShape = aBoundingFromShape->impl<TopoDS_Shape>();
+ Standard_Real aMaxToDist = 0, aMaxFromDist = 0;
+ gp_Vec aNormal(aBaseDir->impl<gp_Dir>());
+ for(int i = 0; i < 8; i++) {
+ gp_Lin aLine(aPoints[i], aNormal);
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(aLine).Edge();
+ BRepExtrema_ExtCF aToExt(anEdge, TopoDS::Face(aBndToShape));
+ BRepExtrema_ExtCF aFromExt(anEdge, TopoDS::Face(aBndFromShape));
+ if(aToExt.NbExt() == 0 || aFromExt.NbExt() == 0) {
+ return;
+ }
+ const gp_Pnt& aPntOnToFace = aToExt.PointOnFace(1);
+ const gp_Pnt& aPntOnFromFace = aFromExt.PointOnFace(1);
+ if(aPoints[i].Distance(aPntOnToFace) > aMaxToDist) {
+ aMaxToDist = aPoints[i].Distance(aPntOnToFace);
+ }
+ if(aPoints[i].Distance(aPntOnFromFace) > aMaxFromDist) {
+ aMaxFromDist = aPoints[i].Distance(aPntOnFromFace);
+ }
+ }
+ Standard_Real aPipeLength = aMaxToDist + aMaxFromDist;
+
+ // Making wire for pipe.
+ std::shared_ptr<GeomAPI_Pnt> aCentreOfMass = GeomAlgoAPI_ShapeTools::centreOfMass(theBasis);
+ const gp_Pnt aCentrePnt = aCentreOfMass->impl<gp_Pnt>();
+ TopoDS_Face aFace = TopoDS::Face(aBaseFace->impl<TopoDS_Shape>());
+ gp_Pnt aPipeStartPnt = aCentrePnt.Translated(aNormal.Scaled(aPipeLength));
+ gp_Pnt aPipeEndPnt = aCentrePnt.Translated(aNormal.Scaled(-aPipeLength));
+ TopoDS_Edge aPipeEdge = BRepBuilderAPI_MakeEdge(aPipeStartPnt, aPipeEndPnt);
+ TopoDS_Wire aPipeWire = BRepBuilderAPI_MakeWire(aPipeEdge).Wire();
+
+ // Making pipe.
+ ListOfMakeShape aListOfMakeShape;
+ BRepOffsetAPI_MakePipe* aPipeBuilder = new BRepOffsetAPI_MakePipe(aPipeWire, aBasisShape);
+ if(!aPipeBuilder) {
return;
}
+ std::shared_ptr<GeomAPI_Shape> aWire(new GeomAPI_Shape);
+ aWire->setImpl(new TopoDS_Shape(aPipeWire));
+ aListOfMakeShape.push_back(std::make_shared<GeomAlgoAPI_MakeShape>(aPipeBuilder, aWire));
+ TopoDS_Shape aResult = aPipeBuilder->Shape();
- const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
- BRepFeat_MakePrism* aBuilder = new BRepFeat_MakePrism(aBasis, aBasis, aBasis, aNormal, 2, Standard_True);
-
- if(aBuilder) {
- const TopoDS_Shape& aFromShape = aBoundingFromShape->impl<TopoDS_Shape>();
- const TopoDS_Shape& aToShape = aBoundingToShape->impl<TopoDS_Shape>();
- aBuilder->Perform(aFromShape, aToShape);
- myDone = aBuilder->IsDone() == Standard_True;
- if(myDone){
- TopoDS_Shape aResult = aBuilder->Shape();
- TopExp_Explorer anExp(aResult, TopAbs_SOLID);
- if(!anExp.More()) {
- return;
- }
- if(aResult.ShapeType() == TopAbs_COMPOUND) {
- aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
- }
- // fill data map to keep correct orientation of sub-shapes
- myMap = std::shared_ptr<GeomAPI_DataMapOfShapeShape>(new GeomAPI_DataMapOfShapeShape());
- 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 = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
- myShape->setImpl(new TopoDS_Shape(aResult));
- myFirst = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
- myFirst->setImpl(new TopoDS_Shape(aBuilder->Modified(aFromShape).First()));
- myLast = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
- myLast->setImpl(new TopoDS_Shape(aBuilder->Modified(aToShape).First()));
- myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape());
- myMkShape->setImpl(aBuilder);
+ // Orienting bounding planes.
+ gp_Lin aLine(aCentrePnt, aNormal);
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(aLine).Edge();
+ BRepExtrema_ExtCF aToExt(anEdge, TopoDS::Face(aBndToShape));
+ BRepExtrema_ExtCF aFromExt(anEdge, TopoDS::Face(aBndFromShape));
+ Standard_Real aToParameter = aToExt.ParameterOnEdge(1);
+ Standard_Real aFromParameter = aFromExt.ParameterOnEdge(1);
+ if(aToParameter > aFromParameter) {
+ gp_Vec aVec = aToDir->impl<gp_Dir>();
+ if((aVec * aNormal) > 0) {
+ aToDir->setImpl(new gp_Dir(aVec.Reversed()));
+ aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
+ }
+ aVec = aFromDir->impl<gp_Dir>();
+ if((aVec * aNormal) < 0) {
+ aFromDir->setImpl(new gp_Dir(aVec.Reversed()));
+ aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
+ }
+ } else {
+ gp_Vec aVec = aToDir->impl<gp_Dir>();
+ if((aVec * aNormal) < 0) {
+ aToDir->setImpl(new gp_Dir(aVec.Reversed()));
+ aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
}
+ aVec = aFromDir->impl<gp_Dir>();
+ if((aVec * aNormal) > 0) {
+ aFromDir->setImpl(new gp_Dir(aVec.Reversed()));
+ aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
+ }
+ }
+
+ // Making solids from bounding planes.
+ TopoDS_Shell aToShell, aFromShell;
+ TopoDS_Solid aToSolid, aFromSolid;
+ const TopoDS_Shape& aToShape = aBoundingToShape->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aFromShape = aBoundingFromShape->impl<TopoDS_Shape>();
+ BRep_Builder aBoundingBuilder;
+ aBoundingBuilder.MakeShell(aToShell);
+ aBoundingBuilder.MakeShell(aFromShell);
+ aBoundingBuilder.Add(aToShell, aToShape);
+ aBoundingBuilder.Add(aFromShell, aFromShape);
+ aBoundingBuilder.MakeSolid(aToSolid);
+ aBoundingBuilder.MakeSolid(aFromSolid);
+ aBoundingBuilder.Add(aToSolid, aToShell);
+ aBoundingBuilder.Add(aFromSolid, aFromShell);
+
+ // Cutting with to plane.
+ BRepAlgoAPI_Cut* aToCutBuilder = new BRepAlgoAPI_Cut(aResult, aToSolid);
+ aToCutBuilder->Build();
+ if(!aToCutBuilder->IsDone()) {
+ return;
+ }
+ aListOfMakeShape.push_back(std::make_shared<GeomAlgoAPI_MakeShape>(aToCutBuilder));
+ const TopTools_ListOfShape& aToShapes = aToCutBuilder->Modified(aToShape);
+ for(TopTools_ListIteratorOfListOfShape anIt(aToShapes); anIt.More(); anIt.Next()) {
+ std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(anIt.Value()));
+ myToFaces.push_back(aShape);
+ }
+ aResult = aToCutBuilder->Shape();
+
+ // Cutting with from plane.
+ BRepAlgoAPI_Cut* aFromCutBuilder = new BRepAlgoAPI_Cut(aResult, aFromSolid);
+ aFromCutBuilder->Build();
+ if(!aFromCutBuilder->IsDone()) {
+ return;
}
+ aListOfMakeShape.push_back(std::make_shared<GeomAlgoAPI_MakeShape>(aFromCutBuilder));
+ const TopTools_ListOfShape& aFromShapes = aFromCutBuilder->Modified(aFromShape);
+ for(TopTools_ListIteratorOfListOfShape anIt(aFromShapes); anIt.More(); anIt.Next()) {
+ std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(anIt.Value()));
+ myFromFaces.push_back(aShape);
+ }
+ aResult = aFromCutBuilder->Shape();
+
+ TopExp_Explorer anExp(aResult, TopAbs_SOLID);
+ if(!anExp.More()) {
+ return;
+ }
+ if(aResult.ShapeType() == TopAbs_COMPOUND) {
+ aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
+ }
+
+ myShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
+ myShape->setImpl(new TopoDS_Shape(aResult));
+
+ // Fill data map to keep correct orientation of sub-shapes.
+ myMap = std::shared_ptr<GeomAPI_DataMapOfShapeShape>(new GeomAPI_DataMapOfShapeShape);
+ 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);
+ }
+
+ myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
+ myDone = true;
}
//=================================================================================================
}
//=================================================================================================
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Prism::firstShape() const
+const ListOfShape& GeomAlgoAPI_Prism::fromFaces() const
{
- return myFirst;
+ return myFromFaces;
}
//=================================================================================================
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Prism::lastShape() const
+const ListOfShape& GeomAlgoAPI_Prism::toFaces() const
{
- return myLast;
+ return myToFaces;
}
//=================================================================================================
/// \return result of the Prism algorithm.
GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape() const;
- /// \returns the first shape.
- GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> firstShape() const;
+ /// \returns the list of from faces.
+ GEOMALGOAPI_EXPORT const ListOfShape& fromFaces() const;
- /// \return the last shape.
- GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> lastShape() const;
+ /// \return the list of to faces.
+ GEOMALGOAPI_EXPORT const ListOfShape& toFaces() const;
/// \return map of sub-shapes of the result. To be used for History keeping.
GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_DataMapOfShapeShape> mapOfShapes() const;
/// Fields.
bool myDone;
std::shared_ptr<GeomAPI_Shape> myShape;
- std::shared_ptr<GeomAPI_Shape> myFirst;
- std::shared_ptr<GeomAPI_Shape> myLast;
+ ListOfShape myFromFaces;
+ ListOfShape myToFaces;
std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap;
std::shared_ptr<GeomAlgoAPI_MakeShape> myMkShape;
};
#include <GeomAlgoAPI_DFLoader.h>
#include <GeomAlgoAPI_MakeShapeList.h>
#include <GeomAlgoAPI_Rotation.h>
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
// Orienting bounding planes properly so that the center of mass of the base face stays
// on the result shape after cut.
- gp_Pnt aBasisCentr = GeomAlgoAPI_ShapeProps::centreOfMass(theBasis)->impl<gp_Pnt>();
+ gp_Pnt aBasisCentr = GeomAlgoAPI_ShapeTools::centreOfMass(theBasis)->impl<gp_Pnt>();
aFromFace = makeFaceFromPlane(aFromPln, aBasisCentr);
aToFace = makeFaceFromPlane(aToPln, aBasisCentr);
// Orienting bounding plane properly so that the center of mass of the base face stays
// on the result shape after cut.
- gp_Pnt aBasisCentr = GeomAlgoAPI_ShapeProps::centreOfMass(theBasis)->impl<gp_Pnt>();
+ gp_Pnt aBasisCentr = GeomAlgoAPI_ShapeTools::centreOfMass(theBasis)->impl<gp_Pnt>();
aBoundingFace = makeFaceFromPlane(aBoundingPln, aBasisCentr);
// Making solid from bounding plane.
}
myShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
myShape->setImpl(new TopoDS_Shape(aResult));
- myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(new GeomAlgoAPI_MakeShapeList());
+ myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
myDone = true;
return;
}
#include <GeomAlgoAPI_Rotation.h>
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepCheck_Analyzer.hxx>
const bool GeomAlgoAPI_Rotation::hasVolume() const
{
bool hasVolume(false);
- if(isValid() && (GeomAlgoAPI_ShapeProps::volume(myShape) > Precision::Confusion())) {
+ if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) {
hasVolume = true;
}
return hasVolume;
+++ /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;
- if(!theShape) {
- return 0.0;
- }
- const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
- if(aShape.IsNull()) {
- return 0.0;
- }
- BRepGProp::VolumeProperties(aShape, aGProps);
- return aGProps.Mass();
-}
-
-//=================================================================================================
-std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_ShapeProps::centreOfMass(std::shared_ptr<GeomAPI_Shape> theShape)
-{
- GProp_GProps aGProps;
- if(!theShape) {
- return std::shared_ptr<GeomAPI_Pnt>();
- }
- const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
- if(aShape.IsNull()) {
- return std::shared_ptr<GeomAPI_Pnt>();
- }
- BRepGProp::SurfaceProperties(aShape, aGProps);
- gp_Pnt aCentre = aGProps.CentreOfMass();
- return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z()));
-}
+++ /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_
-
-#include <GeomAlgoAPI.h>
-
-#include <GeomAPI_Pnt.h>
-#include <GeomAPI_Shape.h>
-
-/** \class GeomAlgoAPI_ShapeProps
- * \ingroup DataAlgo
- * \brief Allows to compute different shape props.
- */
-class GEOMALGOAPI_EXPORT GeomAlgoAPI_ShapeProps
-{
-public:
- /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
- static double volume(std::shared_ptr<GeomAPI_Shape> theShape);
-
- /// \return the centre of mass of the current face. The coordinates returned for the center of mass
- /// are expressed in the absolute Cartesian coordinate system. (This function works only for surfaces).
- static std::shared_ptr<GeomAPI_Pnt> centreOfMass(std::shared_ptr<GeomAPI_Shape> theShape);
-};
-
-#endif
-
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_ShapeTools.h
+// Created: 3 August 2015
+// Author: Dmitry Bobylev
+
+#include <GeomAlgoAPI_ShapeTools.h>
+
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+#include <BOPTools.hxx>
+#include <BRepGProp.hxx>
+#include <BRepTools.hxx>
+#include <GProp_GProps.hxx>
+#include <NCollection_Vector.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TopoDS_Builder.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Shell.hxx>
+
+//=================================================================================================
+double GeomAlgoAPI_ShapeTools::volume(std::shared_ptr<GeomAPI_Shape> theShape)
+{
+ GProp_GProps aGProps;
+ if(!theShape) {
+ return 0.0;
+ }
+ const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+ if(aShape.IsNull()) {
+ return 0.0;
+ }
+ BRepGProp::VolumeProperties(aShape, aGProps);
+ return aGProps.Mass();
+}
+
+//=================================================================================================
+std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_ShapeTools::centreOfMass(std::shared_ptr<GeomAPI_Shape> theShape)
+{
+ GProp_GProps aGProps;
+ if(!theShape) {
+ return std::shared_ptr<GeomAPI_Pnt>();
+ }
+ const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+ if(aShape.IsNull()) {
+ return std::shared_ptr<GeomAPI_Pnt>();
+ }
+ BRepGProp::SurfaceProperties(aShape, aGProps);
+ gp_Pnt aCentre = aGProps.CentreOfMass();
+ return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z()));
+}
+
+//=================================================================================================
+void GeomAlgoAPI_ShapeTools::combineFacesToShells(const ListOfShape& theFacesList,
+ ListOfShape& theShells,
+ ListOfShape& theFreeFaces)
+{
+ if(theFacesList.empty()) {
+ return;
+ }
+
+ // Adding all faces to compoud.
+ std::shared_ptr<GeomAPI_Shape> aFacesCompound = GeomAlgoAPI_CompoundBuilder::compound(theFacesList);
+ if(!aFacesCompound.get()) {
+ return;
+ }
+
+ // Map edges and faces.
+ const TopoDS_Shape& aFacesComp = aFacesCompound->impl<TopoDS_Shape>();
+ BOPCol_IndexedDataMapOfShapeListOfShape aMapEF;
+ BOPTools::MapShapesAndAncestors(aFacesComp, TopAbs_EDGE, TopAbs_FACE, aMapEF);
+ if(aMapEF.IsEmpty()) {
+ return;
+ }
+
+ // Get all faces with common edges and free faces.
+ NCollection_Map<TopoDS_Shape> aFreeFaces;
+ NCollection_Vector<NCollection_Map<TopoDS_Shape>> aFacesWithCommonEdges;
+ for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapEF); anIter.More(); anIter.Next()) {
+ const TopoDS_Shape& aShape = anIter.Key();
+ BOPCol_ListOfShape& aListOfShape = anIter.ChangeValue();
+ if(aListOfShape.IsEmpty()) {
+ continue;
+ }
+ else if(aListOfShape.Size() == 1) {
+ aFreeFaces.Add(aListOfShape.First());
+ aListOfShape.Clear();
+ } else {
+ NCollection_Map<TopoDS_Shape> aTempMap;
+ aTempMap.Add(aListOfShape.First());
+ aTempMap.Add(aListOfShape.Last());
+ aFreeFaces.Remove(aListOfShape.First());
+ aFreeFaces.Remove(aListOfShape.Last());
+ aListOfShape.Clear();
+ for(NCollection_Map<TopoDS_Shape>::Iterator aTempIter(aTempMap); aTempIter.More(); aTempIter.Next()) {
+ const TopoDS_Shape& aTempShape = aTempIter.Value();
+ for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapEF); anIter.More(); anIter.Next()) {
+ BOPCol_ListOfShape& aTempListOfShape = anIter.ChangeValue();
+ if(aTempListOfShape.IsEmpty()) {
+ continue;
+ } else if(aTempListOfShape.Size() == 1 && aTempListOfShape.First() == aTempShape) {
+ aTempListOfShape.Clear();
+ } else if(aTempListOfShape.Size() > 1) {
+ if(aTempListOfShape.First() == aTempShape) {
+ aTempMap.Add(aTempListOfShape.Last());
+ aFreeFaces.Remove(aTempListOfShape.Last());
+ aTempListOfShape.Clear();
+ } else if(aTempListOfShape.Last() == aTempShape) {
+ aTempMap.Add(aTempListOfShape.First());
+ aFreeFaces.Remove(aTempListOfShape.First());
+ aTempListOfShape.Clear();
+ }
+ }
+ }
+ }
+ aFacesWithCommonEdges.Append(aTempMap);
+ }
+ }
+
+ // Make shells from faces with common edges.
+ NCollection_Vector<TopoDS_Shape> aShells;
+ for(NCollection_Vector<NCollection_Map<TopoDS_Shape>>::Iterator anIter(aFacesWithCommonEdges); anIter.More(); anIter.Next()) {
+ TopoDS_Shell aShell;
+ TopoDS_Builder aBuilder;
+ aBuilder.MakeShell(aShell);
+ const NCollection_Map<TopoDS_Shape>& aShapesMap = anIter.Value();
+ for(NCollection_Map<TopoDS_Shape>::Iterator aShIter(aShapesMap); aShIter.More(); aShIter.Next()) {
+ const TopoDS_Shape& aFace = aShIter.Value();
+ aBuilder.Add(aShell, aFace);
+ }
+ std::shared_ptr<GeomAPI_Shape> aGeomShell(std::make_shared<GeomAPI_Shape>());
+ aGeomShell->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShell));
+ theShells.push_back(aGeomShell);
+ }
+
+ // Adding free faces.
+ for(NCollection_Map<TopoDS_Shape>::Iterator aShIter(aFreeFaces); aShIter.More(); aShIter.Next()) {
+ const TopoDS_Shape& aFace = aShIter.Value();
+ std::shared_ptr<GeomAPI_Shape> aGeomFace(std::make_shared<GeomAPI_Shape>());
+ aGeomFace->setImpl<TopoDS_Shape>(new TopoDS_Shape(aFace));
+ theFreeFaces.push_back(aGeomFace);
+ }
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_ShapeTools.h
+// Created: 3 August 2015
+// Author: Dmitry Bobylev
+
+#ifndef GeomAlgoAPI_ShapeTools_H_
+#define GeomAlgoAPI_ShapeTools_H_
+
+#include <GeomAlgoAPI.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Shape.h>
+
+#include <map>
+
+/** \class GeomAlgoAPI_ShapeTools
+ * \ingroup DataAlgo
+ * \brief
+ */
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_ShapeTools
+{
+public:
+ /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
+ static double volume(std::shared_ptr<GeomAPI_Shape> theShape);
+
+ /// \return the centre of mass of the current face. The coordinates returned for the center of mass
+ /// are expressed in the absolute Cartesian coordinate system. (This function works only for surfaces).
+ static std::shared_ptr<GeomAPI_Pnt> centreOfMass(std::shared_ptr<GeomAPI_Shape> theShape);
+
+ /** \brief Combines faces with common edges to shells
+ * \param[in] theFacesList list of faces to be combined.
+ * \param[out] theShells resulting shells.
+ * \param[out] theFreeFaces faces that does not have common edges.
+ */
+ static void combineFacesToShells(const ListOfShape& theFacesList,
+ ListOfShape& theShells,
+ ListOfShape& theFreeFaces);
+};
+
+#endif
#include <GeomAlgoAPI_Transform.h>
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepCheck_Analyzer.hxx>
const bool GeomAlgoAPI_Transform::hasVolume() const
{
bool hasVolume(false);
- if(isValid() && (GeomAlgoAPI_ShapeProps::volume(myShape) > Precision::Confusion())) {
+ if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) {
hasVolume = true;
}
return hasVolume;
anIt++;
if(aSelectedMethod == aCreationMethod) {
- if(aToSize == 0.0 && aFromSize == 0.0) {
+ if(aToSize == -aFromSize) {
return false;
} else {
return true;
}
if(((!aFromShape && !aToShape) || ((aFromShape && aToShape) && aFromShape->isEqual(aToShape)))
- && (aFromSize == 0.0 && aToSize == 0.0)) {
+ && (aFromSize == -aToSize)) {
return false;
}
#include <ModelAPI_Tools.h>
#include <GeomAlgoAPI_FaceBuilder.h>
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Dir.h>
#include <GeomAPI_XYZ.h>
// orienting projection
if(aBaseShape.get() != NULL) {
- std::shared_ptr<GeomAPI_Pnt> aCenterPnt = GeomAlgoAPI_ShapeProps::centreOfMass(aGShape);
+ std::shared_ptr<GeomAPI_Pnt> aCenterPnt = GeomAlgoAPI_ShapeTools::centreOfMass(aGShape);
gp_Pnt aPnt = aCenterPnt->impl<gp_Pnt>();
aPnt.Translate(aDir->impl<gp_Dir>().XYZ() * (10 * Precision::Confusion()));