// Created on: 1991-07-02
// Created by: Remi LEQUETTE
// Copyright (c) 1991-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 <TopoDS_Face.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRep_TFace.hxx>
#include <BRep_TVertex.hxx>
#include <BRep_Tool.hxx>


//=======================================================================
//function : MakeFace
//purpose  : 
//=======================================================================

inline void BRep_Builder::MakeFace(TopoDS_Face& F) const
{
  Handle(BRep_TFace) TF = new BRep_TFace();
  MakeShape(F,TF);
}


//=======================================================================
//function : MakeEdge
//purpose  : make edge from curve 
//=======================================================================

inline void BRep_Builder::MakeEdge(TopoDS_Edge& E, 
                                   const Handle(Geom_Curve)& C, 
                                   const Standard_Real Tol) const
{
  MakeEdge(E);
  UpdateEdge(E,C,TopLoc_Location(),Tol);
}


//=======================================================================
//function : MakeEdge
//purpose  : make edge from curve 
//=======================================================================

inline void BRep_Builder::MakeEdge(TopoDS_Edge& E, 
                                   const Handle(Poly_Polygon3D)& P) const
{
  MakeEdge(E);
  UpdateEdge(E,P);
}

//=======================================================================
//function : MakeEdge
//purpose  : make edge from triangulation
//=======================================================================

inline void BRep_Builder::MakeEdge(TopoDS_Edge& E,
                                   const Handle(Poly_PolygonOnTriangulation)& P,
                                   const Handle(Poly_Triangulation)& T) const
{
  MakeEdge(E);
  UpdateEdge(E,P,T,TopLoc_Location());
}


//=======================================================================
//function : MakeEdge
//purpose  : make edge from triangulation
//=======================================================================

inline void BRep_Builder::MakeEdge(TopoDS_Edge& E,
                                   const Handle(Poly_PolygonOnTriangulation)& P,
                                   const Handle(Poly_Triangulation)& T,
                                   const TopLoc_Location& L) const
{
  MakeEdge(E);
  UpdateEdge(E,P,T,L);
}


//=======================================================================
//function : MakeEdge
//purpose  : make edge from curve 
//=======================================================================

inline void BRep_Builder::MakeEdge(TopoDS_Edge& E,
                                   const Handle(Geom_Curve)& C,
                                   const TopLoc_Location& L,
                                   const Standard_Real Tol) const
{
  MakeEdge(E);
  UpdateEdge(E,C,L,Tol);
}


//=======================================================================
//function : UpdateEdge
//purpose  : 
//=======================================================================

inline void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
                                     const Handle(Geom_Curve)& C,
                                     const Standard_Real Tol) const
{
  UpdateEdge(E,C,TopLoc_Location(),Tol);
}


//=======================================================================
//function : UpdateEdge
//purpose  : 
//=======================================================================

inline void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
                                     const Handle(Geom2d_Curve)& C,
                                     const TopoDS_Face& F,
                                     const Standard_Real Tol) const
{
  TopLoc_Location l;
  UpdateEdge(E,C,BRep_Tool::Surface(F,l),l,Tol);
}


//=======================================================================
//function : UpdateEdge
//purpose  : 
//=======================================================================

inline void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
                                     const Handle(Geom2d_Curve)& C1,
                                     const Handle(Geom2d_Curve)& C2,
                                     const TopoDS_Face& F,
                                     const Standard_Real Tol) const
{
  TopLoc_Location l;
  UpdateEdge(E,C1,C2,BRep_Tool::Surface(F,l),l,Tol);
}


//=======================================================================
//function : UpdateEdge
//purpose  : 
//=======================================================================

inline void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
                                     const Handle(Poly_Polygon3D)& P) const
{
  UpdateEdge(E,P,TopLoc_Location());
}


//=======================================================================
//function : UpdateEdge
//purpose  : 
//=======================================================================

inline void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
                                     const Handle(Poly_PolygonOnTriangulation)& P,
                                     const Handle(Poly_Triangulation)& T) const
{
  UpdateEdge(E,P,T,TopLoc_Location());
}


//=======================================================================
//function : UpdateEdge
//purpose  : 
//=======================================================================

inline void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
                                     const Handle(Poly_PolygonOnTriangulation)& P1,
                                     const Handle(Poly_PolygonOnTriangulation)& P2,
                                     const Handle(Poly_Triangulation)& T) const
{
  UpdateEdge(E,P1,P2,T,TopLoc_Location());
}


//=======================================================================
//function : Range
//purpose  : 
//=======================================================================

inline void BRep_Builder::Range(const TopoDS_Edge& E, 
                                const TopoDS_Face& F, 
                                const Standard_Real First, 
                                const Standard_Real Last) const
{
  TopLoc_Location l;
  Range(E,BRep_Tool::Surface(F,l),l,First,Last);
}


//=======================================================================
//function : MakeVertex
//purpose  : undefined vertex
//=======================================================================

inline void BRep_Builder::MakeVertex(TopoDS_Vertex& V) const
{
  Handle(BRep_TVertex) TV = new BRep_TVertex();
  MakeShape(V,TV);
}


//=======================================================================
//function : MakeVertex
//purpose  : vertex from 3d point
//=======================================================================

inline void BRep_Builder::MakeVertex(TopoDS_Vertex& V,
                                     const gp_Pnt& P,
                                     const Standard_Real Tol) const
{
  MakeVertex(V);
  UpdateVertex(V,P,Tol);
}


//=======================================================================
//function : UpdateVertex
//purpose  : update vertex with parameter on edge on face
//=======================================================================

inline void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
                                       const Standard_Real  Par,
                                       const TopoDS_Edge&   E,
                                       const TopoDS_Face&   F,
                                       const Standard_Real  Tol) const
{
  TopLoc_Location l;
  UpdateVertex(V,Par,E,BRep_Tool::Surface(F,l),l,Tol);
}
