1 // Copyright (C) 2007-2013 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.
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 #include "GEOMImpl_PolylineDriver.hxx"
25 #include "GEOMImpl_ICurveParametric.hxx"
26 #include "GEOMImpl_IPolyline.hxx"
27 #include "GEOMImpl_Types.hxx"
28 #include "GEOM_Function.hxx"
30 #include <BRepBuilderAPI_MakePolygon.hxx>
31 #include <BRepBuilderAPI_MakeVertex.hxx>
32 #include <BRep_Tool.hxx>
33 #include <Precision.hxx>
34 #include <TColgp_Array1OfPnt.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Vertex.hxx>
40 #include <TopoDS_Wire.hxx>
43 //=======================================================================
46 //=======================================================================
47 const Standard_GUID& GEOMImpl_PolylineDriver::GetID()
49 static Standard_GUID aPolylineDriver("FF1BBB31-5D14-4df2-980B-3A668264EA16");
50 return aPolylineDriver;
54 //=======================================================================
55 //function : GEOMImpl_PolylineDriver
57 //=======================================================================
58 GEOMImpl_PolylineDriver::GEOMImpl_PolylineDriver()
62 //=======================================================================
65 //=======================================================================
66 Standard_Integer GEOMImpl_PolylineDriver::Execute(TFunction_Logbook& log) const
68 if (Label().IsNull()) return 0;
69 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
71 GEOMImpl_IPolyline aCI (aFunction);
72 Standard_Integer aType = aFunction->GetType();
76 if (aType == POLYLINE_POINTS) {
78 bool useCoords = aCI.GetConstructorType() == COORD_CONSTRUCTOR;
79 TColgp_Array1OfPnt points(1, (useCoords ? aCI.GetLength() : 1) );
81 Handle(TColStd_HArray1OfReal) aCoordsArray = aCI.GetCoordinates();
82 int anArrayLength = aCoordsArray->Length();
83 for (int i = 0, j = 1; i <= (anArrayLength-3); i += 3) {
84 gp_Pnt aPnt = gp_Pnt(aCoordsArray->Value(i+1), aCoordsArray->Value(i+2), aCoordsArray->Value(i+3));
85 points.SetValue(j,aPnt);
90 int aLen = aCI.GetLength();
92 BRepBuilderAPI_MakePolygon aMakePoly;
93 for (; ind <= aLen; ind++)
96 aMakePoly.Add(BRepBuilderAPI_MakeVertex(points.Value(ind)));
98 Handle(GEOM_Function) aRefPoint = aCI.GetPoint(ind);
99 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
100 if (aShapePnt.ShapeType() != TopAbs_VERTEX) {
101 Standard_TypeMismatch::Raise
102 ("Polyline creation aborted : arguments are not a vertexes");
105 if (aShapePnt.ShapeType() == TopAbs_VERTEX) {
106 aMakePoly.Add(TopoDS::Vertex(aShapePnt));
107 //if (!aMakePoly.Added()) return 0;
111 // Compare first and last point coordinates and close polyline if it's the same.
115 aV1 = BRepBuilderAPI_MakeVertex(points.Value(1));
117 Handle(GEOM_Function) aFPoint = aCI.GetPoint(1);
118 TopoDS_Shape aFirstPnt = aFPoint->GetValue();
119 aV1 = TopoDS::Vertex(aFirstPnt);
124 aV2 = BRepBuilderAPI_MakeVertex(points.Value(aLen));
126 Handle(GEOM_Function) aLPoint = aCI.GetPoint(aLen);
127 TopoDS_Shape aLastPnt = aLPoint->GetValue();
128 aV2 = TopoDS::Vertex(aLastPnt);
131 if ( (!aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2)) ||
136 if (aMakePoly.IsDone()) {
137 aShape = aMakePoly.Wire();
143 if (aShape.IsNull()) return 0;
145 aFunction->SetValue(aShape);
147 log.SetTouched(Label());
152 //================================================================================
154 * \brief Returns a name of creation operation and names and values of creation parameters
156 //================================================================================
158 bool GEOMImpl_PolylineDriver::
159 GetCreationInformation(std::string& theOperationName,
160 std::vector<GEOM_Param>& theParams)
162 if (Label().IsNull()) return 0;
163 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
165 GEOMImpl_IPolyline aCI( function );
166 GEOMImpl_ICurveParametric aIP( function );
167 Standard_Integer aType = function->GetType();
169 theOperationName = "CURVE";
172 case POLYLINE_POINTS:
173 AddParam( theParams, "Type", "Polyline");
176 AddParam( theParams, "X(t) equation", aIP.GetExprX() );
177 AddParam( theParams, "Y(t) equation", aIP.GetExprY() );
178 AddParam( theParams, "Z(t) equation", aIP.GetExprZ() );
179 AddParam( theParams, "Min t", aIP.GetParamMin() );
180 AddParam( theParams, "Max t", aIP.GetParamMax() );
181 if ( aIP.GetParamNbStep() )
182 AddParam( theParams, "Number of steps", aIP.GetParamNbStep() );
184 AddParam( theParams, "t step", aIP.GetParamStep() );
188 GEOM_Param& pntParam = AddParam( theParams, "Points");
189 if ( aCI.GetConstructorType() == COORD_CONSTRUCTOR )
191 Handle(TColStd_HArray1OfReal) coords = aCI.GetCoordinates();
192 if ( coords->Length() > 3 )
193 pntParam << ( coords->Length() ) / 3 << " points: ";
194 for ( int i = coords->Lower(), nb = coords->Upper(); i <= nb; )
195 pntParam << "( " << coords->Value( i++ )
196 << ", " << coords->Value( i++ )
197 << ", " << coords->Value( i++ ) << " ) ";
201 if ( aCI.GetLength() > 1 )
202 pntParam << aCI.GetLength() << " points: ";
203 for ( int i = 1, nb = aCI.GetLength(); i <= nb; ++i )
204 pntParam << aCI.GetPoint( i ) << " ";
206 AddParam( theParams, "Is closed", aCI.GetIsClosed() );
216 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_PolylineDriver,GEOM_BaseDriver);
217 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_PolylineDriver,GEOM_BaseDriver);