mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
41
src/ShapeBuild/ShapeBuild.cdl
Executable file
41
src/ShapeBuild/ShapeBuild.cdl
Executable file
@@ -0,0 +1,41 @@
|
||||
-- File: ShapeBuild.cdl
|
||||
-- Created: Wed Jun 3 12:41:54 1998
|
||||
-- Author: data exchange team
|
||||
-- <det@loufox.nnov.matra-dtv.fr>
|
||||
---Copyright: Matra Datavision 1998
|
||||
|
||||
|
||||
package ShapeBuild
|
||||
|
||||
---Purpose: This package provides basic building tools for other packages in ShapeHealing.
|
||||
-- These tools are rather internal for ShapeHealing .
|
||||
|
||||
uses
|
||||
gp,
|
||||
Geom,
|
||||
Geom2d,
|
||||
TopAbs,
|
||||
TopLoc,
|
||||
TopoDS,
|
||||
TopTools,
|
||||
BRep,
|
||||
ShapeExtend,
|
||||
BRepTools
|
||||
|
||||
is
|
||||
|
||||
class Vertex;
|
||||
---Purpose: Provides low-level functions used for constructing vertices
|
||||
|
||||
class Edge;
|
||||
---Purpose: Provides low-level functions used for rebuilding edge
|
||||
|
||||
class ReShape;
|
||||
---Purpose: Rebuilds a shape with substitution of some components
|
||||
|
||||
PlaneXOY returns Plane from Geom;
|
||||
---Purpose: Returns a Geom_Surface which is the Plane XOY (Z positive)
|
||||
-- This allows to consider an UV space homologous to a 3D space,
|
||||
-- with this support surface
|
||||
|
||||
end ShapeBuild;
|
20
src/ShapeBuild/ShapeBuild.cxx
Executable file
20
src/ShapeBuild/ShapeBuild.cxx
Executable file
@@ -0,0 +1,20 @@
|
||||
// File: ShapeBuild.cxx
|
||||
// Created: Wed Jun 10 16:03:56 1998
|
||||
// Author: data exchange team
|
||||
// <det@nicebox.nnov.matra-dtv.fr>
|
||||
|
||||
|
||||
#include <ShapeBuild.ixx>
|
||||
|
||||
//=======================================================================
|
||||
//function : PlaneXOY
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(Geom_Plane) ShapeBuild::PlaneXOY()
|
||||
{
|
||||
static Handle(Geom_Plane) xoy;
|
||||
if (xoy.IsNull()) xoy = new Geom_Plane (0,0,1,0);
|
||||
return xoy;
|
||||
}
|
||||
|
136
src/ShapeBuild/ShapeBuild_Edge.cdl
Executable file
136
src/ShapeBuild/ShapeBuild_Edge.cdl
Executable file
@@ -0,0 +1,136 @@
|
||||
-- File: ShapeBuild_Edge.cdl
|
||||
-- Created: Tue Jun 9 11:11:14 1998
|
||||
-- Author: data exchange team
|
||||
-- <det@toctox.nnov.matra-dtv.fr>
|
||||
---Copyright: Matra Datavision 1998
|
||||
|
||||
|
||||
class Edge from ShapeBuild
|
||||
|
||||
---Purpose: This class provides low-level operators for building an edge
|
||||
-- 3d curve, copying edge with replaced vertices etc.
|
||||
|
||||
uses
|
||||
Trsf2d from gp,
|
||||
Curve from Geom,
|
||||
Surface from Geom,
|
||||
Curve from Geom2d,
|
||||
Location from TopLoc,
|
||||
Vertex from TopoDS,
|
||||
Face from TopoDS,
|
||||
Edge from TopoDS
|
||||
|
||||
is
|
||||
|
||||
CopyReplaceVertices (me; edge: Edge from TopoDS; V1, V2: Vertex from TopoDS)
|
||||
returns Edge from TopoDS;
|
||||
---Purpose: Copy edge and replace one or both its vertices to a given
|
||||
-- one(s). Vertex V1 replaces FORWARD vertex, and V2 - REVERSED,
|
||||
-- as they are found by TopoDS_Iterator.
|
||||
-- If V1 or V2 is NULL, the original vertex is taken
|
||||
|
||||
CopyRanges (me; toedge, fromedge: Edge from TopoDS;
|
||||
alpha: Real = 0;
|
||||
beta: Real = 1);
|
||||
---Purpose: Copies ranges for curve3d and all common pcurves from
|
||||
-- edge <fromedge> into edge <toedge>.
|
||||
|
||||
SetRange3d (me; edge: Edge from TopoDS; first, last : Real);
|
||||
---Purpose: Sets range on 3d curve only.
|
||||
|
||||
CopyPCurves (me; toedge, fromedge: Edge from TopoDS);
|
||||
---Purpose: Makes a copy of pcurves from edge <fromedge> into edge
|
||||
-- <toedge>. Pcurves which are already present in <toedge>,
|
||||
-- are replaced by copies, other are copied. Ranges are also
|
||||
-- copied.
|
||||
|
||||
Copy (me; edge: Edge from TopoDS; sharepcurves: Boolean = Standard_True)
|
||||
returns Edge from TopoDS;
|
||||
---Purpose: Make a copy of <edge> by call to CopyReplaceVertices()
|
||||
-- (i.e. construct new TEdge with the same pcurves and vertices).
|
||||
-- If <sharepcurves> is False, pcurves are also replaced by
|
||||
-- their copies with help of method CopyPCurves
|
||||
|
||||
RemovePCurve (me; edge: Edge from TopoDS; face: Face from TopoDS);
|
||||
---Purpose : Removes the PCurve(s) which could be recorded in an Edge for
|
||||
-- the given Face
|
||||
|
||||
RemovePCurve (me; edge: Edge from TopoDS; surf: Surface from Geom);
|
||||
---Purpose : Removes the PCurve(s) which could be recorded in an Edge for
|
||||
-- the given Surface
|
||||
|
||||
RemovePCurve (me; edge: Edge from TopoDS; surf: Surface from Geom;
|
||||
loc: Location from TopLoc);
|
||||
---Purpose : Removes the PCurve(s) which could be recorded in an Edge for
|
||||
-- the given Surface, with given Location
|
||||
|
||||
ReplacePCurve (me; edge: Edge from TopoDS; pcurve: Curve from Geom2d;
|
||||
face: Face from TopoDS);
|
||||
---Purpose : Replace the PCurve in an Edge for the given Face
|
||||
-- In case if edge is seam, i.e. has 2 pcurves on that face,
|
||||
-- only pcurve corresponding to the orientation of the edge is
|
||||
-- replaced
|
||||
|
||||
ReassignPCurve (me; edge: Edge from TopoDS;
|
||||
old, sub: Face from TopoDS)
|
||||
returns Boolean;
|
||||
---Purpose: Reassign edge pcurve lying on face <old> to another face <sub>.
|
||||
-- If edge has two pcurves on <old> face, only one of them will be
|
||||
-- reassigned, and other will left alone. Similarly, if edge already
|
||||
-- had a pcurve on face <sub>, it will have two pcurves on it.
|
||||
-- Returns True if succeeded, False if no pcurve lying on <old> found.
|
||||
|
||||
TransformPCurve(me; pcurve: Curve from Geom2d;
|
||||
trans : Trsf2d from gp;
|
||||
uFact : Real;
|
||||
aFirst: in out Real;
|
||||
aLast : in out Real)
|
||||
returns Curve from Geom2d;
|
||||
---Purpose: Transforms the PCurve with given matrix and affinity U factor.
|
||||
|
||||
RemoveCurve3d (me; edge: Edge from TopoDS);
|
||||
---Purpose : Removes the Curve3D recorded in an Edge
|
||||
|
||||
BuildCurve3d (me; edge: Edge from TopoDS) returns Boolean;
|
||||
---Purpose: Calls BRepTools::BuildCurve3D
|
||||
---Returns: True if curve computed OK, False if any error occured
|
||||
|
||||
|
||||
---Extension of BRepAPI_MakeEdge
|
||||
|
||||
MakeEdge (me; edge : out Edge from TopoDS;
|
||||
curve: Curve from Geom;
|
||||
L : Location from TopLoc);
|
||||
---Purpose: Makes edge with curve and location
|
||||
|
||||
MakeEdge (me; edge : out Edge from TopoDS;
|
||||
curve : Curve from Geom;
|
||||
L : Location from TopLoc;
|
||||
p1, p2: Real);
|
||||
---Purpose: Makes edge with curve, location and range [p1, p2]
|
||||
|
||||
MakeEdge (me; edge : out Edge from TopoDS;
|
||||
pcurve: Curve from Geom2d;
|
||||
face : Face from TopoDS) ;
|
||||
---Purpose: Makes edge with pcurve and face
|
||||
|
||||
MakeEdge (me; edge : out Edge from TopoDS;
|
||||
pcurve: Curve from Geom2d;
|
||||
face :Face from TopoDS;
|
||||
p1, p2: Real) ;
|
||||
---Purpose: Makes edge with pcurve, face and range [p1, p2]
|
||||
|
||||
MakeEdge (me; edge : out Edge from TopoDS;
|
||||
pcurve: Curve from Geom2d;
|
||||
S : Surface from Geom;
|
||||
L : Location from TopLoc) ;
|
||||
---Purpose: Makes edge with pcurve, surface and location
|
||||
|
||||
MakeEdge (me; edge : out Edge from TopoDS;
|
||||
pcurve: Curve from Geom2d;
|
||||
S : Surface from Geom;
|
||||
L : Location from TopLoc;
|
||||
p1, p2: Real) ;
|
||||
---Purpose: Makes edge with pcurve, surface, location and range [p1, p2]
|
||||
|
||||
end Edge;
|
727
src/ShapeBuild/ShapeBuild_Edge.cxx
Executable file
727
src/ShapeBuild/ShapeBuild_Edge.cxx
Executable file
@@ -0,0 +1,727 @@
|
||||
//#4 szv S4163: optimizing
|
||||
// pdn 20.04.99 S4181 Moving algorithm for transforming pcurves from IGES processor
|
||||
// abv 05.05.99 S4137: adding methods for copying ranges, reassigning pcurves etc.
|
||||
#include <ShapeBuild_Edge.ixx>
|
||||
#include <Standard_ErrorHandler.hxx>
|
||||
#include <Standard_Failure.hxx>
|
||||
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Iterator.hxx>
|
||||
#include <TopExp.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <BRep_TEdge.hxx>
|
||||
#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
|
||||
#include <BRep_GCurve.hxx>
|
||||
#include <BRepLib.hxx>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp_Lin2d.hxx>
|
||||
#include <gp_GTrsf2d.hxx>
|
||||
#include <gp_Pln.hxx>
|
||||
#include <ElCLib.hxx>
|
||||
#include <Precision.hxx>
|
||||
|
||||
#include <Geom2d_TrimmedCurve.hxx>
|
||||
#include <Geom2d_Line.hxx>
|
||||
#include <Geom2d_BSplineCurve.hxx>
|
||||
#include <Geom2d_Conic.hxx>
|
||||
#include <Geom2dConvert.hxx>
|
||||
#include <Geom2dConvert_ApproxCurve.hxx>
|
||||
#include <GeomAPI.hxx>
|
||||
#include <Geom2d_BezierCurve.hxx>
|
||||
#include <Geom2d_TrimmedCurve.hxx>
|
||||
#include <BRep_Curve3D.hxx>
|
||||
#include <BRep_CurveOnSurface.hxx>
|
||||
#include <Geom2d_OffsetCurve.hxx>
|
||||
#include <Geom_TrimmedCurve.hxx>
|
||||
#include <Geom_OffsetCurve.hxx>
|
||||
#include <TopTools_SequenceOfShape.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : CopyReplaceVertices
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TopoDS_Edge ShapeBuild_Edge::CopyReplaceVertices (const TopoDS_Edge& edge,
|
||||
const TopoDS_Vertex& V1,
|
||||
const TopoDS_Vertex& V2) const
|
||||
{
|
||||
TopTools_SequenceOfShape aNMVertices;
|
||||
TopoDS_Vertex newV1 = V1, newV2 = V2;
|
||||
if ( newV1.IsNull() || newV2.IsNull() ) {
|
||||
for ( TopoDS_Iterator it(edge); it.More(); it.Next() ) {
|
||||
TopoDS_Vertex V = TopoDS::Vertex ( it.Value() );
|
||||
if ( V.Orientation() == TopAbs_FORWARD ) {
|
||||
if ( newV1.IsNull() ) newV1 = V;
|
||||
}
|
||||
else if ( V.Orientation() == TopAbs_REVERSED ) {
|
||||
if ( newV2.IsNull() ) newV2 = V;
|
||||
}
|
||||
else if(V1.IsNull() && V2.IsNull())
|
||||
aNMVertices.Append(V);
|
||||
}
|
||||
}
|
||||
newV1.Orientation ( TopAbs_FORWARD );
|
||||
newV2.Orientation ( TopAbs_REVERSED );
|
||||
|
||||
//szv#4:S4163:12Mar99 SGI warns
|
||||
TopoDS_Shape sh = edge.EmptyCopied();
|
||||
TopoDS_Edge E = TopoDS::Edge( sh );
|
||||
|
||||
BRep_Builder B;
|
||||
if ( ! newV1.IsNull() ) B.Add ( E, newV1 );
|
||||
if ( ! newV2.IsNull() ) B.Add ( E, newV2 );
|
||||
|
||||
//addition of the internal or external vertices to edge
|
||||
Standard_Integer i =1;
|
||||
for( ; i <= aNMVertices.Length(); i++)
|
||||
B.Add ( E,TopoDS::Vertex(aNMVertices.Value(i)));
|
||||
|
||||
//S4054, rln 17.11.98 annie_surf.igs entity D77, 3D and pcurve have different
|
||||
//ranges, after B.Range all the ranges become as 3D
|
||||
CopyRanges ( E, edge );
|
||||
/*
|
||||
for (BRep_ListIteratorOfListOfCurveRepresentation itcr
|
||||
((*((Handle(BRep_TEdge)*)&edge.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 ( E, first, last );
|
||||
else if ( GC->IsCurveOnSurface() )
|
||||
B.Range (E, GC->Surface(), edge.Location().Multiplied (GC->Location()), first, last);//BUC50003 entity 132 edge 1
|
||||
}
|
||||
*/
|
||||
return E;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CopyRanges
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
// Added, cause invoke ShapeAnalysis leads to cyclic dependancy.
|
||||
static Standard_Real AdjustByPeriod(const Standard_Real Val,
|
||||
const Standard_Real ToVal,
|
||||
const Standard_Real Period)
|
||||
{
|
||||
Standard_Real diff = Val - ToVal;
|
||||
Standard_Real D = Abs ( diff );
|
||||
Standard_Real P = Abs ( Period );
|
||||
if ( D <= 0.5 * P ) return 0.;
|
||||
if ( P < 1e-100 ) return diff;
|
||||
return ( diff >0 ? -P : P ) * (Standard_Integer)( D / P + 0.5 );
|
||||
}
|
||||
|
||||
static Standard_Boolean IsPeriodic(const Handle(Geom_Curve)& theCurve)
|
||||
{
|
||||
// 15.11.2002 PTV OCC966
|
||||
// remove regressions in DE tests (diva, divb, divc, toe3) in KAS:dev
|
||||
// ask IsPeriodic on BasisCurve
|
||||
Handle(Geom_Curve) aTmpCurve = theCurve;
|
||||
while ( (aTmpCurve->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) ||
|
||||
(aTmpCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) ) {
|
||||
if (aTmpCurve->IsKind(STANDARD_TYPE(Geom_OffsetCurve)))
|
||||
aTmpCurve = Handle(Geom_OffsetCurve)::DownCast(aTmpCurve)->BasisCurve();
|
||||
if (aTmpCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve)))
|
||||
aTmpCurve = Handle(Geom_TrimmedCurve)::DownCast(aTmpCurve)->BasisCurve();
|
||||
}
|
||||
return aTmpCurve->IsPeriodic();
|
||||
}
|
||||
|
||||
Standard_Boolean IsPeriodic(const Handle(Geom2d_Curve)& theCurve)
|
||||
{
|
||||
// 15.11.2002 PTV OCC966
|
||||
// remove regressions in DE tests (diva, divb, divc, toe3) in KAS:dev
|
||||
// ask IsPeriodic on BasisCurve
|
||||
Handle(Geom2d_Curve) aTmpCurve = theCurve;
|
||||
while ( (aTmpCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) ||
|
||||
(aTmpCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) ) {
|
||||
if (aTmpCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve)))
|
||||
aTmpCurve = Handle(Geom2d_OffsetCurve)::DownCast(aTmpCurve)->BasisCurve();
|
||||
if (aTmpCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve)))
|
||||
aTmpCurve = Handle(Geom2d_TrimmedCurve)::DownCast(aTmpCurve)->BasisCurve();
|
||||
}
|
||||
return aTmpCurve->IsPeriodic();
|
||||
}
|
||||
|
||||
void ShapeBuild_Edge::CopyRanges (const TopoDS_Edge& toedge,
|
||||
const TopoDS_Edge& fromedge,
|
||||
const Standard_Real alpha,
|
||||
const Standard_Real beta) const
|
||||
{
|
||||
/* 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;
|
||||
Standard_Real newF = first+alpha*len;
|
||||
Standard_Real newL = first+beta*len;
|
||||
|
||||
// PTV: 22.03.2002 fix for edge range.
|
||||
// file test-m020306-v2.step Shell #665 (Faces #40110. #40239).
|
||||
Standard_Real aPeriod=1., aCrvF=0., aCrvL=1.;
|
||||
Standard_Boolean doCheck = Standard_False;
|
||||
if (toGC->IsKind(STANDARD_TYPE(BRep_Curve3D))) {
|
||||
Handle(Geom_Curve) aCrv3d = Handle(BRep_Curve3D)::DownCast(toGC)->Curve3D();
|
||||
// 15.11.2002 PTV OCC966
|
||||
if ( ! aCrv3d.IsNull() && IsPeriodic(aCrv3d) ) {
|
||||
aPeriod = aCrv3d->Period();
|
||||
aCrvF = aCrv3d->FirstParameter();
|
||||
aCrvL = aCrv3d->LastParameter();
|
||||
doCheck = Standard_True;
|
||||
}
|
||||
}
|
||||
else if (toGC->IsKind(STANDARD_TYPE(BRep_CurveOnSurface))) {
|
||||
Handle(Geom2d_Curve) aCrv2d = Handle(BRep_CurveOnSurface)::DownCast(toGC)->PCurve();
|
||||
// 15.11.2002 PTV OCC966
|
||||
if (!aCrv2d.IsNull() && IsPeriodic(aCrv2d)) {
|
||||
aPeriod = aCrv2d->Period();
|
||||
aCrvF = aCrv2d->FirstParameter();
|
||||
aCrvL = aCrv2d->LastParameter();
|
||||
doCheck = Standard_True;
|
||||
}
|
||||
}
|
||||
if ( doCheck && ( (fabs(newF -aCrvF ) > Precision::PConfusion() && newF < aCrvF) || newF >= aCrvL ) ) {
|
||||
Standard_Real aShift = AdjustByPeriod(newF, 0.5*(aCrvF+aCrvL), aPeriod);
|
||||
newF += aShift;
|
||||
newL += aShift;
|
||||
BRep_Builder().SameRange(toedge,Standard_False);
|
||||
BRep_Builder().SameParameter(toedge,Standard_False);
|
||||
}
|
||||
|
||||
toGC->SetRange ( newF, newL );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetRange3d
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::SetRange3d (const TopoDS_Edge& edge,
|
||||
const Standard_Real first,
|
||||
const Standard_Real last) const
|
||||
{
|
||||
|
||||
for (BRep_ListIteratorOfListOfCurveRepresentation itcr
|
||||
((*((Handle(BRep_TEdge)*)&edge.TShape()))->ChangeCurves()); itcr.More(); itcr.Next()) {
|
||||
Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
|
||||
if ( GC.IsNull() || !GC->IsCurve3D() ) continue;
|
||||
GC->SetRange ( first, last );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CopyPCurves
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::CopyPCurves (const TopoDS_Edge& toedge, const TopoDS_Edge& fromedge) const
|
||||
{
|
||||
TopLoc_Location fromLoc = fromedge.Location();
|
||||
TopLoc_Location toLoc = toedge.Location();
|
||||
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;
|
||||
if ( fromGC->IsCurveOnSurface() ) {
|
||||
Handle(Geom_Surface) surface = fromGC->Surface();
|
||||
TopLoc_Location L = fromGC->Location();
|
||||
Standard_Boolean found = Standard_False;
|
||||
BRep_ListOfCurveRepresentation& tolist = (*((Handle(BRep_TEdge)*)&toedge.TShape()))->ChangeCurves();
|
||||
Handle(BRep_GCurve) toGC;
|
||||
for (BRep_ListIteratorOfListOfCurveRepresentation toitcr (tolist); toitcr.More() && !found; toitcr.Next()) {
|
||||
toGC = Handle(BRep_GCurve)::DownCast(toitcr.Value());
|
||||
if ( toGC.IsNull() || !toGC->IsCurveOnSurface() ||
|
||||
surface != toGC->Surface() || L != toGC->Location() ) continue;
|
||||
found = Standard_True;
|
||||
break;
|
||||
}
|
||||
if (!found) {
|
||||
toGC = Handle(BRep_GCurve)::DownCast(fromGC->Copy());
|
||||
tolist.Append (toGC);
|
||||
}
|
||||
Handle(Geom2d_Curve) pcurve = fromGC->PCurve();
|
||||
toGC->PCurve(Handle(Geom2d_Curve)::DownCast(pcurve->Copy()));
|
||||
|
||||
//bug OCC209 invalid location of pcurve in the edge after copying
|
||||
TopLoc_Location newLoc = (fromLoc*L).Predivided(toLoc);//(L * fromLoc).Predivided(toLoc);
|
||||
toGC->Location(newLoc);
|
||||
if ( fromGC->IsCurveOnClosedSurface() ) {
|
||||
pcurve = fromGC->PCurve2();
|
||||
toGC->PCurve2(Handle(Geom2d_Curve)::DownCast(pcurve->Copy()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//=======================================================================
|
||||
//function : Copy
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TopoDS_Edge ShapeBuild_Edge::Copy (const TopoDS_Edge &edge,
|
||||
const Standard_Boolean sharepcurves) const
|
||||
{
|
||||
TopoDS_Vertex dummy1, dummy2;
|
||||
TopoDS_Edge newedge = CopyReplaceVertices ( edge, dummy1, dummy2 );
|
||||
if ( ! sharepcurves ) CopyPCurves ( newedge, edge );
|
||||
return newedge;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemovePCurve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::RemovePCurve (const TopoDS_Edge& edge,
|
||||
const TopoDS_Face& face) const
|
||||
{
|
||||
BRep_Builder B;
|
||||
Handle(Geom2d_Curve) c2dNull;
|
||||
//:S4136 Standard_Real tol = BRep_Tool::Tolerance ( edge );
|
||||
if ( BRep_Tool::IsClosed ( edge, face ) )
|
||||
B.UpdateEdge ( edge, c2dNull, c2dNull, face, 0. ); //:S4136: tol
|
||||
else B.UpdateEdge ( edge, c2dNull, face, 0. ); //:S4136: tol
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemovePCurve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::RemovePCurve (const TopoDS_Edge& edge,
|
||||
const Handle(Geom_Surface)& surf) const
|
||||
{
|
||||
RemovePCurve ( edge, surf, TopLoc_Location() );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemovePCurve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::RemovePCurve (const TopoDS_Edge& edge,
|
||||
const Handle(Geom_Surface)& surf,
|
||||
const TopLoc_Location &loc) const
|
||||
{
|
||||
BRep_Builder B;
|
||||
Handle(Geom2d_Curve) c2dNull;
|
||||
//:S4136 Standard_Real tol = BRep_Tool::Tolerance ( edge );
|
||||
if ( BRep_Tool::IsClosed ( edge, surf, loc ) )
|
||||
B.UpdateEdge ( edge, c2dNull, c2dNull, surf, loc, 0. ); //:S4136: tol
|
||||
else B.UpdateEdge ( edge, c2dNull, surf, loc, 0. ); //:S4136: tol
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ReplacePCurve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::ReplacePCurve (const TopoDS_Edge& edge,
|
||||
const Handle(Geom2d_Curve)& pcurve,
|
||||
const TopoDS_Face& face) const
|
||||
{
|
||||
BRep_Builder B;
|
||||
Standard_Real f,l;
|
||||
TopoDS_Shape dummy = edge.Reversed();
|
||||
TopoDS_Edge edgerev = TopoDS::Edge(dummy);
|
||||
// reverse face to take second pcurve for seams like SA_Edge::PCurve() does
|
||||
TopoDS_Face F = TopoDS::Face(face.Oriented ( TopAbs_FORWARD ) );
|
||||
Handle(Geom2d_Curve) pcurve0 = BRep_Tool::CurveOnSurface(edge,F,f,l);
|
||||
Handle(Geom2d_Curve) c2d = BRep_Tool::CurveOnSurface(edgerev,F,f,l);
|
||||
// Add pcurve to edge (either as single, or as seam)
|
||||
if ( c2d.IsNull() || c2d == pcurve0 ) { // non-seam
|
||||
B.UpdateEdge(edge,pcurve,face,0);
|
||||
}
|
||||
else { // seam
|
||||
if(edge.Orientation()==TopAbs_FORWARD)
|
||||
B.UpdateEdge(edge,pcurve,c2d,face,0);
|
||||
else
|
||||
B.UpdateEdge(edge,c2d,pcurve,face,0);
|
||||
}
|
||||
B.Range ( edge, face, f, l );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ReassignPCurve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
// Count exact number of pcurves STORED in edge for face
|
||||
// This makes difference for faces based on plane surfaces where pcurves can be
|
||||
// not stored but returned by BRep_Tools::CurveOnSurface
|
||||
static Standard_Integer CountPCurves (const TopoDS_Edge &edge,
|
||||
const TopoDS_Face &face)
|
||||
{
|
||||
TopLoc_Location L;
|
||||
Handle(Geom_Surface) S = BRep_Tool::Surface ( face, L );
|
||||
TopLoc_Location l = L.Predivided(edge.Location());
|
||||
|
||||
for (BRep_ListIteratorOfListOfCurveRepresentation itcr
|
||||
((*((Handle(BRep_TEdge)*)&edge.TShape()))->ChangeCurves()); itcr.More(); itcr.Next()) {
|
||||
Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
|
||||
if ( ! GC.IsNull() && GC->IsCurveOnSurface ( S, l ) )
|
||||
return ( GC->IsCurveOnClosedSurface() ? 2 : 1 );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Standard_Boolean ShapeBuild_Edge::ReassignPCurve (const TopoDS_Edge& edge,
|
||||
const TopoDS_Face& old,
|
||||
const TopoDS_Face& sub) const
|
||||
{
|
||||
Standard_Integer npcurves = CountPCurves ( edge, old );
|
||||
//if ( npcurves <1 ) return Standard_False; //gka
|
||||
|
||||
Standard_Real f, l;
|
||||
Handle(Geom2d_Curve) pc;
|
||||
pc = BRep_Tool::CurveOnSurface ( edge, old, f, l );
|
||||
if ( pc.IsNull() ) return Standard_False;
|
||||
else if( npcurves == 0) npcurves =1; //gka
|
||||
|
||||
|
||||
BRep_Builder B;
|
||||
|
||||
// if the pcurve was only one, remove; else leave second one
|
||||
if ( npcurves >1 ) {
|
||||
//smh#8 Porting AIX
|
||||
TopoDS_Shape tmpshape = edge.Reversed();
|
||||
TopoDS_Edge erev = TopoDS::Edge (tmpshape);
|
||||
Handle(Geom2d_Curve) pc2 = BRep_Tool::CurveOnSurface ( erev, old, f, l );
|
||||
B.UpdateEdge ( edge, pc2, old, 0. );
|
||||
B.Range ( edge, old, f, l );
|
||||
}
|
||||
else RemovePCurve ( edge, old );
|
||||
|
||||
// if edge does not have yet pcurves on sub, just add; else add as first
|
||||
Standard_Integer npcs = CountPCurves ( edge, sub );
|
||||
if ( npcs <1 ) B.UpdateEdge ( edge, pc, sub, 0. );
|
||||
else {
|
||||
//smh#8 Porting AIX
|
||||
TopoDS_Shape tmpshape = edge.Reversed();
|
||||
TopoDS_Edge erev = TopoDS::Edge (tmpshape);
|
||||
Standard_Real cf, cl;
|
||||
Handle(Geom2d_Curve) pcs = BRep_Tool::CurveOnSurface ( erev, sub, cf, cl );
|
||||
if ( edge.Orientation() == TopAbs_REVERSED ) // because B.UpdateEdge does not check edge orientation
|
||||
B.UpdateEdge ( edge, pcs, pc, sub, 0. );
|
||||
else B.UpdateEdge ( edge, pc, pcs, sub, 0. );
|
||||
}
|
||||
|
||||
B.Range ( edge, sub, f, l );
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : TransformPCurve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(Geom2d_Curve) ShapeBuild_Edge::TransformPCurve(const Handle(Geom2d_Curve)& pcurve,
|
||||
const gp_Trsf2d& trans,
|
||||
const Standard_Real uFact,
|
||||
Standard_Real& aFirst,
|
||||
Standard_Real& aLast) const
|
||||
{
|
||||
Handle(Geom2d_Curve) result = Handle(Geom2d_Curve)::DownCast(pcurve->Copy());
|
||||
if(trans.Form()!=gp_Identity) {
|
||||
result->Transform (trans);
|
||||
aFirst = result->TransformedParameter(aFirst,trans);
|
||||
aLast = result->TransformedParameter(aLast, trans);
|
||||
}
|
||||
if(uFact==1.)
|
||||
return result;
|
||||
|
||||
if (result->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
|
||||
Handle(Geom2d_TrimmedCurve) thecurve = Handle(Geom2d_TrimmedCurve)::DownCast(result);
|
||||
result = thecurve->BasisCurve();
|
||||
}
|
||||
|
||||
gp_GTrsf2d tMatu;
|
||||
tMatu.SetAffinity(gp::OY2d(), uFact);
|
||||
gp_XY pXY;
|
||||
|
||||
if (result->IsKind(STANDARD_TYPE(Geom2d_Line))) {
|
||||
Handle(Geom2d_Line) aLine2d = Handle(Geom2d_Line)::DownCast(result);
|
||||
gp_Pnt2d Pf, Pl;
|
||||
aLine2d->D0(aFirst,Pf);
|
||||
pXY = Pf.XY();
|
||||
tMatu.Transforms(pXY);
|
||||
Pf.SetXY(pXY);
|
||||
aLine2d->D0(aLast, Pl);
|
||||
pXY = Pl.XY();
|
||||
tMatu.Transforms(pXY);
|
||||
Pl.SetXY(pXY);
|
||||
gp_Lin2d line2d(Pf, gp_Dir2d(gp_Vec2d(Pf,Pl)));
|
||||
aFirst = ElCLib::Parameter(line2d, Pf);
|
||||
aLast = ElCLib::Parameter(line2d, Pl);
|
||||
Handle(Geom2d_Line) Gline2d = new Geom2d_Line(line2d);
|
||||
return Gline2d;
|
||||
}
|
||||
else if(result->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) {
|
||||
Handle(Geom2d_BezierCurve) bezier = Handle(Geom2d_BezierCurve)::DownCast(result);
|
||||
// transform the Poles of the BSplineCurve
|
||||
Standard_Integer nbPol = bezier->NbPoles();
|
||||
gp_Pnt2d Pt1;
|
||||
for (Standard_Integer i = 1; i<=nbPol ; i++) {
|
||||
pXY = bezier->Pole(i).XY();
|
||||
tMatu.Transforms(pXY);
|
||||
Pt1.SetXY(pXY);
|
||||
bezier->SetPole(i, Pt1);
|
||||
}
|
||||
return bezier;
|
||||
} else {
|
||||
Handle(Geom2d_BSplineCurve) aBSpline2d;
|
||||
if(result->IsKind(STANDARD_TYPE(Geom2d_Conic))) {
|
||||
//gp_Pln pln(gp_Pnt(0,0,0),gp_Dir(0,0,1));
|
||||
//Handle(Geom_Curve) curve = GeomAPI::To3d(result,pln);
|
||||
Handle(Geom2d_TrimmedCurve) tcurve = new Geom2d_TrimmedCurve(result,aFirst,aLast); //protection agains parabols ets
|
||||
Geom2dConvert_ApproxCurve approx (tcurve, Precision::Approximation(),
|
||||
GeomAbs_C1, 100, 6 );
|
||||
if ( approx.HasResult() )
|
||||
aBSpline2d = Handle(Geom2d_BSplineCurve)::DownCast(approx.Curve());
|
||||
else
|
||||
aBSpline2d = Geom2dConvert::CurveToBSplineCurve(tcurve,Convert_QuasiAngular);
|
||||
aFirst = aBSpline2d->FirstParameter();
|
||||
aLast = aBSpline2d->LastParameter();
|
||||
}
|
||||
else if(!result->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) {
|
||||
aBSpline2d = Geom2dConvert::CurveToBSplineCurve(result,Convert_QuasiAngular);
|
||||
}
|
||||
else
|
||||
aBSpline2d = Handle(Geom2d_BSplineCurve)::DownCast(result);
|
||||
|
||||
// transform the Poles of the BSplineCurve
|
||||
Standard_Integer nbPol = aBSpline2d->NbPoles();
|
||||
gp_Pnt2d Pt1;
|
||||
for (Standard_Integer i = 1; i<=nbPol ; i++) {
|
||||
pXY = aBSpline2d->Pole(i).XY();
|
||||
tMatu.Transforms(pXY);
|
||||
Pt1.SetXY(pXY);
|
||||
aBSpline2d->SetPole(i, Pt1);
|
||||
}
|
||||
return aBSpline2d;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemoveCurve3d
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::RemoveCurve3d (const TopoDS_Edge& edge) const
|
||||
{
|
||||
BRep_Builder B;
|
||||
Handle(Geom_Curve) c3dNull;
|
||||
//:S4136 Standard_Real tol = BRep_Tool::Tolerance (edge);
|
||||
B.UpdateEdge (edge, c3dNull, 0. ); //:S4136: tol
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : BuildCurve3d
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean ShapeBuild_Edge::BuildCurve3d (const TopoDS_Edge& edge) const
|
||||
{
|
||||
try {
|
||||
OCC_CATCH_SIGNALS
|
||||
//#48 rln 10.12.98 S4054 UKI60107-5 entity 365
|
||||
//C0 surface (but curve 3d is required as C1) and tolerance is 1e-07
|
||||
//lets use maximum of tolerance and default parameter 1.e-5
|
||||
//Another solutions: use quite big Tolerance or require C0 curve on C0 surface
|
||||
if ( BRepLib::BuildCurve3d (edge, Max (1.e-5, BRep_Tool::Tolerance(edge) ) ) ) {
|
||||
//#50 S4054 rln 14.12.98 write cylinder in BRep mode into IGES and read back
|
||||
//with 2DUse_Forced - pcurve and removed 3D curves have different ranges
|
||||
if (BRep_Tool::SameRange (edge)) {
|
||||
Standard_Real first, last;
|
||||
BRep_Tool::Range (edge, first, last);
|
||||
BRep_Builder().Range (edge, first, last);//explicit setting for all reps
|
||||
}
|
||||
Handle(Geom_Curve) c3d;
|
||||
Standard_Real f,l;
|
||||
c3d = BRep_Tool::Curve(edge,f,l);
|
||||
// 15.11.2002 PTV OCC966
|
||||
if(!IsPeriodic(c3d)) {
|
||||
Standard_Boolean isLess = Standard_False;
|
||||
if(f < c3d->FirstParameter()) {
|
||||
isLess = Standard_True;
|
||||
f = c3d->FirstParameter();
|
||||
}
|
||||
if(l > c3d->LastParameter()) {
|
||||
isLess = Standard_True;
|
||||
l = c3d->LastParameter();
|
||||
}
|
||||
if(isLess) {
|
||||
SetRange3d(edge,f,l);
|
||||
BRep_Builder().SameRange(edge,Standard_False);
|
||||
}
|
||||
}
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
}
|
||||
catch(Standard_Failure) {
|
||||
#ifdef DEB
|
||||
cout << "\nWarning: ShapeBuild_Edge: Exception in BuildCurve3d: ";
|
||||
Standard_Failure::Caught()->Print(cout); cout << endl;
|
||||
#endif
|
||||
}
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : MakeEdge
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::MakeEdge(TopoDS_Edge& edge,const Handle(Geom_Curve)& curve,const TopLoc_Location& L) const
|
||||
{
|
||||
MakeEdge (edge,curve, L, curve->FirstParameter(), curve->LastParameter());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : MakeEdge
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::MakeEdge(TopoDS_Edge& edge,const Handle(Geom_Curve)& curve,const TopLoc_Location& L,const Standard_Real p1,const Standard_Real p2) const
|
||||
{
|
||||
BRepBuilderAPI_MakeEdge ME (curve, p1, p2);
|
||||
if (!ME.IsDone()) {
|
||||
#ifdef DEB
|
||||
cout << "\nWarning: ShapeBuild_Edge::MakeEdge BRepAPI_NotDone";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
TopoDS_Edge E = ME.Edge();
|
||||
if (!L.IsIdentity()) {
|
||||
BRep_Builder B;
|
||||
B.UpdateEdge (E, curve, L, 0.);
|
||||
B.Range (E, p1, p2);
|
||||
|
||||
TopoDS_Vertex V1, V2;
|
||||
TopExp::Vertices (E, V1, V2);
|
||||
gp_Pnt P1 = BRep_Tool::Pnt (V1), P2 = BRep_Tool::Pnt (V2);
|
||||
B.UpdateVertex (V1, P1.Transformed (L.Transformation()), 0.);
|
||||
B.UpdateVertex (V2, P2.Transformed (L.Transformation()), 0.);
|
||||
}
|
||||
edge = E;
|
||||
return;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : MakeEdge
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::MakeEdge(TopoDS_Edge& edge,const Handle(Geom2d_Curve)& pcurve,const TopoDS_Face& face) const
|
||||
{
|
||||
MakeEdge (edge, pcurve, face, pcurve->FirstParameter(), pcurve->LastParameter());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : MakeEdge
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::MakeEdge(TopoDS_Edge& edge,const Handle(Geom2d_Curve)& pcurve,const TopoDS_Face& face,const Standard_Real p1,const Standard_Real p2) const
|
||||
{
|
||||
TopLoc_Location L;
|
||||
const Handle(Geom_Surface)& S = BRep_Tool::Surface(face, L);
|
||||
MakeEdge (edge, pcurve, S, L, p1, p2);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : MakeEdge
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::MakeEdge(TopoDS_Edge& edge,const Handle(Geom2d_Curve)& pcurve,
|
||||
const Handle(Geom_Surface)& S,const TopLoc_Location& L) const
|
||||
{
|
||||
MakeEdge(edge, pcurve, S, L, pcurve->FirstParameter(), pcurve->LastParameter());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : MakeEdge
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void ShapeBuild_Edge::MakeEdge(TopoDS_Edge& edge,const Handle(Geom2d_Curve)& pcurve,
|
||||
const Handle(Geom_Surface)& S,const TopLoc_Location& L,
|
||||
const Standard_Real p1,const Standard_Real p2) const
|
||||
{
|
||||
BRepBuilderAPI_MakeEdge ME (pcurve, S, p1, p2);
|
||||
if (!ME.IsDone()) {
|
||||
#ifdef DEB
|
||||
cout << "\nWarning: ShapeBuild_Edge::MakeEdge BRepAPI_NotDone";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
TopoDS_Edge E = ME.Edge();
|
||||
if (!L.IsIdentity()) {
|
||||
RemovePCurve (E, S);
|
||||
BRep_Builder B;
|
||||
B.UpdateEdge (E, pcurve, S, L, 0.);
|
||||
B.Range (E, S, L, p1, p2);
|
||||
|
||||
TopoDS_Vertex V1, V2;
|
||||
TopExp::Vertices (E, V1, V2);
|
||||
gp_Pnt P1 = BRep_Tool::Pnt (V1), P2 = BRep_Tool::Pnt (V2);
|
||||
B.UpdateVertex (V1, P1.Transformed (L.Transformation()), 0.);
|
||||
B.UpdateVertex (V2, P2.Transformed (L.Transformation()), 0.);
|
||||
}
|
||||
edge = E;
|
||||
return;
|
||||
}
|
||||
|
84
src/ShapeBuild/ShapeBuild_ReShape.cdl
Executable file
84
src/ShapeBuild/ShapeBuild_ReShape.cdl
Executable file
@@ -0,0 +1,84 @@
|
||||
-- File: ShapeBuild_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 ShapeBuild inherits ReShape from BRepTools
|
||||
|
||||
---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,
|
||||
Status from ShapeExtend
|
||||
|
||||
is
|
||||
|
||||
Create returns mutable ReShape from ShapeBuild;
|
||||
---Purpose: Returns an empty Reshape
|
||||
|
||||
Apply (me: mutable; shape: Shape from TopoDS; until: ShapeEnum from TopAbs; buildmode: Integer)
|
||||
returns Shape from TopoDS is redefined;
|
||||
---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 redefined;
|
||||
---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.
|
||||
|
||||
Status (me: mutable; shape: Shape from TopoDS; newsh: out Shape from TopoDS; last : Boolean = Standard_False)
|
||||
returns Integer is redefined;
|
||||
---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.
|
||||
|
||||
Status (me; status: Status from ShapeExtend) returns Boolean;
|
||||
---Purpose: Queries the status of last call to Apply(shape,enum)
|
||||
-- OK : no (sub)shapes replaced or removed
|
||||
-- DONE1: source (starting) shape replaced
|
||||
-- DONE2: source (starting) shape removed
|
||||
-- DONE3: some subshapes replaced
|
||||
-- DONE4: some subshapes removed
|
||||
-- FAIL1: some replacements not done because of bad type of subshape
|
||||
|
||||
end ReShape;
|
139
src/ShapeBuild/ShapeBuild_ReShape.cxx
Executable file
139
src/ShapeBuild/ShapeBuild_ReShape.cxx
Executable file
@@ -0,0 +1,139 @@
|
||||
// abv 28.04.99 S4137: ading method Apply for work on all types of shapes
|
||||
|
||||
#include <ShapeBuild_ReShape.ixx>
|
||||
|
||||
#include <TopoDS_Shell.hxx>
|
||||
#include <TopoDS_Solid.hxx>
|
||||
#include <TopoDS_Compound.hxx>
|
||||
#include <TopoDS_Iterator.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <ShapeExtend.hxx>
|
||||
#include <ShapeBuild_Edge.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : ShapeBuild_ReShape
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
ShapeBuild_ReShape::ShapeBuild_ReShape()
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Apply
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TopoDS_Shape ShapeBuild_ReShape::Apply (const TopoDS_Shape& shape,
|
||||
const TopAbs_ShapeEnum until,
|
||||
const Standard_Integer buildmode)
|
||||
{
|
||||
return BRepTools_ReShape::Apply (shape,until,buildmode);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Apply
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TopoDS_Shape ShapeBuild_ReShape::Apply (const TopoDS_Shape& shape,
|
||||
const TopAbs_ShapeEnum until)
|
||||
{
|
||||
myStatus = 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 = ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
|
||||
return newsh;
|
||||
}
|
||||
|
||||
// if shape replaced, apply modifications to the result recursively
|
||||
Standard_Boolean aConsLoc = ModeConsiderLocation();
|
||||
if ( (aConsLoc && ! newsh.IsPartner (shape)) ||
|
||||
(!aConsLoc &&! newsh.IsSame ( shape )) ) {
|
||||
|
||||
TopoDS_Shape res = Apply ( newsh, until );
|
||||
myStatus |= 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
|
||||
|
||||
BRep_Builder B;
|
||||
|
||||
TopoDS_Shape result = shape.EmptyCopied();
|
||||
TopAbs_Orientation orient = shape.Orientation(); //JR/Hp: or -> orient
|
||||
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 ( ShapeExtend::DecodeStatus ( myStatus, ShapeExtend_DONE4 ) )
|
||||
locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE4 );
|
||||
modif = 1;
|
||||
}
|
||||
if ( newsh.IsNull() ) {
|
||||
locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE4 );
|
||||
continue;
|
||||
}
|
||||
locStatus |= 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 );
|
||||
else locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 );
|
||||
}
|
||||
if ( ! nitems ) locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 );
|
||||
}
|
||||
if ( ! modif ) return shape;
|
||||
|
||||
// restore Range on edge broken by EmptyCopied()
|
||||
if ( st == TopAbs_EDGE ) {
|
||||
ShapeBuild_Edge sbe;
|
||||
sbe.CopyRanges ( TopoDS::Edge ( result ), TopoDS::Edge ( shape ));
|
||||
}
|
||||
result.Orientation(orient);
|
||||
myStatus = locStatus;
|
||||
Replace ( shape, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Status
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer ShapeBuild_ReShape::Status(const TopoDS_Shape& ashape,
|
||||
TopoDS_Shape& newsh,
|
||||
const Standard_Boolean last)
|
||||
{
|
||||
return BRepTools_ReShape::Status(ashape,newsh,last);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Status
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean ShapeBuild_ReShape::Status (const ShapeExtend_Status status) const
|
||||
{
|
||||
return ShapeExtend::DecodeStatus ( myStatus, status );
|
||||
}
|
35
src/ShapeBuild/ShapeBuild_Vertex.cdl
Executable file
35
src/ShapeBuild/ShapeBuild_Vertex.cdl
Executable file
@@ -0,0 +1,35 @@
|
||||
-- File: ShapeBuild_Vertex.cdl
|
||||
-- Created: Thu Jun 11 19:18:12 1998
|
||||
-- Author: data exchange team
|
||||
-- <det@nicebox.nnov.matra-dtv.fr>
|
||||
---Copyright: Matra Datavision 1998
|
||||
|
||||
|
||||
class Vertex from ShapeBuild
|
||||
|
||||
---Purpose: Provides low-level functions used for constructing vertices
|
||||
|
||||
uses
|
||||
Pnt from gp,
|
||||
Vertex from TopoDS
|
||||
|
||||
is
|
||||
|
||||
CombineVertex ( me; V1, V2: Vertex from TopoDS; tolFactor: Real = 1.0001 )
|
||||
returns Vertex from TopoDS;
|
||||
---Purpose: Combines new vertex from two others. This new one is the
|
||||
-- smallest vertex which comprises both of the source vertices.
|
||||
-- The function takes into account the positions and tolerances
|
||||
-- of the source vertices.
|
||||
-- The tolerance of the new vertex will be equal to the minimal
|
||||
-- tolerance that is required to comprise source vertices
|
||||
-- multiplied by tolFactor (in order to avoid errors because
|
||||
-- of discreteness of calculations).
|
||||
|
||||
CombineVertex ( me; pnt1, pnt2: Pnt from gp; tol1, tol2: Real;
|
||||
tolFactor: Real = 1.0001 )
|
||||
returns Vertex from TopoDS;
|
||||
---Purpose: The same function as above, except that it accepts two points
|
||||
-- and two tolerances instead of vertices
|
||||
|
||||
end Vertex;
|
59
src/ShapeBuild/ShapeBuild_Vertex.cxx
Executable file
59
src/ShapeBuild/ShapeBuild_Vertex.cxx
Executable file
@@ -0,0 +1,59 @@
|
||||
// rln 22.03.99: syntax correction in CombineVertex
|
||||
//szv#4 S4163
|
||||
#include <ShapeBuild_Vertex.ixx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <Precision.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : CombineVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TopoDS_Vertex ShapeBuild_Vertex::CombineVertex (const TopoDS_Vertex& V1,
|
||||
const TopoDS_Vertex& V2,
|
||||
const Standard_Real tolFactor) const
|
||||
{
|
||||
return CombineVertex ( BRep_Tool::Pnt ( V1 ), BRep_Tool::Pnt ( V2 ),
|
||||
BRep_Tool::Tolerance ( V1 ), BRep_Tool::Tolerance ( V2 ),
|
||||
tolFactor );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CombineVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TopoDS_Vertex ShapeBuild_Vertex::CombineVertex (const gp_Pnt& pnt1,
|
||||
const gp_Pnt& pnt2,
|
||||
const Standard_Real tol1,
|
||||
const Standard_Real tol2,
|
||||
const Standard_Real tolFactor) const
|
||||
{
|
||||
gp_Pnt pos;
|
||||
Standard_Real tol;
|
||||
|
||||
gp_Vec v = pnt2.XYZ() - pnt1.XYZ();
|
||||
Standard_Real dist = v.Magnitude();
|
||||
|
||||
//#47 rln 09.12.98 S4054 PRO14323 entity 2844
|
||||
if ( dist + tol2 <= tol1 ) {
|
||||
pos = pnt1;
|
||||
tol = tol1;
|
||||
}
|
||||
else if ( dist + tol1 <= tol2 ) {
|
||||
pos = pnt2;
|
||||
tol = tol2;
|
||||
}
|
||||
else {
|
||||
tol = 0.5 * ( dist + tol1 + tol2 );
|
||||
Standard_Real s = ( dist > 0. )? ( tol2 - tol1 ) / dist : 0.; //szv#4:S4163:12Mar99 anti-exception
|
||||
pos = 0.5 * ( ( 1 - s ) * pnt1.XYZ() + ( 1 + s ) * pnt2.XYZ() );
|
||||
}
|
||||
|
||||
TopoDS_Vertex V;
|
||||
BRep_Builder B;
|
||||
B.MakeVertex ( V, pos, tolFactor * tol );
|
||||
return V;
|
||||
}
|
||||
|
Reference in New Issue
Block a user