1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef HYDRODATA_TOPOCURVE_H
20 #define HYDRODATA_TOPOCURVE_H
23 #include <Handle_Geom_BSplineCurve.hxx>
24 #include <HYDROData.h>
27 #include <TopoDS_Edge.hxx>
28 #include <TopoDS_Vertex.hxx>
32 //! The type represents a 1 monifold connected topo curve
33 //! with forward orientation.
34 class HYDROData_TopoCurve
37 //! The default computer.
38 HYDROData_TopoCurve() {}
40 //! Constructs the curve from the edge.
41 HYDROData_TopoCurve(const TopoDS_Edge& theEdge) {myEdges.push_back(theEdge);}
43 //! Initializes the curve by the wire.
44 //! Returns 'false' if the wire is not 1 monifold or
45 //! is disconnected or is empty.
46 HYDRODATA_EXPORT bool Initialize(const TopoDS_Wire& theWire);
48 //! Converts the curve to the wire.
49 HYDRODATA_EXPORT TopoDS_Wire Wire() const;
51 //! Returns 'true' if the curve has no edges.
52 bool IsEmpty() const {return myEdges.empty();}
54 //! Returns 'true' whether the curve is closed.
57 return TopExp::LastVertex(myEdges.back(), Standard_True).
58 IsSame(TopExp::FirstVertex(myEdges.front(), Standard_True)) ==
62 //! Returns the curve edges.
63 const std::list<TopoDS_Edge>& Edges() const {return myEdges;}
65 //! Returns the curve edges.
66 std::list<TopoDS_Edge>& Edges() {return myEdges;}
68 //! Cuts the curve in the given parameter of the given edge and
69 //! fills the cut part.
70 //! Returns 'true' if:
71 //! - the curve is open and was splitted into two parts or
72 //! - the curve is closed and was cut into an open curve.
73 HYDRODATA_EXPORT bool Cut(
74 const std::list<TopoDS_Edge>::iterator& theEdgePosition,
75 const double theParameter,
76 HYDROData_TopoCurve& theCurve);
78 //! Cuts the curve in the given parameter of the given edge and
79 //! fills the cut parts.
80 HYDRODATA_EXPORT void Cut(
81 const std::list<TopoDS_Edge>::const_iterator& theEdgePosition,
82 const double theParameter,
83 HYDROData_TopoCurve& theCurve1,
84 HYDROData_TopoCurve& theCurve2) const;
86 //! Cuts the curve at the parameters.
87 //! Each parameter vector list corresponds to the curve edge and
88 //! is ordered in the ascending order.
89 HYDRODATA_EXPORT bool Cut(
90 const std::deque<std::list<double> >& theParameters,
91 std::deque<HYDROData_TopoCurve>& theCurves) const;
93 //! Projects the point to the nearest point of the curve.
94 //! Fills the iterator of the edge and
95 //! the parameter on the edge for the projection.
96 //! Returns the square distance from the point to the projection.
97 HYDRODATA_EXPORT double Project(
98 const gp_XYZ& thePoint,
99 std::list<TopoDS_Edge>::const_iterator& theEdgeIterator,
100 double& theParameter) const;
102 //! Adds the intersection parameters of the curve with the wire to the vector.
103 HYDRODATA_EXPORT int Intersect(
104 const TopoDS_Wire& theWire,
105 std::deque<std::list<double> >& theParameters) const;
107 //! Replaces the first vertex by the last one.
108 HYDRODATA_EXPORT void CloseCurve();
110 //! Topologically extends the curve by the parameter at the position:
111 //! 0 - start, 1 - end.
112 HYDRODATA_EXPORT void Merge(
113 const int thePosition, HYDROData_TopoCurve& theCurve);
115 //! Topologically merges the curve to the curves.
116 HYDRODATA_EXPORT void Merge(
117 const double theTolerance, std::deque<HYDROData_TopoCurve>& theCurves);
119 //! Topologically merges the wire curve to the curves.
120 //! Returns 'false' if the wire is not a curve.
122 const double theTolerance,
123 const TopoDS_Wire& theWire,
124 std::deque<HYDROData_TopoCurve>& theCurves)
126 HYDROData_TopoCurve aCurve;
127 const bool aResult = aCurve.Initialize(theWire);
130 aCurve.Merge(theTolerance, theCurves);
135 //! Topologically connects the curve to the first open one of the curves.
136 //! If the gap between the curve and the first open curve is more than the
137 //! tolerance then the gap is smoothly filled by a curve.
138 //! It is assumed that only one of the parameter curves may be open.
139 //! If the curve is closed then it is added to the curves.
140 HYDRODATA_EXPORT bool Connect(
141 const Standard_Real theTolerance,
142 std::deque<HYDROData_TopoCurve>& theCurves);
144 //! Works by the same way as the above method.
146 const Standard_Real theTolerance,
147 const TopoDS_Wire& theWire,
148 std::deque<HYDROData_TopoCurve>& theCurves)
150 HYDROData_TopoCurve aCurve;
151 if (aCurve.Initialize(theWire))
153 return aCurve.Connect(theTolerance, theCurves);
159 //! Creates a B-spline piecewise curve corresponding to the curve
160 //! and using the deflection.
161 //! Returns the piece count.
162 //! Returns 0 in the case of any error.
163 HYDRODATA_EXPORT int BSplinePiecewiseCurve(
164 const double theDeflection, HYDROData_TopoCurve& theCurve) const;
166 //! Calculates the values of the curve in its knots.
167 //! Returns 'false' if a curve edge has a nonidentity location or a nonforward
168 //! orientation or has no a B-spline representation.
169 HYDRODATA_EXPORT bool ValuesInKnots(std::list<gp_XYZ>& theValues) const;
172 //! Transfers the edges of the parameter to this curve end.
173 void append(HYDROData_TopoCurve& theCurve)
174 {myEdges.splice(myEdges.end(), theCurve.myEdges);}
176 //! Transfers the edges of the parameter to this curve start.
177 void prepend(HYDROData_TopoCurve& theCurve)
178 {myEdges.splice(myEdges.begin(), theCurve.myEdges);}
180 std::list<TopoDS_Edge> myEdges; //!< The ordered curve edges.