1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef HYDRODATA_TOPOCURVE_H
24 #define HYDRODATA_TOPOCURVE_H
27 #include <Handle_Geom_BSplineCurve.hxx>
28 #include <HYDROData.h>
31 #include <TopoDS_Edge.hxx>
32 #include <TopoDS_Vertex.hxx>
36 //! The type represents a 1 monifold connected topo curve
37 //! with forward orientation.
38 class HYDROData_TopoCurve
41 //! The default computer.
42 HYDROData_TopoCurve() {}
44 //! Constructs the curve from the edge.
45 HYDROData_TopoCurve(const TopoDS_Edge& theEdge) {myEdges.push_back(theEdge);}
47 //! Initializes the curve by the wire.
48 //! Returns 'false' if the wire is not 1 monifold or
49 //! is disconnected or is empty.
50 HYDRODATA_EXPORT bool Initialize(const TopoDS_Wire& theWire);
52 //! Converts the curve to the wire.
53 HYDRODATA_EXPORT TopoDS_Wire Wire() const;
55 //! Returns 'true' if the curve has no edges.
56 bool IsEmpty() const {return myEdges.empty();}
58 //! Returns 'true' whether the curve is closed.
61 return TopExp::LastVertex(myEdges.back(), Standard_True).
62 IsSame(TopExp::FirstVertex(myEdges.front(), Standard_True)) ==
66 //! Returns the curve edges.
67 const std::list<TopoDS_Edge>& Edges() const {return myEdges;}
69 //! Cuts the curve in the given parameter of the given edge and
70 //! fills the cut part.
71 HYDRODATA_EXPORT void Cut(
72 const std::list<TopoDS_Edge>::iterator& theEdgePosition,
73 const double theParameter,
74 HYDROData_TopoCurve& theCurve);
76 //! Cuts the curve in the given parameter of the given edge and
77 //! fills the cut parts.
78 HYDRODATA_EXPORT void Cut(
79 const std::list<TopoDS_Edge>::const_iterator& theEdgePosition,
80 const double theParameter,
81 HYDROData_TopoCurve& theCurve1,
82 HYDROData_TopoCurve& theCurve2) const;
84 //! Cuts the curve at the parameters.
85 //! Each parameter vector list corresponds to the curve edge and
86 //! is ordered in the ascending order.
87 HYDRODATA_EXPORT void Cut(
88 const std::deque<std::list<double> >& theParameters,
89 std::deque<HYDROData_TopoCurve>& theCurves) const;
91 //! Projects the point to the nearest point of the curve.
92 //! Fills the iterator of the edge and
93 //! the parameter on the edge for the projection.
94 //! Returns the square distance from the point to the projection.
95 HYDRODATA_EXPORT double Project(
96 const gp_XYZ& thePoint,
97 std::list<TopoDS_Edge>::const_iterator& theEdgeIterator,
98 double& theParameter) const;
100 //! Adds the intersection parameters of the curve with the wire to the vector.
101 HYDRODATA_EXPORT int Intersect(
102 const TopoDS_Wire& theWire,
103 std::deque<std::list<double> >& theParameters) const;
105 //! Replaces the first vertex by the last one.
106 HYDRODATA_EXPORT void CloseCurve();
108 //! Topologically extends the curve by the parameter at the position:
109 //! 0 - start, 1 - end.
110 HYDRODATA_EXPORT void Merge(
111 const int thePosition, HYDROData_TopoCurve& theCurve);
113 //! Topologically merges the curve to the curves.
114 HYDRODATA_EXPORT void Merge(
115 const double theTolerance, std::deque<HYDROData_TopoCurve>& theCurves);
117 //! Topologically merges the wire curve to the curves.
118 //! Returns 'false' if the wire is not a curve.
120 const double theTolerance,
121 const TopoDS_Wire& theWire,
122 std::deque<HYDROData_TopoCurve>& theCurves)
124 HYDROData_TopoCurve aCurve;
125 const bool aResult = aCurve.Initialize(theWire);
128 aCurve.Merge(theTolerance, theCurves);
133 //! Topologically connects the curve to the first open one of the curves.
134 //! If the gap between the curve and the first open curve is more than the
135 //! tolerance then the gap is smoothly filled by a curve.
136 //! It is assumed that only one of the parameter curves may be open.
137 //! If the curve is closed then it is added to the curves.
138 HYDRODATA_EXPORT bool Connect(
139 const Standard_Real theTolerance,
140 std::deque<HYDROData_TopoCurve>& theCurves);
142 //! Works by the same way as the above method.
144 const Standard_Real theTolerance,
145 const TopoDS_Wire& theWire,
146 std::deque<HYDROData_TopoCurve>& theCurves)
148 HYDROData_TopoCurve aCurve;
149 if (!aCurve.Initialize(theWire))
151 return aCurve.Connect(theTolerance, theCurves);
157 //! Creates a B-spline piecewise curve corresponding to the curve
158 //! and using the deflection.
159 HYDRODATA_EXPORT bool BSplinePiecewiseCurve(
160 const double theDeflection, HYDROData_TopoCurve& theCurve) const;
162 //! Calculates the values of the curve in its knots.
163 //! Returns 'false' if a curve edge has a nonidentity location or a nonforward
164 //! orientation or has no a B-spline representation.
165 HYDRODATA_EXPORT bool ValuesInKnots(std::deque<gp_XYZ>& theValues) const;
168 //! Transfers the edges of the parameter to this curve end.
169 void append(HYDROData_TopoCurve& theCurve)
170 {myEdges.splice(myEdges.end(), theCurve.myEdges);}
172 //! Transfers the edges of the parameter to this curve start.
173 void prepend(HYDROData_TopoCurve& theCurve)
174 {myEdges.splice(myEdges.begin(), theCurve.myEdges);}
176 std::list<TopoDS_Edge> myEdges; //!< The ordered curve edges.