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 #include "HYDROData_PolylineXY.h"
21 #include "HYDROData_BSplineOperation.h"
22 #include "HYDROData_Document.h"
23 #include "HYDROData_ShapesTool.h"
24 #include "HYDROData_Tool.h"
25 #include "HYDROData_PolylineOperator.h"
26 #include "HYDROData_TopoCurve.h"
28 #include <BRep_Builder.hxx>
29 #include <BRepBuilderAPI_MakeEdge.hxx>
30 #include <BRepBuilderAPI_MakeWire.hxx>
31 #include <BRepBuilderAPI_MakePolygon.hxx>
32 #include <BRepBuilderAPI_MakeFace.hxx>
33 #include <BRepOffsetAPI_NormalProjection.hxx>
34 #include <BRepAdaptor_Curve.hxx>
40 #include <GeomAPI_ProjectPointOnCurve.hxx>
41 #include <GeomAdaptor_Curve.hxx>
42 #include <Geom_Line.hxx>
43 #include <Geom_BSplineCurve.hxx>
45 #include <GCPnts_AbscissaPoint.hxx>
46 #include <GCPnts_QuasiUniformDeflection.hxx>
47 #include <GCPnts_UniformDeflection.hxx>
49 #include <ImageComposer_MetaTypes.h>
55 #include <NCollection_Map.hxx>
57 #include <TCollection_ExtendedString.hxx>
59 #include <TDataStd_ListIteratorOfListOfByte.hxx>
60 #include <TColStd_ListIteratorOfListOfInteger.hxx>
61 #include <TColStd_ListIteratorOfListOfReal.hxx>
63 #include <TColStd_Array1OfReal.hxx>
64 #include <TColgp_Array1OfPnt.hxx>
66 #include <TDataStd_AsciiString.hxx>
67 #include <TDataStd_BooleanList.hxx>
68 #include <TDataStd_ExtStringList.hxx>
69 #include <TDataStd_IntegerList.hxx>
70 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
71 #include <TDataStd_RealList.hxx>
72 #include <TDataStd_UAttribute.hxx>
74 #include <TopoDS_Iterator.hxx>
75 #include <TopTools_ListIteratorOfListOfShape.hxx>
76 #include <TopTools_HSequenceOfShape.hxx>
77 #include <TopExp_Explorer.hxx>
78 #include <ShapeAnalysis_FreeBounds.hxx>
82 #include <QPainterPath>
86 #include "HYDRO_trace.hxx"
87 #include <BRepTools.hxx>
91 static const Standard_GUID GUID_IS_UNEDITABLE("e5799736-9030-4051-91a4-2e58321fa153");
93 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
95 TCollection_AsciiString getUniqueSectionName( const NCollection_Sequence<TCollection_AsciiString>& theNamesSeq )
97 NCollection_Map<TCollection_AsciiString> aNamesMap;
99 for ( int i = 1, n = theNamesSeq.Size(); i <= n; ++i )
101 const TCollection_AsciiString& aSectName = theNamesSeq.Value( i );
102 aNamesMap.Add( aSectName );
105 TCollection_AsciiString aResName;
110 aResName = TCollection_AsciiString( "Section_" ) + aPrefIdx;
113 while ( aNamesMap.Contains( aResName ) );
118 TCollection_AsciiString getUniqueSectionName( const Handle(TDataStd_ExtStringList)& theNamesList )
120 NCollection_Sequence<TCollection_AsciiString> aNamesSeq;
122 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( theNamesList->List() );
123 for ( ; aNamesIter.More(); aNamesIter.Next() )
124 aNamesSeq.Append( aNamesIter.Value() );
126 return getUniqueSectionName( aNamesSeq );
129 IMPLEMENT_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline)
130 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline)
132 HYDROData_PolylineXY::HYDROData_PolylineXY()
133 : HYDROData_IPolyline(),
134 myIsInCustomFlag( false )
138 HYDROData_PolylineXY::~HYDROData_PolylineXY()
142 QStringList HYDROData_PolylineXY::DumpToPython( const QString& thePyScriptPath,
143 MapOfTreatedObjects& theTreatedObjects ) const
145 QStringList aResList = dumpObjectCreation( theTreatedObjects );
146 QString aPolylineName = GetObjPyName();
148 // Set the wire color
149 QStringList aWireColorDef;
151 QColor aWireColor = GetWireColor();
152 setPythonObjectColor( aWireColorDef, aWireColor, DefaultWireColor(), "SetWireColor" );
154 if ( !aWireColorDef.isEmpty() )
156 aResList << aWireColorDef;
157 aResList << QString( "" );
160 bool anIsEditable = IsEditable();
163 // If polyline is not editable we try to import the shape from geom
164 TCollection_AsciiString aGeomObjectEntry = GetGeomObjectEntry();
165 if ( !aGeomObjectEntry.IsEmpty() )
167 QString aSalomeObjName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "polyline_sobj" );
168 aResList << QString( "%1 = salome.myStudy.FindObjectID( \"%2\" )" )
169 .arg( aSalomeObjName ).arg( aGeomObjectEntry.ToCString() );
171 aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() )" )
172 .arg( aPolylineName ).arg( aSalomeObjName );
174 aResList << QString( "%1.SetGeomObjectEntry( \"%2\" )" )
175 .arg( aPolylineName ).arg( aGeomObjectEntry.ToCString() );
181 NCollection_Sequence<TCollection_AsciiString> aSectNames;
182 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
183 NCollection_Sequence<bool> aSectClosures;
184 GetSections( aSectNames, aSectTypes, aSectClosures );
186 for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
188 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
189 const SectionType& aSectType = aSectTypes.Value( i );
190 bool aSectClosure = aSectClosures.Value( i );
192 aResList << QString( "%1.AddSection( \"%2\", %3, %4 )" ).arg( aPolylineName )
193 .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
195 HYDROData_IPolyline::PointsList aSectPointsList = GetPoints( i - 1 );
196 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
198 const Point& aSectPoint = aSectPointsList.Value( k );
200 QString anXStr = QString::number( aSectPoint.X(), 'f', 2 );
201 QString anYStr = QString::number( aSectPoint.Y(), 'f', 2 );
202 aResList << QString( "%1.AddPoint( %2, gp_XY( %3, %4 ) )" ).arg( aPolylineName )
203 .arg( i - 1 ).arg( anXStr ).arg( anYStr );
207 aResList << QString( "" );
208 aResList << QString( "%1.Update()" ).arg( aPolylineName );
209 aResList << QString( "" );
214 QVariant HYDROData_PolylineXY::GetDataVariant()
216 QPainterPath aPath = GetPainterPath();
219 aVarData.setValue<QPainterPath>( aPath );
224 QColor HYDROData_PolylineXY::DefaultWireColor()
226 return QColor( Qt::black );
229 bool HYDROData_PolylineXY::ImportFromGeomIOR( const TCollection_AsciiString& theIOR )
234 if ( theIOR.IsEmpty() )
237 TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() );
238 if ( aShape.IsNull() )
241 return ImportShape( aShape, false, NULL );
245 void HYDROData_PolylineXY::SetGeomObjectEntry( const TCollection_AsciiString& theEntry )
247 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), theEntry );
250 TCollection_AsciiString HYDROData_PolylineXY::GetGeomObjectEntry() const
252 TCollection_AsciiString aRes;
254 TDF_Label aLabel = myLab.FindChild( DataTag_GeomObjectEntry, false );
255 if ( !aLabel.IsNull() )
257 Handle(TDataStd_AsciiString) anAsciiStr;
258 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
259 aRes = anAsciiStr->Get();
265 bool convertEdgeToSection( const TopoDS_Edge& theEdge,
266 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
267 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
268 NCollection_Sequence<bool>& theSectClosures,
269 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
271 bool IsInterpolationAllowed,
272 double theDeflection )
274 Standard_Real aFirst = 0.0, aLast = 0.0;
275 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
276 if ( anEdgeGeomCurve.IsNull() )
279 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
280 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
282 HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
283 HYDROData_PolylineXY::PointsList aPointsList;
285 if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
287 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
289 gp_Pnt aFirstPoint, aLastPoint;
290 aGeomLine->D0( aFirst, aFirstPoint );
291 aGeomLine->D0( aLast, aLastPoint );
293 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
294 aPointsList.Append( aSectFirstPoint );
296 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
297 aPointsList.Append( aSectLastPoint );
299 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
301 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
303 BRepAdaptor_Curve anAdaptorCurve( theEdge );
304 GCPnts_QuasiUniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
305 //GCPnts_UniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
307 int aNbPoints = aDiscrete.NbPoints();
309 // Decrease the number of imported poles because of last one
310 // pole is the closing point which are the start point
311 if ( anIsEdgeClosed ) aNbPoints--;
313 for ( int i = 1; i <= aNbPoints; ++i )
315 const gp_Pnt& aPoint = aDiscrete.Value( i );
317 HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
318 aPointsList.Append( aSectPoint );
323 // Other curve types are not supported
327 if ( aPointsList.IsEmpty() )
330 theSectNames.Append( aSectName );
331 theSectTypes.Append( aSectionType );
332 theSectClosures.Append( anIsEdgeClosed );
333 theSectPoints.Append( aPointsList );
339 bool convertEdgesToSections( const TopoDS_Edge& theEdge,
340 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
341 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
342 NCollection_Sequence<bool>& theSectClosures,
343 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
345 bool IsInterpolationAllowed,
346 double theDeflection,
347 const Handle( HYDROData_PolylineXY )& theOldPolyline )
349 DEBTRACE("convertEdgesToSections")
350 Standard_Real aFirst = 0.0, aLast = 0.0;
351 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
352 if ( anEdgeGeomCurve.IsNull() )
355 bool isPrevious = (theSectTypes.Size() > 0);
356 DEBTRACE("nb sections: " << theSectTypes.Size());
357 HYDROData_PolylineXY::SectionType prevSectType = HYDROData_PolylineXY::SECTION_SPLINE;;
358 HYDROData_PolylineXY::PointsList prevPointList;
359 bool isPrevClosed = true;
362 prevSectType = theSectTypes.Last();
363 prevPointList = theSectPoints.Last();
364 isPrevClosed = theSectClosures.Last();
367 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
368 anIsEdgeClosed &= IsCanBeClosed; // on split, resulting edges are normally not closed...
369 HYDROData_PolylineXY::SectionType aSectionType ;
370 if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
372 aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
374 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
376 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
380 // Other curve types are not supported
384 bool isNewSection = !isPrevious || isPrevClosed || anIsEdgeClosed || prevSectType != aSectionType;
385 DEBTRACE(isNewSection <<": " << !isPrevious << " " << isPrevClosed << " " << anIsEdgeClosed << " " << (prevSectType != aSectionType));
387 HYDROData_PolylineXY::PointsList aPointsList;
390 aPointsList = prevPointList;
393 if( aSectionType == HYDROData_PolylineXY::SECTION_POLYLINE )
395 DEBTRACE("SECTION_POLYLINE");
396 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
398 gp_Pnt aFirstPoint, aLastPoint;
399 aGeomLine->D0( aFirst, aFirstPoint );
400 aGeomLine->D0( aLast, aLastPoint );
401 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
402 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
405 if (aSectFirstPoint == prevPointList.Last())
407 DEBTRACE("points shared: a");//aPointsList.Append( aSectFirstPoint );
408 aPointsList.Append( aSectLastPoint );
410 else if (aSectLastPoint == prevPointList.Last())
412 DEBTRACE("points shared: b");//aPointsList.Append( aSectLastPoint );
413 aPointsList.Append( aSectFirstPoint );
415 else if (aSectFirstPoint == prevPointList.First())
417 DEBTRACE("points shared: c");//aPointsList.Prepend( aSectFirstPoint );
418 aPointsList.Prepend( aSectLastPoint );
420 else if (aSectLastPoint == prevPointList.First())
422 DEBTRACE("points shared: d");//aPointsList.Prepend( aSectLastPoint );
423 aPointsList.Prepend( aSectFirstPoint );
427 DEBTRACE("no point shared")
428 isNewSection = true; // no point shared, new section
430 aPointsList.Append( aSectFirstPoint );
431 aPointsList.Append( aSectLastPoint );
436 DEBTRACE("new section");
437 aPointsList.Append( aSectFirstPoint );
438 aPointsList.Append( aSectLastPoint );
441 else // aSectionType == HYDROData_PolylineXY::SECTION_SPLINE
443 DEBTRACE("SECTION_SPLINE");
447 BRepAdaptor_Curve anAdaptorCurve(theEdge);
448 if (theOldPolyline.IsNull()) // --- no previous polyline: build a set of points from scratch for the spline
450 GCPnts_QuasiUniformDeflection aDiscrete(anAdaptorCurve, theDeflection);
452 int aNbPoints = aDiscrete.NbPoints();
454 // Decrease the number of imported poles because of last one
455 // pole is the closing point which are the start point
459 for (int i = 1; i <= aNbPoints; ++i)
461 const gp_Pnt& aPoint = aDiscrete.Value(i);
462 HYDROData_PolylineXY::Point aSectPoint(aPoint.X(), aPoint.Y());
463 aPointsList.Append(aSectPoint);
466 gp_Pnt endPts[] = {gp_Pnt(aPointsList.First().X(),aPointsList.First().Y(), 0),
467 gp_Pnt(aPointsList.Last().X(),aPointsList.Last().Y(), 0) };
468 DEBTRACE("curve start: "<< endPts[0].X() << " " << endPts[0].Y());
469 DEBTRACE("curve end: "<< endPts[1].X() << " " << endPts[1].Y());
471 else // --- split of a previous polyline: try to retrieve old sets of points and add intersection points
473 const gp_Pnt aEndPs[] = { anAdaptorCurve.Value(anAdaptorCurve.FirstParameter()).XYZ(),
474 anAdaptorCurve.Value(anAdaptorCurve.LastParameter()).XYZ() };
475 double midPar = (anAdaptorCurve.LastParameter() + anAdaptorCurve.FirstParameter())/2;
477 anAdaptorCurve.D0(midPar, midPnt);
478 DEBTRACE("curve first point: " << aEndPs[0].X() << " " << aEndPs[0].Y() << " " << aEndPs[0].Z());
479 DEBTRACE("curve last point: " << aEndPs[1].X() << " " << aEndPs[1].Y() << " " << aEndPs[1].Z());
480 DEBTRACE("curve mid point: " << midPnt.X() << " " << midPnt.Y() << " " << midPnt.Z());
482 std::vector<TopoDS_Wire> aCurves;
483 HYDROData_PolylineOperator::GetWires(theOldPolyline, aCurves);
485 int nbSections = theOldPolyline->NbSections();
486 DEBTRACE("nbSections: "<< nbSections << ", nbCurves: " << aCurves.size() );
487 for (int isec = 0; isec < nbSections; isec++)
489 DEBTRACE("section: "<< isec);
490 bool isOldSectionclosed = theOldPolyline->IsClosedSection(isec);
491 TopoDS_Wire aWire = aCurves[isec]; // we suppose sections and wires are in the same order
492 TopExp_Explorer anExp(aWire, TopAbs_EDGE);
493 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current()); // the first is OK: only one normally with splines
494 BRepAdaptor_Curve adaptorOldCurve(anEdge);
495 double pfirst = adaptorOldCurve.FirstParameter();
496 double plast = adaptorOldCurve.LastParameter();
497 DEBTRACE("previous curve first last : "<< pfirst << " " << plast);
498 double p[3] = {-1, -1};
499 double d0= ProjectPointToCurve(aEndPs[0].XYZ(), adaptorOldCurve,p[0]);
500 double d1= ProjectPointToCurve(aEndPs[1].XYZ(), adaptorOldCurve,p[1]);
501 double d2= ProjectPointToCurve(midPnt.XYZ(), adaptorOldCurve, p[2]);
502 DEBTRACE("d0: "<<d0<<" d1: "<<d1<<" d2: "<<d2<<" p0: "<<p[0]<<" p1: "<<p[1]<<" p2: "<<p[2]);
503 if ((d0 < 1.e-3) and (d1 < 1.e-3) and (d2 < 1.e-3)) // we got the good old curve (and the good section)
508 if (! isOldSectionclosed) // no need to check first and last points on an open curve
514 else // old section closed: check if we use first or last points...
516 if((pmin < pmax) and((abs(pmin - pfirst)> 1.e-3) and (abs(pmax - plast) >1.e-3))) // internal points forward
518 else if ((pmin > pmax) and((abs(pmin - plast)> 1.e-3) and (abs(pmax - pfirst) >1.e-3))) // internal points reverse
524 else if ((abs(pmin - plast) <1.e-3) and (p[2] < pmax)) // forward, replace pmin par pfirst
526 else if ((abs(pmin - plast) <1.e-3) and (p[2] > pmax)) // reverse
532 else if ((abs(pmax - pfirst) <1.e-3) and (p[2] < pmin)) // reverse
538 else if ((abs(pmax - pfirst) <1.e-3) and (p[2] > pmin)) // forward, replace pmax par plast
541 HYDROData_PolylineXY::Point aFirstPoint, aLastPoint;
544 aFirstPoint = HYDROData_PolylineXY::Point(aEndPs[0].X(), aEndPs[0].Y());
545 aLastPoint = HYDROData_PolylineXY::Point(aEndPs[1].X(), aEndPs[1].Y());
549 aFirstPoint = HYDROData_PolylineXY::Point(aEndPs[1].X(), aEndPs[1].Y());
550 aLastPoint = HYDROData_PolylineXY::Point(aEndPs[0].X(), aEndPs[0].Y());
552 aPointsList.Append(aFirstPoint);
554 HYDROData_PolylineXY::PointsList aSectPoints = theOldPolyline->GetPoints(isec, false);
555 int nbPoints = aSectPoints.Length();
557 for (int i=1; i<=nbPoints; i++)
559 HYDROData_PolylineXY::Point aPoint = aSectPoints.Value(i);
560 gp_XYZ p(aPoint.X(), aPoint.Y(), 0);
562 double d = ProjectPointToCurve(p, adaptorOldCurve, param);
563 if ((param > pmin) and (param < pmax))
565 DEBTRACE("param: " << param);
566 aPointsList.Append(aPoint);
570 for (int i=nbPoints; i>0; i--)
572 HYDROData_PolylineXY::Point aPoint = aSectPoints.Value(i);
573 gp_XYZ p(aPoint.X(), aPoint.Y(), 0);
575 double d = ProjectPointToCurve(p, adaptorOldCurve, param);
576 if ((param > pmin) and (param < pmax))
578 DEBTRACE("param: " << param);
579 aPointsList.Append(aPoint);
583 aPointsList.Append(aLastPoint);
590 if ( aPointsList.IsEmpty() )
593 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
596 DEBTRACE("isNewSection");
597 theSectNames.Append( aSectName );
598 theSectTypes.Append( aSectionType );
599 theSectClosures.Append( anIsEdgeClosed );
600 theSectPoints.Append( aPointsList );
604 DEBTRACE("sameSection");
605 theSectPoints.SetValue(theSectPoints.Length(), aPointsList);
611 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape,
612 bool IsInterpolationAllowed,
613 const Handle( HYDROData_PolylineXY )& theOldPolyline,
614 bool IsClosureAllowed,
615 double theDeviation )
617 DEBTRACE("ImportShape");
618 if ( theShape.IsNull() )
621 std::string brepName = this->GetName().toStdString();
623 BRepTools::Write( theShape, brepName.c_str() );
627 bool anIsCanBeImported = false;
629 NCollection_Sequence<TCollection_AsciiString> aSectNames;
630 NCollection_Sequence<SectionType> aSectTypes;
631 NCollection_Sequence<bool> aSectClosures;
632 NCollection_Sequence<PointsList> aSectPoints;
634 if ( theShape.ShapeType() == TopAbs_EDGE )
636 DEBTRACE("TopAbs_EDGE");
637 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
638 // anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes,
639 // aSectClosures, aSectPoints, true, IsInterpolationAllowed, theDeviation );
640 anIsCanBeImported = convertEdgesToSections( anEdge, aSectNames, aSectTypes, aSectClosures,
641 aSectPoints, IsClosureAllowed, IsInterpolationAllowed,
642 theDeviation, theOldPolyline );
644 else if ( theShape.ShapeType() == TopAbs_WIRE )
646 DEBTRACE("TopAbs_WIRE");
647 TopTools_SequenceOfShape anEdges;
648 HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
650 anIsCanBeImported = !anEdges.IsEmpty();
651 for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
653 TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
654 anIsCanBeImported = convertEdgesToSections( aWireEdge, aSectNames, aSectTypes, aSectClosures,
655 aSectPoints, IsClosureAllowed, IsInterpolationAllowed,
656 theDeviation, theOldPolyline );
660 if ( anIsCanBeImported )
662 for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
664 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
665 const SectionType& aSectType = aSectTypes.Value( i );
666 bool anIsSectionClosed = aSectClosures.Value( i );
667 const PointsList& aSectPointsList = aSectPoints( i );
669 AddSection( aSectName, aSectType, anIsSectionClosed );
670 SetPoints( i - 1, aSectPointsList );
675 TopoDS_Shape aShape = theShape;
677 if ( theShape.ShapeType() == TopAbs_EDGE )
679 // We make the wire from incoming edge because of other algorithms
680 // are waiting at least the wire from polyline
681 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
682 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
684 if ( aMakeWire.IsDone() )
685 aShape = aMakeWire.Wire();
688 gp_Pln aPlane( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
689 BRepBuilderAPI_MakeFace aMakeFace( aPlane );
691 BRepOffsetAPI_NormalProjection aProj( aMakeFace.Face() );
694 TopoDS_Shape aResult;
696 aResult = aProj.Shape();
701 setEditable( anIsCanBeImported );
706 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
707 const bool& theIsClosed,
708 const NCollection_Sequence<gp_XYZ>& thePoints )
711 if( theType == SECTION_POLYLINE )
713 int aNbPoints = thePoints.Length();
714 BRepBuilderAPI_MakePolygon aMakeWire;
715 for ( int i = 1, n = aNbPoints; i <= n ; ++i )
717 gp_XYZ aPoint = thePoints.Value( i );
718 gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
719 aMakeWire.Add( aPnt );
721 if( theIsClosed && ( aNbPoints > 2 ) )
724 if ( aMakeWire.IsDone() )
725 aWire = aMakeWire.Wire();
727 else //if( theType == PolylineSection::SECTION_SPLINE )
729 BRepBuilderAPI_MakeWire aMakeWire;
731 if ( thePoints.Size() > 1 )
733 Handle(Geom_BSplineCurve) aCurve =
734 HYDROData_BSplineOperation::ComputeCurve( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
736 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aCurve ).Edge();
737 aMakeWire.Add( anEdge );
740 if ( aMakeWire.IsDone() )
747 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
748 const SectionType& theType,
749 const bool& theIsClosed,
750 const NCollection_Sequence<gp_XYZ>& thePoints )
752 if ( thePoints.IsEmpty() )
755 if ( theType == SECTION_POLYLINE )
757 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
758 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
760 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
762 const gp_XYZ& aSectPoint = thePoints.Value( i );
764 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
768 thePath.closeSubpath();
772 Handle(Geom_BSplineCurve) aCurve =
773 HYDROData_BSplineOperation::ComputeCurve( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
774 HYDROData_BSplineOperation::ComputePath( aCurve, thePath );
778 void HYDROData_PolylineXY::Update()
782 // If polyline is not editable we no need to update it wire
787 HYDROData_IPolyline::Update();
789 NCollection_Sequence<TCollection_AsciiString> aSectNames;
790 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
791 NCollection_Sequence<bool> aSectClosures;
792 GetSections( aSectNames, aSectTypes, aSectClosures );
794 //BRepBuilderAPI_MakeWire aMakeWire;
796 TopTools_ListOfShape aSectionWiresList;
798 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
800 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
801 SectionType aSectionType = aSectTypes.Value( aSectionId );
802 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
804 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
805 if ( aSectPointsList.IsEmpty() )
808 NCollection_Sequence<gp_XYZ> aPoints;
809 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
811 const Point& aSectPoint = aSectPointsList.Value( i );
813 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
814 aPoints.Append( aPoint );
817 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
818 if ( !aSectionWire.IsNull() ) {
819 aSectionWiresList.Append( aSectionWire );
820 //aMakeWire.Add( aSectionWire );
823 // all input wires in the <aSectionWiresList>
824 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
825 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
826 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
827 for(;it.More();it.Next())
829 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
830 for(;it2.More();it2.Next())
831 aSeqEdges->Append(it2.Current());
835 TopoDS_Compound aCmp;
836 TopoDS_Shape aResult;
837 aBB.MakeCompound(aCmp);
838 if(aSeqEdges->Length() >1)
840 ShapeAnalysis_FreeBounds::ConnectEdgesToWires( aSeqEdges, 1E-5, Standard_True, aSeqWires );
842 if( aSeqWires->Length()==1 )
843 aResult = aSeqWires->Value( 1 );
846 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
848 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
854 else if (aSeqEdges->Length() == 1)
856 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
858 aResult = mkWire.Wire();
864 bool HYDROData_PolylineXY::IsHas2dPrs() const
869 bool HYDROData_PolylineXY::IsEditable() const
871 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
874 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
876 if ( !theIsEditable )
877 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
879 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
883 * Returns true if polyline is closed
885 bool HYDROData_PolylineXY::IsClosed(const bool theIsSimpleCheck) const
887 //DEBTRACE("IsClosed " << theIsSimpleCheck << " " << GetName());
888 bool anIsClosed = false;
890 TopoDS_Shape aShape = GetShape();
894 TopTools_SequenceOfShape aWires;
895 HYDROData_ShapesTool::ExploreShapeToShapes(aShape, TopAbs_WIRE, aWires);
897 int aNbWires = aWires.Length();
898 if (theIsSimpleCheck)
900 anIsClosed = aNbWires > 0;
901 for (int i = 1; i <= aNbWires && anIsClosed; ++i)
903 const TopoDS_Shape& aWire = aWires.Value(i);
904 anIsClosed = BRep_Tool::IsClosed(aWire);
910 anIsClosed = BRep_Tool::IsClosed(aWires.First());
913 //DEBTRACE("aNbWires " << aNbWires);
914 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
915 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
916 for (int i = 1; i <= aNbWires; ++i)
918 const TopoDS_Shape& aWire = aWires.Value(i);
919 TopExp_Explorer it2(aWire, TopAbs_EDGE);
920 for (; it2.More(); it2.Next())
921 aSeqEdges->Append(it2.Current());
923 if (aSeqEdges->Length() > 1)
925 //DEBTRACE(aSeqEdges->Length());
926 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires);
927 if (aSeqWires->Length() == 1)
929 //DEBTRACE(aSeqWires->Length());
930 const TopoDS_Wire& aPolylineWire = TopoDS::Wire(aSeqWires->Value(1));
931 anIsClosed = BRep_Tool::IsClosed(aPolylineWire);
940 int HYDROData_PolylineXY::GetNbConnectedWires(Handle(TopTools_HSequenceOfShape)& aConnectedWires) const
942 TopoDS_Shape aShape = GetShape();
945 int aNbconnectedWires = 0;
946 TopTools_SequenceOfShape aWires;
947 HYDROData_ShapesTool::ExploreShapeToShapes(aShape, TopAbs_WIRE, aWires);
948 int aNbWires = aWires.Length();
951 aNbconnectedWires = aNbWires;
952 aConnectedWires->Append(aWires.First());
956 //DEBTRACE("aNbWires " << aNbWires);
957 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
958 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
959 for (int i = 1; i <= aNbWires; ++i)
961 const TopoDS_Shape& aWire = aWires.Value(i);
962 TopExp_Explorer it2(aWire, TopAbs_EDGE);
963 for (; it2.More(); it2.Next())
964 aSeqEdges->Append(it2.Current());
966 if (aSeqEdges->Length() > 1)
968 //DEBTRACE(aSeqEdges->Length());
969 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires);
971 aConnectedWires = aSeqWires;
972 aNbconnectedWires = aConnectedWires->Length();
973 DEBTRACE("aNbconnectedWires " << aNbconnectedWires);
975 return aNbconnectedWires;
978 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
979 const int thePointIndex ) const
981 double aResDistance = -1;
982 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
985 if ( thePointIndex == 0 )
988 SectionType aSectionType = GetSectionType( theSectionIndex );
989 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
990 PointsList aSectPointsList = GetPoints( theSectionIndex );
991 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
994 if ( aSectionType == SECTION_POLYLINE )
998 Point aPrevPoint = aSectPointsList.Value( 1 );
999 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
1001 const Point& aSectPoint = aSectPointsList.Value( i );
1002 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
1003 aPrevPoint = aSectPoint;
1005 if ( thePointIndex == i - 1 )
1011 gp_XYZ aPointToTest;
1013 int aSectNbPoints = aSectPointsList.Size();
1014 NCollection_Sequence<gp_XYZ> aPoints;
1015 for( int i = 1 ; i <= aSectNbPoints; ++i )
1017 const Point& aSectPoint = aSectPointsList.Value( i );
1019 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1020 aPoints.Append( aPoint );
1022 if ( thePointIndex == i - 1 )
1023 aPointToTest = aPoint;
1026 Handle(Geom_BSplineCurve) aCurve =
1027 HYDROData_BSplineOperation::ComputeCurve( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
1029 Quantity_Parameter aFirstParam = aCurve->FirstParameter();
1030 Quantity_Parameter aSecondParam = aCurve->LastParameter();
1032 if ( thePointIndex != aSectNbPoints - 1 )
1034 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aCurve );
1035 aSecondParam = aProject.LowerDistanceParameter();
1038 GeomAdaptor_Curve anAdap( aCurve );
1040 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
1043 return aResDistance;
1046 int HYDROData_PolylineXY::NbSections() const
1048 Handle(TDataStd_ExtStringList) aNamesList;
1049 Handle(TDataStd_IntegerList) aTypesList;
1050 Handle(TDataStd_BooleanList) aClosuresList;
1051 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1053 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
1056 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
1057 const SectionType theSectionType,
1058 const bool theIsClosed )
1060 Handle(TDataStd_ExtStringList) aNamesList;
1061 Handle(TDataStd_IntegerList) aTypesList;
1062 Handle(TDataStd_BooleanList) aClosuresList;
1063 getSectionsLists( aNamesList, aTypesList, aClosuresList );
1065 TCollection_ExtendedString aSectName( theSectName );
1066 if ( aSectName.Length() <= 0 )
1067 aSectName = getUniqueSectionName( aNamesList );
1069 aNamesList->Append( aSectName );
1070 aTypesList->Append( theSectionType );
1071 aClosuresList->Append( theIsClosed );
1076 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
1078 TCollection_AsciiString aResName;
1080 Handle(TDataStd_ExtStringList) aNamesList;
1081 Handle(TDataStd_IntegerList) aTypesList;
1082 Handle(TDataStd_BooleanList) aClosuresList;
1083 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1084 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1087 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
1088 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
1090 if ( aNamesIter.More() )
1091 aResName = aNamesIter.Value();
1096 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
1097 const TCollection_AsciiString& theSectionName )
1099 Handle(TDataStd_ExtStringList) aNamesList;
1100 Handle(TDataStd_IntegerList) aTypesList;
1101 Handle(TDataStd_BooleanList) aClosuresList;
1102 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1103 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1106 TDataStd_ListOfExtendedString anOldNamesList;
1107 anOldNamesList = aNamesList->List();
1109 // Refill the existing list
1110 aNamesList->Clear();
1112 TCollection_ExtendedString aNewSectName = theSectionName;
1114 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
1115 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
1116 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
1119 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
1121 Handle(TDataStd_ExtStringList) aNamesList;
1122 Handle(TDataStd_IntegerList) aTypesList;
1123 Handle(TDataStd_BooleanList) aClosuresList;
1124 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1125 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
1126 return SECTION_POLYLINE;
1128 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
1129 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
1131 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
1134 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
1135 const SectionType theSectionType )
1137 Handle(TDataStd_ExtStringList) aNamesList;
1138 Handle(TDataStd_IntegerList) aTypesList;
1139 Handle(TDataStd_BooleanList) aClosuresList;
1140 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1141 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
1144 TColStd_ListOfInteger anOldTypesList;
1145 anOldTypesList = aTypesList->List();
1147 // Refill the existing list
1148 aTypesList->Clear();
1150 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
1151 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
1152 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
1157 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
1159 Handle(TDataStd_ExtStringList) aNamesList;
1160 Handle(TDataStd_IntegerList) aTypesList;
1161 Handle(TDataStd_BooleanList) aClosuresList;
1162 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1163 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
1166 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
1167 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
1169 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
1172 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
1173 const bool theIsClosed )
1175 Handle(TDataStd_ExtStringList) aNamesList;
1176 Handle(TDataStd_IntegerList) aTypesList;
1177 Handle(TDataStd_BooleanList) aClosuresList;
1178 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1179 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
1182 TDataStd_ListOfByte anOldClosuresList;
1183 anOldClosuresList = aClosuresList->List();
1185 // Refill the existing list
1186 aClosuresList->Clear();
1188 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
1189 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
1190 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
1195 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
1196 NCollection_Sequence<SectionType>& theSectTypes,
1197 NCollection_Sequence<bool>& theSectClosures ) const
1199 theSectNames.Clear();
1200 theSectTypes.Clear();
1201 theSectClosures.Clear();
1205 const_cast<HYDROData_PolylineXY*>( this )->Interpolate();
1208 Handle(TDataStd_ExtStringList) aNamesList;
1209 Handle(TDataStd_IntegerList) aTypesList;
1210 Handle(TDataStd_BooleanList) aClosuresList;
1211 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1212 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
1215 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
1216 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
1217 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
1218 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
1219 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
1221 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
1222 SectionType aSectType = (SectionType)aTypesIter.Value();
1223 bool aSectClosures = aClosuresIter.Value();
1225 theSectNames.Append( aSectName );
1226 theSectTypes.Append( aSectType );
1227 theSectClosures.Append( aSectClosures );
1231 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
1233 Handle(TDataStd_ExtStringList) aNamesList;
1234 Handle(TDataStd_IntegerList) aTypesList;
1235 Handle(TDataStd_BooleanList) aClosuresList;
1236 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1237 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1240 if ( aNamesList->Extent() == 1 )
1242 removeSectionsLists();
1243 removePointsLists();
1247 TDataStd_ListOfExtendedString anOldNamesList;
1248 anOldNamesList = aNamesList->List();
1250 TColStd_ListOfInteger anOldTypesList;
1251 anOldTypesList = aTypesList->List();
1253 TDataStd_ListOfByte anOldClosuresList;
1254 anOldClosuresList = aClosuresList->List();
1256 // Refill the existing lists
1257 aNamesList->Clear();
1258 aTypesList->Clear();
1259 aClosuresList->Clear();
1261 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
1262 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
1263 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
1264 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
1265 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
1267 if ( i == theSectionIndex )
1268 continue; // skip index to remove
1270 aNamesList->Append( aNamesIter.Value() );
1271 aTypesList->Append( aTypesIter.Value() );
1272 aClosuresList->Append( (bool)aClosuresIter.Value() );
1275 // Remove points that belongs to removed section
1276 removePointsLists( theSectionIndex );
1282 void HYDROData_PolylineXY::RemoveSections()
1284 removeSectionsLists();
1285 removePointsLists();
1289 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
1290 const Point& thePoint,
1291 const int thePointIndex )
1293 Handle(TDataStd_RealList) aListX, aListY;
1294 getPointsLists( theSectionIndex, aListX, aListY );
1296 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
1298 aListX->Append( thePoint.X() );
1299 aListY->Append( thePoint.Y() );
1303 TColStd_ListOfReal anOldListX;
1304 anOldListX = aListX->List();
1306 TColStd_ListOfReal anOldListY;
1307 anOldListY = aListY->List();
1309 // Refill the existing lists
1313 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1314 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1315 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1317 double aCoordX = anIterX.Value();
1318 double aCoordY = anIterY.Value();
1320 if ( i == thePointIndex )
1322 // Insert our new point
1323 aListX->Append( thePoint.X() );
1324 aListY->Append( thePoint.Y() );
1327 aListX->Append( aCoordX );
1328 aListY->Append( aCoordY );
1335 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
1336 const Point& thePoint,
1337 const int thePointIndex )
1339 Handle(TDataStd_RealList) aListX, aListY;
1340 getPointsLists( theSectionIndex, aListX, aListY );
1342 if ( thePointIndex < 0 )
1344 aListX->Prepend( thePoint.X() );
1345 aListY->Prepend( thePoint.Y() );
1347 else if ( thePointIndex >= aListX->Extent() )
1349 aListX->Append( thePoint.X() );
1350 aListY->Append( thePoint.Y() );
1354 TColStd_ListOfReal anOldListX;
1355 anOldListX = aListX->List();
1357 TColStd_ListOfReal anOldListY;
1358 anOldListY = aListY->List();
1360 // Refill the existing lists
1364 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1365 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1366 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1368 double aCoordX = anIterX.Value();
1369 double aCoordY = anIterY.Value();
1371 if ( i == thePointIndex )
1373 // Insert our new point instead of old one
1374 aCoordX = thePoint.X();
1375 aCoordY = thePoint.Y();
1378 aListX->Append( aCoordX );
1379 aListY->Append( aCoordY );
1386 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
1387 const PointsList& thePoints )
1389 Handle(TDataStd_RealList) aListX, aListY;
1390 getPointsLists( theSectionIndex, aListX, aListY );
1395 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1397 const Point& aPoint = thePoints.Value( i );
1398 aListX->Append( aPoint.X() );
1399 aListY->Append( aPoint.Y() );
1403 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
1404 const int thePointIndex )
1406 Handle(TDataStd_RealList) aListX, aListY;
1407 getPointsLists( theSectionIndex, aListX, aListY, false );
1408 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1411 if ( aListX->Extent() == 1 )
1413 removePointsLists( theSectionIndex );
1417 TColStd_ListOfReal anOldListX;
1418 anOldListX = aListX->List();
1420 TColStd_ListOfReal anOldListY;
1421 anOldListY = aListY->List();
1423 // Refill the existing lists
1427 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1428 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1429 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1431 if ( i == thePointIndex )
1432 continue; // skip index to remove
1434 aListX->Append( anIterX.Value() );
1435 aListY->Append( anIterY.Value() );
1442 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex, bool IsConvertToGlobal ) const
1444 PointsList aResList;
1448 const_cast<HYDROData_PolylineXY*>( this )->Interpolate();
1451 Handle(TDataStd_RealList) aListX, aListY;
1452 getPointsLists( theSectionIndex, aListX, aListY, false );
1453 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1456 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
1457 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
1458 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
1459 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
1461 Point aPoint( anIterX.Value(), anIterY.Value() );
1462 if (IsConvertToGlobal)
1463 aDoc->Transform( aPoint, false );
1464 aResList.Append( aPoint );
1470 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
1474 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1475 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1476 NCollection_Sequence<bool> aSectClosures;
1477 GetSections( aSectNames, aSectTypes, aSectClosures );
1479 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1481 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1482 SectionType aSectionType = aSectTypes.Value( aSectionId );
1483 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1485 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1486 if ( aSectPointsList.IsEmpty() )
1489 NCollection_Sequence<gp_XYZ> aPoints;
1490 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1492 const Point& aSectPoint = aSectPointsList.Value( i );
1494 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1495 aPoints.Append( aPoint );
1498 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );
1504 void HYDROData_PolylineXY::UpdateLocalCS( double theDx, double theDy )
1506 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1507 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1508 NCollection_Sequence<bool> aSectClosures;
1509 GetSections( aSectNames, aSectTypes, aSectClosures );
1511 gp_XY aDelta( theDx, theDy );
1512 for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ )
1514 PointsList aPoints = GetPoints( i );
1515 for( int j = 1, n = aPoints.Size(); j <= n; ++j )
1517 Point& aPoint = aPoints.ChangeValue( j );
1520 SetPoints( i, aPoints );
1525 void HYDROData_PolylineXY::Transform( const QTransform& theTrsf )
1527 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1528 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1529 NCollection_Sequence<bool> aSectClosures;
1530 GetSections( aSectNames, aSectTypes, aSectClosures );
1532 for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ ) {
1533 PointsList aPoints = GetPoints( i );
1534 for( int j = 1, n = aPoints.Size(); j <= n; ++j ) {
1535 Point& aPoint = aPoints.ChangeValue( j );
1537 QPointF aTrsfPoint = theTrsf.map( QPointF( aPoint.X(), aPoint.Y() ) );
1539 aPoint.SetX( aTrsfPoint.x() );
1540 aPoint.SetY( aTrsfPoint.y() );
1542 SetPoints( i, aPoints );
1548 bool HYDROData_PolylineXY::IsCustom() const
1550 if( myIsInCustomFlag )
1553 bool isNull = GetShape().IsNull();
1556 HYDROData_PolylineXY* aThat = const_cast<HYDROData_PolylineXY*>( this );
1557 aThat->myIsInCustomFlag = true;
1558 for( int i=0, n=NbSections(); i<n; i++ )
1559 aNbPoints += NbPoints( i );
1560 aThat->myIsInCustomFlag = false;
1562 return !isNull && aNbPoints == 0;
1565 bool HYDROData_PolylineXY::GetIsInCustomFlag() const
1567 return myIsInCustomFlag;
1570 void HYDROData_PolylineXY::SetIsInCustomFlag( bool theValue )
1572 myIsInCustomFlag = theValue;
1575 void HYDROData_PolylineXY::Interpolate()
1577 ImportShape( GetShape(), true, NULL );