*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeWire
- (std::list<Handle(GEOM_Object)> theShapes)
+ (std::list<Handle(GEOM_Object)> theShapes,
+ const Standard_Real theTolerance)
{
- return MakeShape(theShapes, GEOM_WIRE, WIRE_EDGES, "MakeWire");
+ SetErrorCode(KO);
+
+ //Add a new object
+ Handle(GEOM_Object) aWire = GetEngine()->AddObject(GetDocID(), GEOM_WIRE);
+
+ //Add a new function
+ Handle(GEOM_Function) aFunction =
+ aWire->AddFunction(GEOMImpl_ShapeDriver::GetID(), WIRE_EDGES);
+ if (aFunction.IsNull()) return NULL;
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
+
+ GEOMImpl_IShapes aCI (aFunction);
+ aCI.SetTolerance(theTolerance);
+
+ Handle(TColStd_HSequenceOfTransient) aShapesSeq = new TColStd_HSequenceOfTransient;
+
+ // Shapes
+ std::list<Handle(GEOM_Object)>::iterator it = theShapes.begin();
+ for (; it != theShapes.end(); it++) {
+ Handle(GEOM_Function) aRefSh = (*it)->GetLastFunction();
+ if (aRefSh.IsNull()) {
+ SetErrorCode("NULL argument shape for the shape construction");
+ return NULL;
+ }
+ aShapesSeq->Append(aRefSh);
+ }
+ aCI.SetShapes(aShapesSeq);
+
+ //Compute the shape
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Shape driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure) {
+ Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+ SetErrorCode(aFail->GetMessageString());
+ return NULL;
+ }
+
+ //Make a Python command
+ GEOM::TPythonDump pd (aFunction);
+ pd << aWire << " = geompy.MakeWire([";
+
+ // Shapes
+ it = theShapes.begin();
+ if (it != theShapes.end()) {
+ pd << (*it++);
+ while (it != theShapes.end()) {
+ pd << ", " << (*it++);
+ }
+ }
+ pd << "])";
+
+ SetErrorCode(OK);
+ return aWire;
}
//=============================================================================
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeShape
- (std::list<Handle(GEOM_Object)> theShapes,
+ (std::list<Handle(GEOM_Object)> theShapes,
const Standard_Integer theObjectType,
const Standard_Integer theFunctionType,
const TCollection_AsciiString& theMethodName)
}
//Make a Python command
- if(anAsciiList.Length()>0)
+ if( anAsciiList.Length() > 0 ) {
anAsciiList.Trunc(anAsciiList.Length() - 1);
- Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
- GEOM::TPythonDump pd (aFunction, /*append=*/true);
- pd << "[" << anAsciiList.ToCString();
- pd << "] = geompy.GetGlueFaces(" << theShape << ", " << theTolerance << ")";
+ Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
+ GEOM::TPythonDump pd (aFunction, /*append=*/true);
+ pd << "[" << anAsciiList.ToCString();
+ pd << "] = geompy.GetGlueFaces(" << theShape << ", " << theTolerance << ")";
+ }
SetErrorCode(OK);
//=============================================================================
/*!
- * NumberOfFaces
+ * NumberOfSubShapes
*/
//=============================================================================
-Standard_Integer GEOMImpl_IShapesOperations::NumberOfFaces (Handle(GEOM_Object) theShape)
+Standard_Integer GEOMImpl_IShapesOperations::NumberOfSubShapes
+ (Handle(GEOM_Object) theShape,
+ const Standard_Integer theShapeType)
{
SetErrorCode(KO);
-
- Standard_Integer nb = 0;
+ Standard_Integer nbShapes = 0;
if (theShape.IsNull()) return -1;
TopoDS_Shape aShape = theShape->GetValue();
if (aShape.IsNull()) return -1;
+ /*
TopTools_MapOfShape mapShape;
- TopExp_Explorer exp (aShape, TopAbs_FACE);
- for (; exp.More(); exp.Next())
- if (mapShape.Add(exp.Current()))
- nb++;
-
- SetErrorCode(OK);
- return nb;
-}
-
-//=============================================================================
-/*!
- * NumberOfEdges
- */
-//=============================================================================
-Standard_Integer GEOMImpl_IShapesOperations::NumberOfEdges (Handle(GEOM_Object) theShape)
-{
- SetErrorCode(KO);
-
- Standard_Integer nb = 0;
-
- if (theShape.IsNull()) return -1;
- TopoDS_Shape aShape = theShape->GetValue();
- if (aShape.IsNull()) return -1;
+ if (aShape.ShapeType() == TopAbs_COMPOUND &&
+ (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
+ TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
+ TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND)) {
+ TopoDS_Iterator It (aShape, Standard_True, Standard_True);
+ for (; It.More(); It.Next()) {
+ if (mapShape.Add(It.Value())) {
+ if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
+ TopAbs_ShapeEnum(theShapeType) == It.Value().ShapeType()) {
+ nbShapes++;
+ }
+ }
+ }
+ } else {
+ TopExp_Explorer exp (aShape, TopAbs_ShapeEnum(theShapeType));
+ for (; exp.More(); exp.Next())
+ if (mapShape.Add(exp.Current()))
+ nbShapes++;
+ }
+ */
- TopTools_MapOfShape mapShape;
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ int iType, nbTypes [TopAbs_SHAPE];
+ for (iType = 0; iType < TopAbs_SHAPE; ++iType)
+ nbTypes[iType] = 0;
+ nbTypes[aShape.ShapeType()]++;
+
+ TopTools_MapOfShape aMapOfShape;
+ aMapOfShape.Add(aShape);
+ TopTools_ListOfShape aListOfShape;
+ aListOfShape.Append(aShape);
+
+ TopTools_ListIteratorOfListOfShape itL (aListOfShape);
+ for (; itL.More(); itL.Next()) {
+ TopoDS_Iterator it (itL.Value());
+ for (; it.More(); it.Next()) {
+ TopoDS_Shape s = it.Value();
+ if (aMapOfShape.Add(s)) {
+ aListOfShape.Append(s);
+ nbTypes[s.ShapeType()]++;
+ }
+ }
+ }
- TopExp_Explorer exp (aShape, TopAbs_EDGE);
- for (; exp.More(); exp.Next())
- if (mapShape.Add(exp.Current()))
- nb++;
+ if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE)
+ nbShapes = aMapOfShape.Extent();
+ else
+ nbShapes = nbTypes[theShapeType];
+ }
+ catch (Standard_Failure) {
+ Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+ SetErrorCode(aFail->GetMessageString());
+ return -1;
+ }
SetErrorCode(OK);
- return nb;
+ return nbShapes;
}
//=============================================================================
{
GProp_GProps theProps;
gp_Pnt aCenterMass;
- TopoDS_Shape aPntShape;
+ //TopoDS_Shape aPntShape;
Standard_Real aShapeSize;
if (aShape.ShapeType() == TopAbs_EDGE) BRepGProp::LinearProperties(aShape, theProps);
aCenterMass = theProps.CentreOfMass();
aShapeSize = theProps.Mass();
- aPntShape = BRepBuilderAPI_MakeVertex(aCenterMass).Shape();
- aVertex = BRep_Tool::Pnt( TopoDS::Vertex( aPntShape ) );
+// aPntShape = BRepBuilderAPI_MakeVertex(aCenterMass).Shape();
+// aVertex = BRep_Tool::Pnt( TopoDS::Vertex( aPntShape ) );
+ aVertex = aCenterMass;
tab[0] = aVertex.X();
tab[1] = aVertex.Y();
tab[2] = aVertex.Z();
return;
}
+namespace {
+
+ //================================================================================
+ /*!
+ * \brief Return normal to face at extrema point
+ */
+ //================================================================================
+
+ gp_Vec GetNormal(const TopoDS_Face& face, const BRepExtrema_DistShapeShape& extrema)
+ {
+ gp_Vec defaultNorm(1,0,0); // to have same normals on different faces
+ try {
+ // get UV at extrema point
+ Standard_Real u,v, f,l;
+ switch ( extrema.SupportTypeShape2(1) ) {
+ case BRepExtrema_IsInFace: {
+ extrema.ParOnFaceS2(1, u, v );
+ break;
+ }
+ case BRepExtrema_IsOnEdge: {
+ TopoDS_Edge edge = TopoDS::Edge( extrema.SupportOnShape2(1));
+ Handle(Geom2d_Curve) pcurve = BRep_Tool::CurveOnSurface( edge, face, f,l );
+ extrema.ParOnEdgeS2( 1, u );
+ gp_Pnt2d uv = pcurve->Value( u );
+ u = uv.Coord(1);
+ v = uv.Coord(2);
+ break;
+ }
+ case BRepExtrema_IsVertex: return defaultNorm;
+ }
+ // get derivatives
+ BRepAdaptor_Surface surface( face, false );
+ gp_Vec du, dv; gp_Pnt p;
+ surface.D1( u, v, p, du, dv );
+
+ return du ^ dv;
+
+ } catch (Standard_Failure ) {
+ }
+ return defaultNorm;
+ }
+}
+
//=============================================================================
/*!
- * GetInPlace
+ case GetInPlace:
+ default:
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object) theShapeWhere,
else if ( aWhat.ShapeType() == TopAbs_SOLID || aWhat.ShapeType() == TopAbs_COMPSOLID ) iType = TopAbs_SOLID;
else if ( aWhat.ShapeType() == TopAbs_COMPOUND ) {
// Only the iType of the first shape in the compound is taken into account
- TopoDS_Iterator It (aWhat, Standard_True, Standard_True);
+ TopoDS_Iterator It (aWhat, Standard_False, Standard_False);
+ if ( !It.More() ) {
+ SetErrorCode("Error: theShapeWhat is an empty COMPOUND.");
+ return NULL;
+ }
compType = It.Value().ShapeType();
if ( compType == TopAbs_EDGE || compType == TopAbs_WIRE ) iType = TopAbs_EDGE;
else if ( compType == TopAbs_FACE || compType == TopAbs_SHELL) iType = TopAbs_FACE;
aVertex = TopoDS::Vertex( aPntShape );
BRepExtrema_DistShapeShape aWhereDistance ( aVertex, Exp_aWhere.Current() );
BRepExtrema_DistShapeShape aWhatDistance ( aVertex, Exp_aWhat.Current() );
- if ( fabs(aWhereDistance.Value() - aWhatDistance.Value()) <= Tol_1D )
- isFound = true;
+ if ( aWhereDistance.IsDone() && aWhatDistance.IsDone() &&
+ fabs(aWhereDistance.Value() - aWhatDistance.Value()) <= Tol_1D )
+ {
+ // 0020162: "EDF 961 GEOM : Getinplace is getting additionnal orthogonal faces"
+ // aVertex must be projected to the same point on Where and on What
+ gp_Pnt pOnWhat = aWhatDistance.PointOnShape2(1);
+ gp_Pnt pOnWhere = aWhereDistance.PointOnShape2(1);
+ isFound = ( pOnWhat.Distance(pOnWhere) <= Tol_1D );
+ if ( isFound && iType == TopAbs_FACE )
+ {
+ // check normals at pOnWhat and pOnWhere
+ const double angleTol = PI/180.;
+ gp_Vec normToWhat = GetNormal( TopoDS::Face(Exp_aWhat.Current()), aWhatDistance);
+ gp_Vec normToWhere = GetNormal( TopoDS::Face(Exp_aWhere.Current()), aWhereDistance);
+ if ( normToWhat * normToWhere < 0 )
+ normToWhat.Reverse();
+ isFound = ( normToWhat.Angle( normToWhere ) < angleTol );
+ }
+ }
}
}
if ( isFound ) {