From: jfa Date: Wed, 13 Dec 2006 09:40:11 +0000 (+0000) Subject: Add new idl function GEOM_IBooleanOperations::MakePartitionNonSelfIntersectedShape... X-Git-Tag: NPAL14357 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=da257d8d0634353fccde683e9c2f72320dfd8df1;p=modules%2Fgeom.git Add new idl function GEOM_IBooleanOperations::MakePartitionNonSelfIntersectedShape to provide correct publishing in study of a partition arguments and also to provide homogeneous behaviour of Partition in GUI and in python scripts. --- diff --git a/doc/salome/gui/GEOM/geompy_doc/namespacegeompy.html b/doc/salome/gui/GEOM/geompy_doc/namespacegeompy.html index d82d96d09..4cc08c421 100644 --- a/doc/salome/gui/GEOM/geompy_doc/namespacegeompy.html +++ b/doc/salome/gui/GEOM/geompy_doc/namespacegeompy.html @@ -219,9 +219,18 @@ def GetShapesOnQuadrangleIDs  Works like the above method, but returns list of sub-shapes indices.
+def GetShapesOnBox + + Find in theShape all sub-shapes of type theShapeType, situated relatively the specified theBox by the certain way, defined through theState parameter.
+def GetShapesOnBoxIDs + + Works like the above method, but returns list of sub-shapes indices.
def GetInPlace  Get sub-shape(s) of theShapeWhere, which are coincident with theShapeWhat or could be a part of it.
+def GetSame + + Get sub-shape of theShapeWhere, which is equal to theShapeWhat.
def GetSubShape  Obtain a composite sub-shape of <aShape>, composed from sub-shapes of <aShape>, selected by their unique IDs inside <aShape>.
@@ -306,9 +315,9 @@ def MakePartition  Perform partition operation.
-def MakePartitionNonSelfIntersectedShape +def MakePartitionNonSelfIntersectedShape - Perform partition operation.
+ Perform partition operation.
def Partition  Shortcut to MakePartition().
@@ -3934,6 +3943,113 @@ Example: see GEOM_TestOthers.py Example: see GEOM_TestOthers.py +

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
def geompy::GetShapesOnBox   theBox,
  theShape,
  theShapeType,
  theState
+
+ + + + + +
+   + + +

+

Parameters:
+ + + + + +
theBox Shape for relative comparing.
theShape Shape to find sub-shapes of.
theShapeType Type of sub-shapes to be retrieved.
theState The state of the subshapes to find. It can be one of ST_ON, ST_OUT, ST_ONOUT, ST_IN, ST_ONIN.
+
+
Returns:
List of all found sub-shapes.
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
def geompy::GetShapesOnBoxIDs   theBox,
  theShape,
  theShapeType,
  theState
+
+ + + + + +
+   + + +

+

@@ -3978,6 +4094,50 @@ Example: see GEOM_TestOthers.py Example: see GEOM_TestOthers.py
+

+ + + + +
+ + + + + + + + + + + + + + + + + + +
def geompy::GetSame   theShapeWhere,
  theShapeWhat
+
+ + + + + +
+   + + +

+

Parameters:
+ + + +
theShapeWhere Shape to find sub-shape of.
theShapeWhat Shape, specifying what to find.
+
+
Returns:
New GEOM_Object for found sub-shape.
+

@@ -5208,13 +5368,13 @@ Example: see GEOM_TestOthers.py
+
ListShapes Shapes to be intersected.
ListTools Shapes to intersect theShapes. !!!NOTE: Each compound from ListShapes and ListTools will be exploded in order to avoid possible intersection between shapes from this compound.
Limit Type of resulting shapes (corresponding to TopAbs_ShapeEnum).
After implementation new version of PartitionAlgo (October 2006) other parameters are ignored by current functionality. They are kept in this function only for support old versions. Ignored parameters:

Parameters:
-
ListKeepInside Shapes, outside which the results will be deleted. Each shape from theKeepInside must belong to theShapes also.
ListRemoveInside Shapes, inside which the results will be deleted. Each shape from theRemoveInside must belong to theShapes also.
Limit Type of resulting shapes (corresponding to TopAbs_ShapeEnum).
RemoveWebs If TRUE, perform Glue 3D algorithm.
ListMaterials Material indices for each shape. Make sence, only if theRemoveWebs is TRUE.
@@ -5223,7 +5383,7 @@ After implementation new version of PartitionAlgo (October 2006) other parameter Example: see GEOM_TestAll.py -

+

This method may be useful if it is needed to make a partition for compound contains nonintersected shapes. Performance will be better since intersection between shapes from compound is not performed.

Description of all parameters as in previous method MakePartition()

-!!!NOTE: Compounds from ListShapes can not have intersections with each other and compounds from ListTools can not have intersections with each other.

+!!!NOTE: Passed compounds (via ListShapes or via ListTools) have to consist of nonintersecting shapes.

Returns:
New GEOM_Object, containing the result shapes.
diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index b617b3c0f..59f490e7f 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -1645,13 +1645,21 @@ module GEOM * Perform partition operation. * \param theShapes Shapes to be intersected. * \param theTools Shapes to intersect theShapes. + * \note Each compound from ListShapes and ListTools will be exploded in order + * to avoid possible intersection between shapes from this compound. + * \param theLimit Type of resulting shapes (corresponding to TopAbs_ShapeEnum). + * + * After implementation new version of PartitionAlgo (October 2006) + * other parameters are ignored by current functionality. They are kept + * in this function only for supporting old versions. + * Ignored parameters: * \param theKeepInside Shapes, outside which the results will be deleted. * Each shape from theKeepInside must belong to theShapes also. * \param theRemoveInside Shapes, inside which the results will be deleted. * Each shape from theRemoveInside must belong to theShapes also. - * \param theLimit Type of resulting shapes (corresponding to TopAbs_ShapeEnum). * \param theRemoveWebs If TRUE, perform Glue 3D algorithm. * \param theMaterials Material indices for each shape. Make sence, only if theRemoveWebs is TRUE. + * * \return New GEOM_Object, containing the result shapes. */ GEOM_Object MakePartition (in ListOfGO theShapes, @@ -1662,6 +1670,27 @@ module GEOM in boolean theRemoveWebs, in ListOfLong theMaterials); + /*! + * Perform partition operation. + * This method may be usefull if it is needed to make a partition for + * a compound containing nonintersected shapes. Performance will be better + * since intersection between shapes from compound is not performed. + * + * Description of all parameters as in previous method MakePartition() + * + * \note Passed compounds (via ListShapes or via ListTools) + * have to consist of nonintersecting shapes. + * + * \return New GEOM_Object, containing the result shapes. + */ + GEOM_Object MakePartitionNonSelfIntersectedShape (in ListOfGO theShapes, + in ListOfGO theTools, + in ListOfGO theKeepInside, + in ListOfGO theRemoveInside, + in short theLimit, + in boolean theRemoveWebs, + in ListOfLong theMaterials); + /*! * Perform partition of the Shape with the Plane * \param theShape Shape to be intersected. diff --git a/src/GEOMImpl/GEOMImpl_IBooleanOperations.cxx b/src/GEOMImpl/GEOMImpl_IBooleanOperations.cxx index bedeef3df..d2753622d 100644 --- a/src/GEOMImpl/GEOMImpl_IBooleanOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IBooleanOperations.cxx @@ -1,22 +1,23 @@ // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include #include @@ -44,7 +45,7 @@ * constructor: */ //============================================================================= -GEOMImpl_IBooleanOperations::GEOMImpl_IBooleanOperations (GEOM_Engine* theEngine, int theDocID) +GEOMImpl_IBooleanOperations::GEOMImpl_IBooleanOperations (GEOM_Engine* theEngine, int theDocID) : GEOM_IOperations(theEngine, theDocID) { MESSAGE("GEOMImpl_IBooleanOperations::GEOMImpl_IBooleanOperations"); @@ -73,10 +74,10 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean (Handle(GEOM_Object SetErrorCode(KO); if (theShape1.IsNull() || theShape2.IsNull()) return NULL; - - //Add a new Boolean object + + //Add a new Boolean object Handle(GEOM_Object) aBool = GetEngine()->AddObject(GetDocID(), GEOM_BOOLEAN); - + //Add a new Boolean function Handle(GEOM_Function) aFunction; if (theOp == 1) { @@ -92,10 +93,10 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean (Handle(GEOM_Object if (aFunction.IsNull()) return NULL; //Check if the function is set correctly - if (aFunction->GetDriverGUID() != GEOMImpl_BooleanDriver::GetID()) return NULL; + if (aFunction->GetDriverGUID() != GEOMImpl_BooleanDriver::GetID()) return NULL; GEOMImpl_IBoolean aCI (aFunction); - + Handle(GEOM_Function) aRef1 = theShape1->GetLastFunction(); Handle(GEOM_Function) aRef2 = theShape2->GetLastFunction(); @@ -131,7 +132,7 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean (Handle(GEOM_Object pd << theShape1 << ", " << theShape2 << ")"; SetErrorCode(OK); - return aBool; + return aBool; } //============================================================================= @@ -140,31 +141,32 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean (Handle(GEOM_Object */ //============================================================================= Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakePartition - (const Handle(TColStd_HSequenceOfTransient)& theShapes, + (const Handle(TColStd_HSequenceOfTransient)& theShapes, const Handle(TColStd_HSequenceOfTransient)& theTools, const Handle(TColStd_HSequenceOfTransient)& theKeepIns, const Handle(TColStd_HSequenceOfTransient)& theRemoveIns, - const Standard_Integer theLimit, - const Standard_Boolean theRemoveWebs, - const Handle(TColStd_HArray1OfInteger)& theMaterials) + const Standard_Integer theLimit, + const Standard_Boolean theRemoveWebs, + const Handle(TColStd_HArray1OfInteger)& theMaterials, + const Standard_Boolean thePerformSelfIntersections) { SetErrorCode(KO); - //Add a new Partition object + //Add a new Partition object Handle(GEOM_Object) aPartition = GetEngine()->AddObject(GetDocID(), GEOM_PARTITION); - + //Add a new Partition function - Handle(GEOM_Function) aFunction = - aPartition->AddFunction(GEOMImpl_PartitionDriver::GetID(), PARTITION_PARTITION); + Handle(GEOM_Function) aFunction; + if (thePerformSelfIntersections) + aFunction = aPartition->AddFunction(GEOMImpl_PartitionDriver::GetID(), PARTITION_PARTITION); + else + aFunction = aPartition->AddFunction(GEOMImpl_PartitionDriver::GetID(), PARTITION_NO_SELF_INTERSECTIONS); if (aFunction.IsNull()) return NULL; //Check if the function is set correctly - if (aFunction->GetDriverGUID() != GEOMImpl_PartitionDriver::GetID()) return NULL; + if (aFunction->GetDriverGUID() != GEOMImpl_PartitionDriver::GetID()) return NULL; GEOMImpl_IPartition aCI (aFunction); - -// int aLen = theShapes.size(); -// aCI.SetLength(aLen); Handle(TColStd_HSequenceOfTransient) aShapesSeq = new TColStd_HSequenceOfTransient; Handle(TColStd_HSequenceOfTransient) aToolsSeq = new TColStd_HSequenceOfTransient; @@ -278,15 +280,19 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakePartition return NULL; } - //Make a Python command + //Make a Python command GEOM::TPythonDump pd (aFunction); - pd << aPartition << " = geompy.MakePartition(["; + if (thePerformSelfIntersections) + pd << aPartition << " = geompy.MakePartition(["; + else + pd << aPartition << " = geompy.MakePartitionNonSelfIntersectedShape(["; + // Shapes, Tools pd << aShapesDescr.ToCString() << "], [" << aToolsDescr.ToCString() << "], ["; // Keep Ins, Remove Ins pd << aKeepInsDescr.ToCString() << "], [" << aRemoveInsDescr.ToCString() << "], "; // Limit, Remove Webs - pd << theLimit << ", " << (int)theRemoveWebs << ", ["; + pd << TopAbs_ShapeEnum(theLimit) << ", " << (int)theRemoveWebs << ", ["; // Materials if (!theMaterials.IsNull() && theMaterials->Length() > 0) { int i = theMaterials->Lower(); @@ -299,7 +305,7 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakePartition pd << "])"; SetErrorCode(OK); - return aPartition; + return aPartition; } //============================================================================= @@ -313,20 +319,20 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeHalfPartition SetErrorCode(KO); if (theShape.IsNull() || thePlane.IsNull()) return NULL; - - //Add a new Boolean object - Handle(GEOM_Object) aPart = GetEngine()->AddObject(GetDocID(), GEOM_BOOLEAN); - + + //Add a new Boolean object + Handle(GEOM_Object) aPart = GetEngine()->AddObject(GetDocID(), GEOM_PARTITION); + //Add a new Partition function Handle(GEOM_Function) aFunction = aPart->AddFunction(GEOMImpl_PartitionDriver::GetID(), PARTITION_HALF); if (aFunction.IsNull()) return NULL; //Check if the function is set correctly - if (aFunction->GetDriverGUID() != GEOMImpl_PartitionDriver::GetID()) return NULL; + if (aFunction->GetDriverGUID() != GEOMImpl_PartitionDriver::GetID()) return NULL; GEOMImpl_IPartition aCI (aFunction); - + Handle(GEOM_Function) aRef1 = theShape->GetLastFunction(); Handle(GEOM_Function) aRef2 = thePlane->GetLastFunction(); @@ -351,10 +357,10 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeHalfPartition return NULL; } - //Make a Python command + //Make a Python command GEOM::TPythonDump(aFunction) << aPart << " = geompy.MakeHalfPartition(" << theShape << ", " << thePlane << ")"; SetErrorCode(OK); - return aPart; + return aPart; } diff --git a/src/GEOMImpl/GEOMImpl_IBooleanOperations.hxx b/src/GEOMImpl/GEOMImpl_IBooleanOperations.hxx index d0b6e87ca..fd82587b2 100644 --- a/src/GEOMImpl/GEOMImpl_IBooleanOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IBooleanOperations.hxx @@ -23,8 +23,6 @@ #include "GEOM_IOperations.hxx" -//#include "TColStd_HSequenceOfTransient.hxx" - #include "list" class GEOM_Engine; @@ -37,19 +35,21 @@ class GEOMImpl_IBooleanOperations : public GEOM_IOperations { Standard_EXPORT ~GEOMImpl_IBooleanOperations(); Standard_EXPORT Handle(GEOM_Object) MakeBoolean (Handle(GEOM_Object) theShape1, - Handle(GEOM_Object) theShape2, - Standard_Integer theOp); - - Standard_EXPORT Handle(GEOM_Object) MakePartition (const Handle(TColStd_HSequenceOfTransient)& theShapes, - const Handle(TColStd_HSequenceOfTransient)& theTools, - const Handle(TColStd_HSequenceOfTransient)& theKeepInside, - const Handle(TColStd_HSequenceOfTransient)& theRemoveInside, - const Standard_Integer theLimit, - const Standard_Boolean theRemoveWebs, - const Handle(TColStd_HArray1OfInteger)& theMaterials); + Handle(GEOM_Object) theShape2, + Standard_Integer theOp); + + Standard_EXPORT Handle(GEOM_Object) MakePartition + (const Handle(TColStd_HSequenceOfTransient)& theShapes, + const Handle(TColStd_HSequenceOfTransient)& theTools, + const Handle(TColStd_HSequenceOfTransient)& theKeepInside, + const Handle(TColStd_HSequenceOfTransient)& theRemoveInside, + const Standard_Integer theLimit, + const Standard_Boolean theRemoveWebs, + const Handle(TColStd_HArray1OfInteger)& theMaterials, + const Standard_Boolean thePerformSelfIntersections); Standard_EXPORT Handle(GEOM_Object) MakeHalfPartition (Handle(GEOM_Object) theShape, - Handle(GEOM_Object) thePlane); + Handle(GEOM_Object) thePlane); }; #endif diff --git a/src/GEOMImpl/GEOMImpl_PartitionDriver.cxx b/src/GEOMImpl/GEOMImpl_PartitionDriver.cxx index db6b6e381..b079521e8 100644 --- a/src/GEOMImpl/GEOMImpl_PartitionDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_PartitionDriver.cxx @@ -1,18 +1,18 @@ // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com @@ -36,12 +36,13 @@ #include #include +#include +#include #include #include #include #include -#include -#include +#include #include #include @@ -54,29 +55,54 @@ //======================================================================= //function : GetID //purpose : -//======================================================================= +//======================================================================= const Standard_GUID& GEOMImpl_PartitionDriver::GetID() { static Standard_GUID aPartitionDriver("FF1BBB22-5D14-4df2-980B-3A668264EA16"); - return aPartitionDriver; + return aPartitionDriver; } //======================================================================= //function : GEOMImpl_PartitionDriver -//purpose : +//purpose : //======================================================================= -GEOMImpl_PartitionDriver::GEOMImpl_PartitionDriver() +GEOMImpl_PartitionDriver::GEOMImpl_PartitionDriver() { } +//======================================================================= +//function : SimplifyCompound +//purpose : +//======================================================================= +static void PrepareShapes (const TopoDS_Shape& theShape, + Standard_Integer theType, + TopTools_ListOfShape& theSimpleList) +{ + if (theType == PARTITION_NO_SELF_INTERSECTIONS || + theShape.ShapeType() != TopAbs_COMPOUND) { + theSimpleList.Append(theShape); + return; + } + + // explode compound on simple shapes to allow their intersections + TopoDS_Iterator It (theShape, Standard_True, Standard_True); + TopTools_MapOfShape mapShape; + for (; It.More(); It.Next()) { + if (mapShape.Add(It.Value())) { + TopoDS_Shape curSh = It.Value(); + PrepareShapes(curSh, theType, theSimpleList); + } + } +} + //======================================================================= //function : Execute //purpose : -//======================================================================= +//======================================================================= Standard_Integer GEOMImpl_PartitionDriver::Execute(TFunction_Logbook& log) const { - if (Label().IsNull()) return 0; + if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_IPartition aCI (aFunction); @@ -86,19 +112,21 @@ Standard_Integer GEOMImpl_PartitionDriver::Execute(TFunction_Logbook& log) const //sklNMTAlgo_Splitter1 PS; GEOMAlgo_Splitter PS; - if (aType == PARTITION_PARTITION) { + if (aType == PARTITION_PARTITION || aType == PARTITION_NO_SELF_INTERSECTIONS) + { Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes(); Handle(TColStd_HSequenceOfTransient) aTools = aCI.GetTools(); Handle(TColStd_HSequenceOfTransient) aKeepIns = aCI.GetKeepIns(); Handle(TColStd_HSequenceOfTransient) aRemIns = aCI.GetRemoveIns(); Handle(TColStd_HArray1OfInteger) aMaterials = aCI.GetMaterials(); - //sklStandard_Boolean DoRemoveWebs = !aMaterials.IsNull(); - - unsigned int ind, nbshapes = 0; - nbshapes += aShapes->Length() + aTools->Length(); - nbshapes += aKeepIns->Length() + aRemIns->Length(); + //skl Standard_Boolean DoRemoveWebs = !aMaterials.IsNull(); - TopTools_MapOfShape ShapesMap(nbshapes), ToolsMap(nbshapes); + unsigned int ind; + //unsigned int ind, nbshapes = 0; + //nbshapes += aShapes->Length() + aTools->Length(); + //nbshapes += aKeepIns->Length() + aRemIns->Length(); + //TopTools_MapOfShape ShapesMap(nbshapes), ToolsMap(nbshapes); + TopTools_MapOfShape ShapesMap, ToolsMap; // add object shapes that are in ListShapes; for (ind = 1; ind <= aShapes->Length(); ind++) { @@ -107,12 +135,19 @@ Standard_Integer GEOMImpl_PartitionDriver::Execute(TFunction_Logbook& log) const if (aShape_i.IsNull()) { Standard_NullObject::Raise("In Partition a shape is null"); } - if (ShapesMap.Add(aShape_i)) { - PS.AddShape(aShape_i); -//skl if (DoRemoveWebs) { -//skl if (aMaterials->Length() >= ind) -//skl PS.SetMaterial(aShape_i, aMaterials->Value(ind)); -//skl } + // + TopTools_ListOfShape aSimpleShapes; + PrepareShapes(aShape_i, aType, aSimpleShapes); + TopTools_ListIteratorOfListOfShape aSimpleIter (aSimpleShapes); + for (; aSimpleIter.More(); aSimpleIter.Next()) { + const TopoDS_Shape& aSimpleSh = aSimpleIter.Value(); + if (ShapesMap.Add(aSimpleSh)) { + PS.AddShape(aSimpleSh); + //skl if (DoRemoveWebs) { + //skl if (aMaterials->Length() >= ind) + //skl PS.SetMaterial(aSimpleSh, aMaterials->Value(ind)); + //skl } + } } } @@ -123,8 +158,15 @@ Standard_Integer GEOMImpl_PartitionDriver::Execute(TFunction_Logbook& log) const if (aShape_i.IsNull()) { Standard_NullObject::Raise("In Partition a tool shape is null"); } - if (!ShapesMap.Contains(aShape_i) && ToolsMap.Add(aShape_i)) { - PS.AddTool(aShape_i); + // + TopTools_ListOfShape aSimpleShapes; + PrepareShapes(aShape_i, aType, aSimpleShapes); + TopTools_ListIteratorOfListOfShape aSimpleIter (aSimpleShapes); + for (; aSimpleIter.More(); aSimpleIter.Next()) { + const TopoDS_Shape& aSimpleSh = aSimpleIter.Value(); + if (!ShapesMap.Contains(aSimpleSh) && ToolsMap.Add(aSimpleSh)) { + PS.AddTool(aSimpleSh); + } } } @@ -135,8 +177,15 @@ Standard_Integer GEOMImpl_PartitionDriver::Execute(TFunction_Logbook& log) const if (aShape_i.IsNull()) { Standard_NullObject::Raise("In Partition a Keep Inside shape is null"); } - if (!ToolsMap.Contains(aShape_i) && ShapesMap.Add(aShape_i)) - PS.AddShape(aShape_i); + // + TopTools_ListOfShape aSimpleShapes; + PrepareShapes(aShape_i, aType, aSimpleShapes); + TopTools_ListIteratorOfListOfShape aSimpleIter (aSimpleShapes); + for (; aSimpleIter.More(); aSimpleIter.Next()) { + const TopoDS_Shape& aSimpleSh = aSimpleIter.Value(); + if (!ToolsMap.Contains(aSimpleSh) && ShapesMap.Add(aSimpleSh)) + PS.AddShape(aSimpleSh); + } } // add shapes that are in ListRemoveInside, as object shapes; @@ -146,16 +195,23 @@ Standard_Integer GEOMImpl_PartitionDriver::Execute(TFunction_Logbook& log) const if (aShape_i.IsNull()) { Standard_NullObject::Raise("In Partition a Remove Inside shape is null"); } - if (!ToolsMap.Contains(aShape_i) && ShapesMap.Add(aShape_i)) - PS.AddShape(aShape_i); + // + TopTools_ListOfShape aSimpleShapes; + PrepareShapes(aShape_i, aType, aSimpleShapes); + TopTools_ListIteratorOfListOfShape aSimpleIter (aSimpleShapes); + for (; aSimpleIter.More(); aSimpleIter.Next()) { + const TopoDS_Shape& aSimpleSh = aSimpleIter.Value(); + if (!ToolsMap.Contains(aSimpleSh) && ShapesMap.Add(aSimpleSh)) + PS.AddShape(aSimpleSh); + } } PS.SetLimit( (TopAbs_ShapeEnum)aCI.GetLimit() ); PS.Perform(); - //sklPS.Compute(); - //sklPS.SetRemoveWebs(!DoRemoveWebs); - //sklPS.Build((TopAbs_ShapeEnum) aCI.GetLimit()); + //skl PS.Compute(); + //skl PS.SetRemoveWebs(!DoRemoveWebs); + //skl PS.Build((TopAbs_ShapeEnum) aCI.GetLimit()); /*skl // suppress result outside of shapes in KInsideMap for (ind = 1; ind <= aKeepIns->Length(); ind++) { @@ -172,7 +228,8 @@ Standard_Integer GEOMImpl_PartitionDriver::Execute(TFunction_Logbook& log) const } */ } - else if (aType == PARTITION_HALF) { + else if (aType == PARTITION_HALF) + { Handle(GEOM_Function) aRefShape = aCI.GetShape(); Handle(GEOM_Function) aRefPlane = aCI.GetPlane(); TopoDS_Shape aShapeArg = aRefShape->GetValue(); @@ -188,7 +245,7 @@ Standard_Integer GEOMImpl_PartitionDriver::Execute(TFunction_Logbook& log) const // add tool shapes that are in ListTools and not in ListShapes; PS.AddTool(aPlaneArg); - //sklPS.Compute(); + //skl PS.Compute(); PS.Perform(); //PS.SetRemoveWebs(Standard_False); //PS.Build(aShapeArg.ShapeType()); @@ -263,17 +320,17 @@ Standard_Integer GEOMImpl_PartitionDriver::Execute(TFunction_Logbook& log) const //======================================================================= //function : GEOMImpl_PartitionDriver_Type_ //purpose : -//======================================================================= +//======================================================================= Standard_EXPORT Handle_Standard_Type& GEOMImpl_PartitionDriver_Type_() { static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver); if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver); static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared); - if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); + if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient); if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient); - + static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL}; static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PartitionDriver", @@ -288,7 +345,7 @@ Standard_EXPORT Handle_Standard_Type& GEOMImpl_PartitionDriver_Type_() //======================================================================= //function : DownCast //purpose : -//======================================================================= +//======================================================================= const Handle(GEOMImpl_PartitionDriver) Handle(GEOMImpl_PartitionDriver)::DownCast(const Handle(Standard_Transient)& AnObject) { Handle(GEOMImpl_PartitionDriver) _anOtherObject; diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index 4c436de29..c1c516fb7 100755 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -173,6 +173,7 @@ #define PARTITION_PARTITION 1 #define PARTITION_HALF 2 +#define PARTITION_NO_SELF_INTERSECTIONS 3 #define POLYLINE_POINTS 1 diff --git a/src/GEOM_I/GEOM_IBooleanOperations_i.cc b/src/GEOM_I/GEOM_IBooleanOperations_i.cc index 56726b072..c7a594259 100644 --- a/src/GEOM_I/GEOM_IBooleanOperations_i.cc +++ b/src/GEOM_I/GEOM_IBooleanOperations_i.cc @@ -1,22 +1,23 @@ // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include #include "GEOM_IBooleanOperations_i.hh" @@ -57,7 +58,7 @@ GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i() /*! * MakeBoolean */ -//============================================================================= +//============================================================================= GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2, @@ -90,14 +91,100 @@ GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean /*! * MakePartition */ -//============================================================================= +//============================================================================= GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition (const GEOM::ListOfGO& theShapes, const GEOM::ListOfGO& theTools, const GEOM::ListOfGO& theKeepIns, const GEOM::ListOfGO& theRemoveIns, - const CORBA::Short theLimit, - const CORBA::Boolean theRemoveWebs, + CORBA::Short theLimit, + CORBA::Boolean theRemoveWebs, + const GEOM::ListOfLong& theMaterials) +{ + GEOM::GEOM_Object_var aGEOMObject; + + //Set a not done flag + GetOperations()->SetNotDone(); + + int ind, aLen; + Handle(TColStd_HSequenceOfTransient) aShapes = new TColStd_HSequenceOfTransient; + Handle(TColStd_HSequenceOfTransient) aTools = new TColStd_HSequenceOfTransient; + Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient; + Handle(TColStd_HSequenceOfTransient) aRemIns = new TColStd_HSequenceOfTransient; + Handle(TColStd_HArray1OfInteger) aMaterials; + + //Get the shapes + aLen = theShapes.length(); + for (ind = 0; ind < aLen; ind++) { + if (theShapes[ind] == NULL) return aGEOMObject._retn(); + Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject + (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry()); + if (aSh.IsNull()) return aGEOMObject._retn(); + aShapes->Append(aSh); + } + + //Get the tools + aLen = theTools.length(); + for (ind = 0; ind < aLen; ind++) { + if (theTools[ind] == NULL) return aGEOMObject._retn(); + Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject + (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry()); + if (aSh.IsNull()) return aGEOMObject._retn(); + aTools->Append(aSh); + } + + //Get the keep inside shapes + aLen = theKeepIns.length(); + for (ind = 0; ind < aLen; ind++) { + if (theKeepIns[ind] == NULL) return aGEOMObject._retn(); + Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject + (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry()); + if (aSh.IsNull()) return aGEOMObject._retn(); + aKeepIns->Append(aSh); + } + + //Get the remove inside shapes + aLen = theRemoveIns.length(); + for (ind = 0; ind < aLen; ind++) { + if (theRemoveIns[ind] == NULL) return aGEOMObject._retn(); + Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject + (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry()); + if (aSh.IsNull()) return aGEOMObject._retn(); + aRemIns->Append(aSh); + } + + //Get the materials + aLen = theMaterials.length(); + if ( aLen ) { + aMaterials = new TColStd_HArray1OfInteger (1, aLen); + for (ind = 0; ind < aLen; ind++) { + aMaterials->SetValue(ind+1, theMaterials[ind]); + } + } + + // Make Partition + Handle(GEOM_Object) anObject = + GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns, + theLimit, theRemoveWebs, aMaterials, + /*PerformSelfIntersections*/Standard_True); + if (!GetOperations()->IsDone() || anObject.IsNull()) + return aGEOMObject._retn(); + + return GetObject(anObject); +} + +//============================================================================= +/*! + * MakePartitionNonSelfIntersectedShape + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape + (const GEOM::ListOfGO& theShapes, + const GEOM::ListOfGO& theTools, + const GEOM::ListOfGO& theKeepIns, + const GEOM::ListOfGO& theRemoveIns, + CORBA::Short theLimit, + CORBA::Boolean theRemoveWebs, const GEOM::ListOfLong& theMaterials) { GEOM::GEOM_Object_var aGEOMObject; @@ -164,7 +251,8 @@ GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition // Make Partition Handle(GEOM_Object) anObject = GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns, - theLimit, theRemoveWebs, aMaterials); + theLimit, theRemoveWebs, aMaterials, + /*PerformSelfIntersections*/Standard_False); if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn(); @@ -175,7 +263,7 @@ GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition /*! * MakeHalfPartition */ -//============================================================================= +//============================================================================= GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition (GEOM::GEOM_Object_ptr theShape, GEOM::GEOM_Object_ptr thePlane) diff --git a/src/GEOM_I/GEOM_IBooleanOperations_i.hh b/src/GEOM_I/GEOM_IBooleanOperations_i.hh index 8a70bb33d..94ab4c876 100644 --- a/src/GEOM_I/GEOM_IBooleanOperations_i.hh +++ b/src/GEOM_I/GEOM_IBooleanOperations_i.hh @@ -47,10 +47,18 @@ class GEOM_IBooleanOperations_i : const GEOM::ListOfGO& theTools, const GEOM::ListOfGO& theKeepInside, const GEOM::ListOfGO& theRemoveInside, - CORBA::Short theLimit, - CORBA::Boolean theRemoveWebs, + CORBA::Short theLimit, + CORBA::Boolean theRemoveWebs, const GEOM::ListOfLong& theMaterials); + GEOM::GEOM_Object_ptr MakePartitionNonSelfIntersectedShape (const GEOM::ListOfGO& theShapes, + const GEOM::ListOfGO& theTools, + const GEOM::ListOfGO& theKeepInside, + const GEOM::ListOfGO& theRemoveInside, + CORBA::Short theLimit, + CORBA::Boolean theRemoveWebs, + const GEOM::ListOfLong& theMaterials); + GEOM::GEOM_Object_ptr MakeHalfPartition (GEOM::GEOM_Object_ptr theShape, GEOM::GEOM_Object_ptr thePlane); diff --git a/src/GEOM_SWIG/geompy.py b/src/GEOM_SWIG/geompy.py index 5ec3ceb7f..428939deb 100644 --- a/src/GEOM_SWIG/geompy.py +++ b/src/GEOM_SWIG/geompy.py @@ -1379,27 +1379,13 @@ def MakeFuse(s1, s2): def MakeSection(s1, s2): return MakeBoolean(s1, s2, 4) -## Perform explode of compound -# Auxilary method for MakePartition -def ExplodeCompound(aComp): - ResListShapes = [] - shapes = SubShapeAll(aComp,ShapeType["SHAPE"]) - nbss = len(shapes) - for i in range(0,nbss): - if shapes[i].GetShapeType()==GEOM.COMPOUND: - ResListShapes.extend(ExplodeCompound(shapes[i])) - else: - ResListShapes.append(shapes[i]) - pass - pass - return ResListShapes - ## Perform partition operation. # @param ListShapes Shapes to be intersected. # @param ListTools Shapes to intersect theShapes. # !!!NOTE: Each compound from ListShapes and ListTools will be exploded # in order to avoid possible intersection between shapes from # this compound. +# @param Limit Type of resulting shapes (corresponding to TopAbs_ShapeEnum). # # After implementation new version of PartitionAlgo (October 2006) # other parameters are ignored by current functionality. They are kept @@ -1409,7 +1395,6 @@ def ExplodeCompound(aComp): # Each shape from theKeepInside must belong to theShapes also. # @param ListRemoveInside Shapes, inside which the results will be deleted. # Each shape from theRemoveInside must belong to theShapes also. -# @param Limit Type of resulting shapes (corresponding to TopAbs_ShapeEnum). # @param RemoveWebs If TRUE, perform Glue 3D algorithm. # @param ListMaterials Material indices for each shape. Make sence, # only if theRemoveWebs is TRUE. @@ -1419,28 +1404,12 @@ def ExplodeCompound(aComp): # Example: see GEOM_TestAll.py def MakePartition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[], Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[]): - - NewListShapes = [] - nbs = len(ListShapes) - for i in range(0,nbs): - if ListShapes[i].GetShapeType()==GEOM.COMPOUND: - # need to explode - NewListShapes.extend(ExplodeCompound(ListShapes[i])) - else: NewListShapes.append(ListShapes[i]) - pass - - NewListTools = [] - nbs = len(ListTools) - for i in range(0,nbs): - if ListTools[i].GetShapeType()==GEOM.COMPOUND: - # need to explode - NewListTools.extend(ExplodeCompound(ListTools[i])) - else: NewListTools.append(ListTools[i]) - pass - - return MakePartitionNonSelfIntersectedShape(NewListShapes, NewListTools, - ListKeepInside, ListRemoveInside, - Limit, RemoveWebs, ListMaterials) + anObj = BoolOp.MakePartition(ListShapes, ListTools, + ListKeepInside, ListRemoveInside, + Limit, RemoveWebs, ListMaterials); + if BoolOp.IsDone() == 0: + print "MakePartition : ", BoolOp.GetErrorCode() + return anObj ## Perform partition operation. # This method may be useful if it is needed to make a partition for @@ -1449,19 +1418,18 @@ def MakePartition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside= # # Description of all parameters as in previous method MakePartition() # -# !!!NOTE: Compounds from ListShapes can not have intersections with each -# other and compounds from ListTools can not have intersections -# with each other. +# !!!NOTE: Passed compounds (via ListShapes or via ListTools) +# have to consist of nonintersecting shapes. # # @return New GEOM_Object, containing the result shapes. # def MakePartitionNonSelfIntersectedShape(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[], Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[]): - anObj = BoolOp.MakePartition(ListShapes, ListTools, - ListKeepInside, ListRemoveInside, - Limit, RemoveWebs, ListMaterials); + anObj = BoolOp.MakePartitionNonSelfIntersectedShape(ListShapes, ListTools, + ListKeepInside, ListRemoveInside, + Limit, RemoveWebs, ListMaterials); if BoolOp.IsDone() == 0: - print "MakePartition : ", BoolOp.GetErrorCode() + print "MakePartitionNonSelfIntersectedShape : ", BoolOp.GetErrorCode() return anObj ## Shortcut to MakePartition()
@@ -5289,7 +5449,7 @@ Example: see GEOM_TestAll.py