Back to index

salome-geom  6.5.0
Public Member Functions | Static Public Member Functions | Friends
GEOMImpl_BooleanDriver Class Reference

#include <GEOMImpl_BooleanDriver.hxx>

List of all members.

Public Member Functions

void * operator new (size_t, void *anAddress)
void * operator new (size_t size)
void operator delete (void *anAddress)
Standard_EXPORT GEOMImpl_BooleanDriver ()
virtual Standard_EXPORT
Standard_Integer 
Execute (TFunction_Logbook &log) const
virtual Standard_EXPORT void Validate (TFunction_Logbook &) const
Standard_EXPORT Standard_Boolean MustExecute (const TFunction_Logbook &) const
Standard_EXPORT ~GEOMImpl_BooleanDriver ()
Standard_EXPORT const Handle (Standard_Type)&DynamicType() const
Standard_EXPORT Standard_Boolean IsKind (const Handle(Standard_Type)&AType) const

Static Public Member Functions

static Standard_EXPORT const
Standard_GUID & 
GetID ()

Friends

Standard_EXPORT friend
Handle_Standard_Type & 
GEOMImpl_BooleanDriver_Type_ ()

Detailed Description

Definition at line 125 of file GEOMImpl_BooleanDriver.hxx.


Constructor & Destructor Documentation

Definition at line 71 of file GEOMImpl_BooleanDriver.cxx.

{
}

Definition at line 149 of file GEOMImpl_BooleanDriver.hxx.

{};

Member Function Documentation

Standard_Integer GEOMImpl_BooleanDriver::Execute ( TFunction_Logbook &  log) const [virtual]

the changes temporary commented because of customer needs (see the same mantis bug)

Definition at line 103 of file GEOMImpl_BooleanDriver.cxx.

{
  if (Label().IsNull()) return 0;
  Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());

  GEOMImpl_IBoolean aCI (aFunction);
  Standard_Integer aType = aFunction->GetType();

  TopoDS_Shape aShape;

  Handle(GEOM_Function) aRefShape1 = aCI.GetShape1();
  Handle(GEOM_Function) aRefShape2 = aCI.GetShape2();
  TopoDS_Shape aShape1 = aRefShape1->GetValue();
  TopoDS_Shape aShape2 = aRefShape2->GetValue();

  if (!aShape1.IsNull() && !aShape2.IsNull()) {
    // check arguments for Mantis issue 0021019
    BRepCheck_Analyzer ana (aShape1, Standard_True);
    if (!ana.IsValid())
      StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is not valid");
    ana.Init(aShape2);
    if (!ana.IsValid())
      StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is not valid");

    // perform COMMON operation
    if (aType == BOOLEAN_COMMON) {
      BRep_Builder B;
      TopoDS_Compound C;
      B.MakeCompound(C);

      TopTools_ListOfShape listShape1, listShape2;
      AddSimpleShapes(aShape1, listShape1);
      AddSimpleShapes(aShape2, listShape2);

      Standard_Boolean isCompound =
        (listShape1.Extent() > 1 || listShape2.Extent() > 1);

      TopTools_ListIteratorOfListOfShape itSub1 (listShape1);
      for (; itSub1.More(); itSub1.Next()) {
        TopoDS_Shape aValue1 = itSub1.Value();
        TopTools_ListIteratorOfListOfShape itSub2 (listShape2);
        for (; itSub2.More(); itSub2.Next()) {
          TopoDS_Shape aValue2 = itSub2.Value();
          BRepAlgoAPI_Common BO (aValue1, aValue2);
          if (!BO.IsDone()) {
            StdFail_NotDone::Raise("Common operation can not be performed on the given shapes");
          }
          if (isCompound) {
            TopoDS_Shape aStepResult = BO.Shape();

            // check result of this step: if it is a compound (boolean operations
            // allways return a compound), we add all sub-shapes of it.
            // This allows to avoid adding empty compounds,
            // resulting from COMMON on two non-intersecting shapes.
            if (aStepResult.ShapeType() == TopAbs_COMPOUND) {
              TopoDS_Iterator aCompIter (aStepResult);
              for (; aCompIter.More(); aCompIter.Next()) {
                // add shape in a result
                B.Add(C, aCompIter.Value());
              }
            }
            else {
              // add shape in a result
              B.Add(C, aStepResult);
            }
          }
          else
            aShape = BO.Shape();
        }
      }

      if (isCompound) {
        /*
        TopTools_ListOfShape listShapeC;
        AddSimpleShapes(C, listShapeC);
        TopTools_ListIteratorOfListOfShape itSubC (listShapeC);
        bool isOnlySolids = true;
        for (; itSubC.More(); itSubC.Next()) {
          TopoDS_Shape aValueC = itSubC.Value();
          if (aValueC.ShapeType() != TopAbs_SOLID) isOnlySolids = false;
        }
        if (isOnlySolids)
          aShape = GEOMImpl_GlueDriver::GlueFaces(C, Precision::Confusion());
        else
          aShape = C;
        */

        // As GlueFaces has been improved to keep all kind of shapes
        TopExp_Explorer anExp (C, TopAbs_VERTEX);
        if (anExp.More())
          aShape = GEOMImpl_GlueDriver::GlueFaces(C, Precision::Confusion(), Standard_True);
        else
          aShape = C;
      }
    }

    // perform CUT operation
    else if (aType == BOOLEAN_CUT) {
      BRep_Builder B;
      TopoDS_Compound C;
      B.MakeCompound(C);

      TopTools_ListOfShape listShapes, listTools;
      AddSimpleShapes(aShape1, listShapes);
      AddSimpleShapes(aShape2, listTools);

      Standard_Boolean isCompound = (listShapes.Extent() > 1);

      TopTools_ListIteratorOfListOfShape itSub1 (listShapes);
      for (; itSub1.More(); itSub1.Next()) {
        TopoDS_Shape aCut = itSub1.Value();
        // tools
        TopTools_ListIteratorOfListOfShape itSub2 (listTools);
        for (; itSub2.More(); itSub2.Next()) {
          TopoDS_Shape aTool = itSub2.Value();
          BRepAlgoAPI_Cut BO (aCut, aTool);
          if (!BO.IsDone()) {
            StdFail_NotDone::Raise("Cut operation can not be performed on the given shapes");
          }
          aCut = BO.Shape();
        }
        if (isCompound) {
          // check result of this step: if it is a compound (boolean operations
          // allways return a compound), we add all sub-shapes of it.
          // This allows to avoid adding empty compounds,
          // resulting from CUT of parts
          if (aCut.ShapeType() == TopAbs_COMPOUND) {
            TopoDS_Iterator aCompIter (aCut);
            for (; aCompIter.More(); aCompIter.Next()) {
              // add shape in a result
              B.Add(C, aCompIter.Value());
            }
          }
          else {
            // add shape in a result
            B.Add(C, aCut);
          }
        }
        else
          aShape = aCut;
      }

      if (isCompound) {
        /*
        TopTools_ListOfShape listShapeC;
        AddSimpleShapes(C, listShapeC);
        TopTools_ListIteratorOfListOfShape itSubC (listShapeC);
        bool isOnlySolids = true;
        for (; itSubC.More(); itSubC.Next()) {
          TopoDS_Shape aValueC = itSubC.Value();
          if (aValueC.ShapeType() != TopAbs_SOLID) isOnlySolids = false;
        }
        if (isOnlySolids)
          aShape = GEOMImpl_GlueDriver::GlueFaces(C, Precision::Confusion());
        else
          aShape = C;
        */

        // As GlueFaces has been improved to keep all kind of shapes
        TopExp_Explorer anExp (C, TopAbs_VERTEX);
        if (anExp.More())
          aShape = GEOMImpl_GlueDriver::GlueFaces(C, Precision::Confusion(), Standard_True);
        else
          aShape = C;
      }
    }

    // perform FUSE operation
    else if (aType == BOOLEAN_FUSE) {
      /* Fix for NPAL15379: refused
      // Check arguments
      TopTools_ListOfShape listShape1, listShape2;
      AddSimpleShapes(aShape1, listShape1);
      AddSimpleShapes(aShape2, listShape2);

      Standard_Boolean isIntersect = Standard_False;

      if (listShape1.Extent() > 1 && !isIntersect) {
        // check intersections inside the first compound
        TopTools_ListIteratorOfListOfShape it1 (listShape1);
        for (; it1.More() && !isIntersect; it1.Next()) {
          TopoDS_Shape aValue1 = it1.Value();
          TopTools_ListIteratorOfListOfShape it2 (listShape1);
          for (; it2.More() && !isIntersect; it2.Next()) {
            TopoDS_Shape aValue2 = it2.Value();
            if (aValue2 != aValue1) {
              BRepAlgoAPI_Section BO (aValue1, aValue2);
              if (BO.IsDone()) {
                TopoDS_Shape aSect = BO.Shape();
                TopExp_Explorer anExp (aSect, TopAbs_EDGE);
                if (anExp.More()) {
                  isIntersect = Standard_True;
                }
              }
            }
          }
        }
      }

      if (listShape2.Extent() > 1 && !isIntersect) {
        // check intersections inside the second compound
        TopTools_ListIteratorOfListOfShape it1 (listShape2);
        for (; it1.More() && !isIntersect; it1.Next()) {
          TopoDS_Shape aValue1 = it1.Value();
          TopTools_ListIteratorOfListOfShape it2 (listShape2);
          for (; it2.More() && !isIntersect; it2.Next()) {
            TopoDS_Shape aValue2 = it2.Value();
            if (aValue2 != aValue1) {
              BRepAlgoAPI_Section BO (aValue1, aValue2);
              if (BO.IsDone()) {
                TopoDS_Shape aSect = BO.Shape();
                TopExp_Explorer anExp (aSect, TopAbs_EDGE);
                if (anExp.More()) {
                  isIntersect = Standard_True;
                }
              }
            }
          }
        }
      }

      if (isIntersect) {
        // have intersections inside compounds
        // check intersections between compounds
        TopTools_ListIteratorOfListOfShape it1 (listShape1);
        for (; it1.More(); it1.Next()) {
          TopoDS_Shape aValue1 = it1.Value();
          TopTools_ListIteratorOfListOfShape it2 (listShape2);
          for (; it2.More(); it2.Next()) {
            TopoDS_Shape aValue2 = it2.Value();
            if (aValue2 != aValue1) {
              BRepAlgoAPI_Section BO (aValue1, aValue2);
              if (BO.IsDone()) {
                TopoDS_Shape aSect = BO.Shape();
                TopExp_Explorer anExp (aSect, TopAbs_EDGE);
                if (anExp.More()) {
                  StdFail_NotDone::Raise("Bad argument for Fuse: compound with intersecting sub-shapes");
                }
              }
            }
          }
        }
      }
      */

      // Perform
      BRepAlgoAPI_Fuse BO (aShape1, aShape2);
      if (!BO.IsDone()) {
        StdFail_NotDone::Raise("Fuse operation can not be performed on the given shapes");
      }
      aShape = BO.Shape();
    }

    // perform SECTION operation
    else if (aType == BOOLEAN_SECTION) {
      BRep_Builder B;
      TopoDS_Compound C;
      B.MakeCompound(C);

      TopTools_ListOfShape listShape1, listShape2;
      AddSimpleShapes(aShape1, listShape1);
      AddSimpleShapes(aShape2, listShape2);

      Standard_Boolean isCompound =
        (listShape1.Extent() > 1 || listShape2.Extent() > 1);

      TopTools_ListIteratorOfListOfShape itSub1 (listShape1);
      for (; itSub1.More(); itSub1.Next()) {
        TopoDS_Shape aValue1 = itSub1.Value();
        TopTools_ListIteratorOfListOfShape itSub2 (listShape2);
        for (; itSub2.More(); itSub2.Next()) {
          TopoDS_Shape aValue2 = itSub2.Value();
          BRepAlgoAPI_Section BO (aValue1, aValue2, Standard_False);
          // Set approximation to have an attached 3D BSpline geometry to each edge,
          // where analytic curve is not possible. Without this flag in some cases
          // we obtain BSpline curve of degree 1 (C0), which is slowly
          // processed by some algorithms (Partition for example).
          BO.Approximation(Standard_True);
         //modified by NIZNHY-PKV Tue Oct 18 14:34:16 2011f
         BO.ComputePCurveOn1(Standard_True);
         BO.ComputePCurveOn2(Standard_True);
         //modified by NIZNHY-PKV Tue Oct 18 14:34:18 2011t
         
          BO.Build();
          if (!BO.IsDone()) {
            StdFail_NotDone::Raise("Section operation can not be performed on the given shapes");
          }
          if (isCompound) {
            TopoDS_Shape aStepResult = BO.Shape();

            // check result of this step: if it is a compound (boolean operations
            // allways return a compound), we add all sub-shapes of it.
            // This allows to avoid adding empty compounds,
            // resulting from SECTION on two non-intersecting shapes.
            if (aStepResult.ShapeType() == TopAbs_COMPOUND) {
              TopoDS_Iterator aCompIter (aStepResult);
              for (; aCompIter.More(); aCompIter.Next()) {
                // add shape in a result
                B.Add(C, aCompIter.Value());
              }
            }
            else {
              // add shape in a result
              B.Add(C, aStepResult);
            }
          }
          else
            aShape = BO.Shape();
        }
      }

      if (isCompound) {
        //aShape = C;

        // As GlueFaces has been improved to keep all kind of shapes
        TopExp_Explorer anExp (C, TopAbs_VERTEX);
        if (anExp.More())
          aShape = GEOMImpl_GlueDriver::GlueFaces(C, Precision::Confusion(), Standard_True);
        else
          aShape = C;
      }
    }

    // UNKNOWN operation
    else {
    }
  }

  if (aShape.IsNull()) return 0;

  // as boolean operations always produce compound, lets simplify it
  // for the case, if it contains only one sub-shape
  TopTools_ListOfShape listShapeRes;
  AddSimpleShapes(aShape, listShapeRes);
  if (listShapeRes.Extent() == 1) {
    aShape = listShapeRes.First();
    if (aShape.IsNull()) return 0;
  }

  // 08.07.2008 skl for bug 19761 from Mantis
  BRepCheck_Analyzer ana (aShape, Standard_True);
  ana.Init(aShape);
  if (!ana.IsValid()) {
    ShapeFix_ShapeTolerance aSFT;
    aSFT.LimitTolerance(aShape, Precision::Confusion(),
                        Precision::Confusion(), TopAbs_SHAPE);
    Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
    aSfs->Perform();
    aShape = aSfs->Shape();
    ana.Init(aShape);
    if (!ana.IsValid())
      Standard_ConstructionError::Raise("Boolean operation aborted : non valid shape result");
  }
  //if (!BRepAlgo::IsValid(aShape)) {
  //  Standard_ConstructionError::Raise("Boolean operation aborted : non valid shape result");
  //}

  // BEGIN: Mantis issue 0021060: always limit tolerance of BOP result
  // 1. Get shape parameters for comparison
  int nbTypes [TopAbs_SHAPE];
  {
    for (int 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()]++;
        }
      }
    }
  }

  // 2. Limit tolerance
  TopoDS_Shape aShapeCopy;
  TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
  TNaming_CopyShape::CopyTool(aShape, aMapTShapes, aShapeCopy);
  ShapeFix_ShapeTolerance aSFT;
  aSFT.LimitTolerance(aShapeCopy, Precision::Confusion(), Precision::Confusion(), TopAbs_SHAPE);
  Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShapeCopy);
  aSfs->Perform();
  aShapeCopy = aSfs->Shape();

  // 3. Check parameters
  ana.Init(aShapeCopy);
  if (ana.IsValid()) {
    int iType, nbTypesCopy [TopAbs_SHAPE];

    for (iType = 0; iType < TopAbs_SHAPE; ++iType)
      nbTypesCopy[iType] = 0;
    nbTypesCopy[aShapeCopy.ShapeType()]++;

    TopTools_MapOfShape aMapOfShape;
    aMapOfShape.Add(aShapeCopy);
    TopTools_ListOfShape aListOfShape;
    aListOfShape.Append(aShapeCopy);

    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);
          nbTypesCopy[s.ShapeType()]++;
        }
      }
    }

    bool isEqual = true;
    for (iType = 0; iType < TopAbs_SHAPE && isEqual; ++iType) {
      if (nbTypes[iType] != nbTypesCopy[iType])
        isEqual = false;
    }
    if (isEqual)
      aShape = aShapeCopy;
  }
  // END: Mantis issue 0021060

  //Alternative case to check shape result Mantis 0020604: EDF 1172
/*  TopoDS_Iterator It (aShape, Standard_True, Standard_True);
  int nbSubshapes=0;
  for (; It.More(); It.Next())
    nbSubshapes++;
  if (!nbSubshapes)
    Standard_ConstructionError::Raise("Boolean operation aborted : result object is empty compound");*/
  //end of 0020604: EDF 1172

  aFunction->SetValue(aShape);

  log.SetTouched(Label());

  return 1;
}

Here is the call graph for this function:

const Standard_GUID & GEOMImpl_BooleanDriver::GetID ( ) [static]

Definition at line 61 of file GEOMImpl_BooleanDriver.cxx.

{
  static Standard_GUID aBooleanDriver("FF1BBB21-5D14-4df2-980B-3A668264EA16");
  return aBooleanDriver;
}

Here is the caller graph for this function:

Standard_EXPORT const GEOMImpl_BooleanDriver::Handle ( Standard_Type  ) const [inline]

Definition at line 155 of file GEOMImpl_BooleanDriver.hxx.

Here is the call graph for this function:

Here is the caller graph for this function:

Standard_EXPORT Standard_Boolean GEOMImpl_BooleanDriver::IsKind ( const Handle(Standard_Type)&  AType) const [inline]

Definition at line 156 of file GEOMImpl_BooleanDriver.hxx.

{ return (STANDARD_TYPE(GEOMImpl_BooleanDriver) == AType || TFunction_Driver::IsKind(AType)); } 

Here is the call graph for this function:

Standard_EXPORT Standard_Boolean GEOMImpl_BooleanDriver::MustExecute ( const TFunction_Logbook &  ) const [inline]

Definition at line 147 of file GEOMImpl_BooleanDriver.hxx.

{ return Standard_True; }
void GEOMImpl_BooleanDriver::operator delete ( void *  anAddress) [inline]

Definition at line 137 of file GEOMImpl_BooleanDriver.hxx.

      { 
        if (anAddress) Standard::Free((Standard_Address&)anAddress); 
      }
void* GEOMImpl_BooleanDriver::operator new ( size_t  ,
void *  anAddress 
) [inline]

Definition at line 129 of file GEOMImpl_BooleanDriver.hxx.

      {
        return anAddress;
      }
void* GEOMImpl_BooleanDriver::operator new ( size_t  size) [inline]

Definition at line 133 of file GEOMImpl_BooleanDriver.hxx.

      { 
        return Standard::Allocate(size); 
      }
virtual Standard_EXPORT void GEOMImpl_BooleanDriver::Validate ( TFunction_Logbook &  ) const [inline, virtual]

Definition at line 146 of file GEOMImpl_BooleanDriver.hxx.

{}

Friends And Related Function Documentation

Standard_EXPORT friend Handle_Standard_Type& GEOMImpl_BooleanDriver_Type_ ( ) [friend]

Definition at line 554 of file GEOMImpl_BooleanDriver.cxx.

{
  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);
  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_BooleanDriver",
                                                         sizeof(GEOMImpl_BooleanDriver),
                                                         1,
                                                         (Standard_Address)_Ancestors,
                                                         (Standard_Address)NULL);

  return _aType;
}

The documentation for this class was generated from the following files: