1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

259
src/BRepTools/BRepTools.cdl Executable file
View File

@@ -0,0 +1,259 @@
-- File: BRepTools.cdl
-- Created: Fri Aug 28 18:54:27 1992
-- Author: Remi LEQUETTE
-- <rle@phylox>
---Copyright: Matra Datavision 1992
package BRepTools
---Level : Public.
-- All methods of all classes will be public.
---Purpose: The BRepTools package provides utilities for BRep
-- data structures.
--
-- * WireExplorer : A tool to explore the topology of
-- a wire in the order of the edges.
--
-- * ShapeSet : Tools used for dumping, writing and
-- reading.
--
-- * UVBounds : Methods to compute the limits of the
-- boundary of a face, a wire or an edge in the
-- parametric space of a face.
--
-- * Update : Methods to call when a topology has
-- been created to compute all missing data.
--
-- * UpdateFaceUVPoints : Method to update the UV
-- points stored with the edges on a face. This
-- method ensure that connected edges have the same
-- UV point on their common extremity.
--
-- * Compare : Method to compare two vertices.
--
-- * Compare : Method to compare two edges.
--
-- * OuterWire : A method to find the outer wire of a
-- face.
--
-- * OuterShell : A method to find the outer shell of
-- a solid.
--
-- * Map3DEdges : A method to map all the 3D Edges of
-- a Shape.
--
-- * Dump : A method to dump a BRep object.
--
uses
BRep,
TopExp,
TopTools,
TopoDS,
TopAbs,
TopLoc,
GeomAbs,
GeomTools,
Geom,
Geom2d,
gp,
Bnd,
TColgp,
TColStd,
TCollection,
MMgt,
Message
is
class WireExplorer;
---Purpose: To explore the 3D or the UV topology of a Face.
deferred class Modification;
---Purpose: Defines geometric modifications on a shape
-- ( on the faces, the edges, the vertices).
class Modifier;
---Purpose: Performs geometric modifications on a shape.
class TrsfModification;
---Purpose: Defines a Modification with a Trsf from gp.
-- Inherited from Modification.
class NurbsConvertModification;
---Purpose: Conversion des entites analytiques d'une shape
-- en NURBS (courbes et surface 3D)
-- Inherited from Modification.
class GTrsfModification;
---Purpose: Defines a Modification with a GTrsf from gp.
-- Inherited from Modification.
class Substitution;
---Purpose: Provides a tool to change subshapes in a shape.
class Quilt;
---Purpose: Provides a tool to glue shapes on edges.
-- for exemple glue faces to make a shell.
-- class Sewing;
---Purpose: Provides a tool to
-- - identify contigous boundaries (for control
-- of continuity: C0, C1, ...)
-- - assemble contigous shapes into one shape.
--
-- Dump, Write, Read tools
class ShapeSet;
---Purpose: A set of BRep TShapes. Inherited from TopTools.
class ReShape;
---Purpose: Provides tools for modification of shape.
class MapOfVertexPnt2d instantiates DataMap from TCollection
(Shape from TopoDS,
SequenceOfPnt2d from TColgp,
ShapeMapHasher from TopTools);
--
-- Methods
--
UVBounds(F : Face from TopoDS;
UMin, UMax, VMin, VMax : out Real);
---Purpose: Returns in UMin, UMax, VMin, VMax the bounding
-- values in the parametric space of F.
UVBounds(F : Face from TopoDS;
W : Wire from TopoDS;
UMin, UMax, VMin, VMax : out Real);
---Purpose: Returns in UMin, UMax, VMin, VMax the bounding
-- values of the wire in the parametric space of F.
UVBounds(F : Face from TopoDS;
E : Edge from TopoDS;
UMin, UMax, VMin, VMax : out Real);
---Purpose: Returns in UMin, UMax, VMin, VMax the bounding
-- values of the edge in the parametric space of F.
AddUVBounds(F : Face from TopoDS;
B : in out Box2d from Bnd);
---Purpose: Adds to the box <B> the bounding values in the
-- parametric space of F.
AddUVBounds(F : Face from TopoDS;
W : Wire from TopoDS;
B : in out Box2d from Bnd);
---Purpose: Adds to the box <B> the bounding values of the
-- wire in the parametric space of F.
AddUVBounds(F : Face from TopoDS;
E : Edge from TopoDS;
B : in out Box2d from Bnd);
---Purpose: Adds to the box <B> the bounding values of the
-- edge in the parametric space of F.
Update(V : Vertex from TopoDS);
---Purpose: Update a vertex (nothing is done)
Update(E : Edge from TopoDS);
---Purpose: Update an edge, compute 2d bounding boxes.
Update(W : Wire from TopoDS);
---Purpose: Update a wire (nothing is done)
Update(F : Face from TopoDS);
---Purpose: Update a Face, update UV points.
Update(S : Shell from TopoDS);
---Purpose: Update a shell (nothing is done)
Update(S : Solid from TopoDS);
---Purpose: Update a solid (nothing is done)
Update(C : CompSolid from TopoDS);
---Purpose: Update a composite solid (nothing is done)
Update(C : Compound from TopoDS);
---Purpose: Update a compound (nothing is done)
Update(S : Shape from TopoDS);
---Purpose: Update a shape, call the corect update.
UpdateFaceUVPoints(F : Face from TopoDS);
---Purpose: For all the edges of the face <F> reset the UV
-- points to ensure that connected faces have the
-- same point at there common extremity.
Clean(S: Shape from TopoDS);
---Purpose: Removes all the triangulations of the faces of <S>
-- and removes all polygons on triangulations of the
-- edges.
Triangulation(S: Shape from TopoDS; deflec: Real)
returns Boolean from Standard;
---Purpose: verifies that each face from the shape <S> has got
-- a triangulation with a deflection <= deflec and
-- the edges a discretisation on this triangulation.
Compare(V1,V2 : Vertex from TopoDS) returns Boolean;
---Purpose: Returns True if the distance between the two
-- vertices is lower than their tolerance.
Compare(E1,E2 : Edge from TopoDS) returns Boolean;
---Purpose: Returns True if the distance between the two
-- edges is lower than their tolerance.
OuterWire(F : Face from TopoDS) returns Wire from TopoDS;
---Purpose: Returns the outer most wire of <F>. Returns a Null
-- wire if <F> has no wires.
OuterShell(S : Solid from TopoDS) returns Shell from TopoDS;
---Purpose: Returns the outer most shell of <S>. Returns a Null
-- wire if <S> has no shells.
Map3DEdges(S : Shape from TopoDS;
M : in out IndexedMapOfShape from TopTools);
---Purpose: Stores in the map <M> all the 3D topology edges
-- of <S>.
IsReallyClosed(E: Edge from TopoDS; F: Face from TopoDS)
---Purpose: Verifies that the edge <E> is found two times on
-- the face <F> before calling BRep_Tool::IsClosed.
returns Boolean from Standard;
Dump(Sh : Shape from TopoDS; S : in out OStream);
---Purpose: Dumps the topological structure and the geometry
-- of <Sh> on the stream <S>.
Write(Sh : Shape from TopoDS; S : in out OStream;
PR : ProgressIndicator from Message = NULL);
---Purpose: Writes <Sh> on <S> in an ASCII format.
Read(Sh : out Shape from TopoDS; S : in out IStream;
B : Builder from BRep; PR : ProgressIndicator from Message = NULL);
---Purpose: Reads a Shape from <S> in returns it in <Sh>.
-- <B> is used to build the shape.
Write(Sh : Shape from TopoDS; File : CString;
PR : ProgressIndicator from Message = NULL ) returns Boolean;
---Purpose: Writes <Sh> in <File>.
Read(Sh : out Shape from TopoDS; File : CString;
B : Builder from BRep; PR : ProgressIndicator from Message = NULL)
returns Boolean;
---Purpose: Reads a Shape from <File>, returns it in <Sh>.
-- <B> is used to build the shape.
end BRepTools;

805
src/BRepTools/BRepTools.cxx Executable file
View File

@@ -0,0 +1,805 @@
// File: BRepTools.cxx
// Created: Thu Jan 21 19:59:19 1993
// Author: Remi LEQUETTE
// <rle@phylox>
#include <Standard_Stream.hxx>
#include <BRepTools.ixx>
#include <BRepTools_ShapeSet.hxx>
#include <BRep_Tool.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Iterator.hxx>
#include <BndLib_Add2dCurve.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Geom_Surface.hxx>
#include <Geom_Curve.hxx>
#include <Geom2d_Curve.hxx>
#include <BRepTools_MapOfVertexPnt2d.hxx>
#include <BRep_CurveRepresentation.hxx>
#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
#include <BRep_TEdge.hxx>
#include <TColgp_SequenceOfPnt2d.hxx>
#include <TColStd_SequenceOfReal.hxx>
#include <TColGeom2d_SequenceOfCurve.hxx>
#include <TopTools_SequenceOfShape.hxx>
#include <Precision.hxx>
#include <Poly_Triangulation.hxx>
#include <Poly_PolygonOnTriangulation.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <gp_Lin2d.hxx>
#include <ElCLib.hxx>
#include <gp_Vec2d.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
#include <errno.h>
//=======================================================================
//function : UVBounds
//purpose :
//=======================================================================
void BRepTools::UVBounds(const TopoDS_Face& F,
Standard_Real& UMin, Standard_Real& UMax,
Standard_Real& VMin, Standard_Real& VMax)
{
Bnd_Box2d B;
AddUVBounds(F,B);
B.Get(UMin,VMin,UMax,VMax);
}
//=======================================================================
//function : UVBounds
//purpose :
//=======================================================================
void BRepTools::UVBounds(const TopoDS_Face& F,
const TopoDS_Wire& W,
Standard_Real& UMin, Standard_Real& UMax,
Standard_Real& VMin, Standard_Real& VMax)
{
Bnd_Box2d B;
AddUVBounds(F,W,B);
B.Get(UMin,VMin,UMax,VMax);
}
//=======================================================================
//function : UVBounds
//purpose :
//=======================================================================
void BRepTools::UVBounds(const TopoDS_Face& F,
const TopoDS_Edge& E,
Standard_Real& UMin, Standard_Real& UMax,
Standard_Real& VMin, Standard_Real& VMax)
{
Bnd_Box2d B;
AddUVBounds(F,E,B);
B.Get(UMin,VMin,UMax,VMax);
}
//=======================================================================
//function : AddUVBounds
//purpose :
//=======================================================================
void BRepTools::AddUVBounds(const TopoDS_Face& FF, Bnd_Box2d& B)
{
TopoDS_Face F = FF;
F.Orientation(TopAbs_FORWARD);
TopExp_Explorer ex(F,TopAbs_EDGE);
// fill box for the given face
Bnd_Box2d aBox;
for (;ex.More();ex.Next()) {
BRepTools::AddUVBounds(F,TopoDS::Edge(ex.Current()),aBox);
}
// if the box is empty (face without edges or without pcurves),
// get natural bounds
if (aBox.IsVoid()) {
Standard_Real UMin,UMax,VMin,VMax;
TopLoc_Location L;
BRep_Tool::Surface(F,L)->Bounds(UMin,UMax,VMin,VMax);
aBox.Update(UMin,VMin,UMax,VMax);
}
// add face box to result
B.Add ( aBox );
}
//=======================================================================
//function : AddUVBounds
//purpose :
//=======================================================================
void BRepTools::AddUVBounds(const TopoDS_Face& F,
const TopoDS_Wire& W,
Bnd_Box2d& B)
{
TopExp_Explorer ex;
for (ex.Init(W,TopAbs_EDGE);ex.More();ex.Next()) {
BRepTools::AddUVBounds(F,TopoDS::Edge(ex.Current()),B);
}
}
//=======================================================================
//function : AddUVBounds
//purpose :
//=======================================================================
void BRepTools::AddUVBounds(const TopoDS_Face& F,
const TopoDS_Edge& E,
Bnd_Box2d& B)
{
Standard_Real pf,pl;
Bnd_Box2d Baux;
const Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,pf,pl);
if (pl < pf) { // Petit Blindage
Standard_Real aux;
aux = pf; pf = pl; pl = aux;
}
if (C.IsNull()) return;
Geom2dAdaptor_Curve PC(C,pf,pl);
if (Precision::IsNegativeInfinite(pf) ||
Precision::IsPositiveInfinite(pf)) {
Geom2dAdaptor_Curve GC(PC);
BndLib_Add2dCurve::Add(GC,0.,B);
}
else {
// just compute points to get a close box.
TopLoc_Location L;
Standard_Real Umin,Umax,Vmin,Vmax;
const Handle(Geom_Surface)& Surf=BRep_Tool::Surface(F,L);
Surf->Bounds(Umin,Umax,Vmin,Vmax);
gp_Pnt2d Pa,Pb,Pc;
Standard_Real i, nbp = 20;
if (PC.GetType() == GeomAbs_Line) nbp = 2;
Standard_Real step = (pl - pf) / nbp;
gp_Pnt2d P;
PC.D0(pf,P);
Baux.Add(P);
Standard_Real du=0.0;
Standard_Real dv=0.0;
Pc=P;
for (i = 1; i < nbp; i++) {
pf += step;
PC.D0(pf,P);
Baux.Add(P);
if(i==1) { Pb=Pc; Pc=P; }
else {
//-- Calcul de la fleche
Pa=Pb; Pb=Pc; Pc=P;
gp_Vec2d PaPc(Pa,Pc);
// gp_Lin2d L2d(Pa,PaPc);
// Standard_Real up = ElCLib::Parameter(L2d,Pb);
// gp_Pnt2d PProj = ElCLib::Value(up,L2d);
gp_Pnt2d PProj(Pa.Coord()+(PaPc.XY()/2.));
Standard_Real ddu=Abs(Pb.X()-PProj.X());
Standard_Real ddv=Abs(Pb.Y()-PProj.Y());
if(ddv>dv) dv=ddv;
if(ddu>du) du=ddu;
}
}
PC.D0(pl,P);
Baux.Add(P);
//-- cout<<" du="<<du<<" dv="<<dv<<endl;
Standard_Real u0,u1,v0,v1;
Baux.Get(u0,v0,u1,v1);
du*=1.5;
dv*=1.5;
u0-=du; v0-=dv; u1+=du; v1+=dv;
if(Surf->IsUPeriodic()) { }
else {
if(u0<=Umin) { u0=Umin; }
if(u1>=Umax) { u1=Umax; }
}
if(Surf->IsVPeriodic()) { }
else {
if(v0<=Vmin) { v0=Vmin; }
if(v1>=Vmax) { v1=Vmax; }
}
P.SetCoord(u0,v0) ; Baux.Add(P);
P.SetCoord(u1,v1) ; Baux.Add(P);
B.Add(Baux);
}
}
//=======================================================================
//function : Update
//purpose :
//=======================================================================
void BRepTools::Update(const TopoDS_Vertex&)
{
}
//=======================================================================
//function : Update
//purpose :
//=======================================================================
void BRepTools::Update(const TopoDS_Edge&)
{
}
//=======================================================================
//function : Update
//purpose :
//=======================================================================
void BRepTools::Update(const TopoDS_Wire&)
{
}
//=======================================================================
//function : Update
//purpose :
//=======================================================================
void BRepTools::Update(const TopoDS_Face& F)
{
if (!F.Checked()) {
UpdateFaceUVPoints(F);
F.TShape()->Checked(Standard_True);
}
}
//=======================================================================
//function : Update
//purpose :
//=======================================================================
void BRepTools::Update(const TopoDS_Shell& S)
{
TopExp_Explorer ex(S,TopAbs_FACE);
while (ex.More()) {
Update(TopoDS::Face(ex.Current()));
ex.Next();
}
}
//=======================================================================
//function : Update
//purpose :
//=======================================================================
void BRepTools::Update(const TopoDS_Solid& S)
{
TopExp_Explorer ex(S,TopAbs_FACE);
while (ex.More()) {
Update(TopoDS::Face(ex.Current()));
ex.Next();
}
}
//=======================================================================
//function : Update
//purpose :
//=======================================================================
void BRepTools::Update(const TopoDS_CompSolid& CS)
{
TopExp_Explorer ex(CS,TopAbs_FACE);
while (ex.More()) {
Update(TopoDS::Face(ex.Current()));
ex.Next();
}
}
//=======================================================================
//function : Update
//purpose :
//=======================================================================
void BRepTools::Update(const TopoDS_Compound& C)
{
TopExp_Explorer ex(C,TopAbs_FACE);
while (ex.More()) {
Update(TopoDS::Face(ex.Current()));
ex.Next();
}
}
//=======================================================================
//function : Update
//purpose :
//=======================================================================
void BRepTools::Update(const TopoDS_Shape& S)
{
switch (S.ShapeType()) {
case TopAbs_VERTEX :
Update(TopoDS::Vertex(S));
break;
case TopAbs_EDGE :
Update(TopoDS::Edge(S));
break;
case TopAbs_WIRE :
Update(TopoDS::Wire(S));
break;
case TopAbs_FACE :
Update(TopoDS::Face(S));
break;
case TopAbs_SHELL :
Update(TopoDS::Shell(S));
break;
case TopAbs_SOLID :
Update(TopoDS::Solid(S));
break;
case TopAbs_COMPSOLID :
Update(TopoDS::CompSolid(S));
break;
case TopAbs_COMPOUND :
Update(TopoDS::Compound(S));
break;
default:
break;
}
}
//=======================================================================
//function : UpdateFaceUVPoints
//purpose : reset the UV points of a Face
//=======================================================================
void BRepTools::UpdateFaceUVPoints(const TopoDS_Face& F)
{
// Recompute for each edge the two UV points in order to have the same
// UV point on connected edges.
// First edge loop, store the vertices in a Map with their 2d points
BRepTools_MapOfVertexPnt2d theVertices;
TopoDS_Iterator expE,expV;
TopoDS_Iterator EdgeIt,VertIt;
TColStd_SequenceOfReal aFSeq, aLSeq;
TColGeom2d_SequenceOfCurve aCSeq;
TopTools_SequenceOfShape aShSeq;
gp_Pnt2d P;
Standard_Integer i;
// a 3d tolerance for UV !!
Standard_Real tolerance = BRep_Tool::Tolerance(F);
TColgp_SequenceOfPnt2d emptySequence;
for (expE.Initialize(F); expE.More(); expE.Next()) {
if(expE.Value().ShapeType() != TopAbs_WIRE)
continue;
EdgeIt.Initialize(expE.Value());
for( ; EdgeIt.More(); EdgeIt.Next())
{
const TopoDS_Edge& E = TopoDS::Edge(EdgeIt.Value());
Standard_Real f,l;
Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,f,l);
aFSeq.Append(f);
aLSeq.Append(l);
aCSeq.Append(C);
aShSeq.Append(E);
if (C.IsNull()) continue;
for (expV.Initialize(E.Oriented(TopAbs_FORWARD));
expV.More(); expV.Next()) {
const TopoDS_Vertex& V = TopoDS::Vertex(expV.Value());
TopAbs_Orientation Vori = V.Orientation();
if ( Vori == TopAbs_INTERNAL ) {
continue;
}
Standard_Real p = BRep_Tool::Parameter(V,E,F);
C->D0(p,P);
if (!theVertices.IsBound(V))
theVertices.Bind(V,emptySequence);
TColgp_SequenceOfPnt2d& S = theVertices(V);
for (i = 1; i <= S.Length(); i++) {
if (P.Distance(S(i)) < tolerance) break;
}
if (i > S.Length())
S.Append(P);
}
}
}
// second edge loop, update the edges 2d points
TopoDS_Vertex Vf,Vl;
gp_Pnt2d Pf,Pl;
for(Standard_Integer j = 1; j <= aShSeq.Length(); j++)
{
const TopoDS_Edge& E = TopoDS::Edge(aShSeq.Value(j));
const Handle(Geom2d_Curve)& C = aCSeq.Value(j);
if (C.IsNull()) continue;
TopExp::Vertices(E,Vf,Vl);
if (Vf.IsNull()) {
Pf.SetCoord(RealLast(),RealLast());
}
else {
if ( Vf.Orientation() == TopAbs_INTERNAL ) {
continue;
}
const TColgp_SequenceOfPnt2d& seqf = theVertices(Vf);
if (seqf.Length() == 1)
Pf = seqf(1);
else {
C->D0(aFSeq.Value(j),Pf);
for (i = 1; i <= seqf.Length(); i++) {
if (Pf.Distance(seqf(i)) <= tolerance) {
Pf = seqf(i);
break;
}
}
}
}
if (Vl.IsNull()) {
Pl.SetCoord(RealLast(),RealLast());
}
else {
if ( Vl.Orientation() == TopAbs_INTERNAL ) {
continue;
}
const TColgp_SequenceOfPnt2d& seql = theVertices(Vl);
if (seql.Length() == 1)
Pl = seql(1);
else {
C->D0(aLSeq.Value(j),Pl);
for (i = 1; i <= seql.Length(); i++) {
if (Pl.Distance(seql(i)) <= tolerance) {
Pl = seql(i);
break;
}
}
}
}
// set the correct points
BRep_Tool::SetUVPoints(E,F,Pf,Pl);
}
}
//=======================================================================
//function : Compare
//purpose :
//=======================================================================
Standard_Boolean BRepTools::Compare(const TopoDS_Vertex& V1,
const TopoDS_Vertex& V2)
{
if (V1.IsSame(V2)) return Standard_True;
gp_Pnt p1 = BRep_Tool::Pnt(V1);
gp_Pnt p2 = BRep_Tool::Pnt(V2);
Standard_Real l = p1.Distance(p2);
if (l <= BRep_Tool::Tolerance(V1)) return Standard_True;
if (l <= BRep_Tool::Tolerance(V2)) return Standard_True;
return Standard_False;
}
//=======================================================================
//function : Compare
//purpose :
//=======================================================================
Standard_Boolean BRepTools::Compare(const TopoDS_Edge& E1,
const TopoDS_Edge& E2)
{
if (E1.IsSame(E2)) return Standard_True;
return Standard_False;
}
//=======================================================================
//function : OuterWire
//purpose :
//=======================================================================
TopoDS_Wire BRepTools::OuterWire(const TopoDS_Face& F)
{
TopoDS_Wire Wres;
TopExp_Explorer expw (F,TopAbs_WIRE);
if (expw.More()) {
Wres = TopoDS::Wire(expw.Current());
expw.Next();
if (expw.More()) {
Standard_Real UMin, UMax, VMin, VMax;
Standard_Real umin, umax, vmin, vmax;
BRepTools::UVBounds(F,Wres,UMin,UMax,VMin,VMax);
while (expw.More()) {
const TopoDS_Wire& W = TopoDS::Wire(expw.Current());
BRepTools::UVBounds(F,W,umin, umax, vmin, vmax);
if ((umin <= UMin) &&
(umax >= UMax) &&
(vmin <= VMin) &&
(vmax >= VMax)) {
Wres = W;
UMin = umin;
UMax = umax;
VMin = vmin;
VMax = vmax;
}
expw.Next();
}
}
}
return Wres;
}
//=======================================================================
//function : OuterShell
//purpose :
//=======================================================================
TopoDS_Shell BRepTools::OuterShell(const TopoDS_Solid& S)
{
TopExp_Explorer its(S,TopAbs_SHELL);
if (its.More())
return TopoDS::Shell(its.Current());
else
return TopoDS_Shell();
}
//=======================================================================
//function : Map3DEdges
//purpose :
//=======================================================================
void BRepTools::Map3DEdges(const TopoDS_Shape& S,
TopTools_IndexedMapOfShape& M)
{
TopExp_Explorer Ex;
for (Ex.Init(S,TopAbs_EDGE); Ex.More(); Ex.Next()) {
if (!BRep_Tool::Degenerated(TopoDS::Edge(Ex.Current())))
M.Add(Ex.Current());
}
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void BRepTools::Dump(const TopoDS_Shape& Sh, Standard_OStream& S)
{
BRepTools_ShapeSet SS;
SS.Add(Sh);
SS.Dump(Sh,S);
SS.Dump(S);
}
#ifdef DEB
//=======================================================================
//function : BRepTools_Write
//purpose :
//=======================================================================
void BRepTools_Write (const TopoDS_Shape& S,
const Standard_CString File)
{
BRepTools::Write (S,File);
}
#endif
//=======================================================================
//function : Write
//purpose :
//=======================================================================
void BRepTools::Write(const TopoDS_Shape& Sh, Standard_OStream& S,
const Handle(Message_ProgressIndicator)& PR)
{
BRepTools_ShapeSet SS;
SS.SetProgress(PR);
SS.Add(Sh);
SS.Write(S);
SS.Write(Sh,S);
}
//=======================================================================
//function : Read
//purpose :
//=======================================================================
void BRepTools::Read(TopoDS_Shape& Sh,
istream& S,
const BRep_Builder& B,
const Handle(Message_ProgressIndicator)& PR)
{
BRepTools_ShapeSet SS(B);
SS.SetProgress(PR);
SS.Read(S);
SS.Read(Sh,S);
}
//=======================================================================
//function : Write
//purpose :
//=======================================================================
Standard_Boolean BRepTools::Write(const TopoDS_Shape& Sh,
const Standard_CString File,
const Handle(Message_ProgressIndicator)& PR)
{
ofstream os;
// if (!fic.open(File,output)) return Standard_False;
os.open(File, ios::out);
if (!os.rdbuf()->is_open()) return Standard_False;
Standard_Boolean isGood = (os.good() && !os.eof());
if(!isGood)
return isGood;
BRepTools_ShapeSet SS;
SS.SetProgress(PR);
SS.Add(Sh);
os << "DBRep_DrawableShape\n"; // for easy Draw read
SS.Write(os);
isGood = os.good();
if(isGood )
SS.Write(Sh,os);
os.flush();
isGood = os.good();
errno = 0;
os.close();
#ifdef DEB
// cout<<"!!!"<<strerror(errno)<<endl;
#endif
isGood = os.good() && isGood && !errno;
return isGood;
}
//=======================================================================
//function : Read
//purpose :
//=======================================================================
Standard_Boolean BRepTools::Read(TopoDS_Shape& Sh,
const Standard_CString File,
const BRep_Builder& B,
const Handle(Message_ProgressIndicator)& PR)
{
filebuf fic;
istream in(&fic);
if (!fic.open(File, ios::in)) return Standard_False;
BRepTools_ShapeSet SS(B);
SS.SetProgress(PR);
SS.Read(in);
if(!SS.NbShapes()) return Standard_False;
SS.Read(Sh,in);
return Standard_True;
}
//=======================================================================
//function : Clean
//purpose :
//=======================================================================
void BRepTools::Clean(const TopoDS_Shape& S)
{
BRep_Builder B;
TopExp_Explorer ex;
Handle(Poly_Triangulation) TNULL, T;
Handle(Poly_PolygonOnTriangulation) PolyNULL, Poly;
if (!S.IsNull()) {
TopLoc_Location L;
for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
const TopoDS_Face& F = TopoDS::Face(ex.Current());
B.UpdateFace(F, TNULL);
}
for (ex.Init(S, TopAbs_EDGE); ex.More(); ex.Next()) {
const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
// agv 21.09.01 : Inefficient management of Locations -> improve performance
// do {
// BRep_Tool::PolygonOnTriangulation(E, Poly, T, L);
// B.UpdateEdge(E, PolyNULL, T, L);
// } while(!Poly.IsNull());
//
Handle(BRep_CurveRepresentation) cr;
const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
BRep_ListOfCurveRepresentation& lcr = TE -> ChangeCurves();
BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
// find and remove all representations
while (itcr.More()) {
cr = itcr.Value();
if (cr->IsPolygonOnTriangulation())
lcr.Remove(itcr);
else
itcr.Next();
}
TE->Modified(Standard_True);
// agv : fin
}
}
}
//=======================================================================
//function : Triangulation
//purpose :
//=======================================================================
Standard_Boolean BRepTools::Triangulation(const TopoDS_Shape& S,
const Standard_Real deflec)
{
TopExp_Explorer exf, exe;
TopLoc_Location l;
Handle(Poly_Triangulation) T;
Handle(Poly_PolygonOnTriangulation) Poly;
for (exf.Init(S, TopAbs_FACE); exf.More(); exf.Next()) {
const TopoDS_Face& F = TopoDS::Face(exf.Current());
T = BRep_Tool::Triangulation(F, l);
if (T.IsNull() || (T->Deflection() > deflec))
return Standard_False;
for (exe.Init(F, TopAbs_EDGE); exe.More(); exe.Next()) {
const TopoDS_Edge& E = TopoDS::Edge(exe.Current());
Poly = BRep_Tool::PolygonOnTriangulation(E, T, l);
if (Poly.IsNull()) return Standard_False;
}
}
return Standard_True;
}
//=======================================================================
//function : IsReallyClosed
//purpose :
//=======================================================================
Standard_Boolean BRepTools::IsReallyClosed(const TopoDS_Edge& E,
const TopoDS_Face& F)
{
if (!BRep_Tool::IsClosed(E,F)) {
return Standard_False;
}
Standard_Integer nbocc = 0;
TopExp_Explorer exp;
for (exp.Init(F,TopAbs_EDGE);exp.More();exp.Next()) {
if (exp.Current().IsSame(E)) {
nbocc++;
}
}
return nbocc == 2;
}

View File

@@ -0,0 +1,150 @@
-- File: BRepTools_GTrsfModification.cdl
-- Created: Mon Dec 30 15:58:53 1996
-- Author: Stagiaire Mary FABIEN
-- <fbi@zozox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1996
class GTrsfModification from BRepTools inherits Modification from BRepTools
---Purpose: Defines a modification of the geometry by a GTrsf
-- from gp. All methods return True and transform the
-- geometry.
uses Face from TopoDS,
Edge from TopoDS,
Vertex from TopoDS,
Location from TopLoc,
Shape from GeomAbs,
Surface from Geom,
Curve from Geom,
Curve from Geom2d,
GTrsf from gp,
Pnt from gp
is
Create (T : GTrsf from gp) returns mutable GTrsfModification from BRepTools;
GTrsf(me: mutable)
---Purpose: Gives an access on the GTrsf.
---C++: return &
returns GTrsf from gp
is static;
NewSurface(me: mutable; F : Face from TopoDS;
S : out Surface from Geom;
L : out Location from TopLoc;
Tol : out Real from Standard;
RevWires : out Boolean from Standard;
RevFace : out Boolean from Standard)
---Purpose: Returns Standard_True if the face <F> has been
-- modified. In this case, <S> is the new geometric
-- support of the face, <L> the new location,<Tol>
-- the new tolerance.<RevWires> has to be set to
-- Standard_True when the modification reverses the
-- normal of the surface.(the wires have to be
-- reversed). <RevFace> has to be set to
-- Standard_True if the orientation of the modified
-- face changes in the shells which contain it. --
-- Here, <RevFace> will return Standard_True if the
-- -- gp_Trsf is negative.
returns Boolean from Standard
;
NewCurve(me: mutable; E : Edge from TopoDS;
C : out Curve from Geom;
L : out Location from TopLoc;
Tol: out Real from Standard)
returns Boolean from Standard
;
---Purpose: Returns Standard_True if the edge <E> has been
-- modified. In this case, <C> is the new geometric
-- support of the edge, <L> the new location, <Tol>
-- the new tolerance. Otherwise, returns
-- Standard_False, and <C>, <L>, <Tol> are not
-- significant.
NewPoint(me: mutable; V : Vertex from TopoDS;
P : out Pnt from gp;
Tol: out Real from Standard)
returns Boolean from Standard
;
---Purpose: Returns Standard_True if the vertex <V> has been
-- modified. In this case, <P> is the new geometric
-- support of the vertex, <Tol> the new tolerance.
-- Otherwise, returns Standard_False, and <P>, <Tol>
-- are not significant.
NewCurve2d(me: mutable; E : Edge from TopoDS;
F : Face from TopoDS;
NewE : Edge from TopoDS;
NewF : Face from TopoDS;
C : out Curve from Geom2d;
Tol : out Real from Standard)
returns Boolean from Standard
;
---Purpose: Returns Standard_True if the edge <E> has a new
-- curve on surface on the face <F>.In this case, <C>
-- is the new geometric support of the edge, <L> the
-- new location, <Tol> the new tolerance.
-- Otherwise, returns Standard_False, and <C>, <L>,
-- <Tol> are not significant.
NewParameter(me: mutable; V : Vertex from TopoDS;
E : Edge from TopoDS;
P : out Real from Standard;
Tol: out Real from Standard)
returns Boolean from Standard
;
---Purpose: Returns Standard_True if the Vertex <V> has a new
-- parameter on the edge <E>. In this case, <P> is
-- the parameter, <Tol> the new tolerance.
-- Otherwise, returns Standard_False, and <P>, <Tol>
-- are not significant.
Continuity(me: mutable; E : Edge from TopoDS;
F1,F2 : Face from TopoDS;
NewE : Edge from TopoDS;
NewF1,NewF2: Face from TopoDS)
returns Shape from GeomAbs
---Purpose: Returns the continuity of <NewE> between <NewF1>
-- and <NewF2>.
--
-- <NewE> is the new edge created from <E>. <NewF1>
-- (resp. <NewF2>) is the new face created from <F1>
-- (resp. <F2>).
;
fields
myGTrsf : GTrsf from gp;
myGScale: Real;
end GTrsfModification;

View File

@@ -0,0 +1,240 @@
// File: BRepTools_GTrsfModification.cxx
// Created: Mon Dec 30 16:01:13 1996
// Author: Stagiaire Mary FABIEN
// <fbi@zozox.paris1.matra-dtv.fr>
#include <BRepTools_GTrsfModification.ixx>
#include <Geom_Plane.hxx>
#include <Geom_Line.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom_BezierSurface.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_BezierCurve.hxx>
#include <Standard_Type.hxx>
#include <BRep_Tool.hxx>
#include <gp_GTrsf2d.hxx>
#include <gp_XYZ.hxx>
#include <gp_TrsfForm.hxx>
#include <Standard_NoSuchObject.hxx>
#include <gp.hxx>
#include <GeomLib.hxx>
#include <TopAbs.hxx>
//=======================================================================
//function : BRepTools_GTrsfModification
//purpose :
//=======================================================================
BRepTools_GTrsfModification::BRepTools_GTrsfModification(const gp_GTrsf& T) :
myGTrsf(T)
{
// on prend comme dilatation maximale pour la tolerance la norme sup
Standard_Real loc1, loc2, loc3, loc4;
loc1 = Max(Abs(T.Value(1,1)), Abs(T.Value(1,2)));
loc2 = Max(Abs(T.Value(2,1)), Abs(T.Value(2,2)));
loc3 = Max(Abs(T.Value(3,1)), Abs(T.Value(3,2)));
loc4 = Max(Abs(T.Value(1,3)), Abs(T.Value(2,3)));
loc1 = Max(loc1, loc2);
loc2 = Max(loc3, loc4);
loc1 = Max(loc1, loc2);
myGScale = Max(loc1, Abs(T.Value(3,3)));
}
//=======================================================================
//function : GTrsf
//purpose :
//=======================================================================
gp_GTrsf& BRepTools_GTrsfModification::GTrsf ()
{
return myGTrsf;
}
//=======================================================================
//function : NewSurface
//purpose :
//=======================================================================
Standard_Boolean BRepTools_GTrsfModification::NewSurface
(const TopoDS_Face& F,
Handle(Geom_Surface)& S,
TopLoc_Location& L,
Standard_Real& Tol,
Standard_Boolean& RevWires,
Standard_Boolean& RevFace)
{
gp_GTrsf gtrsf;
gtrsf.SetVectorialPart(myGTrsf.VectorialPart());
gtrsf.SetTranslationPart(myGTrsf.TranslationPart());
S = Handle(Geom_Surface)::DownCast(BRep_Tool::Surface(F,L)->Copy());
Tol = BRep_Tool::Tolerance(F);
Tol *= myGScale;
RevWires = Standard_False;
RevFace = myGTrsf.IsNegative();
S = Handle(Geom_Surface)::DownCast(S->Transformed(L.Transformation()));
Handle(Standard_Type) TheTypeS = S->DynamicType();
if (TheTypeS == STANDARD_TYPE(Geom_BSplineSurface)) {
Handle(Geom_BSplineSurface) S2 = Handle(Geom_BSplineSurface)::DownCast(S);
for(Standard_Integer i = 1; i <= S2->NbUPoles(); i++)
for(Standard_Integer j = 1; j <= S2->NbVPoles(); j++) {
gp_XYZ coor(S2->Pole(i, j).Coord());
gtrsf.Transforms(coor);
gp_Pnt P(coor);
S2->SetPole(i, j, P);
}
}
else
if (TheTypeS == STANDARD_TYPE(Geom_BezierSurface)) {
Handle(Geom_BezierSurface) S2 = Handle(Geom_BezierSurface)::DownCast(S);
for(Standard_Integer i = 1; i <= S2->NbUPoles(); i++)
for(Standard_Integer j = 1; j <= S2->NbVPoles(); j++) {
gp_XYZ coor(S2->Pole(i, j).Coord());
gtrsf.Transforms(coor);
gp_Pnt P(coor);
S2->SetPole(i, j, P);
}
}
else
Standard_NoSuchObject_Raise_if(1,"BRepTools_GTrsfModification : Pb no BSpline/Bezier Type Surface");
L.Identity();
return Standard_True;
}
//=======================================================================
//function : NewCurve
//purpose :
//=======================================================================
Standard_Boolean BRepTools_GTrsfModification::NewCurve
(const TopoDS_Edge& E,
Handle(Geom_Curve)& C,
TopLoc_Location& L,
Standard_Real& Tol)
{
Standard_Real f,l;
gp_GTrsf gtrsf;
gtrsf.SetVectorialPart(myGTrsf.VectorialPart());
gtrsf.SetTranslationPart(myGTrsf.TranslationPart());
Tol = BRep_Tool::Tolerance(E)*myGScale;
C = BRep_Tool::Curve(E, L, f, l);
if (!C.IsNull()) {
C = Handle(Geom_Curve)::DownCast(C->Copy()->Transformed(L.Transformation()));
Handle(Standard_Type) TheTypeC = C->DynamicType();
if (TheTypeC == STANDARD_TYPE(Geom_BSplineCurve)) {
Handle(Geom_BSplineCurve) C2 = Handle(Geom_BSplineCurve)::DownCast(C);
for(Standard_Integer i = 1; i <= C2->NbPoles(); i++) {
gp_XYZ coor(C2->Pole(i).Coord());
gtrsf.Transforms(coor);
gp_Pnt P(coor);
C2->SetPole(i, P);
}
}
else
if(TheTypeC == STANDARD_TYPE(Geom_BezierCurve)) {
Handle(Geom_BezierCurve) C2 = Handle(Geom_BezierCurve)::DownCast(C);
for(Standard_Integer i = 1; i <= C2->NbPoles(); i++) {
gp_XYZ coor(C2->Pole(i).Coord());
gtrsf.Transforms(coor);
gp_Pnt P(coor);
C2->SetPole(i, P);
}
}
else
Standard_NoSuchObject_Raise_if(1,"BRepTools_GTrsfModification : Pb no BSpline/Bezier Type Curve");
C = new Geom_TrimmedCurve(C, f, l);
}
L.Identity() ;
return Standard_True;
}
//=======================================================================
//function : NewPoint
//purpose :
//=======================================================================
Standard_Boolean BRepTools_GTrsfModification::NewPoint
(const TopoDS_Vertex& V,
gp_Pnt& P,
Standard_Real& Tol)
{
gp_Pnt Pnt = BRep_Tool::Pnt(V);
Tol = BRep_Tool::Tolerance(V);
Tol *= myGScale;
gp_XYZ coor(Pnt.Coord());
myGTrsf.Transforms(coor);
P.SetXYZ(coor);
return Standard_True;
}
//=======================================================================
//function : NewCurve2d
//purpose :
//=======================================================================
Standard_Boolean BRepTools_GTrsfModification::NewCurve2d
(const TopoDS_Edge& E,
const TopoDS_Face& F,
const TopoDS_Edge&,
const TopoDS_Face&,
Handle(Geom2d_Curve)& C,
Standard_Real& Tol)
{
TopLoc_Location loc;
Tol = BRep_Tool::Tolerance(E);
Tol *= myGScale;
Standard_Real f,l;
C = BRep_Tool::CurveOnSurface(E,F,f,l);
C = new Geom2d_TrimmedCurve(C, f, l);
return Standard_True;
}
//=======================================================================
//function : NewParameter
//purpose :
//=======================================================================
Standard_Boolean BRepTools_GTrsfModification::NewParameter
(const TopoDS_Vertex& V,
const TopoDS_Edge& E,
Standard_Real& P,
Standard_Real& Tol)
{
Tol = BRep_Tool::Tolerance(V);
Tol *= myGScale;
P = BRep_Tool::Parameter(V,E);
return Standard_True;
}
//=======================================================================
//function : Continuity
//purpose :
//=======================================================================
GeomAbs_Shape BRepTools_GTrsfModification::Continuity
(const TopoDS_Edge& E,
const TopoDS_Face& F1,
const TopoDS_Face& F2,
const TopoDS_Edge&,
const TopoDS_Face&,
const TopoDS_Face&)
{
return BRep_Tool::Continuity(E,F1,F2);
}

View File

@@ -0,0 +1,151 @@
-- File: BRepTools_Modification.cdl
-- Created: Thu Aug 25 09:19:11 1994
-- Author: Jacques GOUSSARD
-- <jag@ecolox>
---Copyright: Matra Datavision 1994
deferred class Modification from BRepTools
---Purpose: Defines geometric modifications to a shape, i.e.
-- changes to faces, edges and vertices.
inherits TShared from MMgt
uses Face from TopoDS,
Edge from TopoDS,
Vertex from TopoDS,
Location from TopLoc,
Shape from GeomAbs,
Surface from Geom,
Curve from Geom,
Curve from Geom2d,
Pnt from gp
is
NewSurface(me: mutable; F : Face from TopoDS;
S : out Surface from Geom;
L : out Location from TopLoc;
Tol : out Real from Standard;
RevWires : out Boolean from Standard;
RevFace : out Boolean from Standard)
---Purpose: Returns true if the face, F, has been modified.
-- If the face has been modified:
-- - S is the new geometry of the face,
-- - L is its new location, and
-- - Tol is the new tolerance.
-- The flag, RevWires, is set to true when the
-- modification reverses the normal of the surface, (i.e.
-- the wires have to be reversed).
-- The flag, RevFace, is set to true if the orientation of
-- the modified face changes in the shells which contain it.
-- If the face has not been modified this function returns
-- false, and the values of S, L, Tol, RevWires and
-- RevFace are not significant.
returns Boolean from Standard
is deferred;
NewCurve(me: mutable; E : Edge from TopoDS;
C : out Curve from Geom;
L : out Location from TopLoc;
Tol: out Real from Standard)
returns Boolean from Standard
---Purpose: Returns true if the edge, E, has been modified.
-- If the edge has been modified:
-- - C is the new geometry associated with the edge,
-- - L is its new location, and
-- - Tol is the new tolerance.
-- If the edge has not been modified, this function
-- returns false, and the values of C, L and Tol are not significant.
is deferred;
NewPoint(me: mutable; V : Vertex from TopoDS;
P : out Pnt from gp;
Tol: out Real from Standard)
returns Boolean from Standard
---Purpose: Returns true if the vertex V has been modified.
-- If V has been modified:
-- - P is the new geometry of the vertex, and
-- - Tol is the new tolerance.
-- If the vertex has not been modified this function
-- returns false, and the values of P and Tol are not significant.
is deferred;
NewCurve2d(me: mutable; E : Edge from TopoDS;
F : Face from TopoDS;
NewE : Edge from TopoDS;
NewF : Face from TopoDS;
C : out Curve from Geom2d;
Tol : out Real from Standard)
returns Boolean from Standard
---Purpose: Returns true if the edge, E, has a new curve on
-- surface on the face, F.
-- If a new curve exists:
-- - C is the new geometry of the edge,
-- - L is the new location, and
-- - Tol is the new tolerance.
-- NewE is the new edge created from E, and NewF is
-- the new face created from F.
-- If there is no new curve on the face, this function
-- returns false, and the values of C, L and Tol are not significant.
is deferred;
NewParameter(me: mutable; V : Vertex from TopoDS;
E : Edge from TopoDS;
P : out Real from Standard;
Tol: out Real from Standard)
returns Boolean from Standard
---Purpose: Returns true if the vertex V has a new parameter on the edge E.
-- If a new parameter exists:
-- - P is the parameter, and
-- - Tol is the new tolerance.
-- If there is no new parameter this function returns
-- false, and the values of P and Tol are not significant.
is deferred;
Continuity(me: mutable; E : Edge from TopoDS;
F1,F2 : Face from TopoDS;
NewE : Edge from TopoDS;
NewF1,NewF2: Face from TopoDS)
returns Shape from GeomAbs
---Purpose: Returns the continuity of <NewE> between <NewF1>
-- and <NewF2>.
-- <NewE> is the new edge created from <E>. <NewF1>
-- (resp. <NewF2>) is the new face created from <F1>
-- (resp. <F2>).
is deferred;
end Modification;

View File

@@ -0,0 +1,9 @@
// File: BRepTools_Modification.cxx
// Created: Thu Aug 25 10:47:38 1994
// Author: Jacques GOUSSARD
// <jag@ecolox>
#include <BRepTools_Modification.ixx>

View File

@@ -0,0 +1,87 @@
-- File: BRepTools_Modifier.cdl
-- Created: Thu Aug 25 10:03:36 1994
-- Author: Jacques GOUSSARD
-- <jag@ecolox>
---Copyright: Matra Datavision 1994
class Modifier from BRepTools
---Purpose:
uses Shape from TopoDS,
Modification from BRepTools,
DataMapOfShapeShape from TopTools
raises NullObject from Standard,
NoSuchObject from Standard
is
Create returns Modifier from BRepTools;
---Purpose: Creates an empty Modifier.
Create(S: Shape from TopoDS)
returns Modifier from BRepTools;
---Purpose: Creates a modifier on the shape <S>.
Create(S: Shape from TopoDS; M: Modification from BRepTools)
returns Modifier from BRepTools;
---Purpose: Creates a modifier on the shape <S>, and performs
-- the modifications described by <M>.
Init(me: in out; S: Shape from TopoDS)
is static;
---Purpose: Initializes the modifier with the shape <S>.
Perform(me: in out; M: Modification from BRepTools)
---Purpose: Performs the modifications described by <M>.
raises NullObject from Standard
-- if the modifier has not been initialized with a shape.
is static;
IsDone(me)
---Purpose: Returns Standard_True if the modification has
-- been computed successfully.
--
---C++: inline
returns Boolean from Standard
is static;
ModifiedShape(me; S: Shape from TopoDS)
returns Shape from TopoDS
---Purpose: Returns the modified shape corresponding to <S>.
---C++: return const&
---C++: inline
raises NoSuchObject from Standard
-- if S is not the initial shape or a sub-shape
-- of the initial shape.
is static;
-- private implementation methods
Put(me: in out; S: Shape from TopoDS)
is static private;
Rebuild(me: in out; S: Shape from TopoDS; M: Modification from BRepTools)
returns Boolean from Standard
is static private;
fields
myMap : DataMapOfShapeShape from TopTools;
myShape: Shape from TopoDS;
myDone : Boolean from Standard;
end Modifier;

View File

@@ -0,0 +1,533 @@
// File: BRepTools_Modifier.cxx
// Created: Thu Aug 25 10:48:00 1994
// Author: Jacques GOUSSARD
// <jag@ecolox>
// IFV 04.06.99 - PRO18974 - treatment of INTERNAL shapes.
#include <BRepTools_Modifier.ixx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TColStd_ListOfTransient.hxx>
#include <TColStd_ListIteratorOfListOfTransient.hxx>
#if 0
#include <Poly_Triangulation.hxx>
#include <Poly_Polygon3D.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#endif
#include <Geom2d_Line.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <BRepTools.hxx>
#include <TopAbs.hxx>
#include <TopExp.hxx>
#include <gp_Pnt.hxx>
#include <gp.hxx>
#include <Standard_NullObject.hxx>
#include <gp_Trsf.hxx>
#include <BRepTools_TrsfModification.hxx>
//=======================================================================
//function : BRepTools_Modifier
//purpose :
//=======================================================================
BRepTools_Modifier::BRepTools_Modifier ():myDone(Standard_False)
{}
//=======================================================================
//function : BRepTools_Modifier
//purpose :
//=======================================================================
BRepTools_Modifier::BRepTools_Modifier (const TopoDS_Shape& S) :
myShape(S),myDone(Standard_False)
{
myMap.Clear();
Put(S);
}
//=======================================================================
//function : BRepTools_Modifier
//purpose :
//=======================================================================
BRepTools_Modifier::BRepTools_Modifier
(const TopoDS_Shape& S,
const Handle(BRepTools_Modification)& M) : myShape(S),myDone(Standard_False)
{
myMap.Clear();
Put(S);
Perform(M);
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void BRepTools_Modifier::Init(const TopoDS_Shape& S)
{
myShape = S;
myDone = Standard_False;
myMap.Clear();
Put(S);
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
void BRepTools_Modifier::Perform(const Handle(BRepTools_Modification)& M)
{
if (myShape.IsNull()) {
Standard_NullObject::Raise();
}
TopTools_DataMapIteratorOfDataMapOfShapeShape theIter(myMap);
// Remise a Null des shapes value, dans le cas ou on applique une autre
// modification au shape de depart.
if (!theIter.Value().IsNull()) {
while (theIter.More()) {
myMap(theIter.Value()).Nullify();
theIter.Next();
}
theIter.Reset();
}
/*
while (theIter.More()) {
Rebuild(theIter.Key(),M);
theIter.Next();
}
*/
Rebuild(myShape,M);
if (myShape.ShapeType() == TopAbs_FACE) {
if (myShape.Orientation() == TopAbs_REVERSED) {
myMap(myShape).Reverse();
}
else{
myMap(myShape).Orientation(myShape.Orientation());
}
}
else {
myMap(myShape).Orientation(myShape.Orientation());
}
// Mise a jour des continuites
TopTools_IndexedDataMapOfShapeListOfShape theEFMap;
TopExp::MapShapesAndAncestors(myShape,TopAbs_EDGE,TopAbs_FACE,theEFMap);
BRep_Builder B;
/*
Standard_Boolean RecomputeTriangles = Standard_False;
Standard_Real MaxDeflection = RealFirst();
Handle(Poly_Triangulation) Tr;
Handle(Poly_Polygon3D) Po;
TopLoc_Location Loc;
*/
while (theIter.More()) {
const TopoDS_Shape& S = theIter.Key();
/*
if (S.ShapeType() == TopAbs_FACE && !S.IsSame(theIter.Value())) {
Tr = BRep_Tool::Triangulation(TopoDS::Face(S),Loc);
if (!Tr.IsNull()) {
RecomputeTriangles = Standard_True;
MaxDeflection = Max(MaxDeflection,Tr->Deflection());
}
}
else */ if (S.ShapeType() == TopAbs_EDGE && !S.IsSame(theIter.Value())) {
const TopoDS_Edge& edg = TopoDS::Edge(S);
/*
Po = BRep_Tool::Polygon3D(edg,Loc);
if (!Po.IsNull()) {
RecomputeTriangles = Standard_True;
MaxDeflection = Max(MaxDeflection,Po->Deflection());
}
*/
TopTools_ListIteratorOfListOfShape it;
it.Initialize(theEFMap.FindFromKey(edg));
TopoDS_Face F1,F2;
while (it.More() && F2.IsNull()) {
if (F1.IsNull()) {
F1 = TopoDS::Face(it.Value());
}
else {
F2 = TopoDS::Face(it.Value());
}
it.Next();
}
if (!F2.IsNull()) {
const TopoDS_Edge& newedg = TopoDS::Edge(myMap(edg));
const TopoDS_Face& newf1 = TopoDS::Face(myMap(F1));
const TopoDS_Face& newf2 = TopoDS::Face(myMap(F2));
GeomAbs_Shape Newcont = M->Continuity(edg,F1,F2,newedg,newf1,newf2);
if (Newcont > GeomAbs_C0) {
B.Continuity(newedg,newf1,newf2,Newcont);
}
}
}
theIter.Next();
}
/*
if (RecomputeTriangles) {
BRepMesh_IncrementalMesh(myMap(myShape),MaxDeflection);
}
*/
myDone = Standard_True;
}
//=======================================================================
//function : Put
//purpose :
//=======================================================================
void BRepTools_Modifier::Put(const TopoDS_Shape& S)
{
if (!myMap.IsBound(S)) {
myMap.Bind(S,TopoDS_Shape());
for(TopoDS_Iterator theIterator(S,Standard_False);theIterator.More();theIterator.Next()) {
Put(theIterator.Value());
}
}
}
//=======================================================================
//function : Rebuild
//purpose :
//=======================================================================
Standard_Boolean BRepTools_Modifier::Rebuild
(const TopoDS_Shape& S,
const Handle(BRepTools_Modification)& M)
{
TopoDS_Shape& result = myMap(S);
// if (!result.IsNull()) return ! S.IsEqual(result);
if (!result.IsNull()) return ! S.IsSame(result);
Standard_Boolean rebuild = Standard_False, RevWires = Standard_False;
TopAbs_Orientation ResOr = TopAbs_FORWARD;
BRep_Builder B;
Standard_Real tol;
Standard_Boolean No3DCurve = Standard_False; // en fait, si on n`a pas de
//modif de geometrie 3d , il faudrait tester l`existence d`une courbe 3d.
// new geometry ?
TopAbs_ShapeEnum ts = S.ShapeType();
switch (ts) {
case TopAbs_FACE:
{
Standard_Boolean RevFace;
Handle(Geom_Surface) surface;
TopLoc_Location location;
rebuild = M->NewSurface(TopoDS::Face(S),surface,location,tol,
RevWires,RevFace);
if (rebuild) {
B.MakeFace(TopoDS::Face(result),surface,
location.Predivided(S.Location()),tol);
result.Location(S.Location());
// result.Orientation(S.Orientation());
if (RevFace) {
ResOr = TopAbs_REVERSED;
}
// set specifics flags of a Face
B.NaturalRestriction(TopoDS::Face(result),
BRep_Tool::NaturalRestriction(TopoDS::Face(S)));
}
}
break;
case TopAbs_EDGE:
{
Handle(Geom_Curve) curve;
TopLoc_Location location;
rebuild = M->NewCurve(TopoDS::Edge(S),curve,location,tol);
if (rebuild) {
if (curve.IsNull()) {
B.MakeEdge(TopoDS::Edge(result));
B.Degenerated(TopoDS::Edge(result),
BRep_Tool::Degenerated(TopoDS::Edge(S)));
B.UpdateEdge(TopoDS::Edge(result),tol); //OCC217
No3DCurve = Standard_True;
}
else {
B.MakeEdge(TopoDS::Edge(result),curve,
location.Predivided(S.Location()),tol);
No3DCurve = Standard_False;
}
result.Location(S.Location());
// result.Orientation(S.Orientation());
// set specifics flags of an Edge
B.SameParameter(TopoDS::Edge(result),
BRep_Tool::SameParameter(TopoDS::Edge(S)));
B.SameRange(TopoDS::Edge(result),
BRep_Tool::SameRange(TopoDS::Edge(S)));
}
}
break;
case TopAbs_VERTEX:
{
gp_Pnt vtx;
rebuild = M->NewPoint(TopoDS::Vertex(S),vtx,tol);
if (rebuild) {
B.MakeVertex(TopoDS::Vertex(result),vtx,tol);
}
}
break;
default:
{
}
}
// rebuild sub-shapes and test new sub-shape ?
Standard_Boolean newgeom = rebuild;
TopoDS_Iterator it;
for (it.Initialize(S, Standard_False); it.More(); it.Next()) {
// always call Rebuild
Standard_Boolean subrebuilt = Rebuild(it.Value(),M);
rebuild = subrebuilt || rebuild ;
}
// make an empty copy
if (rebuild && !newgeom) {
result = S.EmptyCopied();
result.Orientation(TopAbs_FORWARD);
}
// copy the sub-elements
if (rebuild) {
TopAbs_Orientation orient;
for (it.Initialize(S,Standard_False); it.More(); it.Next()) {
orient = it.Value().Orientation();
if (RevWires || myMap(it.Value()).Orientation() == TopAbs_REVERSED) {
orient = TopAbs::Reverse(orient);
}
B.Add(result,myMap(it.Value()).Oriented(orient));
}
if (ts == TopAbs_FACE) {
// pcurves
Handle(Geom2d_Curve) curve2d; //,curve2d1;
TopoDS_Face face = TopoDS::Face(S);
TopAbs_Orientation fcor = face.Orientation();
if(fcor != TopAbs_REVERSED) fcor = TopAbs_FORWARD;
TopExp_Explorer ex(face.Oriented(fcor),TopAbs_EDGE);
for (;ex.More(); ex.Next())
{
const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
if (M->NewCurve2d(edge, face,TopoDS::Edge(myMap(ex.Current())),
TopoDS::Face(result),curve2d, tol))
{
// rem dub 16/09/97 : On fait de la topologie constante ou on
// n'en fait pas.
// On n'en fait pas si CopySurface = 1
// Atention, les VRAIES aretes de couture (RealyClosed) le
// restent meme si CopySurface est vrai.
// check that edge contains two pcurves on this surface:
// either it is true seam on the current face, or belongs to two faces
// built on that same surface (see OCC21772)
// Note: this check could be made separate method in BRepTools
Standard_Boolean isClosed = Standard_False;
if(BRep_Tool::IsClosed(edge,face))
{
isClosed = ( ! newgeom || BRepTools::IsReallyClosed(edge,face) );
if ( ! isClosed )
{
TopLoc_Location aLoc;
TopoDS_Shape resface = (myMap.IsBound(face) ? myMap(face) : face);
if(resface.IsNull())
resface = face;
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(resface), aLoc);
// check other faces sharing the same surface
TopExp_Explorer aExpF(myShape,TopAbs_FACE);
for( ; aExpF.More() && !isClosed; aExpF.Next())
{
TopoDS_Face anOther = TopoDS::Face(aExpF.Current());
if(anOther.IsSame(face))
continue;
TopoDS_Shape resface2 = (myMap.IsBound(anOther) ? myMap(anOther) : anOther);
if(resface2.IsNull())
resface2 = anOther;
TopLoc_Location anOtherLoc;
Handle(Geom_Surface) anOtherSurf =
BRep_Tool::Surface(TopoDS::Face(resface2), anOtherLoc);
if ( aSurf == anOtherSurf && aLoc.IsEqual (anOtherLoc) )
{
TopExp_Explorer aExpE(anOther,TopAbs_EDGE);
for( ; aExpE.More() && !isClosed ; aExpE.Next())
isClosed = edge.IsSame(aExpE.Current());
}
}
}
}
if (isClosed)
{
TopoDS_Edge CurE = TopoDS::Edge(myMap(edge));
TopoDS_Shape aLocalResult = result;
aLocalResult.Orientation(TopAbs_FORWARD);
TopoDS_Face CurF = TopoDS::Face(aLocalResult);
Handle(Geom2d_Curve) curve2d1, currcurv;
Standard_Real f,l;
if ((!RevWires && fcor != edge.Orientation()) ||
( RevWires && fcor == edge.Orientation())) {
CurE.Orientation(TopAbs_FORWARD);
curve2d1 = BRep_Tool::CurveOnSurface(CurE,CurF,f,l);
if (curve2d1.IsNull()) curve2d1 = new Geom2d_Line(gp::OX2d());
B.UpdateEdge (CurE, curve2d1, curve2d, CurF, 0.);
}
else {
CurE.Orientation(TopAbs_REVERSED);
curve2d1 = BRep_Tool::CurveOnSurface(CurE,CurF,f,l);
if (curve2d1.IsNull()) curve2d1 = new Geom2d_Line(gp::OX2d());
B.UpdateEdge (CurE, curve2d, curve2d1, CurF, 0.);
}
currcurv = BRep_Tool::CurveOnSurface(edge,face,f,l);
B.Range(edge,f,l);
}
else {
B.UpdateEdge(TopoDS::Edge(myMap(ex.Current())),
curve2d,
TopoDS::Face(result), 0.);
}
TopLoc_Location theLoc;
Standard_Real theF,theL;
Handle(Geom_Curve) C3D =
BRep_Tool::Curve(TopoDS::Edge(myMap(ex.Current())),
theLoc,theF,theL);
if (C3D.IsNull()) { // Update vertices
Standard_Real param;
TopExp_Explorer ex2(edge,TopAbs_VERTEX);
while (ex2.More()) {
const TopoDS_Vertex& vertex = TopoDS::Vertex(ex2.Current());
if (!M->NewParameter(vertex, edge, param, tol)) {
tol = BRep_Tool::Tolerance(vertex);
param = BRep_Tool::Parameter(vertex,edge);
}
TopAbs_Orientation vtxrelat = vertex.Orientation();
if (edge.Orientation() == TopAbs_REVERSED) {
// Update considere l'edge FORWARD, et le vertex en relatif
vtxrelat= TopAbs::Reverse(vtxrelat);
}
// if (myMap(edge).Orientation() == TopAbs_REVERSED) {
// vtxrelat= TopAbs::Reverse(vtxrelat);
// }
TopoDS_Vertex aLocalVertex = TopoDS::Vertex(myMap(vertex));
aLocalVertex.Orientation(vtxrelat);
// B.UpdateVertex(TopoDS::Vertex
// (myMap(vertex).Oriented(vtxrelat)),
B.UpdateVertex(aLocalVertex,
param,
TopoDS::Edge(myMap(edge)),
tol);
ex2.Next();
}
}
}
}
}
// else if (ts == TopAbs_EDGE) {
else if (ts == TopAbs_EDGE && !No3DCurve) {
// Vertices
Standard_Real param;
const TopoDS_Edge& edge = TopoDS::Edge(S);
TopAbs_Orientation edor = edge.Orientation();
if(edor != TopAbs_REVERSED) edor = TopAbs_FORWARD;
TopExp_Explorer ex(edge.Oriented(edor), TopAbs_VERTEX);
while (ex.More()) {
const TopoDS_Vertex& vertex = TopoDS::Vertex(ex.Current());
if (!M->NewParameter(vertex, edge, param, tol)) {
tol = BRep_Tool::Tolerance(vertex);
param = BRep_Tool::Parameter(vertex,edge);
}
TopAbs_Orientation vtxrelat = vertex.Orientation();
if (edor == TopAbs_REVERSED) {
// Update considere l'edge FORWARD, et le vertex en relatif
vtxrelat= TopAbs::Reverse(vtxrelat);
}
// if (result.Orientation() == TopAbs_REVERSED) {
// vtxrelat= TopAbs::Reverse(vtxrelat);
// }
TopoDS_Vertex aLocalVertex = TopoDS::Vertex(myMap(vertex));
aLocalVertex.Orientation(vtxrelat);
// B.UpdateVertex(TopoDS::Vertex
// (myMap(vertex).Oriented(vtxrelat)),
B.UpdateVertex(aLocalVertex,
param,
TopoDS::Edge(result),
tol);
ex.Next();
}
}
// update flags
result.Orientable(S.Orientable());
result.Closed(S.Closed());
result.Infinite(S.Infinite());
}
else
result = S;
// Set flag of the shape.
result.Orientation(ResOr);
result.Free (S.Free());
result.Modified (S.Modified());
result.Checked (S.Checked());
result.Orientable(S.Orientable());
result.Closed (S.Closed());
result.Infinite (S.Infinite());
result.Convex (S.Convex());
return rebuild;
}

View File

@@ -0,0 +1,30 @@
// File: BRepTools_Modifier.lxx
// Created: Thu Aug 25 15:37:21 1994
// Author: Jacques GOUSSARD
// <jag@ecolox>
#include <Standard_NoSuchObject.hxx>
//=======================================================================
//function : ModifiedShape
//purpose :
//=======================================================================
inline const TopoDS_Shape& BRepTools_Modifier::ModifiedShape
(const TopoDS_Shape& S) const
{
if (!myMap.IsBound(S)) { Standard_NoSuchObject::Raise();}
return myMap(S);
}
//=======================================================================
//function : IsDone
//purpose :
//=======================================================================
inline Standard_Boolean BRepTools_Modifier::IsDone () const
{
return myDone;
}

View File

@@ -0,0 +1,148 @@
-- File: BRepTools_NurbsConvertModification.cdl
-- Created: Fri Jul 12 10:16:32 1996
-- Author: Stagiaire Mary FABIEN
-- <fbi@animax.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1994
class NurbsConvertModification from BRepTools inherits Modification from BRepTools
---Purpose: Defines a modification of the geometry by a Trsf
-- from gp. All methods return True and transform the
-- geometry.
uses Face from TopoDS,
Edge from TopoDS,
Vertex from TopoDS,
Location from TopLoc,
Shape from GeomAbs,
Pnt from gp,
Surface from Geom,
Curve from Geom,
Curve from Geom2d,
MapOfTransient from TColStd,
ListOfShape from TopTools,
ListOfTransient from TColStd,
IndexedDataMapOfTransientTransient from TColStd
is
Create returns mutable NurbsConvertModification from BRepTools;
NewSurface(me: mutable; F : Face from TopoDS;
S : out Surface from Geom;
L : out Location from TopLoc;
Tol : out Real from Standard;
RevWires : out Boolean from Standard;
RevFace : out Boolean from Standard)
---Purpose: Returns Standard_True if the face <F> has been
-- modified. In this case, <S> is the new geometric
-- support of the face, <L> the new location,<Tol>
-- the new tolerance.<RevWires> has to be set to
-- Standard_True when the modification reverses the
-- normal of the surface.(the wires have to be
-- reversed). <RevFace> has to be set to
-- Standard_True if the orientation of the modified
-- face changes in the shells which contain it. --
-- Here, <RevFace> will return Standard_True if the
-- -- gp_Trsf is negative.
returns Boolean from Standard
;
NewCurve(me: mutable; E : Edge from TopoDS;
C : out Curve from Geom;
L : out Location from TopLoc;
Tol: out Real from Standard)
returns Boolean from Standard
;
---Purpose: Returns Standard_True if the edge <E> has been
-- modified. In this case, <C> is the new geometric
-- support of the edge, <L> the new location, <Tol>
-- the new tolerance. Otherwise, returns
-- Standard_False, and <C>, <L>, <Tol> are not
-- significant.
NewPoint(me: mutable; V : Vertex from TopoDS;
P : out Pnt from gp;
Tol: out Real from Standard)
returns Boolean from Standard
;
---Purpose: Returns Standard_True if the vertex <V> has been
-- modified. In this case, <P> is the new geometric
-- support of the vertex, <Tol> the new tolerance.
-- Otherwise, returns Standard_False, and <P>, <Tol>
-- are not significant.
NewCurve2d(me: mutable; E : Edge from TopoDS;
F : Face from TopoDS;
NewE : Edge from TopoDS;
NewF : Face from TopoDS;
C : out Curve from Geom2d;
Tol : out Real from Standard)
returns Boolean from Standard
;
---Purpose: Returns Standard_True if the edge <E> has a new
-- curve on surface on the face <F>.In this case, <C>
-- is the new geometric support of the edge, <L> the
-- new location, <Tol> the new tolerance.
-- Otherwise, returns Standard_False, and <C>, <L>,
-- <Tol> are not significant.
NewParameter(me: mutable; V : Vertex from TopoDS;
E : Edge from TopoDS;
P : out Real from Standard;
Tol: out Real from Standard)
returns Boolean from Standard
;
---Purpose: Returns Standard_True if the Vertex <V> has a new
-- parameter on the edge <E>. In this case, <P> is
-- the parameter, <Tol> the new tolerance.
-- Otherwise, returns Standard_False, and <P>, <Tol>
-- are not significant.
Continuity(me: mutable; E : Edge from TopoDS;
F1,F2 : Face from TopoDS;
NewE : Edge from TopoDS;
NewF1,NewF2: Face from TopoDS)
returns Shape from GeomAbs
---Purpose: Returns the continuity of <NewE> between <NewF1>
-- and <NewF2>.
--
-- <NewE> is the new edge created from <E>. <NewF1>
-- (resp. <NewF2>) is the new face created from <F1>
-- (resp. <F2>).
;
fields
myled : ListOfShape from TopTools;
mylcu : ListOfTransient from TColStd;
myMap : IndexedDataMapOfTransientTransient from TColStd;
end NurbsConvertModification;

View File

@@ -0,0 +1,614 @@
// File: BRepTools_NurbsConvertModification.cxx
// Created: Fri Jul 12 10:16:32 1996
// Author: Stagiaire Mary FABIEN
// <fbi@animax.paris1.matra-dtv.fr>
#include <BRepTools_NurbsConvertModification.ixx>
#include <BRepTools.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_BezierSurface.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <GeomConvert.hxx>
#include <Geom2dConvert.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Line.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <GeomAdaptor_Surface.hxx>
#include <Geom2dAdaptor_HCurve.hxx>
#include <Geom2dAdaptor_HCurve.hxx>
#include <GeomAdaptor_HCurve.hxx>
#include <GeomAdaptor_HSurface.hxx>
#include <BSplCLib.hxx>
#include <Approx_SameParameter.hxx>
#include <BRep_Tool.hxx>
#include <Extrema_LocateExtPC.hxx>
#include <OSD_Chronometer.hxx>
#include <gp_GTrsf2d.hxx>
#include <gp_TrsfForm.hxx>
#include <TopAbs.hxx>
#include <TopoDS.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TColStd_ListIteratorOfListOfTransient.hxx>
#include <ProjLib_ComputeApprox.hxx>
#include <ProjLib_ComputeApproxOnPolarSurface.hxx>
#include <ElSLib.hxx>
#include <BSplCLib.hxx>
#include <Geom_Circle.hxx>
#include <Geom_Ellipse.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <BRep_TEdge.hxx>
#include <BRep_GCurve.hxx>
#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
static void GeomLib_ChangeUBounds(Handle(Geom_BSplineSurface)& aSurface,
const Standard_Real newU1,
const Standard_Real newU2)
{
TColStd_Array1OfReal knots(1,aSurface->NbUKnots()) ;
aSurface->UKnots(knots) ;
BSplCLib::Reparametrize(newU1,
newU2,
knots) ;
aSurface->SetUKnots(knots) ;
}
static void GeomLib_ChangeVBounds(Handle(Geom_BSplineSurface)& aSurface,
const Standard_Real newV1,
const Standard_Real newV2)
{
TColStd_Array1OfReal knots(1,aSurface->NbVKnots()) ;
aSurface->VKnots(knots) ;
BSplCLib::Reparametrize(newV1,
newV2,
knots) ;
aSurface->SetVKnots(knots) ;
}
//=======================================================================
//function : BRepTools_NurbsConvertModification
//purpose :
//=======================================================================
BRepTools_NurbsConvertModification::BRepTools_NurbsConvertModification()
{
}
//=======================================================================
//function : NewSurface
//purpose :
//=======================================================================
Standard_Boolean BRepTools_NurbsConvertModification::NewSurface
(const TopoDS_Face& F,
Handle(Geom_Surface)& S,
TopLoc_Location& L,
Standard_Real& Tol,
Standard_Boolean& RevWires,
Standard_Boolean& RevFace)
{
Standard_Real U1, U2, curvU1, curvU2, surfU1, surfU2, UTol;
Standard_Real V1, V2, curvV1, curvV2, surfV1, surfV2, VTol;
RevWires = Standard_False;
RevFace = Standard_False;
Handle(Geom_Surface) SS = BRep_Tool::Surface(F,L);
Handle(Standard_Type) TheTypeSS = SS->DynamicType();
if ((TheTypeSS == STANDARD_TYPE(Geom_BSplineSurface)) ||
(TheTypeSS == STANDARD_TYPE(Geom_BezierSurface))) {
return Standard_False;
}
S = SS;
BRepTools::UVBounds(F,curvU1,curvU2,curvV1,curvV2);
Tol = BRep_Tool::Tolerance(F);
Standard_Real TolPar = 0.1*Tol;
Standard_Boolean IsUp = S->IsUPeriodic(), IsVp = S->IsVPeriodic();
//OCC466(apo)->
U1 = curvU1; U2 = curvU2;
V1 = curvV1; V2 = curvV2;
SS->Bounds(surfU1,surfU2,surfV1,surfV2);
if(!IsUp){
U1 = Max(surfU1,curvU1);
U2 = Min(surfU2,curvU2);
}
if(!IsVp){
V1 = Max(surfV1,curvV1);
V2 = Min(surfV2,curvV2);
}
//<-OCC466(apo)
if(IsUp && IsVp) {
Standard_Real dU = Abs(U2 - U1), dV = Abs(V2 - V1);
Standard_Real Up = S->UPeriod(), Vp = S->VPeriod();
if(Abs(dU - Up) <= TolPar && U2 <= Up) {
if(Abs(dV - Vp) <= TolPar && V2 <= Vp) { }
else {
SS = new Geom_RectangularTrimmedSurface(S, V1+1e-9, V2-1e-9, Standard_False);
}
}
else {
if(Abs(dV - Vp) <= TolPar && V2 <= Vp)
SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, Standard_True);
else
SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, V1+1e-9, V2-1e-9);
}
}
if(IsUp && !IsVp) {
Standard_Real dU = Abs(U2 - U1);
Standard_Real Up = S->UPeriod();
if(Abs(dU - Up) <= TolPar && U2 <= Up)
SS = new Geom_RectangularTrimmedSurface(S, V1+1e-9, V2-1e-9, Standard_False);
else
SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, V1+1e-9, V2-1e-9);
}
if(!IsUp && IsVp) {
Standard_Real dV = Abs(V2 - V1);
Standard_Real Vp = S->VPeriod();
if(Abs(dV - Vp) <= TolPar && V2 <= Vp)
SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, Standard_True);
else
SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, V1+1e-9, V2-1e-9);
}
if(!IsUp && !IsVp) {
SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, V1+1e-9, V2-1e-9);
}
SS->Bounds(surfU1,surfU2,surfV1,surfV2) ;
S = GeomConvert::SurfaceToBSplineSurface(SS);
Handle(Geom_BSplineSurface) BS = Handle(Geom_BSplineSurface)::DownCast(S) ;
BS->Resolution(Tol, UTol, VTol) ;
//
// on recadre les bornes de S sinon les anciennes PCurves sont aux fraises
//
if (Abs(curvU1-surfU1) > UTol && !BS->IsUPeriodic()) {
GeomLib_ChangeUBounds(BS, U1,U2) ;
}
if (Abs(curvV1-surfV1) > VTol && !BS->IsVPeriodic()) {
GeomLib_ChangeVBounds(BS, V1, V2) ;
}
return Standard_True;
}
static Standard_Boolean IsConvert(const TopoDS_Edge& E)
{
Standard_Boolean isConvert = Standard_False;
Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape());
// iterate on pcurves
BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
for ( ; itcr.More() && !isConvert; itcr.Next() ) {
Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
if ( GC.IsNull() || ! GC->IsCurveOnSurface() ) continue;
Handle(Geom_Surface) aSurface = GC->Surface();
Handle(Geom2d_Curve) aCurve2d = GC->PCurve();
isConvert =((!aSurface->IsKind(STANDARD_TYPE(Geom_BSplineSurface)) &&
!aSurface->IsKind(STANDARD_TYPE(Geom_BezierSurface))) ||
(!aCurve2d->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve)) &&
!aCurve2d->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))));
}
return isConvert;
}
//=======================================================================
//function : NewCurve
//purpose :
//=======================================================================
Standard_Boolean BRepTools_NurbsConvertModification::NewCurve
(const TopoDS_Edge& E,
Handle(Geom_Curve)& C,
TopLoc_Location& L,
Standard_Real& Tol)
{
Tol = BRep_Tool::Tolerance(E);
if(BRep_Tool::Degenerated(E)) {
C.Nullify();
L.Identity();
return Standard_True;
}
Standard_Real f, l;
Handle(Geom_Curve) Caux = BRep_Tool::Curve(E, L, f, l);
if ( Caux.IsNull()) {
L.Identity();
return Standard_False;
}
Handle(Standard_Type) TheType = Caux->DynamicType();
if ((TheType == STANDARD_TYPE(Geom_BSplineCurve)) ||
(TheType == STANDARD_TYPE(Geom_BezierCurve))) {
if(IsConvert(E)) {
C = Handle(Geom_Curve)::DownCast(Caux->Copy());
return Standard_True;
}
return Standard_False;
}
C = Caux;
Standard_Real TolPar = Tol *.1;
if(C->IsPeriodic()) {
Standard_Real p = C->Period();
Standard_Real d = Abs(l - f);
if(Abs(d - p) <= TolPar && l <= p) {}
else
C = new Geom_TrimmedCurve(C, f, l);
}
else
C = new Geom_TrimmedCurve(C, f, l);
//modif WOK++ portage hp (fbi du 14/03/97)
// gp_Trsf trsf(L);
// gp_Trsf trsf = L.Transformation();
// C = GeomConvert::CurveToBSplineCurve(C,Convert_QuasiAngular);
C = GeomConvert::CurveToBSplineCurve(C);
Standard_Real fnew = C->FirstParameter(), lnew = C->LastParameter(), UTol;
Handle(Geom_BSplineCurve) BC = Handle(Geom_BSplineCurve)::DownCast(C) ;
if(!BC->IsPeriodic()) {
BC->Resolution(Tol, UTol) ;
if(Abs(f - fnew) > UTol || Abs(l - lnew) > UTol) {
TColStd_Array1OfReal knots(1,BC->NbKnots()) ;
BC->Knots(knots) ;
BSplCLib::Reparametrize(f, l, knots) ;
BC->SetKnots(knots) ;
}
}
if(!myMap.Contains(Caux)) {
myMap.Add(Caux,C);
}
return Standard_True ;
}
//=======================================================================
//function : NewPoint
//purpose :
//=======================================================================
Standard_Boolean BRepTools_NurbsConvertModification::NewPoint
//(const TopoDS_Vertex& V,
(const TopoDS_Vertex& ,
// gp_Pnt& P,
gp_Pnt& ,
// Standard_Real& Tol)
Standard_Real& )
{
return Standard_False;
}
//=======================================================================
//function : NewCurve2d
//purpose :
//=======================================================================
Standard_Boolean BRepTools_NurbsConvertModification::NewCurve2d
(const TopoDS_Edge& E,
const TopoDS_Face& F,
const TopoDS_Edge& newE,
const TopoDS_Face& newF,
Handle(Geom2d_Curve)& Curve2d,
Standard_Real& Tol)
{
Tol = BRep_Tool::Tolerance(E);
Standard_Real f2d,l2d;
Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f2d,l2d);
Standard_Real f3d,l3d;
TopLoc_Location Loc;
Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, Loc, f3d,l3d);
Standard_Boolean isConvert2d = ((!C3d.IsNull() && !C3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) &&
!C3d->IsKind(STANDARD_TYPE(Geom_BezierCurve))) ||
IsConvert(E));
if(BRep_Tool::Degenerated(E)) {
//Curve2d = C2d;
if(!C2d->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve)))
{
Handle(Geom2d_TrimmedCurve) aTrimC = new Geom2d_TrimmedCurve(C2d,f2d,l2d);
C2d = aTrimC;
}
Curve2d = Geom2dConvert::CurveToBSplineCurve(C2d);
return Standard_True;
}
if(!BRepTools::IsReallyClosed(E,F)) {
Handle(Standard_Type) TheTypeC2d = C2d->DynamicType();
if(TheTypeC2d == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve)::DownCast(C2d);
C2d = TC->BasisCurve();
}
Standard_Real fc = C2d->FirstParameter(), lc = C2d->LastParameter();
if(!C2d->IsPeriodic()) {
if(fc - f2d > Precision::PConfusion()) f2d = fc;
if(l2d - lc > Precision::PConfusion()) l2d = lc;
}
C2d = new Geom2d_TrimmedCurve(C2d, f2d, l2d);
Geom2dAdaptor_Curve G2dAC(C2d, f2d, l2d);
Handle(Geom2dAdaptor_HCurve) G2dAHC = new Geom2dAdaptor_HCurve(G2dAC);
TopLoc_Location Loc;
Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, Loc, f3d,l3d);
if(!newE.IsNull()) {
C3d = BRep_Tool::Curve(newE, f3d, l3d);
}
else {
C3d = BRep_Tool::Curve(E,f3d,l3d);
}
GeomAdaptor_Curve G3dAC(C3d, f3d, l3d);
Handle(GeomAdaptor_HCurve) G3dAHC = new GeomAdaptor_HCurve(G3dAC);
Standard_Real Uinf, Usup, Vinf, Vsup, u = 0, v = 0;
Handle(Geom_Surface) S = BRep_Tool::Surface(F);
Handle(Standard_Type) myT = S->DynamicType();
if(myT != STANDARD_TYPE(Geom_Plane)) {
if(newF.IsNull()) {
Handle(Standard_Type) st = C2d->DynamicType();
if ((st == STANDARD_TYPE(Geom2d_BSplineCurve)) ||
(st == STANDARD_TYPE(Geom2d_BezierCurve))) {
if(isConvert2d) {
Curve2d = Handle(Geom2d_Curve)::DownCast(C2d->Copy());
return Standard_True;
}
return Standard_False;
}
}
else {
S = BRep_Tool::Surface(newF);
}
S->Bounds(Uinf, Usup, Vinf, Vsup);
Uinf -= 1e-9; Usup += 1e-9; Vinf -= 1e-9; Vsup += 1e-9;
u = (Usup - Uinf)*0.1;
v = (Vsup - Vinf)*0.1;
if(S->IsUPeriodic()) {
Standard_Real uperiod = S->UPeriod();
if(uperiod < (Usup+2*u-Uinf)) {
if(uperiod <= (Usup-Uinf)) {
u = 0;
}
else {
u = (uperiod-(Usup-Uinf))*0.5;
}
}
}
if(S->IsVPeriodic()) {
Standard_Real vperiod = S->VPeriod();
if(vperiod < (Vsup+2*v-Vinf)) {
if(vperiod <= (Vsup-Vinf)) {
v = 0;
}
else {
v = (vperiod-(Vsup-Vinf))*0.5;
}
}
}
}
else {
S = BRep_Tool::Surface(F);// Si S est un plan, pas de changement de parametrisation
GeomAdaptor_Surface GAS(S);
Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(GAS);
ProjLib_ComputeApprox ProjOnCurve(G3dAHC,GAHS,Tol);
if(ProjOnCurve.BSpline().IsNull()) {
Curve2d = Geom2dConvert::CurveToBSplineCurve(ProjOnCurve.Bezier());
return Standard_True;
}
Curve2d = ProjOnCurve.BSpline();
return Standard_True;
}
GeomAdaptor_Surface GAS(S,Uinf-u,Usup+u,Vinf-v,Vsup+v);
Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(GAS);
ProjLib_ComputeApproxOnPolarSurface ProjOnCurve(G2dAHC,G3dAHC,GAHS,Tol);
if(ProjOnCurve.IsDone()) {
Curve2d = ProjOnCurve.BSpline();
return Standard_True;
}
else {
Curve2d = Geom2dConvert::CurveToBSplineCurve(C2d);
return Standard_True;
}
}
else {
TopTools_ListIteratorOfListOfShape itled;
TColStd_ListIteratorOfListOfTransient itlcu;
for (itled.Initialize(myled), itlcu.Initialize(mylcu);
itled.More(); // itlcu.More()
itled.Next(),itlcu.Next()) {
if (itled.Value().IsSame(E)) {
// deja traitee
break;
}
}
if (!itled.More()) { // on stocke l`edge et la curve2d
Handle(Geom2d_Curve) C2dBis;
Standard_Real f3d,l3d,f2dBis,l2dBis;
C2d = new Geom2d_TrimmedCurve(C2d, f2d, l2d);
Geom2dAdaptor_Curve G2dAC(C2d, f2d, l2d);
Handle(Geom2dAdaptor_HCurve) G2dAHC = new Geom2dAdaptor_HCurve(G2dAC);
TopoDS_Edge ERevers = E;
ERevers.Reverse();
// TopoDS_Edge ERevers = TopoDS::Edge(E.Reversed());
C2dBis = BRep_Tool::CurveOnSurface(ERevers,F,f2dBis,l2dBis);
Handle(Standard_Type) TheTypeC2dBis = C2dBis->DynamicType();
C2dBis = new Geom2d_TrimmedCurve(C2dBis,f2dBis, l2dBis);
Geom2dAdaptor_Curve G2dACBis(C2dBis, f2dBis, l2dBis);
Handle(Geom2dAdaptor_HCurve) G2dAHCBis = new Geom2dAdaptor_HCurve(G2dACBis);
TopLoc_Location Loc;
Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, f3d,l3d);
if(C3d.IsNull()) {
if(isConvert2d) {
Curve2d = Handle(Geom2d_Curve)::DownCast(C2d->Copy());
return Standard_True;
}
return Standard_False;
}
if(!newE.IsNull()) {
C3d = BRep_Tool::Curve(newE, f3d,l3d);
}
GeomAdaptor_Curve G3dAC(C3d, f3d, l3d);
Handle(GeomAdaptor_HCurve) G3dAHC = new GeomAdaptor_HCurve(G3dAC);
Handle(Geom_Surface) S = BRep_Tool::Surface(F);
Handle(Standard_Type) myT = S->DynamicType();
if(newF.IsNull()) {
mylcu.Append(C2dBis);
Handle(Standard_Type) st = C2d->DynamicType();
if ((st == STANDARD_TYPE(Geom2d_BSplineCurve)) ||
(st == STANDARD_TYPE(Geom2d_BezierCurve))) {
if(isConvert2d) {
Curve2d = Handle(Geom2d_Curve)::DownCast(C2d->Copy());
return Standard_True;
}
return Standard_False;
}
}
else {
S = BRep_Tool::Surface(newF);// S est une BSplineSurface : pas besoin de la trimmed
}
Standard_Real Uinf, Usup, Vinf, Vsup, u = 0, v = 0;
S->Bounds(Uinf, Usup, Vinf, Vsup);
Uinf -= 1e-9; Usup += 1e-9; Vinf -= 1e-9; Vsup += 1e-9;
u = (Usup - Uinf)*0.1;
v = (Vsup - Vinf)*0.1;
if(S->IsUPeriodic()) {
Standard_Real uperiod = S->UPeriod();
if(uperiod < (Usup+2*u-Uinf))
if(uperiod <= (Usup-Uinf))
u = 0;
else
u = (uperiod-(Usup-Uinf))*0.5;
}
if(S->IsVPeriodic()) {
Standard_Real vperiod = S->VPeriod();
if(vperiod < (Vsup+2*v-Vinf))
if(vperiod <= (Vsup-Vinf))
v = 0;
else
v = (vperiod-(Vsup-Vinf))*0.5;
}
GeomAdaptor_Surface GAS(S, Uinf-u,Usup+u,Vinf-v,Vsup+v);
Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(GAS);
myled.Append(E);
ProjLib_ComputeApproxOnPolarSurface
ProjOnCurve(G2dAHC,G2dAHCBis,G3dAHC,GAHS,Tol);
if(ProjOnCurve.IsDone()) {
Curve2d = ProjOnCurve.BSpline();
mylcu.Append(ProjOnCurve.Curve2d());
return Standard_True;
}
else {
Curve2d = Geom2dConvert::CurveToBSplineCurve(C2d);
mylcu.Append(C2dBis);
return Standard_True;
}
}
else { // on est au 2ieme tour
C2d = Handle(Geom2d_Curve)::DownCast(itlcu.Value());
Handle(Standard_Type) st = C2d->DynamicType();
if (!(st == STANDARD_TYPE(Geom2d_BSplineCurve)) &&
!(st == STANDARD_TYPE(Geom2d_BezierCurve))) {
return Standard_False;
}
Curve2d = Geom2dConvert::CurveToBSplineCurve(C2d);
return Standard_True;
}
}
Curve2d = C2d;
return Standard_True;
}
//=======================================================================
//function : NewParameter
//purpose :
//=======================================================================
Standard_Boolean BRepTools_NurbsConvertModification::NewParameter
(const TopoDS_Vertex& V,
const TopoDS_Edge& E,
Standard_Real& P,
Standard_Real& Tol)
{
if(BRep_Tool::Degenerated(E))
return Standard_False;
Standard_Real f, l, param = BRep_Tool::Parameter(V,E);
TopLoc_Location L;
Handle(Geom_Curve) gc = BRep_Tool::Curve(E, L, f, l);
if(!myMap.Contains(gc))
return Standard_False;
Handle(Geom_BSplineCurve) gcc =
Handle(Geom_BSplineCurve)::DownCast(myMap.FindFromKey(gc));
gcc = Handle(Geom_BSplineCurve)::DownCast(gcc->Transformed(L.Transformation()));
GeomAdaptor_Curve ac(gcc);
gp_Pnt pnt = BRep_Tool::Pnt(V);
Extrema_LocateExtPC proj(pnt, ac, param, f, l, Tol);
if(proj.IsDone()) {
Standard_Real Dist2Min = proj.SquareDistance();
if (Dist2Min < Tol*Tol) {
// Standard_Real U_final_point,V_final_point;
P = proj.Point().Parameter();
return Standard_True;
}
}
return Standard_False;
}
//=======================================================================
//function : Continuity
//purpose :
//=======================================================================
GeomAbs_Shape BRepTools_NurbsConvertModification::Continuity
(const TopoDS_Edge& E,
const TopoDS_Face& F1,
const TopoDS_Face& F2,
const TopoDS_Edge&,
const TopoDS_Face&,
const TopoDS_Face&)
{
return BRep_Tool::Continuity(E,F1,F2);
}

101
src/BRepTools/BRepTools_Quilt.cdl Executable file
View File

@@ -0,0 +1,101 @@
-- File: BRepTools_Quilt.cdl
-- Created: Thu Dec 22 15:32:41 1994
-- Author: Remi LEQUETTE
-- <rle@bravox>
---Copyright: Matra Datavision 1994
class Quilt from BRepTools
---Purpose: A Tool to glue faces at common edges and
-- reconstruct shells.
--
-- The user designate pairs of common edges using the
-- method Bind. One edge is designated as the edge to
-- use in place of the other one (they are supposed
-- to be geometrically confused, but this not
-- checked). They can be of opposite directions, this
-- is specified by the orientations.
--
-- The user can add shapes with the Add method, all
-- the faces are registred and copies of faces and
-- edges are made to glue at the bound edges.
--
-- The user can call the Shells methods to compute a
-- compound of shells from the current set of faces.
--
-- If no binding is made this class can be used to
-- make shell from faces already sharing their edges.
uses
Vertex from TopoDS,
Edge from TopoDS,
Shape from TopoDS,
DataMapOfShapeShape from TopTools,
IndexedDataMapOfShapeShape from TopTools
raises
NoSuchObject from Standard
is
Create returns Quilt from BRepTools;
Bind(me : in out; Eold, Enew : Edge from TopoDS)
---Purpose: Binds <Enew> to be the new edge instead of
-- <Eold>.
--
-- The faces of the added shape containing <Eold>
-- will be copied to substitute <Eold> by <Enew>.
--
-- The vertices of <Eold> will be bound to the
-- vertices of <Enew> with the same orientation.
--
-- If <Eold> and <Enew> have different orientations
-- the curves are considered to be opposite and the
-- pcurves of <Eold> will be copied and reversed in
-- the new faces.
--
-- <Eold> must belong to the next added shape, <Enew> must belong
-- to a Shape added before.
is static;
Bind(me : in out; Vold, Vnew : Vertex from TopoDS)
---Purpose: Binds <VNew> to be a new vertex instead of <Vold>.
--
-- The faces of the added shape containing <Vold>
-- will be copied to substitute <Vold> by <Vnew>.
is static;
Add(me : in out; S : Shape from TopoDS)
---Purpose: Add the faces of <S> to the Quilt, the faces
-- containing bounded edges are copied.
is static;
IsCopied(me; S : Shape from TopoDS) returns Boolean
---Purpose: Returns True if <S> has been copied (<S> is a
-- vertex, an edge or a face)
is static;
Copy(me; S : Shape from TopoDS) returns Shape from TopoDS
---Purpose: Returns the shape substitued to <S> in the Quilt.
--
---C++: return const &
raises
NoSuchObject from Standard -- if ! IsCopied(S)
is static;
Shells(me) returns Shape from TopoDS
---Purpose: Returns a Compound of shells made from the current
-- set of faces. The shells will be flagged as closed
-- or not closed.
is static;
fields
myBounds : IndexedDataMapOfShapeShape from TopTools;
hasCopy : Boolean; -- True if at least one copy was made
end Quilt;

518
src/BRepTools/BRepTools_Quilt.cxx Executable file
View File

@@ -0,0 +1,518 @@
// File: BRepTools_Quilt.cxx
// Created: Fri Dec 23 10:37:05 1994
// Author: Remi LEQUETTE
// <rle@bravox>
#include <BRepTools_Quilt.ixx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
#include <TopTools_DataMapOfShapeShape.hxx>
#include <TopExp_Explorer.hxx>
#include <Geom2d_Curve.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopoDS_Shape.hxx>
#include <TopTools_MapIteratorOfMapOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_IndexedDataMapOfShapeShape.hxx>
//=======================================================================
//function : BRepTools_Quilt
//purpose :
//=======================================================================
BRepTools_Quilt::BRepTools_Quilt() : hasCopy(Standard_False)
{
}
//=======================================================================
//function : Add
//purpose :
//=======================================================================
static Standard_Boolean NeedCopied(const TopoDS_Shape& theShape,const TopTools_IndexedDataMapOfShapeShape& myBounds)
{
// test if the shape must be copied
// i.e. it contains a bound subshape
Standard_Boolean IsCopied = Standard_False;
TopoDS_Iterator itv(theShape) ;
for ( ; itv.More(); itv.Next()) {
if (myBounds.Contains(itv.Value())) {
IsCopied = Standard_True;
break;
}
}
return IsCopied;
}
static void CopyShape(const TopoDS_Edge& E,TopTools_IndexedDataMapOfShapeShape& myBounds)
{
TopoDS_Edge NE = E;
NE.EmptyCopy();
NE.Orientation(TopAbs_FORWARD);
BRep_Builder B;
// add the edges
TopoDS_Iterator itv;
itv.Initialize(E,Standard_False) ; //TCollection_DataMap
for ( ; itv.More(); itv.Next()) {
const TopoDS_Shape& V = itv.Value();
if (myBounds.Contains(V)) {
B.Add(NE,myBounds.FindFromKey(V).Oriented(V.Orientation()));
}
else {
B.Add(NE,V);
}
}
// set the 3d range
Standard_Real f,l;
BRep_Tool::Range(E,f,l);
B.Range(NE,f,l);
myBounds.Add(E,NE.Oriented(TopAbs_FORWARD));
}
/*static void CopyShape(const TopoDS_Wire& W,TopTools_DataMapOfShapeShape& myBounds)
{
TopoDS_Wire NW;
B.MakeWire(NW);
TopoDS_Iterator ite(W,Standard_False);
for ( ; ite.More(); ite.Next()){
const TopoDS_Edge& E = TopoDS::Edge(ite.Value());
TopAbs_Orientation OE = E.Orientation();
if (myBounds.IsBound(E)) {
TopoDS_Edge& NE = TopoDS::Edge(myBounds(E));
B.Add(NW,NE.Oriented(OE));
}
else
B.Add(NW,E);
}
NW.Orientation(W.Orientation());
myBounds.Bind(W,NW);
}*/
void BRepTools_Quilt::Add(const TopoDS_Shape& S)
{
//cout <<" Version of sewing with free edges"<<endl;
// Binds all the faces of S
// - to the face itself if it is not copied
// - to the copy if it is copied
if(myBounds.Contains(S)) return;
BRep_Builder B;
for (TopExp_Explorer wex(S,TopAbs_WIRE,TopAbs_FACE); wex.More(); wex.Next())
myBounds.Add(wex.Current(),wex.Current());
for (TopExp_Explorer eex(S,TopAbs_EDGE,TopAbs_WIRE); eex.More(); eex.Next())
myBounds.Add(eex.Current(),eex.Current());
for (TopExp_Explorer vex(S,TopAbs_VERTEX,TopAbs_EDGE); vex.More(); vex.Next())
myBounds.Add(vex.Current(),vex.Current());
// explore the faces
for (TopExp_Explorer fex(S,TopAbs_FACE); fex.More(); fex.Next()) {
// explore the edges of the face and try to copy them
// if one edge is bound the face must be copied
Standard_Boolean copyFace = Standard_False;
const TopoDS_Face& F = TopoDS::Face(fex.Current());
if (hasCopy) { // if their is no binding, do not test for copy
for (TopExp_Explorer fed(F,TopAbs_EDGE); fed.More(); fed.Next()) {
if (myBounds.Contains(fed.Current())) {
copyFace = Standard_True;
}
else {
// test if the edge must be copied
// i.e. it contains a bound vertex
Standard_Boolean copyEdge = NeedCopied(fed.Current(),myBounds);
//Standard_Boolean copyEdge = Standard_False;
const TopoDS_Edge& E = TopoDS::Edge(fed.Current());
// TopoDS_Iterator itv(E) ;
// for ( ; itv.More(); itv.Next()) {
// if (myBounds.IsBound(itv.Value())) {
// copyEdge = Standard_True;
// break;
// }
// }
if (copyEdge) {
// copy of an edge
copyFace = Standard_True;
CopyShape(E,myBounds);
//TopoDS_Edge NE = E; //gka version for free edges
//NE.EmptyCopy();
//NE.Orientation(TopAbs_FORWARD);
// add the edges
//itv.Initialize(E,Standard_False) ;
//for ( ; itv.More(); itv.Next()) {
//const TopoDS_Shape& V = itv.Value();
//if (myBounds.IsBound(V)) {
// B.Add(NE,myBounds(V).Oriented(V.Orientation()));
//}
//else {
// B.Add(NE,V);
//}
//}
// set the 3d range
//Standard_Real f,l;
//BRep_Tool::Range(E,f,l);
//B.Range(NE,f,l);
//myBounds.Bind(E,NE.Oriented(TopAbs_FORWARD));
}
}
}
}
// NF will be the copy of F or F itself
TopoDS_Face NF = F;
if (copyFace) {
// copy of a face
NF.EmptyCopy();
NF.Orientation(TopAbs_FORWARD);
for (TopoDS_Iterator itw(F,Standard_False); itw.More(); itw.Next()) {
const TopoDS_Wire& W = TopoDS::Wire(itw.Value());
TopoDS_Wire NW;
B.MakeWire(NW);
TopoDS_Iterator ite(W,Standard_False);
#ifdef DEB
Standard_Real Tol = BRep_Tool::Tolerance(F);
#else
BRep_Tool::Tolerance(F);
#endif
Standard_Real UFirst,ULast;
// Reconstruction des wires.
for ( ; ite.More(); ite.Next()){
const TopoDS_Edge& E = TopoDS::Edge(ite.Value());
TopAbs_Orientation OE = E.Orientation();
if (myBounds.Contains(E)) {
const TopoDS_Edge& NE = TopoDS::Edge(myBounds.FindFromKey(E));
// pcurve.
if (NE.Orientation() == TopAbs_FORWARD) {
B.UpdateEdge(NE,
BRep_Tool::CurveOnSurface(E,F,UFirst,ULast),
F,BRep_Tool::Tolerance(E));
}
else {
// Si NE est REVERSED
// => les curve3d n ont pas la meme orientation.
// ( C est une convention cf BRepTools_Quilt.cdl. et la methode
// Bind.)
// => la PCurve de E sur F doit etre inversee.
OE = TopAbs::Reverse(OE);
Handle(Geom2d_Curve) CE =
BRep_Tool::CurveOnSurface(E,F,UFirst,ULast);
Handle(Geom2d_Curve) NCE = CE->Reversed();
B.UpdateEdge(NE,NCE,F,BRep_Tool::Tolerance(E));
Standard_Real tmp = UFirst;
UFirst = CE->ReversedParameter(ULast);
ULast = CE->ReversedParameter(tmp);
}
// pcurve range
B.Range(NE,F,UFirst,ULast);
B.Add(NW,NE.Oriented(OE));
}
else {
B.Add(NW,E);
}
}
NW.Orientation(W.Orientation());
B.Add(NF,NW);
}
NF.Orientation(F.Orientation());
}
// binds the face to itself or its copy
myBounds.Add(F,NF);
}
}
//=======================================================================
//function : Bind
//purpose :
//=======================================================================
void BRepTools_Quilt::Bind(const TopoDS_Vertex& Vold,
const TopoDS_Vertex& Vnew)
{
if (!myBounds.Contains(Vold)) {
myBounds.Add(Vold,Vnew);
}
}
//=======================================================================
//function : Bind
//purpose :
//=======================================================================
void BRepTools_Quilt::Bind(const TopoDS_Edge& Eold, const TopoDS_Edge& Enew)
{
if (!myBounds.Contains(Eold)) {
TopoDS_Edge ENew = Enew;
if (IsCopied(Enew)) {
ENew = TopoDS::Edge(Copy(Enew));
ENew.Orientation(Enew.Orientation());
}
if (Eold.Orientation() != ENew.Orientation()) {
myBounds.Add(Eold.Oriented(TopAbs_FORWARD),
ENew.Oriented(TopAbs_REVERSED));
}
else {
myBounds.Add(Eold.Oriented(TopAbs_FORWARD),
ENew.Oriented(TopAbs_FORWARD));
}
// if new binding bind also the vertices
TopoDS_Iterator itold(Eold);
while (itold.More()) {
if (!myBounds.Contains(itold.Value())) {
// find the vertex of Enew with same orientation
TopAbs_Orientation anOrien = itold.Value().Orientation();
TopoDS_Iterator itnew(ENew);
while (itnew.More()) {
if (itnew.Value().Orientation() == anOrien) {
TopoDS_Vertex VNew = TopoDS::Vertex(itnew.Value());
if (IsCopied(VNew)) {
// if VNew has been copied take the copy
VNew = TopoDS::Vertex(Copy(VNew));
}
myBounds.Add(itold.Value(),VNew);
break;
}
itnew.Next();
}
}
itold.Next();
}
hasCopy = Standard_True;
}
}
//=======================================================================
//function : IsBound
//purpose :
//=======================================================================
Standard_Boolean BRepTools_Quilt::IsCopied(const TopoDS_Shape& S) const
{
if (myBounds.Contains(S)) {
return !S.IsSame(myBounds.FindFromKey(S));
}
else
return Standard_False;
}
//=======================================================================
//function : Copy
//purpose :
//=======================================================================
const TopoDS_Shape& BRepTools_Quilt::Copy(const TopoDS_Shape& S) const
{
Standard_NoSuchObject_Raise_if(!IsCopied(S),"BRepTools_Quilt::Copy");
return myBounds.FindFromKey(S);
}
//=======================================================================
//function : Shells
//purpose :
//=======================================================================
TopoDS_Shape BRepTools_Quilt::Shells() const
{
// Outline of the algorithm
//
// In the map M we bind the free edges to their shells
// We explore all the faces in myBounds
// For each one we search the edges in the map and either :
//
// - Start a new shell if no edge is a free edge.
// - Add the face to an existing shell
// - Connect other shells if the face touch more than one shell
// In the Map M the Shell is bound withe the relative orientation of E
// in the shell
// In the map MF we binb the face to its shell.
// In the Map MF the Shell is bound with the relative orientation of F
// in the shell
TopTools_DataMapOfShapeShape M, MF;
BRep_Builder B;
TopoDS_Compound result;
B.MakeCompound(result);
TopTools_MapOfShape MapOtherShape; //gka
TopTools_MapOfShape EdgesFaces;
// loop on the face in myBounds
//TopTools_DataMapIteratorOfDataMapOfShapeShape it(myBounds);
//while (it.More())
for(Standard_Integer ii =1; ii <= myBounds.Extent(); ii++) {
const TopoDS_Shape& Shape = myBounds.FindFromIndex(ii); //it.Value();
if (Shape.ShapeType() == TopAbs_FACE) {
for(TopExp_Explorer aExpEdg(Shape,TopAbs_EDGE); aExpEdg.More(); aExpEdg.Next()) //gka
EdgesFaces.Add(aExpEdg.Current());
TopoDS_Shell SH;
TopAbs_Orientation NewO;
TopExp_Explorer itf1( Shape,TopAbs_EDGE);
for ( ; itf1.More(); itf1.Next()) {
const TopoDS_Shape& E = itf1.Current();
if (M.IsBound(E)) {
SH = TopoDS::Shell(M(E));
if (SH.Orientation() == E.Orientation())
NewO = TopAbs::Reverse(Shape.Orientation());
else
NewO = Shape.Orientation();
MF.Bind (Shape,SH.Oriented(NewO));
break;
}
}
if (SH.IsNull()) {
// Create a new shell, closed. Add it to the result.
B.MakeShell(SH);
SH.Closed(Standard_True);
B.Add(result,SH);
MF.Bind (Shape,SH.Oriented(Shape.Orientation()));
}
// Add the face to the shell
SH.Free(Standard_True);
// B.Add(SH.Oriented(TopAbs_FORWARD), F .Oriented(MF(F).Orientation()));
TopoDS_Shape arefShape = SH.Oriented(TopAbs_FORWARD) ;
B.Add( arefShape , Shape.Oriented(MF(Shape).Orientation()));
TopExp_Explorer itf(Shape.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
for ( ;itf.More(); itf.Next()) {
const TopoDS_Edge& E = TopoDS::Edge(itf.Current());
if (M.IsBound(E)) {
const TopoDS_Shape oldShell = M(E);
if (!oldShell.IsSame(SH)) {
// Fuse the old shell with the new one
// Compare the orientation of E in SH and in oldshell.
TopAbs_Orientation anOrien = E.Orientation();
if (MF(Shape).Orientation() == TopAbs_REVERSED)
anOrien = TopAbs::Reverse(anOrien);
Standard_Boolean Rev = (anOrien == oldShell.Orientation());
//if rev = True oldShell has to be reversed.
// Add the faces of oldShell in SH.
for (TopoDS_Iterator its(oldShell); its.More(); its.Next()) {
const TopoDS_Face Fo = TopoDS::Face(its.Value());
TopAbs_Orientation NewO;
// update the orientation of Fo in SH.
if (Rev)
NewO = TopAbs::Reverse(MF(Fo).Orientation());
else
NewO = MF(Fo).Orientation();
MF.Bind(Fo,SH.Oriented(NewO));
// B.Add (SH.Oriented(TopAbs_FORWARD),Fo.Oriented(NewO));
TopoDS_Shape arefShape = SH.Oriented(TopAbs_FORWARD) ;
B.Add ( arefShape ,Fo.Oriented(NewO));
}
Standard_Integer kk =1;
Standard_Integer p =0;
// Rebind the free edges of the old shell to the new shell
//gka BUG 6491
TopExp_Explorer aexp(SH,TopAbs_EDGE);
for( ; aexp.More(); aexp.Next()) {
//for (TopTools_DataMapIteratorOfDataMapOfShapeShape itm(M);
// itm.More(); ) {
if(!M.IsBound(aexp.Current()))
continue;
TopoDS_Shape ae = aexp.Current();
TopoDS_Shape as = M.Find(ae);
if (as.IsSame(oldShell)) {
// update the orientation of free edges in SH.
if (Rev)
NewO = TopAbs::Reverse(as.Orientation());
else
NewO = as.Orientation();
M.Bind(ae,SH.Oriented(NewO));
}
}
// remove the old shell from the result
B.Remove(result,oldShell.Oriented(TopAbs_FORWARD));
}
// Test if SH is always orientable.
TopAbs_Orientation anOrien = E.Orientation();
if (MF(Shape).Orientation() == TopAbs_REVERSED)
anOrien = TopAbs::Reverse(anOrien);
if (M(E).Orientation() == anOrien)
SH.Orientable(Standard_False);
// remove the edge from M (no more a free edge)
M.UnBind(E);
}
else {
NewO = E.Orientation();
if (MF(Shape).Orientation() == TopAbs_REVERSED)
NewO = TopAbs::Reverse(NewO);
if(!E.IsNull())
M.Bind(E,SH.Oriented(NewO));
else
continue;
}
}
// freeze the shell
SH.Free(Standard_False);
}
else
MapOtherShape.Add(Shape);
//it.Next();
}
// Unclose all shells having free edges
for (TopTools_DataMapIteratorOfDataMapOfShapeShape it(M); it.More(); it.Next()) {
TopoDS_Shape S = it.Value();
S.Closed(Standard_Boolean(Standard_False));
}
TopTools_MapIteratorOfMapOfShape itother(MapOtherShape); //gka version for free edges
for( ; itother.More() ; itother.Next()) {
if(!EdgesFaces.Contains(itother.Key()) && myBounds.Contains(itother.Key())) {
TopoDS_Shape aSh = myBounds.FindFromKey(itother.Key());
B.Add(result,aSh);
}
}
return result;
}

View File

@@ -0,0 +1,119 @@
-- File: BRepTools_ReShape.cdl
-- Created: Wed Jun 3 12:43:06 1998
-- Author: data exchange team
-- <det@loufox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1998
class ReShape from BRepTools inherits TShared from MMgt
---Purpose: Rebuilds a Shape by making pre-defined substitutions on some
-- of its components
--
-- In a first phase, it records requests to replace or remove
-- some individual shapes
-- For each shape, the last given request is recorded
-- Requests may be applied "Oriented" (i.e. only to an item with
-- the SAME orientation) or not (the orientation of replacing
-- shape is respectful of that of the original one)
--
-- Then, these requests may be applied to any shape which may
-- contain one or more of these individual shapes
uses
ShapeEnum from TopAbs,
Shape from TopoDS,
DataMapOfShapeShape from TopTools
is
Create returns mutable ReShape from BRepTools;
---Purpose: Returns an empty Reshape
Clear (me: mutable);
---Purpose: Clears all substitutions requests
Remove (me: mutable; shape: Shape from TopoDS;
oriented: Boolean = Standard_False);
---Purpose: Sets a request to Remove a Shape
-- If <oriented> is True, only for a shape with the SAME
-- orientation. Else, whatever the orientation
Replace (me: mutable; shape, newshape: Shape from TopoDS;
oriented: Boolean = Standard_False);
---Purpose: Sets a request to Replace a Shape by a new one
-- If <oriented> is True, only if the orientation is the same
-- Else, whatever the orientation, and the new shape takes the
-- same orientation as <newshape> if the replaced one has the
-- same as <shape>, else it is reversed
IsRecorded (me; shape: Shape from TopoDS) returns Boolean;
---Purpose: Tells if a shape is recorded for Replace/Remove
Value (me; shape: Shape from TopoDS) returns Shape from TopoDS;
---Purpose: Returns the new value for an individual shape
-- If not recorded, returns the original shape itself
-- If to be Removed, returns a Null Shape
-- Else, returns the replacing item
Status (me: mutable; shape: Shape from TopoDS; newsh: out Shape from TopoDS; last : Boolean = Standard_False)
returns Integer is virtual;
---Purpose: Returns a complete substitution status for a shape
-- 0 : not recorded, <newsh> = original <shape>
-- < 0: to be removed, <newsh> is NULL
-- > 0: to be replaced, <newsh> is a new item
-- If <last> is False, returns status and new shape recorded in
-- the map directly for the shape, if True and status > 0 then
-- recursively searches for the last status and new shape.
Apply (me: mutable; shape: Shape from TopoDS; until: ShapeEnum from TopAbs; buildmode: Integer)
returns Shape from TopoDS is virtual;
---Purpose: Applies the substitutions requests to a shape
--
-- <until> gives the level of type until which requests are taken
-- into account. For subshapes of the type <until> no rebuild
-- and futher exploring are done.
-- ACTUALLY, NOT IMPLEMENTED BELOW TopAbs_FACE
--
-- <buildmode> says how to do on a SOLID,SHELL ... if one of its
-- sub-shapes has been changed:
-- 0: at least one Replace or Remove -> COMPOUND, else as such
-- 1: at least one Remove (Replace are ignored) -> COMPOUND
-- 2: Replace and Remove are both ignored
-- If Replace/Remove are ignored or absent, the result as same
-- type as the starting shape
Apply (me: mutable; shape: Shape from TopoDS; until: ShapeEnum from TopAbs = TopAbs_SHAPE)
returns Shape from TopoDS is virtual;
---Purpose: Applies the substitutions requests to a shape.
--
-- <until> gives the level of type until which requests are taken
-- into account. For subshapes of the type <until> no rebuild
-- and futher exploring are done.
--
-- NOTE: each subshape can be replaced by shape of the same type
-- or by shape containing only shapes of that type (for
-- example, TopoDS_Edge can be replaced by TopoDS_Edge,
-- TopoDS_Wire or TopoDS_Compound containing TopoDS_Edges).
-- If incompatible shape type is encountered, it is ignored
-- and flag FAIL1 is set in Status.
ModeConsiderLocation(me: mutable) returns Boolean;
---C++: return &
---Purpose:Returns (modifiable) the flag which defines whether Location of shape take into account
-- during replacing shapes.
ModeConsiderOrientation(me: mutable) returns Boolean;
---C++: return &
---Purpose:Returns (modifiable) the flag which defines whether Orientation of shape take into account
-- during replacing shapes.
fields
myNMap: DataMapOfShapeShape from TopTools; -- normal case
myRMap: DataMapOfShapeShape from TopTools; -- REVERSED
myStatus: Integer is protected; -- error status
myConsiderLocation : Boolean;
myConsiderOrientation : Boolean;
end ReShape;

View File

@@ -0,0 +1,569 @@
// abv 28.04.99 S4137: ading method Apply for work on all types of shapes
// sln 29.11.01 Bug24: correction iteration through map in method 'Status'
// sln 29.11.01 Bug22: correction of methods Replace and Value for case when mode myConsiderLocation is on
#include <BRepTools_ReShape.ixx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Solid.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopExp_Explorer.hxx>
#include <BRep_Builder.hxx>
//include <ShapeExtend.hxx>
//#include <BRepTools_Edge.hxx>
#include <TopoDS.hxx>
#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
#include <BRep_TEdge.hxx>
#include <BRep_GCurve.hxx>
#include <Geom_Surface.hxx>
#include <TopLoc_Location.hxx>
#include <BRep_ListOfCurveRepresentation.hxx>
#include <BRep_GCurve.hxx>
#include <BRep_Tool.hxx>
#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
#include <TopoDS_Edge.hxx>
static void CopyRanges (const TopoDS_Edge& toedge,
const TopoDS_Edge& fromedge,
const Standard_Real alpha,
const Standard_Real beta)
{
/* BRep_Builder B;
for (BRep_ListIteratorOfListOfCurveRepresentation itcr
((*((Handle(BRep_TEdge)*)&fromedge.TShape()))->ChangeCurves()); itcr.More(); itcr.Next()) {
Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
if ( GC.IsNull() ) continue;
Standard_Real first, last;
GC->Range ( first, last );
if ( GC->IsCurve3D() )
B.Range ( toedge, first, last );
else if ( GC->IsCurveOnSurface() )
B.Range ( toedge, GC->Surface(), fromedge.Location().Multiplied (GC->Location()), first, last);
}
*/
for (BRep_ListIteratorOfListOfCurveRepresentation fromitcr
((*((Handle(BRep_TEdge)*)&fromedge.TShape()))->ChangeCurves()); fromitcr.More(); fromitcr.Next()) {
Handle(BRep_GCurve) fromGC = Handle(BRep_GCurve)::DownCast(fromitcr.Value());
if ( fromGC.IsNull() ) continue;
Standard_Boolean isC3d = fromGC->IsCurve3D();
if(isC3d) {
if(fromGC->Curve3D().IsNull()) continue; }
else {
if(fromGC->PCurve().IsNull()) continue; }
if ( ! isC3d && ! fromGC->IsCurveOnSurface()) continue; // only 3d curves and pcurves are treated
Handle(Geom_Surface) surface;
TopLoc_Location L;
if ( ! isC3d ) {
surface = fromGC->Surface();
L = fromGC->Location();
}
BRep_ListOfCurveRepresentation& tolist = (*((Handle(BRep_TEdge)*)&toedge.TShape()))->ChangeCurves();
Handle(BRep_GCurve) toGC;
for (BRep_ListIteratorOfListOfCurveRepresentation toitcr (tolist); toitcr.More(); toitcr.Next()) {
toGC = Handle(BRep_GCurve)::DownCast(toitcr.Value());
if ( toGC.IsNull() ) continue;
if ( isC3d ) {
if ( ! toGC->IsCurve3D() ) continue;
}
else if ( ! toGC->IsCurveOnSurface() ||
surface != toGC->Surface() || L != toGC->Location() ) continue;
Standard_Real first = fromGC->First();
Standard_Real last = fromGC->Last();
Standard_Real len = last - first;
toGC->SetRange ( first+alpha*len, first+beta*len );
break;
}
}
}
//=======================================================================
//function : BRepTools_ReShape
//purpose :
//=======================================================================
BRepTools_ReShape::BRepTools_ReShape()
{
myConsiderLocation = Standard_False;
myConsiderOrientation = Standard_False;
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void BRepTools_ReShape::Clear()
{
myNMap.Clear();
myRMap.Clear();
}
//=======================================================================
//function : Remove
//purpose :
//=======================================================================
void BRepTools_ReShape::Remove (const TopoDS_Shape& shape,
const Standard_Boolean oriented)
{
TopoDS_Shape nulshape;
Replace (shape,nulshape,oriented);
}
//=======================================================================
//function : Replace
//purpose :
//=======================================================================
void BRepTools_ReShape::Replace (const TopoDS_Shape& ashape,
const TopoDS_Shape& anewshape,
const Standard_Boolean oriented)
{
TopoDS_Shape shape = ashape;
TopoDS_Shape newshape = anewshape;
if ( shape.IsNull() || shape == newshape ) return;
if (myConsiderLocation) {
//sln 29.11.01 Bug22: Change location of 'newshape' in accordance with location of 'shape'
newshape.Location(newshape.Location().Multiplied(shape.Location().Inverted()));
TopLoc_Location nullLoc;
shape.Location ( nullLoc );
}
#ifdef DEB
if ( IsRecorded ( shape ) && ((myConsiderLocation && ! Value ( shape ).IsPartner ( newshape )) ||
(!myConsiderLocation && ! Value ( shape ).IsSame ( newshape ))))
cout << "Warning: BRepTools_ReShape::Replace: shape already recorded" << endl;
#endif
if (oriented) {
if( shape.Orientation()==TopAbs_REVERSED ) {
if( myConsiderOrientation )
myRMap.Bind (shape,newshape);
else {
myNMap.Bind (shape.Reversed(),newshape.Reversed());
}
}
else
myNMap.Bind (shape,newshape);
}
else {
// protect against INTERNAL or EXTERNAL shape
if ( shape.Orientation() == TopAbs_INTERNAL ||
shape.Orientation() == TopAbs_EXTERNAL ) {
Replace ( shape.Oriented ( TopAbs_FORWARD ),
newshape.Oriented ( newshape.Orientation() == shape.Orientation() ?
TopAbs_FORWARD : TopAbs_REVERSED ), oriented );
return;
}
Replace (shape,newshape,Standard_True);
if(myConsiderOrientation)
Replace (shape.Reversed(),newshape.Reversed(),Standard_True);
}
}
//=======================================================================
//function : IsRecorded
//purpose :
//=======================================================================
Standard_Boolean BRepTools_ReShape::IsRecorded (const TopoDS_Shape& ashape) const
{
TopoDS_Shape shape = ashape;
if (myConsiderLocation) {
TopLoc_Location nullLoc;
shape.Location ( nullLoc );
}
if (shape.IsNull()) return Standard_False;
if ( myConsiderOrientation && shape.Orientation()==TopAbs_REVERSED )
return myRMap.IsBound (shape);
else
return myNMap.IsBound (shape);
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
TopoDS_Shape BRepTools_ReShape::Value (const TopoDS_Shape& ashape) const
{
TopoDS_Shape res;
if (ashape.IsNull()) return res;
TopoDS_Shape shape = ashape;
if (myConsiderLocation) {
TopLoc_Location nullLoc;
shape.Location ( nullLoc );
}
Standard_Boolean fromMap = Standard_False;
if ( shape.Orientation()==TopAbs_REVERSED ) {
if( myConsiderOrientation ) {
if (!myRMap.IsBound (shape)) res = shape;
else {
res = myRMap.Find (shape);
fromMap = Standard_True;
}
}
else {
if (!myNMap.IsBound (shape)) res = shape;
else {
res = myNMap.Find (shape).Reversed();
fromMap = Standard_True;
}
}
}
else {
if (!myNMap.IsBound (shape)) res = shape;
else {
res = myNMap.Find (shape);
fromMap = Standard_True;
}
}
// for INTERNAL/EXTERNAL, since they are not fully supported, keep orientation
if ( shape.Orientation() == TopAbs_INTERNAL ||
shape.Orientation() == TopAbs_EXTERNAL )
res.Orientation ( shape.Orientation() );
if (myConsiderLocation) {
//sln 29.11.01 Bug22: Recalculate location of resulting shape in accordance with
//whether result is from map or not
if(fromMap) res.Location(ashape.Location()*res.Location());
else res.Location(ashape.Location());
}
return res;
}
//=======================================================================
//function : Status
//purpose :
//=======================================================================
Standard_Integer BRepTools_ReShape::Status(const TopoDS_Shape& ashape,
TopoDS_Shape& newsh,
const Standard_Boolean last)
{
Standard_Integer res = 0;
if (ashape.IsNull()) { newsh.Nullify(); return res; }
TopoDS_Shape shape = ashape;
TopLoc_Location aLocSh = shape.Location();
if (myConsiderLocation) {
TopLoc_Location nullLoc;
shape.Location ( nullLoc );
}
if ( myConsiderOrientation && shape.Orientation()==TopAbs_REVERSED ) {
if (!myRMap.IsBound (shape)) { newsh = shape; res = 0; }
else { newsh = myRMap.Find (shape); res = 1; }
}
else {
if (!myNMap.IsBound (shape)) { newsh = shape; res = 0; }
else { newsh = myNMap.Find (shape); res = 1; }
}
if (res > 0) {
if (newsh.IsNull()) res = -1;
else if (newsh.IsEqual (shape)) res = 0;
else if ( last && ((myConsiderLocation && ! newsh.IsPartner (shape)) ||
(!myConsiderLocation && ! newsh.IsSame (shape)))) {
//TopoDS_Shape newnewsh;
//Standard_Integer newres = Status (newsh, newnewsh, last);
//newsh = newnewsh;
//if (newres) res = newres;
// sln 29.11.01 Bug24: Correction iteration through maps. Way of iteration used early does not
// correspond to way of storing information in the maps.
newsh = Apply(shape, TopAbs_SHAPE);
if (newsh.IsNull()) res = -1;
if (newsh.IsEqual (shape)) res = 0;
}
}
if(myConsiderLocation && !newsh.IsNull())
{
TopLoc_Location aResLoc = (res >0 && !newsh.Location().IsIdentity() ?
aLocSh * newsh.Location() : aLocSh);
newsh.Location(aResLoc);
}
return res;
}
//=======================================================================
//function : Apply
//purpose :
//=======================================================================
TopoDS_Shape BRepTools_ReShape::Apply (const TopoDS_Shape& shape,
const TopAbs_ShapeEnum until,
const Standard_Integer buildmode)
{
if (shape.IsNull()) return shape;
TopoDS_Shape newsh;
if (Status (shape,newsh,Standard_False) != 0) return newsh;
TopAbs_ShapeEnum st = shape.ShapeType();
if (st == until) return newsh; // critere d arret
Standard_Integer modif = 0;
if (st == TopAbs_COMPOUND || st == TopAbs_COMPSOLID) {
BRep_Builder B;
TopoDS_Compound C;
B.MakeCompound (C);
for (TopoDS_Iterator it (shape); it.More(); it.Next()) {
TopoDS_Shape sh = it.Value();
Standard_Integer stat = Status (sh,newsh,Standard_False);
if (stat != 0) modif = 1;
if (stat >= 0) B.Add (C,newsh);
}
if (modif == 0) return shape;
return C;
}
if (st == TopAbs_SOLID) {
BRep_Builder B;
TopoDS_Compound C;
B.MakeCompound (C);
TopoDS_Solid S;
B.MakeSolid (S);
for (TopoDS_Iterator it (shape); it.More(); it.Next()) {
TopoDS_Shape sh = it.Value();
newsh = Apply (sh,until,buildmode);
if (newsh.IsNull()) {
modif = -1;
}
else if (newsh.ShapeType() != TopAbs_SHELL) {
Standard_Integer nbsub = 0;
for (TopExp_Explorer exh(newsh,TopAbs_SHELL); exh.More(); exh.Next()) {
TopoDS_Shape onesh = exh.Current ();
B.Add (S,onesh);
nbsub ++;
}
if (nbsub == 0) modif = -1;
B.Add (C,newsh); // c est tout
}
else {
if (modif == 0 && !sh.IsEqual(newsh)) modif = 1;
B.Add (C,newsh);
B.Add (S,newsh);
}
}
if ( (modif < 0 && buildmode < 2) || (modif == 0 && buildmode < 1) )
return C;
else return S;
}
if (st == TopAbs_SHELL) {
BRep_Builder B;
TopoDS_Compound C;
B.MakeCompound (C);
TopoDS_Shell S;
B.MakeShell (S);
for (TopoDS_Iterator it (shape); it.More(); it.Next()) {
TopoDS_Shape sh = it.Value();
newsh = Apply (sh,until,buildmode);
if (newsh.IsNull()) {
modif = -1;
}
else if (newsh.ShapeType() != TopAbs_FACE) {
Standard_Integer nbsub = 0;
for (TopExp_Explorer exf(newsh,TopAbs_FACE); exf.More(); exf.Next()) {
TopoDS_Shape onesh = exf.Current ();
B.Add (S,onesh);
nbsub ++;
}
if (nbsub == 0) modif = -1;
B.Add (C,newsh); // c est tout
}
else {
if (modif == 0 && !sh.IsEqual(newsh)) modif = 1;
B.Add (C,newsh);
B.Add (S,newsh);
}
}
if ( (modif < 0 && buildmode < 2) || (modif == 0 && buildmode < 1) )
return C;
else return S;
}
cout<<"BRepTools_ReShape::Apply NOT YET IMPLEMENTED"<<endl;
return shape;
}
//=======================================================================
//function : EncodeStatus
//purpose : static
//=======================================================================
static Standard_Integer EncodeStatus (const Standard_Integer status)
{
switch ( status ) {
case 0 : return 0x0000; //ShapeExtend_OK
case 1: return 0x0001; //ShapeExtend_DONE1
case 2: return 0x0002; //....
case 3: return 0x0004;
case 4: return 0x0008;
case 5: return 0x0010;
case 6: return 0x0020;
case 7: return 0x0040;
case 8: return 0x0080; //....
case 9 : return 0x00ff; //ShapeExtend_DONE
case 10: return 0x0100; //ShapeExtend_FAIL1
case 11: return 0x0200; //...
case 12: return 0x0400;
case 13: return 0x0800;
case 14: return 0x1000;
case 15: return 0x2000;
case 16: return 0x4000;
case 17: return 0x8000; //....
case 18 : return 0xff00; //ShapeExtend_FAIL
}
return 0;
}
//=======================================================================
//function : Apply
//purpose :
//=======================================================================
TopoDS_Shape BRepTools_ReShape::Apply (const TopoDS_Shape& shape,
const TopAbs_ShapeEnum until)
{
myStatus = EncodeStatus(0); //ShapeExtend::EncodeStatus ( ShapeExtend_OK );
if ( shape.IsNull() ) return shape;
// apply direct replacement
TopoDS_Shape newsh = Value ( shape );
// if shape removed, return NULL
if ( newsh.IsNull() ) {
myStatus = EncodeStatus (2); //ShapeExtend_DONE2
return newsh;
}
// if shape replaced, apply modifications to the result recursively
if ( (myConsiderLocation && ! newsh.IsPartner (shape)) ||
(!myConsiderLocation &&! newsh.IsSame ( shape )) ) {
TopoDS_Shape res = Apply ( newsh, until );
myStatus |= EncodeStatus(1); //ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
return res;
}
TopAbs_ShapeEnum st = shape.ShapeType(); //, subt;
if ( st >= until ) return newsh; // critere d arret
if(st == TopAbs_VERTEX || st == TopAbs_SHAPE)
return shape;
// define allowed types of components
//fix for SAMTECH bug OCC322 about abcense internal vertices after sewing.
/*
switch ( st ) {
case TopAbs_COMPOUND: subt = TopAbs_SHAPE; break;
case TopAbs_COMPSOLID: subt = TopAbs_SOLID; break;
case TopAbs_SOLID: subt = TopAbs_SHELL; break;
case TopAbs_SHELL: subt = TopAbs_FACE; break;
case TopAbs_FACE: subt = TopAbs_WIRE; break;
case TopAbs_WIRE: subt = TopAbs_EDGE; break;
case TopAbs_EDGE: subt = TopAbs_VERTEX; break;
case TopAbs_VERTEX:
case TopAbs_SHAPE:
default: return shape;
}
*/
BRep_Builder B;
TopoDS_Shape result = shape.EmptyCopied();
TopAbs_Orientation orien = shape.Orientation();
result.Orientation(TopAbs_FORWARD); // protect against INTERNAL or EXTERNAL shapes
Standard_Boolean modif = Standard_False;
Standard_Integer locStatus = myStatus;
// apply recorded modifications to subshapes
for ( TopoDS_Iterator it(shape,Standard_False); it.More(); it.Next() ) {
TopoDS_Shape sh = it.Value();
newsh = Apply ( sh, until );
if ( newsh != sh ) {
if ( myStatus & EncodeStatus(4)) //ShapeExtend::DecodeStatus ( myStatus, ShapeExtend_DONE4 ) )
locStatus |= EncodeStatus(4); //|= ShapeExtend::EncodeStatus ( ShapeExtend_DONE4 );
modif = 1;
}
if ( newsh.IsNull() ) {
locStatus |= EncodeStatus(4); //ShapeExtend::EncodeStatus ( ShapeExtend_DONE4 );
continue;
}
locStatus |= EncodeStatus(3);//ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
if ( st == TopAbs_COMPOUND || newsh.ShapeType() == sh.ShapeType()) { //fix for SAMTECH bug OCC322 about abcense internal vertices after sewing.
B.Add ( result, newsh );
continue;
}
Standard_Integer nitems = 0;
for ( TopoDS_Iterator subit(newsh); subit.More(); subit.Next(), nitems++ ) {
TopoDS_Shape subsh = subit.Value();
if ( subsh.ShapeType() == sh.ShapeType() ) B.Add ( result, subsh );//fix for SAMTECH bug OCC322 about abcense internal vertices after sewing.
else locStatus |= EncodeStatus(10);//ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 );
}
if ( ! nitems ) locStatus |= EncodeStatus(10);//ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 );
}
if ( ! modif ) return shape;
// restore Range on edge broken by EmptyCopied()
if ( st == TopAbs_EDGE ) {
//BRepTools_Edge sbe;
CopyRanges ( TopoDS::Edge ( result ), TopoDS::Edge ( shape ),0,1 );
}
if (st == TopAbs_FACE) {
TopoDS_Face face = TopoDS::Face ( shape );
if( BRep_Tool::NaturalRestriction( face ) ) {
BRep_Builder aB;
aB.NaturalRestriction( TopoDS::Face ( result ), Standard_True );
}
}
result.Orientation(orien);
myStatus = locStatus;
Replace ( shape, result );
return result;
}
//=======================================================================
//function : Status
//purpose :
//=======================================================================
/*Standard_Boolean BRepTools_ReShape::Status (const ShapeExtend_Status status) const
{
return ShapeExtend::DecodeStatus ( myStatus, status );
}*/
//=======================================================================
//function : ModeConsiderLocation
//purpose :
//=======================================================================
Standard_Boolean& BRepTools_ReShape::ModeConsiderLocation()
{
return myConsiderLocation;
}
//=======================================================================
//function : ModeConsiderOrientation
//purpose :
//=======================================================================
Standard_Boolean& BRepTools_ReShape::ModeConsiderOrientation()
{
return myConsiderOrientation;
}

View File

@@ -0,0 +1,151 @@
-- File: BRepTools_ShapeSet.cdl
-- Created: Mon Jul 19 15:28:48 1993
-- Author: Remi LEQUETTE
-- <rle@nonox>
---Copyright: Matra Datavision 1993
class ShapeSet from BRepTools inherits ShapeSet from TopTools
---Purpose: Contains a Shape and all its subshapes, locations
-- and geometries.
--
-- The topology is inherited from TopTools.
uses
Shape from TopoDS,
Builder from BRep,
ShapeEnum from TopAbs,
SurfaceSet from GeomTools,
CurveSet from GeomTools,
Curve2dSet from GeomTools,
IndexedMapOfTransient from TColStd
is
Create(isWithTriangles: Boolean from Standard = Standard_True)
returns ShapeSet from BRepTools;
---Purpose: Builds an empty ShapeSet.
-- Parameter <isWithTriangles> is added for XML Persistence
Create(B : Builder from BRep;
isWithTriangles: Boolean from Standard = Standard_True)
returns ShapeSet from BRepTools;
---Purpose: Builds an empty ShapeSet.
-- Parameter <isWithTriangles> is added for XML Persistence
Clear(me : in out)
---Purpose: Clears the content of the set.
is redefined;
AddGeometry(me : in out; S : Shape from TopoDS)
---Purpose: Stores the goemetry of <S>.
is redefined;
DumpGeometry(me; OS : in out OStream)
---Purpose: Dumps the geometry of me on the stream <OS>.
is redefined;
WriteGeometry(me : in out; OS : in out OStream)
---Purpose: Writes the geometry of me on the stream <OS> in a
-- format that can be read back by Read.
is redefined;
ReadGeometry(me : in out; IS : in out IStream)
---Purpose: Reads the geometry of me from the stream <IS>.
is redefined;
DumpGeometry(me; S : Shape from TopoDS; OS : in out OStream)
---Purpose: Dumps the geometry of <S> on the stream <OS>.
is redefined;
WriteGeometry(me; S : Shape from TopoDS; OS : in out OStream)
---Purpose: Writes the geometry of <S> on the stream <OS> in a
-- format that can be read back by Read.
is redefined;
ReadGeometry(me : in out; T : ShapeEnum from TopAbs;
IS : in out IStream;
S : out Shape from TopoDS)
---Purpose: Reads the geometry of a shape of type <T> from the
-- stream <IS> and returns it in <S>.
is redefined;
AddShapes(me : in out; S1 : in out Shape from TopoDS;
S2 : Shape from TopoDS)
---Purpose: Inserts the shape <S2> in the shape <S1>. This
-- method must be redefined to use the correct
-- builder.
is redefined;
Check(me : in out; T : ShapeEnum from TopAbs;
S : in out Shape from TopoDS)
is redefined;
ReadPolygon3D(me: in out; IS: in out IStream)
---Purpose: Reads the 3d polygons of me
-- from the stream <IS>.
is static;
WritePolygon3D(me; OS: in out OStream;
Compact: Boolean=Standard_True)
---Purpose: Writes the 3d polygons
-- on the stream <OS> in a format that can
-- be read back by Read.
is static;
DumpPolygon3D(me; OS: in out OStream)
---Purpose: Dumps the 3d polygons
-- on the stream <OS>.
is static;
ReadTriangulation(me: in out; IS: in out IStream)
---Purpose: Reads the triangulation of me
-- from the stream <IS>.
is static;
WriteTriangulation(me; OS: in out OStream;
Compact: Boolean=Standard_True)
---Purpose: Writes the triangulation
-- on the stream <OS> in a format that can
-- be read back by Read.
is static;
DumpTriangulation(me; OS: in out OStream)
---Purpose: Dumps the triangulation
-- on the stream <OS>.
is static;
ReadPolygonOnTriangulation(me: in out; IS: in out IStream)
---Purpose: Reads the polygons on triangulation of me
-- from the stream <IS>.
is static;
WritePolygonOnTriangulation(me; OS: in out OStream;
Compact: Boolean=Standard_True)
---Purpose: Writes the polygons on triangulation
-- on the stream <OS> in a format that can
-- be read back by Read.
is static;
DumpPolygonOnTriangulation(me; OS: in out OStream)
---Purpose: Dumps the polygons on triangulation
-- on the stream <OS>.
is static;
fields
myBuilder : Builder from BRep;
mySurfaces : SurfaceSet from GeomTools;
myCurves : CurveSet from GeomTools;
myCurves2d : Curve2dSet from GeomTools;
myPolygons2D: IndexedMapOfTransient from TColStd;
myPolygons3D: IndexedMapOfTransient from TColStd;
myTriangulations: IndexedMapOfTransient from TColStd;
myNodes : IndexedMapOfTransient from TColStd;
myWithTriangles: Boolean from Standard; -- for XML Persistence
end ShapeSet;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,75 @@
-- File: BRepTools_Substitution.cdl
-- Created: Tue Mar 28 09:17:56 1995
-- Author: Yves FRICAUD
-- <yfr@stylox>
---Copyright: Matra Datavision 1995
class Substitution from BRepTools
---Purpose: A tool to substitute subshapes by other shapes.
--
--
-- The user use the method Substitute to define the
-- modifications.
-- A set of shapes is designated to replace a initial
-- shape.
--
-- The method Build reconstructs a new Shape with the
-- modifications.The Shape and the new shape are
-- registered.
--
uses
Shape from TopoDS,
ListOfShape from TopTools,
DataMapOfShapeListOfShape from TopTools
raises
NoSuchObject from Standard
is
Create returns Substitution from BRepTools;
Clear ( me : in out)
---Purpose: Reset all the fields.
is static;
Substitute (me : in out;
OldShape : Shape from TopoDS;
NewShapes : ListOfShape from TopTools)
---Purpose: <Oldshape> will be replaced by <NewShapes>.
--
-- <NewShapes> can be empty , in this case <OldShape>
-- will disparate from its ancestors.
--
-- if an item of <NewShapes> is oriented FORWARD.
-- it will be oriented as <OldShape> in its ancestors.
-- else it will be reversed.
is static;
Build (me : in out; S : Shape from TopoDS)
---Purpose: Build NewShape from <S> if its subshapes has modified.
--
-- The methods <IsCopied> and <Copy> allows you to keep
-- the resul of <Build>
is static;
IsCopied(me; S : Shape from TopoDS) returns Boolean
---Purpose: Returns True if <S> has been replaced .
is static;
Copy(me; S : Shape from TopoDS) returns ListOfShape from TopTools
---Purpose: Returns the set of shapes substitued to <S> .
---C++: return const &
raises
NoSuchObject from Standard -- if ! IsCopied(S)
is static;
fields
myMap : DataMapOfShapeListOfShape from TopTools;
end Substitution;

View File

@@ -0,0 +1,160 @@
// File: BRepTools_Substitution.cxx
// Created: Tue Mar 28 09:54:41 1995
// Author: Yves FRICAUD
// <yfr@stylox>
#include <BRepTools_Substitution.ixx>
#include <TopoDS.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <BRep_Builder.hxx>
#include <Standard_ConstructionError.hxx>
#include <BRep_Tool.hxx>
//=======================================================================
//function : BRepTools_Substitution
//purpose :
//=======================================================================
BRepTools_Substitution::BRepTools_Substitution()
{}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void BRepTools_Substitution::Clear()
{
myMap.Clear();
}
//=======================================================================
//function : Substitute
//purpose :
//=======================================================================
void BRepTools_Substitution::Substitute(const TopoDS_Shape& OS,
const TopTools_ListOfShape& NS)
{
Standard_ConstructionError_Raise_if
(IsCopied(OS),"BRepTools_CutClue::Substitute");
myMap.Bind(OS,NS);
}
//=======================================================================
//function : Build
//purpose :
//=======================================================================
void BRepTools_Substitution::Build(const TopoDS_Shape& S)
{
if (IsCopied(S)) return;
BRep_Builder B;
TopoDS_Iterator iteS (S.Oriented(TopAbs_FORWARD));
Standard_Boolean IsModified = Standard_False;
Standard_Boolean HasSubShape = Standard_False;
//------------------------------------------
// look S is modified and build subshapes.
//------------------------------------------
for (; iteS.More(); iteS.Next()) {
const TopoDS_Shape& SS = iteS.Value();
Build (SS);
if (IsCopied(SS)) {
IsModified = Standard_True;
}
}
TopoDS_Shape NewS = S.Oriented(TopAbs_FORWARD);
if (IsModified) {
//----------------------------------------
// Rebuild S.
//------------------------------------------
NewS.EmptyCopy();
if (NewS.ShapeType() == TopAbs_EDGE) {
Standard_Real f,l;
BRep_Tool::Range(TopoDS::Edge(S),f,l);
B.Range(TopoDS::Edge(NewS),f,l);
}
iteS.Initialize(S.Oriented(TopAbs_FORWARD));
//------------------------------------------
// Add the copy of subshapes of S to NewS.
//------------------------------------------
for ( ;iteS.More(); iteS.Next()) {
TopAbs_Orientation OS = iteS.Value().Orientation();
TopTools_ListOfShape L;
L = myMap(iteS.Value());
TopTools_ListIteratorOfListOfShape iteL(L);
for ( ; iteL.More(); iteL.Next()){
const TopoDS_Shape NSS = iteL.Value();
//------------------------------------------
// Rebuild NSS and add its copy to NewS.
//------------------------------------------
Build(NSS);
const TopTools_ListOfShape& NL = myMap(NSS);
TopAbs_Orientation NewOr = TopAbs::Compose(OS,NSS.Orientation());
TopTools_ListIteratorOfListOfShape iteNL(NL);
for ( ; iteNL.More(); iteNL.Next()){
B.Add (NewS,iteNL.Value().Oriented(NewOr));
HasSubShape = Standard_True;
}
}
}
if (!HasSubShape) {
if (NewS.ShapeType() == TopAbs_WIRE || NewS.ShapeType() == TopAbs_SHELL ||
NewS.ShapeType() == TopAbs_SOLID || NewS.ShapeType() == TopAbs_COMPOUND)
//----------------------------------------------------------------
// Wire,Solid,Shell,Compound mut have subshape else they disapear
//---------------------------------------------------------------
NewS.Nullify();
}
}
TopTools_ListOfShape L;
//-------------------------------------------------------
// NewS has the same orientation than S in its ancestors
// so NewS is bound with orientation FORWARD.
//-------------------------------------------------------
if (!NewS.IsNull()) L.Append(NewS.Oriented(TopAbs_FORWARD));
Substitute(S, L);
}
//=======================================================================
//function : IsCopied
//purpose :
//=======================================================================
Standard_Boolean BRepTools_Substitution::IsCopied(const TopoDS_Shape& S) const
{
if (myMap.IsBound(S)) {
if (myMap (S).IsEmpty()) return Standard_True;
else
return !S.IsSame(myMap(S).First());
}
else
return Standard_False;
}
//=======================================================================
//function : Copy
//purpose :
//=======================================================================
const TopTools_ListOfShape& BRepTools_Substitution::Copy (const TopoDS_Shape& S)
const
{
Standard_NoSuchObject_Raise_if(!IsCopied(S),"BRepTools_Substitution::Copy");
return myMap(S);
}

View File

@@ -0,0 +1,155 @@
-- File: BRepTools_TrsfModification.cdl
-- Created: Thu Aug 25 16:38:07 1994
-- Author: Jacques GOUSSARD
-- <jag@ecolox>
---Copyright: Matra Datavision 1994
class TrsfModification from BRepTools inherits Modification from BRepTools
---Purpose: Describes a modification that uses a gp_Trsf to
-- change the geometry of a shape. All functions return
-- true and transform the geometry of the shape.
uses Face from TopoDS,
Edge from TopoDS,
Vertex from TopoDS,
Location from TopLoc,
Shape from GeomAbs,
Surface from Geom,
Curve from Geom,
Curve from Geom2d,
Trsf from gp,
Pnt from gp
is
Create (T : Trsf from gp) returns mutable TrsfModification from BRepTools;
Trsf(me: mutable)
---Purpose: Provides access to the gp_Trsf associated with this
-- modification. The transformation can be changed.
---C++: return &
returns Trsf from gp
is static;
NewSurface(me: mutable; F : Face from TopoDS;
S : out Surface from Geom;
L : out Location from TopLoc;
Tol : out Real from Standard;
RevWires : out Boolean from Standard;
RevFace : out Boolean from Standard)
---Purpose: Returns true if the face F has been modified.
-- If the face has been modified:
-- - S is the new geometry of the face,
-- - L is its new location, and
-- - Tol is the new tolerance.
-- RevWires is set to true when the modification
-- reverses the normal of the surface (the wires have to be reversed).
-- RevFace is set to true if the orientation of the
-- modified face changes in the shells which contain it.
-- For this class, RevFace returns true if the gp_Trsf
-- associated with this modification is negative.
returns Boolean from Standard
;
NewCurve(me: mutable; E : Edge from TopoDS;
C : out Curve from Geom;
L : out Location from TopLoc;
Tol: out Real from Standard)
returns Boolean from Standard
;
---Purpose: Returns true if the edge E has been modified.
-- If the edge has been modified:
-- - C is the new geometric support of the edge,
-- - L is the new location, and
-- - Tol is the new tolerance.
-- If the edge has not been modified, this function
-- returns false, and the values of C, L and Tol are not significant.
NewPoint(me: mutable; V : Vertex from TopoDS;
P : out Pnt from gp;
Tol: out Real from Standard)
returns Boolean from Standard
;
---Purpose: Returns true if the vertex V has been modified.
-- If the vertex has been modified:
-- - P is the new geometry of the vertex, and
-- - Tol is the new tolerance.
-- If the vertex has not been modified this function
-- returns false, and the values of P and Tol are not significant.
NewCurve2d(me: mutable; E : Edge from TopoDS;
F : Face from TopoDS;
NewE : Edge from TopoDS;
NewF : Face from TopoDS;
C : out Curve from Geom2d;
Tol : out Real from Standard)
returns Boolean from Standard
;
---Purpose: Returns true if the edge E has a new curve on surface on the face F.
-- If a new curve exists:
-- - C is the new geometric support of the edge,
-- - L is the new location, and
-- - Tol the new tolerance.
-- If no new curve exists, this function returns false, and
-- the values of C, L and Tol are not significant.
NewParameter(me: mutable; V : Vertex from TopoDS;
E : Edge from TopoDS;
P : out Real from Standard;
Tol: out Real from Standard)
returns Boolean from Standard
;
---Purpose: Returns true if the Vertex V has a new parameter on the edge E.
-- If a new parameter exists:
-- - P is the parameter, and
-- - Tol is the new tolerance.
-- If no new parameter exists, this function returns false,
-- and the values of P and Tol are not significant.
Continuity(me: mutable; E : Edge from TopoDS;
F1,F2 : Face from TopoDS;
NewE : Edge from TopoDS;
NewF1,NewF2: Face from TopoDS)
returns Shape from GeomAbs
---Purpose: Returns the continuity of <NewE> between <NewF1>
-- and <NewF2>.
--
-- <NewE> is the new edge created from <E>. <NewF1>
-- (resp. <NewF2>) is the new face created from <F1>
-- (resp. <F2>).
;
fields
myTrsf : Trsf from gp;
end TrsfModification;

View File

@@ -0,0 +1,235 @@
// File: BRepTools_TrsfModification.cxx
// Created: Thu Aug 25 16:44:16 1994
// Author: Jacques GOUSSARD
// <jag@ecolox>
#include <BRepTools_TrsfModification.ixx>
#include <Geom_Line.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <BRep_Tool.hxx>
#include <gp_GTrsf2d.hxx>
#include <gp_TrsfForm.hxx>
#include <gp.hxx>
#include <GeomLib.hxx>
#include <TopAbs.hxx>
#include <TopExp.hxx>
#include <TopoDS.hxx>
#include <Precision.hxx>
//=======================================================================
//function : BRepTools_TrsfModification
//purpose :
//=======================================================================
BRepTools_TrsfModification::BRepTools_TrsfModification(const gp_Trsf& T) :
myTrsf(T)
{
}
//=======================================================================
//function : Trsf
//purpose :
//=======================================================================
gp_Trsf& BRepTools_TrsfModification::Trsf ()
{
return myTrsf;
}
//=======================================================================
//function : NewSurface
//purpose :
//=======================================================================
Standard_Boolean BRepTools_TrsfModification::NewSurface
(const TopoDS_Face& F,
Handle(Geom_Surface)& S,
TopLoc_Location& L,
Standard_Real& Tol,
Standard_Boolean& RevWires,
Standard_Boolean& RevFace)
{
S = BRep_Tool::Surface(F,L);
Tol = BRep_Tool::Tolerance(F);
Tol *= Abs(myTrsf.ScaleFactor());
RevWires = Standard_False;
RevFace = myTrsf.IsNegative();
gp_Trsf LT = L.Transformation();
LT.Invert();
LT.Multiply(myTrsf);
LT.Multiply(L.Transformation());
S = Handle(Geom_Surface)::DownCast(S->Transformed(LT));
return Standard_True;
}
//=======================================================================
//function : NewCurve
//purpose :
//=======================================================================
Standard_Boolean BRepTools_TrsfModification::NewCurve
(const TopoDS_Edge& E,
Handle(Geom_Curve)& C,
TopLoc_Location& L,
Standard_Real& Tol)
{
Standard_Real f,l;
C = BRep_Tool::Curve(E,L,f,l);
Tol = BRep_Tool::Tolerance(E);
Tol *= Abs(myTrsf.ScaleFactor());
gp_Trsf LT = L.Transformation();
LT.Invert();
LT.Multiply(myTrsf);
LT.Multiply(L.Transformation());
if (!C.IsNull()) {
C = Handle(Geom_Curve)::DownCast(C->Transformed(LT));
}
return Standard_True;
}
//=======================================================================
//function : NewPoint
//purpose :
//=======================================================================
Standard_Boolean BRepTools_TrsfModification::NewPoint
(const TopoDS_Vertex& V,
gp_Pnt& P,
Standard_Real& Tol)
{
P = BRep_Tool::Pnt(V);
Tol = BRep_Tool::Tolerance(V);
Tol *= Abs(myTrsf.ScaleFactor());
P.Transform(myTrsf);
return Standard_True;
}
//=======================================================================
//function : NewCurve2d
//purpose :
//=======================================================================
Standard_Boolean BRepTools_TrsfModification::NewCurve2d
(const TopoDS_Edge& E,
const TopoDS_Face& F,
const TopoDS_Edge&,
const TopoDS_Face&,
Handle(Geom2d_Curve)& C,
Standard_Real& Tol)
{
TopLoc_Location loc;
Tol = BRep_Tool::Tolerance(E);
Standard_Real scale = myTrsf.ScaleFactor();
Tol *= Abs(scale);
const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,loc);
Standard_Real f,l;
Handle(Geom2d_Curve) NewC = BRep_Tool::CurveOnSurface(E,F,f,l);
if (NewC.IsNull())
return Standard_False;
Standard_Real newf,newl;
Handle(Standard_Type) TheType = NewC->DynamicType();
if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve)::DownCast(NewC);
NewC = TC->BasisCurve();
}
Standard_Real fc = NewC->FirstParameter(), lc = NewC->LastParameter();
if(!NewC->IsPeriodic()) {
if(fc - f > Precision::PConfusion()) f = fc;
if(l - lc > Precision::PConfusion()) l = lc;
}
newf = f;
newl = l;
if (Abs(scale) != 1.) {
NewC = new Geom2d_TrimmedCurve(NewC,f,l);
gp_GTrsf2d gtrsf = S->ParametricTransformation(myTrsf);
if ( gtrsf.Form() != gp_Identity) {
NewC = GeomLib::GTransform(NewC,gtrsf);
if (NewC.IsNull()) {
Standard_DomainError::Raise("TrsfModification:Error in NewCurve2d");
return Standard_False;
}
newf = NewC->FirstParameter();
newl = NewC->LastParameter();
}
}
// il faut parfois recadrer les ranges 3d / 2d
TopoDS_Vertex V1, V2;
TopExp::Vertices(E,V1,V2);
TopoDS_Shape initEFOR = E.Oriented(TopAbs_FORWARD); // skl
TopoDS_Edge EFOR = TopoDS::Edge(initEFOR/*E.Oriented(TopAbs_FORWARD)*/); //skl
NewParameter(V1,EFOR,f,Tol);
NewParameter(V2,EFOR,l,Tol);
GeomLib::SameRange(Tol,NewC,newf,newl,f,l,C);
return Standard_True;
}
//=======================================================================
//function : NewParameter
//purpose :
//=======================================================================
Standard_Boolean BRepTools_TrsfModification::NewParameter
(const TopoDS_Vertex& V,
const TopoDS_Edge& E,
Standard_Real& P,
Standard_Real& Tol)
{
if (V.IsNull()) return Standard_False; // infinite edge may have Null vertex
TopLoc_Location loc;
Tol = BRep_Tool::Tolerance(V);
Tol *= Abs(myTrsf.ScaleFactor());
P = BRep_Tool::Parameter(V,E);
Standard_Real f,l;
Handle(Geom_Curve) C = BRep_Tool::Curve(E,loc,f,l);
if (!C.IsNull()) {
P = C->TransformedParameter(P,myTrsf);
}
return Standard_True;
}
//=======================================================================
//function : Continuity
//purpose :
//=======================================================================
GeomAbs_Shape BRepTools_TrsfModification::Continuity
(const TopoDS_Edge& E,
const TopoDS_Face& F1,
const TopoDS_Face& F2,
const TopoDS_Edge&,
const TopoDS_Face&,
const TopoDS_Face&)
{
return BRep_Tool::Continuity(E,F1,F2);
}

View File

@@ -0,0 +1,109 @@
-- File: BRepTools_WireExplorer.cdl
-- Created: Thu Jan 21 17:55:54 1993
-- Author: Remi LEQUETTE
-- <rle@phylox>
---Copyright: Matra Datavision 1993
class WireExplorer from BRepTools
---Purpose: The WireExplorer is a tool to explore the edges of
-- a wire in a connection order.
--
-- i.e. each edge is connected to the previous one by
-- its origin.
-- If a wire is not closed returns only a segment of edges which
-- length depends on started in exploration edge. If wire has
-- singularities (for example, loops) WireExplorer can return not all
-- edges in a wire. it depends on type of singularity.
uses
Orientation from TopAbs,
Wire from TopoDS,
Edge from TopoDS,
Vertex from TopoDS,
Face from TopoDS,
DataMapOfShapeListOfShape from TopTools,
MapOfShape from TopTools
raises
DomainError from Standard,
NoSuchObject from Standard,
NoMoreObject from Standard
is
Create returns WireExplorer from BRepTools;
---Purpose: Constructs an empty explorer (which can be initialized using Init)
Create(W : Wire from TopoDS ) returns WireExplorer from BRepTools
---Purpose: Initializes an exploration of the wire <W> face F is used to
-- involve 2D analysis while exploration).
raises DomainError from Standard;
Create(W : Wire from TopoDS;
F : Face from TopoDS) returns WireExplorer from BRepTools
---Purpose: Initializes an exploration of the wire <W>.
-- F is used to select the edge connected to the
-- previous in the parametric representation of <F>.
raises DomainError from Standard;
Init(me : in out; W : Wire from TopoDS)
---Purpose: Initializes an exploration of the wire <W>.
raises DomainError from Standard
is static;
Init(me : in out; W : Wire from TopoDS;
F : Face from TopoDS)
---Purpose: Initializes an exploration of the wire <W>.
-- F is used to select the edge connected to the
-- previous in the parametric representation of <F>.
--
raises DomainError from Standard
is static;
More(me) returns Boolean
---Purpose: Returns True if there is a current edge.
is static;
Next(me : in out)
---Purpose: Proceeds to the next edge.
raises
NoMoreObject from Standard
is static;
Current(me) returns Edge from TopoDS
---Purpose: Returns the current edge.
raises
NoSuchObject from Standard
---C++: return const &
is static;
Orientation(me) returns Orientation from TopAbs
---Purpose: Returns an Orientation for the current edge.
is static;
CurrentVertex(me) returns Vertex from TopoDS
---Purpose: Returns the vertex connecting the current edge to
-- the previous one.
raises
NoSuchObject from Standard
--
---C++: return const &
is static;
Clear(me : in out)
---Purpose: Clears the content of the explorer.
is static;
fields
myMap : DataMapOfShapeListOfShape from TopTools;
myEdge : Edge from TopoDS;
myVertex : Vertex from TopoDS;
myFace : Face from TopoDS;
myDoubles: MapOfShape from TopTools;
myReverse: Boolean from Standard;
myTolU : Real from Standard;
myTolV : Real from Standard;
end WireExplorer;

View File

@@ -0,0 +1,710 @@
// File: BRepTools_WireExplorer.cxx
// Created: Thu Jan 21 19:09:53 1993
// Author: Remi LEQUETTE
// <rle@phylox>
#include <BRepTools_WireExplorer.ixx>
#include <TopExp.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_MapIteratorOfMapOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
#include <BRep_Tool.hxx>
#include <gp_Pnt2d.hxx>
#include <Precision.hxx>
#include <BRepTools.hxx>
#include <Geom2d_Curve.hxx>
#include <GeomAdaptor_Surface.hxx>
#include <TopExp_Explorer.hxx>
#include <Geom_Surface.hxx>
//=======================================================================
// forward declarations of aux functions
//=======================================================================
static Standard_Boolean SelectDouble(TopTools_MapOfShape& Doubles,
TopTools_ListOfShape& L,
TopoDS_Edge& E);
static Standard_Boolean SelectDegenerated(TopTools_ListOfShape& L,
TopoDS_Edge& E);
static Standard_Real GetNextParamOnPC(const Handle(Geom2d_Curve)& aPC,
const gp_Pnt2d& aPRef,
const Standard_Real& fP,
const Standard_Real& lP,
const Standard_Real& tolU,
const Standard_Real& tolV,
const Standard_Boolean& reverse);
//=======================================================================
//function : BRepTools_WireExplorer
//purpose :
//=======================================================================
BRepTools_WireExplorer::BRepTools_WireExplorer()
{
}
//=======================================================================
//function : BRepTools_WireExplorer
//purpose :
//=======================================================================
BRepTools_WireExplorer::BRepTools_WireExplorer(const TopoDS_Wire& W)
{
TopoDS_Face F = TopoDS_Face();
Init(W,F);
}
//=======================================================================
//function : BRepTools_WireExplorer
//purpose :
//=======================================================================
BRepTools_WireExplorer::BRepTools_WireExplorer(const TopoDS_Wire& W,
const TopoDS_Face& F)
{
Init(W,F);
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void BRepTools_WireExplorer::Init(const TopoDS_Wire& W)
{
TopoDS_Face F = TopoDS_Face();
Init(W,F);
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void BRepTools_WireExplorer::Init(const TopoDS_Wire& W,
const TopoDS_Face& F)
{
myEdge = TopoDS_Edge();
myVertex = TopoDS_Vertex();
myMap.Clear();
myDoubles.Clear();
if( W.IsNull() )
return;
myFace = F;
Standard_Real dfVertToler = 0.;
myReverse = Standard_False;
if (!myFace.IsNull())
{
BRepTools::Update(myFace);
TopLoc_Location aL;
const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(myFace, aL);
GeomAdaptor_Surface aGAS(aSurf);
TopExp_Explorer anExp(W, TopAbs_VERTEX);
for(; anExp.More(); anExp.Next())
{
const TopoDS_Vertex& aV = TopoDS::Vertex(anExp.Current());
dfVertToler = Max(BRep_Tool::Tolerance(aV), dfVertToler);
}
myTolU = 2. * aGAS.UResolution(dfVertToler);
myTolV = 2. * aGAS.VResolution(dfVertToler);
// uresolution for cone with infinite vmin vmax is too small.
if(aGAS.GetType() == GeomAbs_Cone)
{
Standard_Real u1, u2, v1, v2;
BRepTools::UVBounds(myFace, u1, u2, v1, v2);
gp_Pnt aP;
gp_Vec aD1U, aD1V;
aGAS.D1(u1, v1, aP, aD1U, aD1V);
Standard_Real tol1, tol2, maxtol = .0005*(u2-u1);
Standard_Real a = aD1U.Magnitude();
if(a <= Precision::Confusion())
tol1 = maxtol;
else
tol1 = Min(maxtol, dfVertToler/a);
aGAS.D1(u1, v2, aP, aD1U, aD1V);
a = aD1U.Magnitude();
if(a <= Precision::Confusion())
tol2 = maxtol;
else
tol2 = Min(maxtol, dfVertToler/a);
myTolU = 2. * Max(tol1, tol2);
}
if( aGAS.GetType() == GeomAbs_BSplineSurface ||
aGAS.GetType() == GeomAbs_BezierSurface )
{
Standard_Real maxTol = Max(myTolU,myTolV);
myTolU = maxTol;
myTolV = maxTol;
}
myReverse = (myFace.Orientation() == TopAbs_REVERSED);
}
// map of vertices to know if the wire is open
TopTools_MapOfShape vmap;
// Modified by Sergey KHROMOV - Mon May 13 11:50:48 2002 Begin
// map of infinite edges
TopTools_MapOfShape anInfEmap;
// Modified by Sergey KHROMOV - Mon May 13 11:50:49 2002 End
// list the vertices
TopoDS_Vertex V1,V2;
TopTools_ListOfShape empty;
TopoDS_Iterator it(W);
while (it.More())
{
const TopoDS_Edge& E = TopoDS::Edge(it.Value());
TopAbs_Orientation Eori = E.Orientation();
if (Eori == TopAbs_INTERNAL || Eori == TopAbs_EXTERNAL)
{
it.Next();
continue;
}
TopExp::Vertices(E,V1,V2,Standard_True);
if( !V1.IsNull() )
{
if( !myMap.IsBound(V1) )
myMap.Bind(V1,empty);
myMap(V1).Append(E);
// add or remove in the vertex map
V1.Orientation(TopAbs_FORWARD);
if( !vmap.Add(V1) )
vmap.Remove(V1);
}
if( !V2.IsNull() )
{
V2.Orientation(TopAbs_REVERSED);
if(!vmap.Add(V2))
vmap.Remove(V2);
}
// Modified by Sergey KHROMOV - Mon May 13 11:52:20 2002 Begin
if (V1.IsNull() || V2.IsNull())
{
Standard_Real aF = 0., aL = 0.;
BRep_Tool::Range(E, aF, aL);
if(Eori == TopAbs_FORWARD)
{
if (aF == -Precision::Infinite())
anInfEmap.Add(E);
}
else
{ // Eori == TopAbs_REVERSED
if (aL == Precision::Infinite())
anInfEmap.Add(E);
}
}
// Modified by Sergey KHROMOV - Mon May 13 11:52:20 2002 End
it.Next();
}
//Construction de l ensemble des aretes doubles.
TopoDS_Iterator it2(W);
TopTools_MapOfShape emap;
while (it2.More()) {
if (!emap.Add(it2.Value()))
myDoubles.Add(it2.Value());
it2.Next();
}
// if vmap is not empty the wire is open, let us find the first vertex
if (!vmap.IsEmpty()) {
TopTools_MapIteratorOfMapOfShape itt(vmap); // skl : I change "it" to "itt"
while (itt.Key().Orientation() != TopAbs_FORWARD) {
itt.Next();
if (!itt.More()) break;
}
if (itt.More()) V1 = TopoDS::Vertex(itt.Key());
}
else {
// Modified by Sergey KHROMOV - Mon May 13 12:05:30 2002 Begin
// The wire is infinite Try to find the first vertex. It may be NULL.
if (!anInfEmap.IsEmpty()) {
TopTools_MapIteratorOfMapOfShape itt(anInfEmap);
for (; itt.More(); itt.Next()) {
TopoDS_Edge anEdge = TopoDS::Edge(itt.Key());
TopAbs_Orientation anOri = anEdge.Orientation();
Standard_Real aF;
Standard_Real aL;
BRep_Tool::Range(anEdge, aF, aL);
if ((anOri == TopAbs_FORWARD && aF == -Precision::Infinite()) ||
(anOri == TopAbs_REVERSED && aL == Precision::Infinite())) {
myEdge = anEdge;
myVertex = TopoDS_Vertex();
return;
}
}
}
// Modified by Sergey KHROMOV - Mon May 13 12:05:31 2002 End
// use the first vertex in iterator
it.Initialize(W);
while (it.More()) {
const TopoDS_Edge& E = TopoDS::Edge(it.Value());
TopAbs_Orientation Eori = E.Orientation();
if (Eori == TopAbs_INTERNAL || Eori == TopAbs_EXTERNAL) {
// JYL 10-03-97 : en attendant un traitement correct
// des aretes INTERNAL/EXTERNAL
it.Next();
continue;
}
TopExp::Vertices(E,V1,V2,Standard_True);
break;
}
}
if (V1.IsNull() ) return;
if (!myMap.IsBound(V1)) return;
TopTools_ListOfShape& l = myMap(V1);
myEdge = TopoDS::Edge(l.First());
l.RemoveFirst();
myVertex = TopExp::FirstVertex (myEdge, Standard_True);
}
//=======================================================================
//function : More
//purpose :
//=======================================================================
Standard_Boolean BRepTools_WireExplorer::More()const
{
return !myEdge.IsNull();
}
//=======================================================================
//function : Next
//purpose :
//=======================================================================
void BRepTools_WireExplorer::Next()
{
myVertex = TopExp::LastVertex (myEdge, Standard_True);
if (myVertex.IsNull()) {
myEdge = TopoDS_Edge();
return;
}
if (!myMap.IsBound(myVertex)) {
myEdge = TopoDS_Edge();
return;
}
TopTools_ListOfShape& l = myMap(myVertex);
if (l.IsEmpty()) {
myEdge = TopoDS_Edge();
}
else if (l.Extent() == 1) {
// Modified by Sergey KHROMOV - Fri Jun 21 10:28:01 2002 OCC325 Begin
TopoDS_Vertex aV1;
TopoDS_Vertex aV2;
TopoDS_Edge aNextEdge = TopoDS::Edge(l.First());
TopExp::Vertices(aNextEdge, aV1, aV2, Standard_True);
if (!aV1.IsSame(myVertex)) {
myEdge = TopoDS_Edge();
return;
}
if (!myFace.IsNull() && aV1.IsSame(aV2)) {
Handle(Geom2d_Curve) aPrevPC;
Handle(Geom2d_Curve) aNextPC;
Standard_Real aPar11, aPar12;
Standard_Real aPar21, aPar22;
Standard_Real aPrevPar;
Standard_Real aNextFPar;
Standard_Real aNextLPar;
aPrevPC = BRep_Tool::CurveOnSurface(myEdge, myFace, aPar11, aPar12);
aNextPC = BRep_Tool::CurveOnSurface(aNextEdge, myFace, aPar21, aPar22);
if (aPrevPC.IsNull() || aNextPC.IsNull()) {
myEdge = TopoDS_Edge();
return;
}
if (myEdge.Orientation() == TopAbs_FORWARD)
aPrevPar = aPar12;
else
aPrevPar = aPar11;
if (aNextEdge.Orientation() == TopAbs_FORWARD) {
aNextFPar = aPar21;
aNextLPar = aPar22;
} else {
aNextFPar = aPar22;
aNextLPar = aPar21;
}
gp_Pnt2d aPPrev = aPrevPC->Value(aPrevPar);
gp_Pnt2d aPNextF = aNextPC->Value(aNextFPar);
gp_Pnt2d aPNextL = aNextPC->Value(aNextLPar);
if (aPPrev.SquareDistance(aPNextF) > aPPrev.SquareDistance(aPNextL)) {
myEdge = TopoDS_Edge();
return;
}
}
// Modified by Sergey KHROMOV - Fri Jun 21 11:08:16 2002 End
myEdge = TopoDS::Edge(l.First());
l.Clear();
}
else {
if (myFace.IsNull()) {
// Sans la Face On essait qd meme de renvoyer les aretes
// le plus logiquement possible
// En premier choix les aretes degenerees.
TopoDS_Edge E = myEdge;
if (SelectDegenerated(l,E)) {
myEdge = E;
return;
}
// En deuxieme choix les aretes doubles.
E = myEdge;
if (SelectDouble(myDoubles,l,E)) {
myEdge = E;
return;
}
TopTools_ListIteratorOfListOfShape it(l);
Standard_Boolean notfound = Standard_True;
while (it.More()) {
if (!it.Value().IsSame(myEdge)) {
myEdge = TopoDS::Edge(it.Value());
l.Remove(it);
notfound = Standard_False;
break;
}
it.Next();
}
if(notfound) {
myEdge = TopoDS_Edge();
return;
}
}
else
{
// If we have more than one edge attached to the list
// probably wire that we explore contains a loop or loops.
Standard_Real dfFPar = 0., dfLPar = 0.;
Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface (myEdge, myFace, dfFPar, dfLPar);
if(aPCurve.IsNull())
{
myEdge = TopoDS_Edge();
return;
}
// Note: current < myVertex > which is last on < myEdge >
// equals in 2D to following 2D points:
// edge is FORWARD - point with MAX parameter on PCurve;
// edge is REVERSED - point with MIN parameter on PCurve.
// Get 2D point equals to < myVertex > in 2D for current edge.
gp_Pnt2d PRef;
if( myEdge.Orientation() == TopAbs_REVERSED )
aPCurve->D0(dfFPar, PRef);
else
aPCurve->D0(dfLPar, PRef);
// Get next 2D point from current edge's PCurve with parameter
// F + dP (REV) or L - dP (FOR)
Standard_Boolean isrevese = ( myEdge.Orientation() == TopAbs_REVERSED );
Standard_Real dfMPar = GetNextParamOnPC(aPCurve,PRef,dfFPar,dfLPar,myTolU,myTolV,isrevese);
gp_Pnt2d PRefm;
aPCurve->D0(dfMPar, PRefm);
// Get vector from PRef to PRefm
gp_Vec2d anERefDir(PRef,PRefm);
// Search the list of edges looking for the edge having hearest
// 2D point of connected vertex to current one and smallest angle.
// First process all degenerated edges, then - all others.
TopTools_ListIteratorOfListOfShape it;
Standard_Integer k = 1, kMin = 0, iDone = 0;
Standard_Boolean isDegenerated = Standard_True;
Standard_Real dmin = RealLast();
Standard_Real dfMinAngle = 3.0*PI, dfCurAngle = 3.0*PI;
for(iDone = 0; iDone < 2; iDone++)
{
it.Initialize(l);
while( it.More() )
{
const TopoDS_Edge& E = TopoDS::Edge(it.Value());
if( E.IsSame(myEdge) )
{
it.Next();
k++;
continue;
}
TopoDS_Vertex aVert1, aVert2;
TopExp::Vertices (E, aVert1, aVert2, Standard_True);
if( aVert1.IsNull() || aVert2.IsNull() )
{
it.Next();
k++;
continue;
}
aPCurve = BRep_Tool::CurveOnSurface (E, myFace, dfFPar, dfLPar);
if( aPCurve.IsNull() )
{
it.Next();
k++;
continue;
}
gp_Pnt2d aPEb, aPEe;
if( aVert1.IsSame(aVert2) == isDegenerated )
{
if( E.Orientation() == TopAbs_REVERSED )
aPCurve->D0(dfLPar, aPEb);
else
aPCurve->D0(dfFPar, aPEb);
if( Abs(dfLPar-dfFPar) > Precision::PConfusion() )
{
isrevese = ( E.Orientation() == TopAbs_REVERSED );
isrevese = !isrevese;
Standard_Real aEPm = GetNextParamOnPC(aPCurve,aPEb,dfFPar,dfLPar,myTolU,myTolV,isrevese);
aPCurve->D0 (aEPm, aPEe);
gp_Vec2d anEDir(aPEb, aPEe);
dfCurAngle = Abs( anEDir.Angle(anERefDir) );
}
if( dfCurAngle <= dfMinAngle )
{
Standard_Real d = PRef.SquareDistance(aPEb);
if( d <= Precision::PConfusion() )
d = 0.;
if( Abs(aPEb.X()-PRef.X()) < myTolU && Abs(aPEb.Y()-PRef.Y()) < myTolV )
{
if( d <= dmin )
{
dfMinAngle = dfCurAngle;
kMin = k;
dmin = d;
}
}
}
}
it.Next();
k++;
}// while it
if( kMin == 0 )
{
isDegenerated = Standard_False;
k = 1;
dmin = RealLast();
}
else
break;
}// for iDone
if(kMin == 0)
{
// probably unclosed in 2d space wire
myEdge = TopoDS_Edge();
return;
}
// Selection the edge.
it.Initialize(l);
k = 1;
while( it.More() )
{
if( k == kMin )
{
myEdge = TopoDS::Edge(it.Value());
l.Remove(it);
break;
}
it.Next();
k++;
}
}//else face != NULL && l > 1
}//else l > 1
}
//=======================================================================
//function : Current
//purpose :
//=======================================================================
const TopoDS_Edge& BRepTools_WireExplorer::Current()const
{
return myEdge;
}
//=======================================================================
//function : Orientation
//purpose :
//=======================================================================
TopAbs_Orientation BRepTools_WireExplorer::Orientation() const
{
TopoDS_Iterator it(myEdge,Standard_False);
while (it.More()) {
if (myVertex.IsSame(it.Value()))
return it.Value().Orientation();
it.Next();
}
Standard_NoSuchObject::Raise("BRepTools_WireExplorer::Orientation");
return TopAbs_FORWARD;
}
//=======================================================================
//function : CurrentVertex
//purpose :
//=======================================================================
const TopoDS_Vertex& BRepTools_WireExplorer::CurrentVertex() const
{
return myVertex;
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void BRepTools_WireExplorer::Clear()
{
myMap.Clear();
myDoubles.Clear();
myEdge = TopoDS_Edge();
myFace = TopoDS_Face();
myVertex = TopoDS_Vertex();
}
//=======================================================================
//function : SelectDouble
//purpose :
//=======================================================================
Standard_Boolean SelectDouble(TopTools_MapOfShape& Doubles,
TopTools_ListOfShape& L,
TopoDS_Edge& E)
{
TopTools_ListIteratorOfListOfShape it(L);
for (; it.More(); it.Next()) {
const TopoDS_Shape& CE = it.Value();
if (Doubles.Contains(CE) && (!E.IsSame(CE))) {
E = TopoDS::Edge(CE);
L.Remove(it);
return 1;
}
}
return 0;
}
//=======================================================================
//function : SelectDegenerated
//purpose :
//=======================================================================
Standard_Boolean SelectDegenerated(TopTools_ListOfShape& L,
TopoDS_Edge& E)
{
TopTools_ListIteratorOfListOfShape it(L);
while (it.More()) {
if (!it.Value().IsSame(E)) {
E = TopoDS::Edge(it.Value());
if (BRep_Tool::Degenerated(E)) {
L.Remove(it);
return 1;
}
}
it.Next();
}
return 0;
}
//=======================================================================
//function : GetNextParamOnPC
//purpose :
//=======================================================================
Standard_Real GetNextParamOnPC(const Handle(Geom2d_Curve)& aPC,
const gp_Pnt2d& aPRef,
const Standard_Real& fP,
const Standard_Real& lP,
const Standard_Real& tolU,
const Standard_Real& tolV,
const Standard_Boolean& reverse)
{
Standard_Real result = ( reverse ) ? fP : lP;
Standard_Real dP = Abs( lP - fP ) / 1000.; // was / 16.;
if( reverse )
{
Standard_Real startPar = fP;
Standard_Boolean nextPntOnEdge = Standard_False;
while( !nextPntOnEdge && startPar < lP )
{
gp_Pnt2d pnt;
startPar += dP;
aPC->D0(startPar, pnt);
if( Abs( aPRef.X() - pnt.X() ) < tolU && Abs( aPRef.Y() - pnt.Y() ) < tolV )
continue;
else
{
result = startPar;
nextPntOnEdge = Standard_True;
break;
}
}
if( !nextPntOnEdge )
result = lP;
if( result > lP )
result = lP;
}
else
{
Standard_Real startPar = lP;
Standard_Boolean nextPntOnEdge = Standard_False;
while( !nextPntOnEdge && startPar > fP )
{
gp_Pnt2d pnt;
startPar -= dP;
aPC->D0(startPar, pnt);
if( Abs( aPRef.X() - pnt.X() ) < tolU && Abs( aPRef.Y() - pnt.Y() ) < tolV )
continue;
else
{
result = startPar;
nextPntOnEdge = Standard_True;
break;
}
}
if( !nextPntOnEdge )
result = fP;
if( result < fP )
result = fP;
}
return result;
}