// Created on: 1997-04-22
// Created by: Prestataire Mary FABIEN
// Copyright (c) 1997-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.

#include <TopOpeBRepDS_Filter.hxx>
#include <TopOpeBRepDS_Interference.hxx>
#include <NCollection_List.hxx>
#include <TopOpeBRepDS_ProcessInterferencesTool.hxx>

Standard_EXPORT int FUN_unkeepFdoubleGBoundinterferences(
  NCollection_List<occ::handle<TopOpeBRepDS_Interference>>& LI,
  const TopOpeBRepDS_DataStructure&                         BDS,
  const int                                                 SIX);
Standard_EXPORT void FUN_resolveFUNKNOWN(
  NCollection_List<occ::handle<TopOpeBRepDS_Interference>>& LI,
  TopOpeBRepDS_DataStructure&                               BDS,
  const int                                                 SIX,
  const NCollection_DataMap<TopoDS_Shape,
                            TopOpeBRepDS_ListOfShapeOn1State,
                            TopTools_ShapeMapHasher>&       MEsp,
  TopOpeBRepTool_PShapeClassifier                           pClassif);

//=================================================================================================

void TopOpeBRepDS_Filter::ProcessFaceInterferences(
  const int                                           SIX,
  const NCollection_DataMap<TopoDS_Shape,
                            TopOpeBRepDS_ListOfShapeOn1State,
                            TopTools_ShapeMapHasher>& MEsp)
{
  TopOpeBRepDS_DataStructure& BDS = myHDS->ChangeDS();

  //                 BDS.Shape(SIX);
  NCollection_List<occ::handle<TopOpeBRepDS_Interference>>& LI = BDS.ChangeShapeInterferences(SIX);
  ::FUN_reducedoublons(LI, BDS, SIX);

  NCollection_List<occ::handle<TopOpeBRepDS_Interference>> lw, lE, lFE, lFEF, lF, lUU, lall;
  lall.Assign(LI);

  ::FUN_selectTRAUNKinterference(lall, lUU);
  FUN_resolveFUNKNOWN(lUU, BDS, SIX, MEsp, myPShapeClassif);
  lw.Append(lall);
  lw.Append(lUU);

  ::FUN_selectTRASHAinterference(lw, TopAbs_FACE, lF);
  ::FUN_selectGKinterference(lF, TopOpeBRepDS_EDGE, lFE);
  ::FUN_selectSKinterference(lFE, TopOpeBRepDS_FACE, lFEF);
  ::FUN_selectTRASHAinterference(lw, TopAbs_EDGE, lE);

  LI.Clear();
  LI.Append(lF);
  LI.Append(lFE);
  LI.Append(lFEF);
  LI.Append(lE);

} // ProcessFaceInterferences
