mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-26 08:00:34 +05:00
[bos #29603][EDF](2024-T1) Create group: don't find all subshapes.
Add new GetInPlaceCombined method, which combines results of GetInPlace(_) (the "new" one) and GetInPlaceByHistory(_).
This commit is contained in:
parent
55b640ee17
commit
d42545a1e4
@ -2697,6 +2697,17 @@ module GEOM
|
||||
in short theShapeType,
|
||||
in shape_state theState);
|
||||
|
||||
/*!
|
||||
* \brief Get sub-shape(s) of \a theShapeWhere, which are coincident with \a theShapeWhat or could be a part of it.
|
||||
* Combines results of new GetInPlace(_) and GetInPlaceByHistory(_).
|
||||
* \param theShapeWhere Shape to find sub-shapes of.
|
||||
* \param theShapeWhat Shape, specifying what to find.
|
||||
* \return Compound which includes all found sub-shapes if they have different types;
|
||||
* or group of all found shapes of the equal type; or a single found sub-shape.
|
||||
*/
|
||||
GEOM_Object GetInPlaceCombined (in GEOM_Object theShapeWhere,
|
||||
in GEOM_Object theShapeWhat);
|
||||
|
||||
/*!
|
||||
* \brief Get sub-shape(s) of \a theShapeWhere, which are
|
||||
* coincident with \a theShapeWhat or could be a part of it.
|
||||
|
@ -4538,6 +4538,137 @@ Handle(TColStd_HSequenceOfInteger)
|
||||
return aSeqOfIDs;
|
||||
}
|
||||
|
||||
|
||||
Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlaceCombined(
|
||||
Handle(GEOM_Object) theShapeWhere,
|
||||
Handle(GEOM_Object) theShapeWhat)
|
||||
{
|
||||
SetErrorCode(KO);
|
||||
|
||||
if (theShapeWhere.IsNull() || theShapeWhat.IsNull())
|
||||
return NULL;
|
||||
|
||||
TopoDS_Shape aWhere = theShapeWhere->GetValue();
|
||||
TopoDS_Shape aWhat = theShapeWhat->GetValue();
|
||||
|
||||
if (aWhere.IsNull() || aWhat.IsNull()) {
|
||||
SetErrorCode("Error: aWhere and aWhat TopoDS_Shape are Null.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Type of shape to be returned. */
|
||||
Standard_Integer aResultShapeType = -1;
|
||||
/** Return value is a wrapped array of shapes. The map maintains uniqueness of the array content. */
|
||||
TopTools_MapOfShape aResultShapes;
|
||||
|
||||
/** Return value is a wrapped array of shapes. The list maintains order of the array content as in return value of GEOMImpl_IShapesOperations::GetInPlace(_). */
|
||||
TopTools_ListOfShape aResultShapeList;
|
||||
|
||||
|
||||
// Fill array of Where's indices.
|
||||
TopTools_IndexedMapOfShape aWhereIndices;
|
||||
TopExp::MapShapes(aWhere, aWhereIndices);
|
||||
|
||||
|
||||
{ // Search for the sub-shapes inside the aWhere shape using InPlace algorithm.
|
||||
GEOMAlgo_GetInPlace aGIP;
|
||||
if (!GEOMAlgo_GetInPlaceAPI::GetInPlace(aWhere, aWhat, aGIP)) {
|
||||
SetErrorCode("Error in GEOMAlgo_GetInPlace");
|
||||
return NULL;
|
||||
}
|
||||
const TopoDS_Shape& aGIPResult = aGIP.Result();
|
||||
|
||||
|
||||
if (!aGIPResult.IsNull()) {
|
||||
for (TopoDS_Iterator anIt(aGIPResult); anIt.More(); anIt.Next()) {
|
||||
const TopoDS_Shape& aGIPResultSubShape = anIt.Value();
|
||||
|
||||
if (aWhereIndices.Contains(aGIPResultSubShape) && aResultShapes.Add(aGIPResultSubShape)) {
|
||||
const TopAbs_ShapeEnum aType = aGIPResultSubShape.ShapeType();
|
||||
|
||||
if (aResultShapeType == -1) {
|
||||
// Initialization.
|
||||
aResultShapeType = aType;
|
||||
} else if (aResultShapeType != TopAbs_SHAPE && aResultShapeType != aType) {
|
||||
// Different types.
|
||||
aResultShapeType = TopAbs_SHAPE;
|
||||
}
|
||||
|
||||
aResultShapeList.Append(aGIPResultSubShape);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // Search for the sub-shapes inside the aWhere shape using InPlace algorithm.
|
||||
|
||||
{ // Search for the sub-shapes inside the aWhere shape using InPlaceByHistory algorithm.
|
||||
Handle(GEOM_Function) aWhereFunction = theShapeWhere->GetLastFunction();
|
||||
if (aWhereFunction.IsNull() && aResultShapes.IsEmpty()) {
|
||||
SetErrorCode("Error: Both GetInPlace and GetInPlaceByHistory algorithms found no shapes.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TopTools_ListOfShape aGIPBHShapeList;
|
||||
const bool isFound = GEOMAlgo_GetInPlaceAPI::GetInPlaceByHistory(aWhereFunction, aWhereIndices, aWhat, aGIPBHShapeList);
|
||||
if ( (!isFound || aGIPBHShapeList.Extent() < 1) && aResultShapes.IsEmpty() ) {
|
||||
SetErrorCode("Error: Both GetInPlace and GetInPlaceByHistory algorithms found no shapes.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (TopTools_ListIteratorOfListOfShape anItGIPBHShapeList(aGIPBHShapeList); anItGIPBHShapeList.More(); anItGIPBHShapeList.Next()) {
|
||||
const TopoDS_Shape& aGIPBHResultShape = anItGIPBHShapeList.Value();
|
||||
|
||||
if (aWhereIndices.Contains(aGIPBHResultShape) && aResultShapes.Add(aGIPBHResultShape)) {
|
||||
const TopAbs_ShapeEnum aType = aGIPBHResultShape.ShapeType();
|
||||
|
||||
if (aResultShapeType == -1) {
|
||||
// Initialization.
|
||||
aResultShapeType = aType;
|
||||
} else if (aResultShapeType != TopAbs_SHAPE && aResultShapeType != aType) {
|
||||
// Different types.
|
||||
aResultShapeType = TopAbs_SHAPE;
|
||||
}
|
||||
|
||||
aResultShapeList.Append(aGIPBHResultShape);
|
||||
}
|
||||
}
|
||||
} // Search for the sub-shapes inside the aWhere shape using InPlaceByHistory algorithm.
|
||||
|
||||
Handle(TColStd_HArray1OfInteger) aResultShapeArray = new TColStd_HArray1OfInteger (1, aResultShapeList.Extent());
|
||||
TopTools_ListIteratorOfListOfShape anItResultShapeList(aResultShapeList);
|
||||
for (Standard_Integer arrIdx = 1; anItResultShapeList.More(); anItResultShapeList.Next(), arrIdx++) {
|
||||
aResultShapeArray->SetValue(arrIdx, aWhereIndices.FindIndex(anItResultShapeList.Value()));
|
||||
}
|
||||
|
||||
//Add a new object
|
||||
Handle(GEOM_Object) aResult = GetEngine()->AddSubShape(theShapeWhere, aResultShapeArray);
|
||||
if (aResult.IsNull()) {
|
||||
SetErrorCode("Error in algorithm: result found, but cannot be returned.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const Standard_Boolean isSameType = (aResultShapeType != TopAbs_SHAPE);
|
||||
|
||||
if ((aResultShapeArray->Length() > 1 && isSameType) || theShapeWhat->GetType() == GEOM_GROUP) {
|
||||
//Set a GROUP type
|
||||
aResult->SetType(GEOM_GROUP);
|
||||
|
||||
//Set a sub-shape type
|
||||
TopoDS_Shape aFirstFound = aResultShapeList.First();
|
||||
TopAbs_ShapeEnum aShapeType = aFirstFound.ShapeType();
|
||||
|
||||
TDF_Label aFreeLabel = aResult->GetFreeLabel();
|
||||
TDataStd_Integer::Set(aFreeLabel, (Standard_Integer)aShapeType);
|
||||
}
|
||||
|
||||
//Make a Python command
|
||||
Handle(GEOM_Function) aFunction = aResult->GetFunction(1);
|
||||
GEOM::TPythonDump(aFunction) << aResult << " = geompy.GetInPlaceCombined(" << theShapeWhere << ", " << theShapeWhat << ")";
|
||||
|
||||
SetErrorCode(OK);
|
||||
return aResult;
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
/*!
|
||||
* case GetInPlace:
|
||||
|
@ -332,6 +332,12 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations
|
||||
Handle(GEOM_Object) theCenter,
|
||||
const Standard_Real theRadius);
|
||||
|
||||
/*! \returns Combined result of GetInPlace(_) and GetInPlaceByHistory(_). */
|
||||
Standard_EXPORT Handle(GEOM_Object) GetInPlaceCombined( Handle(GEOM_Object) theShapeWhere,
|
||||
Handle(GEOM_Object) theShapeWhat);
|
||||
|
||||
/*! \brief If theShapeWhere has curved subshapes, and centers of mass of these subshapes are closer
|
||||
* to theShapeWhat than to subshapes themselves, such subshapes are not included into result.*/
|
||||
Standard_EXPORT Handle(GEOM_Object) GetInPlace (Handle(GEOM_Object) theShapeWhere,
|
||||
Handle(GEOM_Object) theShapeWhat);
|
||||
|
||||
|
@ -1952,6 +1952,36 @@ GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnShapeIDs
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
/*!
|
||||
* GetInPlaceCombined
|
||||
*/
|
||||
//=============================================================================
|
||||
GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetInPlaceCombined(
|
||||
GEOM::GEOM_Object_ptr theShapeWhere,
|
||||
GEOM::GEOM_Object_ptr theShapeWhat
|
||||
) {
|
||||
GEOM::GEOM_Object_var aGEOMObject;
|
||||
|
||||
//Set a not done flag
|
||||
GetOperations()->SetNotDone();
|
||||
|
||||
//Get the reference objects
|
||||
Handle(::GEOM_Object) aShapeWhere = GetObjectImpl(theShapeWhere);
|
||||
Handle(::GEOM_Object) aShapeWhat = GetObjectImpl(theShapeWhat);
|
||||
|
||||
if (aShapeWhere.IsNull() ||
|
||||
aShapeWhat.IsNull()) return aGEOMObject._retn();
|
||||
|
||||
//Get Shapes in place of aShapeWhat
|
||||
Handle(::GEOM_Object) anObject = GetOperations()->GetInPlaceCombined(aShapeWhere, aShapeWhat);
|
||||
if (!GetOperations()->IsDone() || anObject.IsNull())
|
||||
return aGEOMObject._retn();
|
||||
|
||||
return GetObject(anObject);
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
/*!
|
||||
* GetInPlace
|
||||
|
@ -275,6 +275,9 @@ class GEOM_I_EXPORT GEOM_IShapesOperations_i :
|
||||
CORBA::Short theShapeType,
|
||||
GEOM::shape_state theState);
|
||||
|
||||
GEOM::GEOM_Object_ptr GetInPlaceCombined (GEOM::GEOM_Object_ptr theShapeWhere,
|
||||
GEOM::GEOM_Object_ptr theShapeWhat);
|
||||
|
||||
GEOM::GEOM_Object_ptr GetInPlace (GEOM::GEOM_Object_ptr theShapeWhere,
|
||||
GEOM::GEOM_Object_ptr theShapeWhat);
|
||||
|
||||
|
@ -6052,6 +6052,47 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
|
||||
RaiseIfFailed("GetShapesOnShapeIDs", self.ShapesOp)
|
||||
return aList
|
||||
|
||||
|
||||
## Get sub-shape(s) of theShapeWhere, which are
|
||||
# coincident with \a theShapeWhat or could be a part of it.
|
||||
# @param theShapeWhere Shape to find sub-shapes of.
|
||||
# @param theShapeWhat Shape, specifying what to find.
|
||||
# for result publication in the study. Otherwise, if automatic
|
||||
# publication is switched on, default value is used for result name.
|
||||
#
|
||||
# @return Compound which includes all found sub-shapes if they have different types;
|
||||
# or group of all found shapes of the equal type; or a single found sub-shape.
|
||||
#
|
||||
# @note Combines results of new GetInPlace(_) and GetInPlaceByHistory(_).
|
||||
#
|
||||
# @ref swig_GetInPlace "Example"
|
||||
@ManageTransactions("ShapesOp")
|
||||
def GetInPlaceCombined(self, theShapeWhere, theShapeWhat, theName=None):
|
||||
"""
|
||||
Get sub-shape(s) of theShapeWhere, which are
|
||||
coincident with theShapeWhat or could be a part of it.
|
||||
|
||||
Parameters:
|
||||
theShapeWhere Shape to find sub-shapes of.
|
||||
theShapeWhat Shape, specifying what to find.
|
||||
theName Object name; when specified, this parameter is used
|
||||
for result publication in the study. Otherwise, if automatic
|
||||
publication is switched on, default value is used for result name.
|
||||
|
||||
Returns:
|
||||
Compound which includes all found sub-shapes if they have different types;
|
||||
or group of all found shapes of the equal type; or a single found sub-shape.
|
||||
|
||||
Note:
|
||||
Combines results of new GetInPlace(_) and GetInPlaceByHistory(_).
|
||||
"""
|
||||
anObj = self.ShapesOp.GetInPlaceCombined(theShapeWhere, theShapeWhat)
|
||||
|
||||
RaiseIfFailed("GetInPlaceCombined", self.ShapesOp)
|
||||
self._autoPublish(anObj, theName, "inplace")
|
||||
return anObj
|
||||
|
||||
|
||||
## Get sub-shape(s) of theShapeWhere, which are
|
||||
# coincident with \a theShapeWhat or could be a part of it.
|
||||
# @param theShapeWhere Shape to find sub-shapes of.
|
||||
|
Loading…
Reference in New Issue
Block a user