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_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline)
131 HYDROData_PolylineXY::HYDROData_PolylineXY()
132 : HYDROData_IPolyline(),
133 myIsInCustomFlag( false )
137 HYDROData_PolylineXY::~HYDROData_PolylineXY()
141 QStringList HYDROData_PolylineXY::DumpToPython( const QString& thePyScriptPath,
142 MapOfTreatedObjects& theTreatedObjects ) const
144 QStringList aResList = dumpObjectCreation( theTreatedObjects );
145 QString aPolylineName = GetObjPyName();
147 // Set the wire color
148 QStringList aWireColorDef;
150 QColor aWireColor = GetWireColor();
151 setPythonObjectColor( aWireColorDef, aWireColor, DefaultWireColor(), "SetWireColor" );
153 if ( !aWireColorDef.isEmpty() )
155 aResList << aWireColorDef;
156 aResList << QString( "" );
159 bool anIsEditable = IsEditable();
162 // If polyline is not editable we try to import the shape from geom
163 TCollection_AsciiString aGeomObjectEntry = GetGeomObjectEntry();
164 if ( !aGeomObjectEntry.IsEmpty() )
166 QString aSalomeObjName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "polyline_sobj" );
167 aResList << QString( "%1 = salome.myStudy.FindObjectID( \"%2\" )" )
168 .arg( aSalomeObjName ).arg( aGeomObjectEntry.ToCString() );
170 aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() )" )
171 .arg( aPolylineName ).arg( aSalomeObjName );
173 aResList << QString( "%1.SetGeomObjectEntry( \"%2\" )" )
174 .arg( aPolylineName ).arg( aGeomObjectEntry.ToCString() );
180 NCollection_Sequence<TCollection_AsciiString> aSectNames;
181 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
182 NCollection_Sequence<bool> aSectClosures;
183 GetSections( aSectNames, aSectTypes, aSectClosures );
185 for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
187 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
188 const SectionType& aSectType = aSectTypes.Value( i );
189 bool aSectClosure = aSectClosures.Value( i );
191 aResList << QString( "%1.AddSection( \"%2\", %3, %4 )" ).arg( aPolylineName )
192 .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
194 HYDROData_IPolyline::PointsList aSectPointsList = GetPoints( i - 1 );
195 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
197 const Point& aSectPoint = aSectPointsList.Value( k );
199 QString anXStr = QString::number( aSectPoint.X(), 'f', 2 );
200 QString anYStr = QString::number( aSectPoint.Y(), 'f', 2 );
201 aResList << QString( "%1.AddPoint( %2, gp_XY( %3, %4 ) )" ).arg( aPolylineName )
202 .arg( i - 1 ).arg( anXStr ).arg( anYStr );
206 aResList << QString( "" );
207 aResList << QString( "%1.Update()" ).arg( aPolylineName );
208 aResList << QString( "" );
213 QVariant HYDROData_PolylineXY::GetDataVariant()
215 QPainterPath aPath = GetPainterPath();
218 aVarData.setValue<QPainterPath>( aPath );
223 QColor HYDROData_PolylineXY::DefaultWireColor()
225 return QColor( Qt::black );
228 bool HYDROData_PolylineXY::ImportFromGeomIOR( const TCollection_AsciiString& theIOR )
233 if ( theIOR.IsEmpty() )
236 TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() );
237 if ( aShape.IsNull() )
240 return ImportShape( aShape, false, NULL );
244 void HYDROData_PolylineXY::SetGeomObjectEntry( const TCollection_AsciiString& theEntry )
246 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), theEntry );
249 TCollection_AsciiString HYDROData_PolylineXY::GetGeomObjectEntry() const
251 TCollection_AsciiString aRes;
253 TDF_Label aLabel = myLab.FindChild( DataTag_GeomObjectEntry, false );
254 if ( !aLabel.IsNull() )
256 Handle(TDataStd_AsciiString) anAsciiStr;
257 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
258 aRes = anAsciiStr->Get();
264 bool convertEdgeToSection( const TopoDS_Edge& theEdge,
265 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
266 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
267 NCollection_Sequence<bool>& theSectClosures,
268 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
270 bool IsInterpolationAllowed,
271 double theDeflection )
273 Standard_Real aFirst = 0.0, aLast = 0.0;
274 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
275 if ( anEdgeGeomCurve.IsNull() )
278 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
279 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
281 HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
282 HYDROData_PolylineXY::PointsList aPointsList;
284 if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
286 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
288 gp_Pnt aFirstPoint, aLastPoint;
289 aGeomLine->D0( aFirst, aFirstPoint );
290 aGeomLine->D0( aLast, aLastPoint );
292 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
293 aPointsList.Append( aSectFirstPoint );
295 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
296 aPointsList.Append( aSectLastPoint );
298 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
300 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
302 BRepAdaptor_Curve anAdaptorCurve( theEdge );
303 GCPnts_QuasiUniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
304 //GCPnts_UniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
306 int aNbPoints = aDiscrete.NbPoints();
308 // Decrease the number of imported poles because of last one
309 // pole is the closing point which are the start point
310 if ( anIsEdgeClosed ) aNbPoints--;
312 for ( int i = 1; i <= aNbPoints; ++i )
314 const gp_Pnt& aPoint = aDiscrete.Value( i );
316 HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
317 aPointsList.Append( aSectPoint );
322 // Other curve types are not supported
326 if ( aPointsList.IsEmpty() )
329 theSectNames.Append( aSectName );
330 theSectTypes.Append( aSectionType );
331 theSectClosures.Append( anIsEdgeClosed );
332 theSectPoints.Append( aPointsList );
338 bool convertEdgesToSections( const TopoDS_Edge& theEdge,
339 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
340 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
341 NCollection_Sequence<bool>& theSectClosures,
342 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
344 bool IsInterpolationAllowed,
345 double theDeflection,
346 const Handle( HYDROData_PolylineXY )& theOldPolyline )
348 //DEBTRACE("convertEdgesToSections")
349 Standard_Real aFirst = 0.0, aLast = 0.0;
350 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
351 if ( anEdgeGeomCurve.IsNull() )
354 bool isPrevious = (theSectTypes.Size() > 0);
355 //DEBTRACE("nb sections: " << theSectTypes.Size());
356 HYDROData_PolylineXY::SectionType prevSectType = HYDROData_PolylineXY::SECTION_SPLINE;;
357 HYDROData_PolylineXY::PointsList prevPointList;
358 bool isPrevClosed = true;
361 prevSectType = theSectTypes.Last();
362 prevPointList = theSectPoints.Last();
363 isPrevClosed = theSectClosures.Last();
366 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
367 anIsEdgeClosed &= IsCanBeClosed; // on split, resulting edges are normally not closed...
368 HYDROData_PolylineXY::SectionType aSectionType ;
369 if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
371 aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
373 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
375 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
379 // Other curve types are not supported
383 bool isNewSection = !isPrevious || isPrevClosed || anIsEdgeClosed || prevSectType != aSectionType;
384 //DEBTRACE(isNewSection <<": " << !isPrevious << " " << isPrevClosed << " " << anIsEdgeClosed << " " << (prevSectType != aSectionType));
386 HYDROData_PolylineXY::PointsList aPointsList;
389 aPointsList = prevPointList;
392 if( aSectionType == HYDROData_PolylineXY::SECTION_POLYLINE )
394 //DEBTRACE("SECTION_POLYLINE");
395 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
397 gp_Pnt aFirstPoint, aLastPoint;
398 aGeomLine->D0( aFirst, aFirstPoint );
399 aGeomLine->D0( aLast, aLastPoint );
400 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
401 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
404 if (aSectFirstPoint == prevPointList.Last())
406 //DEBTRACE("points shared: a");//aPointsList.Append( aSectFirstPoint );
407 aPointsList.Append( aSectLastPoint );
409 else if (aSectLastPoint == prevPointList.Last())
411 //DEBTRACE("points shared: b");//aPointsList.Append( aSectLastPoint );
412 aPointsList.Append( aSectFirstPoint );
414 else if (aSectFirstPoint == prevPointList.First())
416 //DEBTRACE("points shared: c");//aPointsList.Prepend( aSectFirstPoint );
417 aPointsList.Prepend( aSectLastPoint );
419 else if (aSectLastPoint == prevPointList.First())
421 //DEBTRACE("points shared: d");//aPointsList.Prepend( aSectLastPoint );
422 aPointsList.Prepend( aSectFirstPoint );
426 //DEBTRACE("no point shared")
427 isNewSection = true; // no point shared, new section
429 aPointsList.Append( aSectFirstPoint );
430 aPointsList.Append( aSectLastPoint );
435 //DEBTRACE("new section");
436 aPointsList.Append( aSectFirstPoint );
437 aPointsList.Append( aSectLastPoint );
440 else // aSectionType == HYDROData_PolylineXY::SECTION_SPLINE
442 //DEBTRACE("SECTION_SPLINE");
446 BRepAdaptor_Curve anAdaptorCurve(theEdge);
447 if (theOldPolyline.IsNull()) // --- no previous polyline: build a set of points from scratch for the spline
449 GCPnts_QuasiUniformDeflection aDiscrete(anAdaptorCurve, theDeflection);
451 int aNbPoints = aDiscrete.NbPoints();
453 // Decrease the number of imported poles because of last one
454 // pole is the closing point which are the start point
458 for (int i = 1; i <= aNbPoints; ++i)
460 const gp_Pnt& aPoint = aDiscrete.Value(i);
461 HYDROData_PolylineXY::Point aSectPoint(aPoint.X(), aPoint.Y());
462 aPointsList.Append(aSectPoint);
465 gp_Pnt endPts[] = {gp_Pnt(aPointsList.First().X(),aPointsList.First().Y(), 0),
466 gp_Pnt(aPointsList.Last().X(),aPointsList.Last().Y(), 0) };
467 //DEBTRACE("curve start: "<< endPts[0].X() << " " << endPts[0].Y());
468 //DEBTRACE("curve end: "<< endPts[1].X() << " " << endPts[1].Y());
470 else // --- split of a previous polyline: try to retrieve old sets of points and add intersection points
472 const gp_Pnt aEndPs[] = { anAdaptorCurve.Value(anAdaptorCurve.FirstParameter()).XYZ(),
473 anAdaptorCurve.Value(anAdaptorCurve.LastParameter()).XYZ() };
474 double midPar = (anAdaptorCurve.LastParameter() + anAdaptorCurve.FirstParameter())/2;
476 anAdaptorCurve.D0(midPar, midPnt);
477 //DEBTRACE("curve first point: " << aEndPs[0].X() << " " << aEndPs[0].Y() << " " << aEndPs[0].Z());
478 //DEBTRACE("curve last point: " << aEndPs[1].X() << " " << aEndPs[1].Y() << " " << aEndPs[1].Z());
479 //DEBTRACE("curve mid point: " << midPnt.X() << " " << midPnt.Y() << " " << midPnt.Z());
481 std::vector<TopoDS_Wire> aCurves;
482 HYDROData_PolylineOperator::GetWires(theOldPolyline, aCurves);
484 int nbSections = theOldPolyline->NbSections();
485 //DEBTRACE("nbSections: "<< nbSections << ", nbCurves: " << aCurves.size() );
486 for (int isec = 0; isec < nbSections; isec++)
488 //DEBTRACE("section: "<< isec);
489 bool isOldSectionclosed = theOldPolyline->IsClosedSection(isec);
490 TopoDS_Wire aWire = aCurves[isec]; // we suppose sections and wires are in the same order
491 TopExp_Explorer anExp(aWire, TopAbs_EDGE);
492 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current()); // the first is OK: only one normally with splines
493 BRepAdaptor_Curve adaptorOldCurve(anEdge);
494 double pfirst = adaptorOldCurve.FirstParameter();
495 double plast = adaptorOldCurve.LastParameter();
496 //DEBTRACE("previous curve first last : "<< pfirst << " " << plast);
497 double p[3] = {-1, -1};
498 double d0= ProjectPointToCurve(aEndPs[0].XYZ(), adaptorOldCurve,p[0]);
499 double d1= ProjectPointToCurve(aEndPs[1].XYZ(), adaptorOldCurve,p[1]);
500 double d2= ProjectPointToCurve(midPnt.XYZ(), adaptorOldCurve, p[2]);
501 //DEBTRACE("d0: "<<d0<<" d1: "<<d1<<" d2: "<<d2<<" p0: "<<p[0]<<" p1: "<<p[1]<<" p2: "<<p[2]);
502 if ((d0 < 1.e-3) && (d1 < 1.e-3) && (d2 < 1.e-3)) // we got the good old curve (and the good section)
507 //DEBTRACE("isOldSectionclosed: " << isOldSectionclosed);
508 if (!isOldSectionclosed) // no need to check first and last points on an open curve
517 else // old section closed: check if we use first or last points...
519 if((pmin < pmax) && ((abs(pmin - pfirst)> 1.e-3) && (abs(pmax - plast) >1.e-3))) // internal points forward
521 else if ((pmin > pmax) && ((abs(pmin - plast)> 1.e-3) && (abs(pmax - pfirst) >1.e-3))) // internal points reverse
527 else if ((abs(pmin - plast) <1.e-3) && (p[2] < pmax)) // forward, replace pmin par pfirst
529 else if ((abs(pmin - plast) <1.e-3) && (p[2] > pmax)) // reverse
535 else if ((abs(pmax - pfirst) <1.e-3) && (p[2] < pmin)) // reverse
541 else if ((abs(pmax - pfirst) <1.e-3) && (p[2] > pmin)) // forward, replace pmax par plast
544 //DEBTRACE("forward: "<< forward << " pmin " << pmin << " pmax " << pmax);
545 HYDROData_PolylineXY::Point aFirstPoint, aLastPoint;
548 aFirstPoint = HYDROData_PolylineXY::Point(aEndPs[0].X(), aEndPs[0].Y());
549 aLastPoint = HYDROData_PolylineXY::Point(aEndPs[1].X(), aEndPs[1].Y());
553 aFirstPoint = HYDROData_PolylineXY::Point(aEndPs[1].X(), aEndPs[1].Y());
554 aLastPoint = HYDROData_PolylineXY::Point(aEndPs[0].X(), aEndPs[0].Y());
556 aPointsList.Append(aFirstPoint);
558 HYDROData_PolylineXY::PointsList aSectPoints = theOldPolyline->GetPoints(isec, false);
559 int nbPoints = aSectPoints.Length();
560 //DEBTRACE("nbPoints " << nbPoints);
562 for (int i=1; i<=nbPoints; i++)
564 HYDROData_PolylineXY::Point aPoint = aSectPoints.Value(i);
565 gp_XYZ p(aPoint.X(), aPoint.Y(), 0);
567 double d = ProjectPointToCurve(p, adaptorOldCurve, param);
568 if ((param > pmin) && (param < pmax))
570 //DEBTRACE("param: " << param);
571 aPointsList.Append(aPoint);
575 for (int i=nbPoints; i>0; i--)
577 HYDROData_PolylineXY::Point aPoint = aSectPoints.Value(i);
578 gp_XYZ p(aPoint.X(), aPoint.Y(), 0);
580 double d = ProjectPointToCurve(p, adaptorOldCurve, param);
581 if ((param > pmin) && (param < pmax))
583 //DEBTRACE("param: " << param);
584 aPointsList.Append(aPoint);
588 aPointsList.Append(aLastPoint);
595 if ( aPointsList.IsEmpty() )
598 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
601 //DEBTRACE("isNewSection");
602 theSectNames.Append( aSectName );
603 theSectTypes.Append( aSectionType );
604 theSectClosures.Append( anIsEdgeClosed );
605 theSectPoints.Append( aPointsList );
609 //DEBTRACE("sameSection");
610 theSectPoints.SetValue(theSectPoints.Length(), aPointsList);
616 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape,
617 bool IsInterpolationAllowed,
618 const Handle( HYDROData_PolylineXY )& theOldPolyline,
619 bool IsClosureAllowed,
620 double theDeviation )
622 //DEBTRACE("ImportShape");
623 if ( theShape.IsNull() )
626 //std::string brepName = this->GetName().toStdString();
627 //brepName += ".brep";
628 //BRepTools::Write( theShape, brepName.c_str() );
632 bool anIsCanBeImported = false;
634 NCollection_Sequence<TCollection_AsciiString> aSectNames;
635 NCollection_Sequence<SectionType> aSectTypes;
636 NCollection_Sequence<bool> aSectClosures;
637 NCollection_Sequence<PointsList> aSectPoints;
639 if ( theShape.ShapeType() == TopAbs_EDGE )
641 //DEBTRACE("TopAbs_EDGE");
642 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
643 // anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes,
644 // aSectClosures, aSectPoints, true, IsInterpolationAllowed, theDeviation );
645 anIsCanBeImported = convertEdgesToSections( anEdge, aSectNames, aSectTypes, aSectClosures,
646 aSectPoints, IsClosureAllowed, IsInterpolationAllowed,
647 theDeviation, theOldPolyline );
649 else if ( theShape.ShapeType() == TopAbs_WIRE )
651 //DEBTRACE("TopAbs_WIRE");
652 TopTools_SequenceOfShape anEdges;
653 HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
655 anIsCanBeImported = !anEdges.IsEmpty();
656 for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
658 TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
659 anIsCanBeImported = convertEdgesToSections( aWireEdge, aSectNames, aSectTypes, aSectClosures,
660 aSectPoints, IsClosureAllowed, IsInterpolationAllowed,
661 theDeviation, theOldPolyline );
665 if ( anIsCanBeImported )
667 for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
669 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
670 const SectionType& aSectType = aSectTypes.Value( i );
671 bool anIsSectionClosed = aSectClosures.Value( i );
672 const PointsList& aSectPointsList = aSectPoints( i );
674 AddSection( aSectName, aSectType, anIsSectionClosed );
675 SetPoints( i - 1, aSectPointsList );
680 TopoDS_Shape aShape = theShape;
682 if ( theShape.ShapeType() == TopAbs_EDGE )
684 // We make the wire from incoming edge because of other algorithms
685 // are waiting at least the wire from polyline
686 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
687 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
689 if ( aMakeWire.IsDone() )
690 aShape = aMakeWire.Wire();
693 gp_Pln aPlane( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
694 BRepBuilderAPI_MakeFace aMakeFace( aPlane );
696 BRepOffsetAPI_NormalProjection aProj( aMakeFace.Face() );
699 TopoDS_Shape aResult;
701 aResult = aProj.Shape();
706 setEditable( anIsCanBeImported );
711 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
712 const bool& theIsClosed,
713 const NCollection_Sequence<gp_XYZ>& thePoints )
716 if( theType == SECTION_POLYLINE )
718 int aNbPoints = thePoints.Length();
719 BRepBuilderAPI_MakePolygon aMakeWire;
720 for ( int i = 1, n = aNbPoints; i <= n ; ++i )
722 gp_XYZ aPoint = thePoints.Value( i );
723 gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
724 aMakeWire.Add( aPnt );
726 if( theIsClosed && ( aNbPoints > 2 ) )
729 if ( aMakeWire.IsDone() )
730 aWire = aMakeWire.Wire();
732 else //if( theType == PolylineSection::SECTION_SPLINE )
734 BRepBuilderAPI_MakeWire aMakeWire;
736 if ( thePoints.Size() > 1 )
738 Handle(Geom_BSplineCurve) aCurve =
739 HYDROData_BSplineOperation::ComputeCurve( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
741 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aCurve ).Edge();
742 aMakeWire.Add( anEdge );
745 if ( aMakeWire.IsDone() )
752 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
753 const SectionType& theType,
754 const bool& theIsClosed,
755 const NCollection_Sequence<gp_XYZ>& thePoints )
757 if ( thePoints.IsEmpty() )
760 if ( theType == SECTION_POLYLINE )
762 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
763 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
765 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
767 const gp_XYZ& aSectPoint = thePoints.Value( i );
769 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
773 thePath.closeSubpath();
777 Handle(Geom_BSplineCurve) aCurve =
778 HYDROData_BSplineOperation::ComputeCurve( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
779 HYDROData_BSplineOperation::ComputePath( aCurve, thePath );
783 void HYDROData_PolylineXY::Update()
787 // If polyline is not editable we no need to update it wire
792 HYDROData_IPolyline::Update();
794 NCollection_Sequence<TCollection_AsciiString> aSectNames;
795 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
796 NCollection_Sequence<bool> aSectClosures;
797 GetSections( aSectNames, aSectTypes, aSectClosures );
799 //BRepBuilderAPI_MakeWire aMakeWire;
801 TopTools_ListOfShape aSectionWiresList;
803 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
805 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
806 SectionType aSectionType = aSectTypes.Value( aSectionId );
807 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
809 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
810 if ( aSectPointsList.IsEmpty() )
813 NCollection_Sequence<gp_XYZ> aPoints;
814 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
816 const Point& aSectPoint = aSectPointsList.Value( i );
818 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
819 aPoints.Append( aPoint );
822 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
823 if ( !aSectionWire.IsNull() ) {
824 aSectionWiresList.Append( aSectionWire );
825 //aMakeWire.Add( aSectionWire );
828 // all input wires in the <aSectionWiresList>
829 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
830 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
831 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
832 for(;it.More();it.Next())
834 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
835 for(;it2.More();it2.Next())
836 aSeqEdges->Append(it2.Current());
840 TopoDS_Compound aCmp;
841 TopoDS_Shape aResult;
842 aBB.MakeCompound(aCmp);
843 if(aSeqEdges->Length() >1)
845 ShapeAnalysis_FreeBounds::ConnectEdgesToWires( aSeqEdges, 1E-5, Standard_True, aSeqWires );
847 if( aSeqWires->Length()==1 )
848 aResult = aSeqWires->Value( 1 );
851 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
853 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
859 else if (aSeqEdges->Length() == 1)
861 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
863 aResult = mkWire.Wire();
869 bool HYDROData_PolylineXY::IsHas2dPrs() const
874 bool HYDROData_PolylineXY::IsEditable() const
876 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
879 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
881 if ( !theIsEditable )
882 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
884 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
888 * Returns true if polyline is closed
890 bool HYDROData_PolylineXY::IsClosed(const bool theIsSimpleCheck) const
892 //DEBTRACE("IsClosed " << theIsSimpleCheck << " " << GetName());
893 bool anIsClosed = false;
895 TopoDS_Shape aShape = GetShape();
899 TopTools_SequenceOfShape aWires;
900 HYDROData_ShapesTool::ExploreShapeToShapes(aShape, TopAbs_WIRE, aWires);
902 int aNbWires = aWires.Length();
903 if (theIsSimpleCheck)
905 anIsClosed = aNbWires > 0;
906 for (int i = 1; i <= aNbWires && anIsClosed; ++i)
908 const TopoDS_Shape& aWire = aWires.Value(i);
909 anIsClosed = BRep_Tool::IsClosed(aWire);
915 anIsClosed = BRep_Tool::IsClosed(aWires.First());
918 //DEBTRACE("aNbWires " << aNbWires);
919 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
920 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
921 for (int i = 1; i <= aNbWires; ++i)
923 const TopoDS_Shape& aWire = aWires.Value(i);
924 TopExp_Explorer it2(aWire, TopAbs_EDGE);
925 for (; it2.More(); it2.Next())
926 aSeqEdges->Append(it2.Current());
928 if (aSeqEdges->Length() > 1)
930 //DEBTRACE(aSeqEdges->Length());
931 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires);
932 if (aSeqWires->Length() == 1)
934 //DEBTRACE(aSeqWires->Length());
935 const TopoDS_Wire& aPolylineWire = TopoDS::Wire(aSeqWires->Value(1));
936 anIsClosed = BRep_Tool::IsClosed(aPolylineWire);
945 int HYDROData_PolylineXY::GetNbConnectedWires(Handle(TopTools_HSequenceOfShape)& aConnectedWires) const
947 TopoDS_Shape aShape = GetShape();
950 int aNbconnectedWires = 0;
951 TopTools_SequenceOfShape aWires;
952 HYDROData_ShapesTool::ExploreShapeToShapes(aShape, TopAbs_WIRE, aWires);
953 int aNbWires = aWires.Length();
956 aNbconnectedWires = aNbWires;
957 aConnectedWires->Append(aWires.First());
961 //DEBTRACE("aNbWires " << aNbWires);
962 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
963 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
964 for (int i = 1; i <= aNbWires; ++i)
966 const TopoDS_Shape& aWire = aWires.Value(i);
967 TopExp_Explorer it2(aWire, TopAbs_EDGE);
968 for (; it2.More(); it2.Next())
969 aSeqEdges->Append(it2.Current());
971 if (aSeqEdges->Length() > 1)
973 //DEBTRACE(aSeqEdges->Length());
974 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires);
976 aConnectedWires = aSeqWires;
977 aNbconnectedWires = aConnectedWires->Length();
978 DEBTRACE("aNbconnectedWires " << aNbconnectedWires);
980 return aNbconnectedWires;
983 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
984 const int thePointIndex ) const
986 double aResDistance = -1;
987 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
990 if ( thePointIndex == 0 )
993 SectionType aSectionType = GetSectionType( theSectionIndex );
994 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
995 PointsList aSectPointsList = GetPoints( theSectionIndex );
996 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
999 if ( aSectionType == SECTION_POLYLINE )
1003 Point aPrevPoint = aSectPointsList.Value( 1 );
1004 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
1006 const Point& aSectPoint = aSectPointsList.Value( i );
1007 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
1008 aPrevPoint = aSectPoint;
1010 if ( thePointIndex == i - 1 )
1016 gp_XYZ aPointToTest;
1018 int aSectNbPoints = aSectPointsList.Size();
1019 NCollection_Sequence<gp_XYZ> aPoints;
1020 for( int i = 1 ; i <= aSectNbPoints; ++i )
1022 const Point& aSectPoint = aSectPointsList.Value( i );
1024 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1025 aPoints.Append( aPoint );
1027 if ( thePointIndex == i - 1 )
1028 aPointToTest = aPoint;
1031 Handle(Geom_BSplineCurve) aCurve =
1032 HYDROData_BSplineOperation::ComputeCurve( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
1034 Quantity_Parameter aFirstParam = aCurve->FirstParameter();
1035 Quantity_Parameter aSecondParam = aCurve->LastParameter();
1037 if ( thePointIndex != aSectNbPoints - 1 )
1039 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aCurve );
1040 aSecondParam = aProject.LowerDistanceParameter();
1043 GeomAdaptor_Curve anAdap( aCurve );
1045 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
1048 return aResDistance;
1051 int HYDROData_PolylineXY::NbSections() const
1053 Handle(TDataStd_ExtStringList) aNamesList;
1054 Handle(TDataStd_IntegerList) aTypesList;
1055 Handle(TDataStd_BooleanList) aClosuresList;
1056 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1058 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
1061 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
1062 const SectionType theSectionType,
1063 const bool theIsClosed )
1065 Handle(TDataStd_ExtStringList) aNamesList;
1066 Handle(TDataStd_IntegerList) aTypesList;
1067 Handle(TDataStd_BooleanList) aClosuresList;
1068 getSectionsLists( aNamesList, aTypesList, aClosuresList );
1070 TCollection_ExtendedString aSectName( theSectName );
1071 if ( aSectName.Length() <= 0 )
1072 aSectName = getUniqueSectionName( aNamesList );
1074 aNamesList->Append( aSectName );
1075 aTypesList->Append( theSectionType );
1076 aClosuresList->Append( theIsClosed );
1081 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
1083 TCollection_AsciiString aResName;
1085 Handle(TDataStd_ExtStringList) aNamesList;
1086 Handle(TDataStd_IntegerList) aTypesList;
1087 Handle(TDataStd_BooleanList) aClosuresList;
1088 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1089 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1092 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
1093 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
1095 if ( aNamesIter.More() )
1096 aResName = aNamesIter.Value();
1101 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
1102 const TCollection_AsciiString& theSectionName )
1104 Handle(TDataStd_ExtStringList) aNamesList;
1105 Handle(TDataStd_IntegerList) aTypesList;
1106 Handle(TDataStd_BooleanList) aClosuresList;
1107 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1108 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1111 TDataStd_ListOfExtendedString anOldNamesList;
1112 anOldNamesList = aNamesList->List();
1114 // Refill the existing list
1115 aNamesList->Clear();
1117 TCollection_ExtendedString aNewSectName = theSectionName;
1119 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
1120 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
1121 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
1124 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
1126 Handle(TDataStd_ExtStringList) aNamesList;
1127 Handle(TDataStd_IntegerList) aTypesList;
1128 Handle(TDataStd_BooleanList) aClosuresList;
1129 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1130 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
1131 return SECTION_POLYLINE;
1133 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
1134 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
1136 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
1139 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
1140 const SectionType theSectionType )
1142 Handle(TDataStd_ExtStringList) aNamesList;
1143 Handle(TDataStd_IntegerList) aTypesList;
1144 Handle(TDataStd_BooleanList) aClosuresList;
1145 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1146 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
1149 TColStd_ListOfInteger anOldTypesList;
1150 anOldTypesList = aTypesList->List();
1152 // Refill the existing list
1153 aTypesList->Clear();
1155 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
1156 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
1157 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
1162 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
1164 Handle(TDataStd_ExtStringList) aNamesList;
1165 Handle(TDataStd_IntegerList) aTypesList;
1166 Handle(TDataStd_BooleanList) aClosuresList;
1167 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1168 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
1171 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
1172 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
1174 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
1177 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
1178 const bool theIsClosed )
1180 Handle(TDataStd_ExtStringList) aNamesList;
1181 Handle(TDataStd_IntegerList) aTypesList;
1182 Handle(TDataStd_BooleanList) aClosuresList;
1183 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1184 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
1187 TDataStd_ListOfByte anOldClosuresList;
1188 anOldClosuresList = aClosuresList->List();
1190 // Refill the existing list
1191 aClosuresList->Clear();
1193 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
1194 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
1195 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
1200 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
1201 NCollection_Sequence<SectionType>& theSectTypes,
1202 NCollection_Sequence<bool>& theSectClosures ) const
1204 theSectNames.Clear();
1205 theSectTypes.Clear();
1206 theSectClosures.Clear();
1210 const_cast<HYDROData_PolylineXY*>( this )->Interpolate();
1213 Handle(TDataStd_ExtStringList) aNamesList;
1214 Handle(TDataStd_IntegerList) aTypesList;
1215 Handle(TDataStd_BooleanList) aClosuresList;
1216 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1217 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
1220 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
1221 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
1222 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
1223 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
1224 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
1226 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
1227 SectionType aSectType = (SectionType)aTypesIter.Value();
1228 bool aSectClosures = aClosuresIter.Value();
1230 theSectNames.Append( aSectName );
1231 theSectTypes.Append( aSectType );
1232 theSectClosures.Append( aSectClosures );
1236 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
1238 Handle(TDataStd_ExtStringList) aNamesList;
1239 Handle(TDataStd_IntegerList) aTypesList;
1240 Handle(TDataStd_BooleanList) aClosuresList;
1241 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1242 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1245 if ( aNamesList->Extent() == 1 )
1247 removeSectionsLists();
1248 removePointsLists();
1252 TDataStd_ListOfExtendedString anOldNamesList;
1253 anOldNamesList = aNamesList->List();
1255 TColStd_ListOfInteger anOldTypesList;
1256 anOldTypesList = aTypesList->List();
1258 TDataStd_ListOfByte anOldClosuresList;
1259 anOldClosuresList = aClosuresList->List();
1261 // Refill the existing lists
1262 aNamesList->Clear();
1263 aTypesList->Clear();
1264 aClosuresList->Clear();
1266 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
1267 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
1268 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
1269 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
1270 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
1272 if ( i == theSectionIndex )
1273 continue; // skip index to remove
1275 aNamesList->Append( aNamesIter.Value() );
1276 aTypesList->Append( aTypesIter.Value() );
1277 aClosuresList->Append( (bool)aClosuresIter.Value() );
1280 // Remove points that belongs to removed section
1281 removePointsLists( theSectionIndex );
1287 void HYDROData_PolylineXY::RemoveSections()
1289 removeSectionsLists();
1290 removePointsLists();
1294 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
1295 const Point& thePoint,
1296 const int thePointIndex )
1298 Handle(TDataStd_RealList) aListX, aListY;
1299 getPointsLists( theSectionIndex, aListX, aListY );
1301 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
1303 aListX->Append( thePoint.X() );
1304 aListY->Append( thePoint.Y() );
1308 TColStd_ListOfReal anOldListX;
1309 anOldListX = aListX->List();
1311 TColStd_ListOfReal anOldListY;
1312 anOldListY = aListY->List();
1314 // Refill the existing lists
1318 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1319 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1320 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1322 double aCoordX = anIterX.Value();
1323 double aCoordY = anIterY.Value();
1325 if ( i == thePointIndex )
1327 // Insert our new point
1328 aListX->Append( thePoint.X() );
1329 aListY->Append( thePoint.Y() );
1332 aListX->Append( aCoordX );
1333 aListY->Append( aCoordY );
1340 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
1341 const Point& thePoint,
1342 const int thePointIndex )
1344 Handle(TDataStd_RealList) aListX, aListY;
1345 getPointsLists( theSectionIndex, aListX, aListY );
1347 if ( thePointIndex < 0 )
1349 aListX->Prepend( thePoint.X() );
1350 aListY->Prepend( thePoint.Y() );
1352 else if ( thePointIndex >= aListX->Extent() )
1354 aListX->Append( thePoint.X() );
1355 aListY->Append( thePoint.Y() );
1359 TColStd_ListOfReal anOldListX;
1360 anOldListX = aListX->List();
1362 TColStd_ListOfReal anOldListY;
1363 anOldListY = aListY->List();
1365 // Refill the existing lists
1369 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1370 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1371 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1373 double aCoordX = anIterX.Value();
1374 double aCoordY = anIterY.Value();
1376 if ( i == thePointIndex )
1378 // Insert our new point instead of old one
1379 aCoordX = thePoint.X();
1380 aCoordY = thePoint.Y();
1383 aListX->Append( aCoordX );
1384 aListY->Append( aCoordY );
1391 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
1392 const PointsList& thePoints )
1394 Handle(TDataStd_RealList) aListX, aListY;
1395 getPointsLists( theSectionIndex, aListX, aListY );
1400 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1402 const Point& aPoint = thePoints.Value( i );
1403 aListX->Append( aPoint.X() );
1404 aListY->Append( aPoint.Y() );
1408 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
1409 const int thePointIndex )
1411 Handle(TDataStd_RealList) aListX, aListY;
1412 getPointsLists( theSectionIndex, aListX, aListY, false );
1413 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1416 if ( aListX->Extent() == 1 )
1418 removePointsLists( theSectionIndex );
1422 TColStd_ListOfReal anOldListX;
1423 anOldListX = aListX->List();
1425 TColStd_ListOfReal anOldListY;
1426 anOldListY = aListY->List();
1428 // Refill the existing lists
1432 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1433 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1434 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1436 if ( i == thePointIndex )
1437 continue; // skip index to remove
1439 aListX->Append( anIterX.Value() );
1440 aListY->Append( anIterY.Value() );
1447 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex, bool IsConvertToGlobal ) const
1449 PointsList aResList;
1453 const_cast<HYDROData_PolylineXY*>( this )->Interpolate();
1456 Handle(TDataStd_RealList) aListX, aListY;
1457 getPointsLists( theSectionIndex, aListX, aListY, false );
1458 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1461 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
1462 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
1463 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
1464 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
1466 Point aPoint( anIterX.Value(), anIterY.Value() );
1467 if (IsConvertToGlobal)
1468 aDoc->Transform( aPoint, false );
1469 aResList.Append( aPoint );
1475 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
1479 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1480 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1481 NCollection_Sequence<bool> aSectClosures;
1482 GetSections( aSectNames, aSectTypes, aSectClosures );
1484 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1486 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1487 SectionType aSectionType = aSectTypes.Value( aSectionId );
1488 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1490 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1491 if ( aSectPointsList.IsEmpty() )
1494 NCollection_Sequence<gp_XYZ> aPoints;
1495 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1497 const Point& aSectPoint = aSectPointsList.Value( i );
1499 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1500 aPoints.Append( aPoint );
1503 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );
1509 void HYDROData_PolylineXY::UpdateLocalCS( double theDx, double theDy )
1511 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1512 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1513 NCollection_Sequence<bool> aSectClosures;
1514 GetSections( aSectNames, aSectTypes, aSectClosures );
1516 gp_XY aDelta( theDx, theDy );
1517 for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ )
1519 PointsList aPoints = GetPoints( i );
1520 for( int j = 1, n = aPoints.Size(); j <= n; ++j )
1522 Point& aPoint = aPoints.ChangeValue( j );
1525 SetPoints( i, aPoints );
1530 void HYDROData_PolylineXY::Transform( const QTransform& theTrsf )
1532 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1533 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1534 NCollection_Sequence<bool> aSectClosures;
1535 GetSections( aSectNames, aSectTypes, aSectClosures );
1537 for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ ) {
1538 PointsList aPoints = GetPoints( i );
1539 for( int j = 1, n = aPoints.Size(); j <= n; ++j ) {
1540 Point& aPoint = aPoints.ChangeValue( j );
1542 QPointF aTrsfPoint = theTrsf.map( QPointF( aPoint.X(), aPoint.Y() ) );
1544 aPoint.SetX( aTrsfPoint.x() );
1545 aPoint.SetY( aTrsfPoint.y() );
1547 SetPoints( i, aPoints );
1553 bool HYDROData_PolylineXY::IsCustom() const
1555 if( myIsInCustomFlag )
1558 bool isNull = GetShape().IsNull();
1561 HYDROData_PolylineXY* aThat = const_cast<HYDROData_PolylineXY*>( this );
1562 aThat->myIsInCustomFlag = true;
1563 for( int i=0, n=NbSections(); i<n; i++ )
1564 aNbPoints += NbPoints( i );
1565 aThat->myIsInCustomFlag = false;
1567 return !isNull && aNbPoints == 0;
1570 bool HYDROData_PolylineXY::GetIsInCustomFlag() const
1572 return myIsInCustomFlag;
1575 void HYDROData_PolylineXY::SetIsInCustomFlag( bool theValue )
1577 myIsInCustomFlag = theValue;
1580 void HYDROData_PolylineXY::Interpolate()
1582 ImportShape( GetShape(), true, NULL );