Implement improvement PAL9905: Incoherence in the GEOM API

This commit is contained in:
rnv 2006-09-27 11:04:58 +00:00
parent 6f6b0b4c18
commit 03ec0eb4cf
7 changed files with 333 additions and 4 deletions

View File

@ -884,7 +884,7 @@ module GEOM
/*!
* Create a face on the given wire.
* \param theWire Wire to build the face on.
* \param theWire closed Wire or Edge to build the face on.
* \param isPlanarWanted If TRUE, only planar face will be built.
* If impossible, NULL object will be returned.
* \return New GEOM_Object, containing the created face.
@ -893,7 +893,7 @@ module GEOM
/*!
* Create a face on the given wires set.
* \param theWires List of wires to build the face on.
* \param theWires List of closed wires or edges to build the face on.
* \param isPlanarWanted If TRUE, only planar face will be built.
* If impossible, NULL object will be returned.
* \return New GEOM_Object, containing the created face.
@ -1053,6 +1053,24 @@ module GEOM
in long theShapeType,
in GEOM_Object theAx1,
in shape_state theState);
/*!
* Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
* the specified plane by the certain way, defined through \a theState parameter.
* \param theShape Shape to find sub-shapes of.
* \param theShapeType Type of sub-shapes to be retrieved.
* \param theAx1 Vector (or line, or linear edge), specifying normal
* direction of the plane to find shapes on.
* \param thePnt Point specifying location of the plane to find shapes on.
* \param theState The state of the subshapes to find.
* \return List of all found sub-shapes.
*/
ListOfGO GetShapesOnPlaneWithLocation (in GEOM_Object theShape,
in long theShapeType,
in GEOM_Object theAx1,
in GEOM_Object thePnt,
in shape_state theState);
/*!
* Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
@ -1121,6 +1139,23 @@ module GEOM
in long theShapeType,
in GEOM_Object theAx1,
in shape_state theState);
/*!
* Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
* the specified plane by the certain way, defined through \a theState parameter.
* \param theShape Shape to find sub-shapes of.
* \param theShapeType Type of sub-shapes to be retrieved.
* \param theAx1 Vector (or line, or linear edge), specifying normal
* direction of the plane to find shapes on.
* \param thePnt Point specifying location of the plane to find shapes on.
* \param theState The state of the subshapes to find.
* \return List of IDs of all found sub-shapes.
*/
ListOfLong GetShapesOnPlaneWithLocationIDs (in GEOM_Object theShape,
in long theShapeType,
in GEOM_Object theAx1,
in GEOM_Object thePnt,
in shape_state theState);
/*!
* Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively

View File

@ -1417,6 +1417,80 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnPlan
return aSeq;
}
//=============================================================================
/*!
* GetShapesOnPlaneWithLocation
*/
//=============================================================================
Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnPlaneWithLocation
(const Handle(GEOM_Object)& theShape,
const Standard_Integer theShapeType,
const Handle(GEOM_Object)& theAx1,
const Handle(GEOM_Object)& thePnt,
const GEOMAlgo_State theState)
{
SetErrorCode(KO);
if (theShape.IsNull() || theAx1.IsNull() || thePnt.IsNull()) return NULL;
TopoDS_Shape aShape = theShape->GetValue();
TopoDS_Shape anAx1 = theAx1->GetValue();
TopoDS_Shape anPnt = thePnt->GetValue();
if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return NULL;
TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
if ( !checkTypeShapesOn( theShapeType ))
return NULL;
// Create plane
if ( anAx1.ShapeType() != TopAbs_EDGE || anPnt.ShapeType() != TopAbs_VERTEX ) return NULL;
TopoDS_Vertex V1, V2, V3;
TopoDS_Edge anEdge = TopoDS::Edge(anAx1);
TopExp::Vertices(anEdge, V1, V2, Standard_True);
if (V1.IsNull() || V2.IsNull()) {
SetErrorCode("Bad edge given for the plane normal vector");
return NULL;
}
V3 = TopoDS::Vertex(anPnt);
if(V3.IsNull()) {
SetErrorCode("Bad vertex given for the plane location");
return NULL;
}
gp_Pnt aLoc = BRep_Tool::Pnt(V3);
gp_Vec aVec(BRep_Tool::Pnt(V1),BRep_Tool::Pnt(V2));
if (aVec.Magnitude() < Precision::Confusion()) {
SetErrorCode("Vector with null magnitude given");
return NULL;
}
Handle(Geom_Surface) aPlane = new Geom_Plane(aLoc, aVec);
if ( aPlane.IsNull() )
return NULL;
// Find objects
TCollection_AsciiString anAsciiList;
Handle(TColStd_HSequenceOfTransient) aSeq;
aSeq = getShapesOnSurface( aPlane, theShape, aShapeType, theState, anAsciiList );
if ( aSeq.IsNull() || aSeq->Length() == 0 )
return NULL;
// Make a Python command
Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast( aSeq->Value( 1 ));
Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
GEOM::TPythonDump(aFunction) << "[" << anAsciiList.ToCString()
<< "] = geompy.GetShapesOnPlaneWithLocation(" << theShape << ", "
<< aShapeType << ", " << theAx1 << ", "<< thePnt <<", " << theState << ")";
SetErrorCode(OK);
return aSeq;
}
//=============================================================================
/*!
* GetShapesOnCylinder
@ -1565,6 +1639,73 @@ Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnPlaneI
return aSeq;
}
//=============================================================================
/*!
* GetShapesOnPlaneWithLocationIDs
*/
//=============================================================================
Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnPlaneWithLocationIDs
(const Handle(GEOM_Object)& theShape,
const Standard_Integer theShapeType,
const Handle(GEOM_Object)& theAx1,
const Handle(GEOM_Object)& thePnt,
const GEOMAlgo_State theState)
{
SetErrorCode(KO);
if (theShape.IsNull() || theAx1.IsNull() || thePnt.IsNull()) return NULL;
TopoDS_Shape aShape = theShape->GetValue();
TopoDS_Shape anAx1 = theAx1->GetValue();
TopoDS_Shape anPnt = thePnt->GetValue();
if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return NULL;
TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
if ( !checkTypeShapesOn( aShapeType ))
return NULL;
// Create plane
if (anAx1.ShapeType() != TopAbs_EDGE || anPnt.ShapeType() != TopAbs_VERTEX) return NULL;
TopoDS_Edge anEdge = TopoDS::Edge(anAx1);
TopoDS_Vertex V1, V2, V3;
TopExp::Vertices(anEdge, V1, V2, Standard_True);
if (V1.IsNull() || V2.IsNull()) {
SetErrorCode("Bad edge given for the plane normal vector");
return NULL;
}
V3 = TopoDS::Vertex(anPnt);
if(V3.IsNull()) {
SetErrorCode("Bad vertex given for the plane location");
return NULL;
}
gp_Pnt aLoc = BRep_Tool::Pnt(V3);
gp_Vec aVec(BRep_Tool::Pnt(V1),BRep_Tool::Pnt(V2));
if (aVec.Magnitude() < Precision::Confusion()) {
SetErrorCode("Vector with null magnitude given");
return NULL;
}
Handle(Geom_Surface) aPlane = new Geom_Plane(aLoc, aVec);
if ( aPlane.IsNull() )
return NULL;
// Find object IDs
Handle(TColStd_HSequenceOfInteger) aSeq;
aSeq = getShapesOnSurfaceIDs( aPlane, aShape, aShapeType, theState );
// The GetShapesOnPlaneIDs() doesn't change object so no new function is required.
Handle(GEOM_Function) aFunction = GEOM::GetCreatedLast(theShape,theAx1)->GetLastFunction();
// Make a Python command
GEOM::TPythonDump(aFunction, /*append=*/true)
<< "listShapesOnPlane = geompy.GetShapesOnPlaneWithLocationIDs"
<< "(" << theShape << ", " << aShapeType << ", " << theAx1 << ", "<< thePnt << ", " << theState << ")";
SetErrorCode(OK);
return aSeq;
}
//=============================================================================
/*!
* GetShapesOnCylinderIDs

View File

@ -97,6 +97,13 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations {
const Handle(GEOM_Object)& theAx1,
const GEOMAlgo_State theState);
Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetShapesOnPlaneWithLocation (const Handle(GEOM_Object)& theShape,
const Standard_Integer theShapeType,
const Handle(GEOM_Object)& theAx1,
const Handle(GEOM_Object)& thePnt,
const GEOMAlgo_State theState);
Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetShapesOnCylinder (const Handle(GEOM_Object)& theShape,
const Standard_Integer theShapeType,
const Handle(GEOM_Object)& theAxis,
@ -114,6 +121,12 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations {
const Handle(GEOM_Object)& theAx1,
const GEOMAlgo_State theState);
Standard_EXPORT Handle(TColStd_HSequenceOfInteger) GetShapesOnPlaneWithLocationIDs (const Handle(GEOM_Object)& theShape,
const Standard_Integer theShapeType,
const Handle(GEOM_Object)& theAx1,
const Handle(GEOM_Object)& thePnt,
const GEOMAlgo_State theState);
Standard_EXPORT Handle(TColStd_HSequenceOfInteger) GetShapesOnCylinderIDs (const Handle(GEOM_Object)& theShape,
const Standard_Integer theShapeType,
const Handle(GEOM_Object)& theAxis,

View File

@ -706,6 +706,49 @@ GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnPlane
return aSeq._retn();
}
//=============================================================================
/*!
* GetShapesOnPlaneWithLocation
*/
//=============================================================================
GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnPlaneWithLocation
(GEOM::GEOM_Object_ptr theShape,
const CORBA::Long theShapeType,
GEOM::GEOM_Object_ptr theAx1,
GEOM::GEOM_Object_ptr thePnt,
const GEOM::shape_state theState)
{
GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
//Set a not done flag
GetOperations()->SetNotDone();
if (theShape == NULL || theAx1 == NULL || thePnt == NULL) return aSeq._retn();
//Get the reference objects
Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
(theShape->GetStudyID(), theShape->GetEntry());
Handle(GEOM_Object) anAx1 = GetOperations()->GetEngine()->GetObject
(theAx1->GetStudyID(), theAx1->GetEntry());
Handle(GEOM_Object) anPnt = GetOperations()->GetEngine()->GetObject
(thePnt->GetStudyID(), thePnt->GetEntry());
if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return aSeq._retn();
//Get Shapes On Plane
Handle(TColStd_HSequenceOfTransient) aHSeq =
GetOperations()->GetShapesOnPlaneWithLocation(aShape, theShapeType, anAx1, anPnt, ShapeState(theState));
if (!GetOperations()->IsDone() || aHSeq.IsNull())
return aSeq._retn();
Standard_Integer aLength = aHSeq->Length();
aSeq->length(aLength);
for (Standard_Integer i = 1; i <= aLength; i++)
aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
return aSeq._retn();
}
//=============================================================================
/*!
* GetShapesOnCylinder
@ -889,6 +932,49 @@ GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnPlaneIDs
return aSeq._retn();
}
//=============================================================================
/*!
* GetShapesOnPlaneWithLocationIDs
*/
//=============================================================================
GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnPlaneWithLocationIDs
(GEOM::GEOM_Object_ptr theShape,
const CORBA::Long theShapeType,
GEOM::GEOM_Object_ptr theAx1,
GEOM::GEOM_Object_ptr thePnt,
const GEOM::shape_state theState)
{
GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
//Set a not done flag
GetOperations()->SetNotDone();
if (theShape == NULL || theAx1 == NULL || thePnt == NULL) return aSeq._retn();
//Get the reference objects
Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
(theShape->GetStudyID(), theShape->GetEntry());
Handle(GEOM_Object) anAx1 = GetOperations()->GetEngine()->GetObject
(theAx1->GetStudyID(), theAx1->GetEntry());
Handle(GEOM_Object) anPnt = GetOperations()->GetEngine()->GetObject
(thePnt->GetStudyID(), thePnt->GetEntry());
if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return aSeq._retn();
//Get Shapes On Plane
Handle(TColStd_HSequenceOfInteger) aHSeq =
GetOperations()->GetShapesOnPlaneWithLocationIDs(aShape, theShapeType, anAx1, anPnt, ShapeState(theState));
if (!GetOperations()->IsDone() || aHSeq.IsNull())
return aSeq._retn();
Standard_Integer aLength = aHSeq->Length();
aSeq->length(aLength);
for (Standard_Integer i = 1; i <= aLength; i++)
aSeq[i-1] = aHSeq->Value(i);
return aSeq._retn();
}
//=============================================================================
/*!
* GetShapesOnCylinderIDs

View File

@ -97,6 +97,12 @@ class GEOM_IShapesOperations_i :
GEOM::GEOM_Object_ptr theAx1,
GEOM::shape_state theState);
GEOM::ListOfGO* GetShapesOnPlaneWithLocation(GEOM::GEOM_Object_ptr theShape,
CORBA::Long theShapeType,
GEOM::GEOM_Object_ptr theAx1,
GEOM::GEOM_Object_ptr thePnt,
GEOM::shape_state theState);
GEOM::ListOfGO* GetShapesOnCylinder (GEOM::GEOM_Object_ptr theShape,
CORBA::Long theShapeType,
GEOM::GEOM_Object_ptr theAxis,
@ -122,6 +128,12 @@ class GEOM_IShapesOperations_i :
GEOM::GEOM_Object_ptr theAx1,
GEOM::shape_state theState);
GEOM::ListOfLong* GetShapesOnPlaneWithLocationIDs (GEOM::GEOM_Object_ptr theShape,
CORBA::Long theShapeType,
GEOM::GEOM_Object_ptr theAx1,
GEOM::GEOM_Object_ptr thePnt,
GEOM::shape_state theState);
GEOM::ListOfLong* GetShapesOnCylinderIDs (GEOM::GEOM_Object_ptr theShape,
CORBA::Long theShapeType,
GEOM::GEOM_Object_ptr theAxis,

View File

@ -303,6 +303,7 @@ def TestOtherOperations (geompy, math):
v_n0p = geompy.MakeVectorDXDYDZ(-1, 0, 1)
v_pp0 = geompy.MakeVectorDXDYDZ( 1, 1, 0)
v_np0 = geompy.MakeVectorDXDYDZ(-1, 1, 0)
v_0n0 = geompy.MakeVectorDXDYDZ( 0, -1, 0)
pln_0pp = geompy.MakePlane(p0, v_0pp, 300)
pln_0np = geompy.MakePlane(p0, v_0np, 300)
@ -418,6 +419,20 @@ def TestOtherOperations (geompy, math):
geompy.UnionIDs(faces_above, faces_above_pln_ids)
geompy.addToStudy(faces_above, "Group of faces above Plane (N = (0, 1, 1))")
# GetShapesOnPlaneWithLocation
Loc = geompy.MakeVertex(0, -50, 0)
edges_on_pln = geompy.GetShapesOnPlaneWithLocation(blocksComp, geompy.ShapeType["EDGE"],
v_0n0, Loc, geompy.GEOM.ST_ON)
for edge_i in edges_on_pln:
geompy.addToStudy(edge_i, "Edge on Plane (N = (0, -1, 0) & Location = (0, -50, 0)")
# GetShapesOnPlaneWithLocationIDs
edges_on_pln_ids = geompy.GetShapesOnPlaneWithLocationIDs(blocksComp, geompy.ShapeType["EDGE"],
v_0n0, Loc, geompy.GEOM.ST_ON)
group_edges_on_pln = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
geompy.UnionIDs(group_edges_on_pln, edges_on_pln_ids)
geompy.addToStudy(group_edges_on_pln, "Group of edges on Plane (N = (0, -1, 0) & Location = (0, -50, 0))")
# GetShapesOnCylinder
edges_out_cyl = geompy.GetShapesOnCylinder(blocksComp, geompy.ShapeType["EDGE"],
vy, 55, geompy.GEOM.ST_OUT)

View File

@ -744,7 +744,7 @@ def MakeWire(theEdgesAndWires):
return anObj
## Create a face on the given wire.
# @param theWire Wire to build the face on.
# @param theWire closed Wire or Edge to build the face on.
# @param isPlanarWanted If TRUE, only planar face will be built.
# If impossible, NULL object will be returned.
# @return New GEOM_Object, containing the created face.
@ -757,7 +757,7 @@ def MakeFace(theWire, isPlanarWanted):
return anObj
## Create a face on the given wires set.
# @param theWires List of wires to build the face on.
# @param theWires List of closed wires or edges to build the face on.
# @param isPlanarWanted If TRUE, only planar face will be built.
# If impossible, NULL object will be returned.
# @return New GEOM_Object, containing the created face.
@ -900,6 +900,33 @@ def GetShapesOnPlaneIDs(theShape, theShapeType, theAx1, theState):
print "GetShapesOnPlaneIDs : ", ShapesOp.GetErrorCode()
return aList
## Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
# the specified plane by the certain way, defined through \a theState parameter.
# @param theShape Shape to find sub-shapes of.
# @param theShapeType Type of sub-shapes to be retrieved.
# @param theAx1 Vector (or line, or linear edge), specifying normal
# direction of the plane to find shapes on.
# @param thePnt Point specifying location of the plane to find shapes on.
# @param theState The state of the subshapes to find. It can be one of
# ST_ON, ST_OUT, ST_ONOUT, ST_IN, ST_ONIN.
# @return List of all found sub-shapes.
#
# Example: see GEOM_TestOthers.py
def GetShapesOnPlaneWithLocation(theShape, theShapeType, theAx1, thePnt, theState):
aList = ShapesOp.GetShapesOnPlaneWithLocation(theShape, theShapeType, theAx1, thePnt, theState)
if ShapesOp.IsDone() == 0:
print "GetShapesOnPlaneWithLocation : ", ShapesOp.GetErrorCode()
return aList
## Works like the above method, but returns list of sub-shapes indices
#
# Example: see GEOM_TestOthers.py
def GetShapesOnPlaneWithLocationIDs(theShape, theShapeType, theAx1, thePnt, theState):
aList = ShapesOp.GetShapesOnPlaneWithLocationIDs(theShape, theShapeType, theAx1, thePnt, theState)
if ShapesOp.IsDone() == 0:
print "GetShapesOnPlaneWithLocationIDs : ", ShapesOp.GetErrorCode()
return aList
## Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
# the specified cylinder by the certain way, defined through \a theState parameter.
# @param theShape Shape to find sub-shapes of.