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>
35 #include <Quantity_Parameter.hxx>
41 #include <GeomAPI_ProjectPointOnCurve.hxx>
42 #include <GeomAdaptor_Curve.hxx>
43 #include <Geom_Line.hxx>
44 #include <Geom_BSplineCurve.hxx>
46 #include <GCPnts_AbscissaPoint.hxx>
47 #include <GCPnts_QuasiUniformDeflection.hxx>
48 #include <GCPnts_UniformDeflection.hxx>
50 #include <ImageComposer_MetaTypes.h>
56 #include <NCollection_Map.hxx>
58 #include <TCollection_ExtendedString.hxx>
60 #include <TDataStd_ListIteratorOfListOfByte.hxx>
61 #include <TColStd_ListIteratorOfListOfInteger.hxx>
62 #include <TColStd_ListIteratorOfListOfReal.hxx>
64 #include <TColStd_Array1OfReal.hxx>
65 #include <TColgp_Array1OfPnt.hxx>
67 #include <TDataStd_AsciiString.hxx>
68 #include <TDataStd_BooleanList.hxx>
69 #include <TDataStd_ExtStringList.hxx>
70 #include <TDataStd_IntegerList.hxx>
71 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
72 #include <TDataStd_RealList.hxx>
73 #include <TDataStd_UAttribute.hxx>
75 #include <TopoDS_Iterator.hxx>
76 #include <TopTools_ListIteratorOfListOfShape.hxx>
77 #include <TopTools_HSequenceOfShape.hxx>
78 #include <TopExp_Explorer.hxx>
79 #include <ShapeAnalysis_FreeBounds.hxx>
83 #include <QPainterPath>
87 #include "HYDRO_trace.hxx"
88 #include <BRepTools.hxx>
92 static const Standard_GUID GUID_IS_UNEDITABLE("e5799736-9030-4051-91a4-2e58321fa153");
94 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
96 TCollection_AsciiString getUniqueSectionName( const NCollection_Sequence<TCollection_AsciiString>& theNamesSeq )
98 NCollection_Map<TCollection_AsciiString> aNamesMap;
100 for ( int i = 1, n = theNamesSeq.Size(); i <= n; ++i )
102 const TCollection_AsciiString& aSectName = theNamesSeq.Value( i );
103 aNamesMap.Add( aSectName );
106 TCollection_AsciiString aResName;
111 aResName = TCollection_AsciiString( "Section_" ) + aPrefIdx;
114 while ( aNamesMap.Contains( aResName ) );
119 TCollection_AsciiString getUniqueSectionName( const Handle(TDataStd_ExtStringList)& theNamesList )
121 NCollection_Sequence<TCollection_AsciiString> aNamesSeq;
123 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( theNamesList->List() );
124 for ( ; aNamesIter.More(); aNamesIter.Next() )
125 aNamesSeq.Append( aNamesIter.Value() );
127 return getUniqueSectionName( aNamesSeq );
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 Handle(TDataStd_AsciiString) anAttr = TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), theEntry );
248 anAttr->SetID(TDataStd_AsciiString::GetID());
251 TCollection_AsciiString HYDROData_PolylineXY::GetGeomObjectEntry() const
253 TCollection_AsciiString aRes;
255 TDF_Label aLabel = myLab.FindChild( DataTag_GeomObjectEntry, false );
256 if ( !aLabel.IsNull() )
258 Handle(TDataStd_AsciiString) anAsciiStr;
259 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
260 aRes = anAsciiStr->Get();
266 bool convertEdgeToSection( const TopoDS_Edge& theEdge,
267 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
268 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
269 NCollection_Sequence<bool>& theSectClosures,
270 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
272 bool IsInterpolationAllowed,
273 double theDeflection )
275 Standard_Real aFirst = 0.0, aLast = 0.0;
276 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
277 if ( anEdgeGeomCurve.IsNull() )
280 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
281 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
283 HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
284 HYDROData_PolylineXY::PointsList aPointsList;
286 if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
288 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
290 gp_Pnt aFirstPoint, aLastPoint;
291 aGeomLine->D0( aFirst, aFirstPoint );
292 aGeomLine->D0( aLast, aLastPoint );
294 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
295 aPointsList.Append( aSectFirstPoint );
297 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
298 aPointsList.Append( aSectLastPoint );
300 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
302 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
304 BRepAdaptor_Curve anAdaptorCurve( theEdge );
305 GCPnts_QuasiUniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
306 //GCPnts_UniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
308 int aNbPoints = aDiscrete.NbPoints();
310 // Decrease the number of imported poles because of last one
311 // pole is the closing point which are the start point
312 if ( anIsEdgeClosed ) aNbPoints--;
314 for ( int i = 1; i <= aNbPoints; ++i )
316 const gp_Pnt& aPoint = aDiscrete.Value( i );
318 HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
319 aPointsList.Append( aSectPoint );
324 // Other curve types are not supported
328 if ( aPointsList.IsEmpty() )
331 theSectNames.Append( aSectName );
332 theSectTypes.Append( aSectionType );
333 theSectClosures.Append( anIsEdgeClosed );
334 theSectPoints.Append( aPointsList );
340 bool convertEdgesToSections( const TopoDS_Edge& theEdge,
341 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
342 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
343 NCollection_Sequence<bool>& theSectClosures,
344 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
346 bool IsInterpolationAllowed,
347 double theDeflection,
348 const Handle( HYDROData_PolylineXY )& theOldPolyline )
350 DEBTRACE("convertEdgesToSections")
351 Standard_Real aFirst = 0.0, aLast = 0.0;
352 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
353 if ( anEdgeGeomCurve.IsNull() )
356 bool isPrevious = (theSectTypes.Size() > 0);
357 DEBTRACE("nb sections: " << theSectTypes.Size());
358 HYDROData_PolylineXY::SectionType prevSectType = HYDROData_PolylineXY::SECTION_SPLINE;;
359 HYDROData_PolylineXY::PointsList prevPointList;
360 bool isPrevClosed = true;
363 prevSectType = theSectTypes.Last();
364 prevPointList = theSectPoints.Last();
365 isPrevClosed = theSectClosures.Last();
368 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
369 anIsEdgeClosed &= IsCanBeClosed; // on split, resulting edges are normally not closed...
370 HYDROData_PolylineXY::SectionType aSectionType ;
371 if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
373 aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
375 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
377 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
381 // Other curve types are not supported
385 bool isNewSection = !isPrevious || isPrevClosed || anIsEdgeClosed || prevSectType != aSectionType;
386 DEBTRACE(isNewSection <<": " << !isPrevious << " " << isPrevClosed << " " << anIsEdgeClosed << " " << (prevSectType != aSectionType));
388 HYDROData_PolylineXY::PointsList aPointsList;
391 aPointsList = prevPointList;
394 if( aSectionType == HYDROData_PolylineXY::SECTION_POLYLINE )
396 DEBTRACE("SECTION_POLYLINE");
397 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
399 gp_Pnt aFirstPoint, aLastPoint;
400 aGeomLine->D0( aFirst, aFirstPoint );
401 aGeomLine->D0( aLast, aLastPoint );
402 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
403 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
406 if (aSectFirstPoint == prevPointList.Last())
408 DEBTRACE("points shared: a");//aPointsList.Append( aSectFirstPoint );
409 aPointsList.Append( aSectLastPoint );
411 else if (aSectLastPoint == prevPointList.Last())
413 DEBTRACE("points shared: b");//aPointsList.Append( aSectLastPoint );
414 aPointsList.Append( aSectFirstPoint );
416 else if (aSectFirstPoint == prevPointList.First())
418 DEBTRACE("points shared: c");//aPointsList.Prepend( aSectFirstPoint );
419 aPointsList.Prepend( aSectLastPoint );
421 else if (aSectLastPoint == prevPointList.First())
423 DEBTRACE("points shared: d");//aPointsList.Prepend( aSectLastPoint );
424 aPointsList.Prepend( aSectFirstPoint );
428 DEBTRACE("no point shared")
429 isNewSection = true; // no point shared, new section
431 aPointsList.Append( aSectFirstPoint );
432 aPointsList.Append( aSectLastPoint );
437 DEBTRACE("new section");
438 aPointsList.Append( aSectFirstPoint );
439 aPointsList.Append( aSectLastPoint );
442 else // aSectionType == HYDROData_PolylineXY::SECTION_SPLINE
444 DEBTRACE("SECTION_SPLINE");
448 BRepAdaptor_Curve anAdaptorCurve(theEdge);
449 if (theOldPolyline.IsNull()) // --- no previous polyline: build a set of points from scratch for the spline
451 GCPnts_QuasiUniformDeflection aDiscrete(anAdaptorCurve, theDeflection);
453 int aNbPoints = aDiscrete.NbPoints();
455 // Decrease the number of imported poles because of last one
456 // pole is the closing point which are the start point
460 for (int i = 1; i <= aNbPoints; ++i)
462 const gp_Pnt& aPoint = aDiscrete.Value(i);
463 HYDROData_PolylineXY::Point aSectPoint(aPoint.X(), aPoint.Y());
464 aPointsList.Append(aSectPoint);
467 gp_Pnt endPts[] = {gp_Pnt(aPointsList.First().X(),aPointsList.First().Y(), 0),
468 gp_Pnt(aPointsList.Last().X(),aPointsList.Last().Y(), 0) };
469 DEBTRACE("curve start: "<< endPts[0].X() << " " << endPts[0].Y());
470 DEBTRACE("curve end: "<< endPts[1].X() << " " << endPts[1].Y());
472 else // --- split of a previous polyline: try to retrieve old sets of points and add intersection points
474 const gp_Pnt aEndPs[] = { anAdaptorCurve.Value(anAdaptorCurve.FirstParameter()).XYZ(),
475 anAdaptorCurve.Value(anAdaptorCurve.LastParameter()).XYZ() };
476 double midPar = (anAdaptorCurve.LastParameter() + anAdaptorCurve.FirstParameter())/2;
478 anAdaptorCurve.D0(midPar, midPnt);
479 DEBTRACE("curve first point: " << aEndPs[0].X() << " " << aEndPs[0].Y() << " " << aEndPs[0].Z());
480 DEBTRACE("curve last point: " << aEndPs[1].X() << " " << aEndPs[1].Y() << " " << aEndPs[1].Z());
481 DEBTRACE("curve mid point: " << midPnt.X() << " " << midPnt.Y() << " " << midPnt.Z());
483 std::vector<TopoDS_Wire> aCurves;
484 HYDROData_PolylineOperator::GetWires(theOldPolyline, aCurves);
486 int nbSections = theOldPolyline->NbSections();
487 DEBTRACE("nbSections: "<< nbSections << ", nbCurves: " << aCurves.size() );
488 for (int isec = 0; isec < nbSections; isec++)
490 DEBTRACE("section: "<< isec);
491 bool isOldSectionclosed = theOldPolyline->IsClosedSection(isec);
492 TopoDS_Wire aWire = aCurves[isec]; // we suppose sections and wires are in the same order
493 TopExp_Explorer anExp(aWire, TopAbs_EDGE);
494 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current()); // the first is OK: only one normally with splines
495 BRepAdaptor_Curve adaptorOldCurve(anEdge);
496 double pfirst = adaptorOldCurve.FirstParameter();
497 double plast = adaptorOldCurve.LastParameter();
498 DEBTRACE("previous curve first last : "<< pfirst << " " << plast);
499 double p[3] = {-1, -1};
500 double d0= ProjectPointToCurve(aEndPs[0].XYZ(), adaptorOldCurve,p[0]);
501 double d1= ProjectPointToCurve(aEndPs[1].XYZ(), adaptorOldCurve,p[1]);
502 double d2= ProjectPointToCurve(midPnt.XYZ(), adaptorOldCurve, p[2]);
503 DEBTRACE("d0: "<<d0<<" d1: "<<d1<<" d2: "<<d2<<" p0: "<<p[0]<<" p1: "<<p[1]<<" p2: "<<p[2]);
504 if ((d0 < 1.e-3) && (d1 < 1.e-3) && (d2 < 1.e-3)) // we got the good old curve (and the good section)
509 DEBTRACE("isOldSectionclosed: " << isOldSectionclosed);
510 if (!isOldSectionclosed) // no need to check first and last points on an open curve
519 else // old section closed: check if we use first or last points...
521 if((pmin < pmax) && ((abs(pmin - pfirst)> 1.e-3) && (abs(pmax - plast) >1.e-3))) // internal points forward
523 else if ((pmin > pmax) && ((abs(pmin - plast)> 1.e-3) && (abs(pmax - pfirst) >1.e-3))) // internal points reverse
529 else if ((abs(pmin - plast) <1.e-3) && (p[2] < pmax)) // forward, replace pmin par pfirst
531 else if ((abs(pmin - plast) <1.e-3) && (p[2] > pmax)) // reverse
537 else if ((abs(pmax - pfirst) <1.e-3) && (p[2] < pmin)) // reverse
543 else if ((abs(pmax - pfirst) <1.e-3) && (p[2] > pmin)) // forward, replace pmax par plast
546 DEBTRACE("forward: "<< forward << " pmin " << pmin << " pmax " << pmax);
547 HYDROData_PolylineXY::Point aFirstPoint, aLastPoint;
550 aFirstPoint = HYDROData_PolylineXY::Point(aEndPs[0].X(), aEndPs[0].Y());
551 aLastPoint = HYDROData_PolylineXY::Point(aEndPs[1].X(), aEndPs[1].Y());
555 aFirstPoint = HYDROData_PolylineXY::Point(aEndPs[1].X(), aEndPs[1].Y());
556 aLastPoint = HYDROData_PolylineXY::Point(aEndPs[0].X(), aEndPs[0].Y());
558 aPointsList.Append(aFirstPoint);
560 HYDROData_PolylineXY::PointsList aSectPoints = theOldPolyline->GetPoints(isec, false);
561 int nbPoints = aSectPoints.Length();
562 DEBTRACE("nbPoints " << nbPoints);
564 for (int i=1; i<=nbPoints; i++)
566 HYDROData_PolylineXY::Point aPoint = aSectPoints.Value(i);
567 gp_XYZ p(aPoint.X(), aPoint.Y(), 0);
569 double d = ProjectPointToCurve(p, adaptorOldCurve, param);
570 if ((param > pmin) && (param < pmax))
572 DEBTRACE("param: " << param);
573 aPointsList.Append(aPoint);
577 for (int i=nbPoints; i>0; i--)
579 HYDROData_PolylineXY::Point aPoint = aSectPoints.Value(i);
580 gp_XYZ p(aPoint.X(), aPoint.Y(), 0);
582 double d = ProjectPointToCurve(p, adaptorOldCurve, param);
583 if ((param > pmin) && (param < pmax))
585 DEBTRACE("param: " << param);
586 aPointsList.Append(aPoint);
590 aPointsList.Append(aLastPoint);
597 if ( aPointsList.IsEmpty() )
600 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
603 DEBTRACE("isNewSection");
604 theSectNames.Append( aSectName );
605 theSectTypes.Append( aSectionType );
606 theSectClosures.Append( anIsEdgeClosed );
607 theSectPoints.Append( aPointsList );
611 DEBTRACE("sameSection");
612 theSectPoints.SetValue(theSectPoints.Length(), aPointsList);
618 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape,
619 bool IsInterpolationAllowed,
620 const Handle( HYDROData_PolylineXY )& theOldPolyline,
621 bool IsClosureAllowed,
622 double theDeviation )
624 DEBTRACE("ImportShape");
625 if ( theShape.IsNull() )
628 //std::string brepName = this->GetName().toStdString();
629 //brepName += ".brep";
630 //BRepTools::Write( theShape, brepName.c_str() );
634 bool anIsCanBeImported = false;
636 NCollection_Sequence<TCollection_AsciiString> aSectNames;
637 NCollection_Sequence<SectionType> aSectTypes;
638 NCollection_Sequence<bool> aSectClosures;
639 NCollection_Sequence<PointsList> aSectPoints;
641 if ( theShape.ShapeType() == TopAbs_EDGE )
643 DEBTRACE("TopAbs_EDGE");
644 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
645 // anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes,
646 // aSectClosures, aSectPoints, true, IsInterpolationAllowed, theDeviation );
647 anIsCanBeImported = convertEdgesToSections( anEdge, aSectNames, aSectTypes, aSectClosures,
648 aSectPoints, IsClosureAllowed, IsInterpolationAllowed,
649 theDeviation, theOldPolyline );
651 else if ( theShape.ShapeType() == TopAbs_WIRE )
653 DEBTRACE("TopAbs_WIRE");
654 TopTools_SequenceOfShape anEdges;
655 HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
657 anIsCanBeImported = !anEdges.IsEmpty();
658 for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
660 TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
661 anIsCanBeImported = convertEdgesToSections( aWireEdge, aSectNames, aSectTypes, aSectClosures,
662 aSectPoints, IsClosureAllowed, IsInterpolationAllowed,
663 theDeviation, theOldPolyline );
667 if ( anIsCanBeImported )
669 for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
671 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
672 const SectionType& aSectType = aSectTypes.Value( i );
673 bool anIsSectionClosed = aSectClosures.Value( i );
674 const PointsList& aSectPointsList = aSectPoints( i );
676 AddSection( aSectName, aSectType, anIsSectionClosed );
677 SetPoints( i - 1, aSectPointsList );
682 TopoDS_Shape aShape = theShape;
684 if ( theShape.ShapeType() == TopAbs_EDGE )
686 // We make the wire from incoming edge because of other algorithms
687 // are waiting at least the wire from polyline
688 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
689 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
691 if ( aMakeWire.IsDone() )
692 aShape = aMakeWire.Wire();
695 gp_Pln aPlane( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
696 BRepBuilderAPI_MakeFace aMakeFace( aPlane );
698 BRepOffsetAPI_NormalProjection aProj( aMakeFace.Face() );
701 TopoDS_Shape aResult;
703 aResult = aProj.Shape();
708 setEditable( anIsCanBeImported );
713 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
714 const bool& theIsClosed,
715 const NCollection_Sequence<gp_XYZ>& thePoints )
718 if( theType == SECTION_POLYLINE )
720 int aNbPoints = thePoints.Length();
721 BRepBuilderAPI_MakePolygon aMakeWire;
722 for ( int i = 1, n = aNbPoints; i <= n ; ++i )
724 gp_XYZ aPoint = thePoints.Value( i );
725 gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
726 aMakeWire.Add( aPnt );
728 if( theIsClosed && ( aNbPoints > 2 ) )
731 if ( aMakeWire.IsDone() )
732 aWire = aMakeWire.Wire();
734 else //if( theType == PolylineSection::SECTION_SPLINE )
736 BRepBuilderAPI_MakeWire aMakeWire;
738 if ( thePoints.Size() > 1 )
740 Handle(Geom_BSplineCurve) aCurve =
741 HYDROData_BSplineOperation::ComputeCurve( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
743 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aCurve ).Edge();
744 aMakeWire.Add( anEdge );
747 if ( aMakeWire.IsDone() )
754 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
755 const SectionType& theType,
756 const bool& theIsClosed,
757 const NCollection_Sequence<gp_XYZ>& thePoints )
759 if ( thePoints.IsEmpty() )
762 if ( theType == SECTION_POLYLINE )
764 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
765 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
767 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
769 const gp_XYZ& aSectPoint = thePoints.Value( i );
771 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
775 thePath.closeSubpath();
779 Handle(Geom_BSplineCurve) aCurve =
780 HYDROData_BSplineOperation::ComputeCurve( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
781 HYDROData_BSplineOperation::ComputePath( aCurve, thePath );
785 void HYDROData_PolylineXY::Update()
789 // If polyline is not editable we no need to update it wire
794 HYDROData_IPolyline::Update();
796 NCollection_Sequence<TCollection_AsciiString> aSectNames;
797 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
798 NCollection_Sequence<bool> aSectClosures;
799 GetSections( aSectNames, aSectTypes, aSectClosures );
801 //BRepBuilderAPI_MakeWire aMakeWire;
803 TopTools_ListOfShape aSectionWiresList;
805 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
807 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
808 SectionType aSectionType = aSectTypes.Value( aSectionId );
809 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
811 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
812 if ( aSectPointsList.IsEmpty() )
815 NCollection_Sequence<gp_XYZ> aPoints;
816 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
818 const Point& aSectPoint = aSectPointsList.Value( i );
820 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
821 aPoints.Append( aPoint );
824 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
825 if ( !aSectionWire.IsNull() ) {
826 aSectionWiresList.Append( aSectionWire );
827 //aMakeWire.Add( aSectionWire );
830 // all input wires in the <aSectionWiresList>
831 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
832 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
833 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
834 for(;it.More();it.Next())
836 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
837 for(;it2.More();it2.Next())
838 aSeqEdges->Append(it2.Current());
842 TopoDS_Compound aCmp;
843 TopoDS_Shape aResult;
844 aBB.MakeCompound(aCmp);
845 if(aSeqEdges->Length() >1)
847 ShapeAnalysis_FreeBounds::ConnectEdgesToWires( aSeqEdges, 1E-5, Standard_True, aSeqWires );
849 if( aSeqWires->Length()==1 )
850 aResult = aSeqWires->Value( 1 );
853 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
855 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
861 else if (aSeqEdges->Length() == 1)
863 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
865 aResult = mkWire.Wire();
871 bool HYDROData_PolylineXY::IsHas2dPrs() const
876 bool HYDROData_PolylineXY::IsEditable() const
878 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
881 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
883 if ( !theIsEditable )
884 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
886 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
890 * Returns true if polyline is closed
892 bool HYDROData_PolylineXY::IsClosed(const bool theIsSimpleCheck) const
894 DEBTRACE("IsClosed " << theIsSimpleCheck << " " << GetName());
895 bool anIsClosed = false;
897 TopoDS_Shape aShape = GetShape();
901 TopTools_SequenceOfShape aWires;
902 HYDROData_ShapesTool::ExploreShapeToShapes(aShape, TopAbs_WIRE, aWires);
904 int aNbWires = aWires.Length();
905 if (theIsSimpleCheck)
907 anIsClosed = aNbWires > 0;
908 for (int i = 1; i <= aNbWires && anIsClosed; ++i)
910 const TopoDS_Shape& aWire = aWires.Value(i);
911 anIsClosed = BRep_Tool::IsClosed(aWire);
917 anIsClosed = BRep_Tool::IsClosed(aWires.First());
920 DEBTRACE("aNbWires " << aNbWires);
921 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
922 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
923 for (int i = 1; i <= aNbWires; ++i)
925 const TopoDS_Shape& aWire = aWires.Value(i);
926 TopExp_Explorer it2(aWire, TopAbs_EDGE);
927 for (; it2.More(); it2.Next())
928 aSeqEdges->Append(it2.Current());
930 if (aSeqEdges->Length() > 1)
932 DEBTRACE(aSeqEdges->Length());
933 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires);
934 if (aSeqWires->Length() == 1)
936 DEBTRACE(aSeqWires->Length());
937 const TopoDS_Wire& aPolylineWire = TopoDS::Wire(aSeqWires->Value(1));
938 anIsClosed = BRep_Tool::IsClosed(aPolylineWire);
947 int HYDROData_PolylineXY::GetNbConnectedWires(Handle(TopTools_HSequenceOfShape)& aConnectedWires) const
949 TopoDS_Shape aShape = GetShape();
952 int aNbconnectedWires = 0;
953 TopTools_SequenceOfShape aWires;
954 HYDROData_ShapesTool::ExploreShapeToShapes(aShape, TopAbs_WIRE, aWires);
955 int aNbWires = aWires.Length();
958 aNbconnectedWires = aNbWires;
959 aConnectedWires->Append(aWires.First());
963 DEBTRACE("aNbWires " << aNbWires);
964 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
965 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
966 for (int i = 1; i <= aNbWires; ++i)
968 const TopoDS_Shape& aWire = aWires.Value(i);
969 TopExp_Explorer it2(aWire, TopAbs_EDGE);
970 for (; it2.More(); it2.Next())
971 aSeqEdges->Append(it2.Current());
973 if (aSeqEdges->Length() > 1)
975 DEBTRACE(aSeqEdges->Length());
976 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires);
978 aConnectedWires = aSeqWires;
979 aNbconnectedWires = aConnectedWires->Length();
980 DEBTRACE("aNbconnectedWires " << aNbconnectedWires);
982 return aNbconnectedWires;
985 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
986 const int thePointIndex ) const
988 double aResDistance = -1;
989 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
992 if ( thePointIndex == 0 )
995 SectionType aSectionType = GetSectionType( theSectionIndex );
996 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
997 PointsList aSectPointsList = GetPoints( theSectionIndex );
998 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
1001 if ( aSectionType == SECTION_POLYLINE )
1005 Point aPrevPoint = aSectPointsList.Value( 1 );
1006 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
1008 const Point& aSectPoint = aSectPointsList.Value( i );
1009 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
1010 aPrevPoint = aSectPoint;
1012 if ( thePointIndex == i - 1 )
1018 gp_XYZ aPointToTest;
1020 int aSectNbPoints = aSectPointsList.Size();
1021 NCollection_Sequence<gp_XYZ> aPoints;
1022 for( int i = 1 ; i <= aSectNbPoints; ++i )
1024 const Point& aSectPoint = aSectPointsList.Value( i );
1026 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1027 aPoints.Append( aPoint );
1029 if ( thePointIndex == i - 1 )
1030 aPointToTest = aPoint;
1033 Handle(Geom_BSplineCurve) aCurve =
1034 HYDROData_BSplineOperation::ComputeCurve( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
1036 Quantity_Parameter aFirstParam = aCurve->FirstParameter();
1037 Quantity_Parameter aSecondParam = aCurve->LastParameter();
1039 if ( thePointIndex != aSectNbPoints - 1 )
1041 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aCurve );
1042 aSecondParam = aProject.LowerDistanceParameter();
1045 GeomAdaptor_Curve anAdap( aCurve );
1047 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
1050 return aResDistance;
1053 int HYDROData_PolylineXY::NbSections() const
1055 Handle(TDataStd_ExtStringList) aNamesList;
1056 Handle(TDataStd_IntegerList) aTypesList;
1057 Handle(TDataStd_BooleanList) aClosuresList;
1058 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1060 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
1063 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
1064 const SectionType theSectionType,
1065 const bool theIsClosed )
1067 Handle(TDataStd_ExtStringList) aNamesList;
1068 Handle(TDataStd_IntegerList) aTypesList;
1069 Handle(TDataStd_BooleanList) aClosuresList;
1070 getSectionsLists( aNamesList, aTypesList, aClosuresList );
1072 TCollection_ExtendedString aSectName( theSectName );
1073 if ( aSectName.Length() <= 0 )
1074 aSectName = getUniqueSectionName( aNamesList );
1076 aNamesList->Append( aSectName );
1077 aTypesList->Append( theSectionType );
1078 aClosuresList->Append( theIsClosed );
1083 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
1085 TCollection_AsciiString aResName;
1087 Handle(TDataStd_ExtStringList) aNamesList;
1088 Handle(TDataStd_IntegerList) aTypesList;
1089 Handle(TDataStd_BooleanList) aClosuresList;
1090 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1091 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1094 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
1095 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
1097 if ( aNamesIter.More() )
1098 aResName = aNamesIter.Value();
1103 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
1104 const TCollection_AsciiString& theSectionName )
1106 Handle(TDataStd_ExtStringList) aNamesList;
1107 Handle(TDataStd_IntegerList) aTypesList;
1108 Handle(TDataStd_BooleanList) aClosuresList;
1109 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1110 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1113 TDataStd_ListOfExtendedString anOldNamesList;
1114 anOldNamesList = aNamesList->List();
1116 // Refill the existing list
1117 aNamesList->Clear();
1119 TCollection_ExtendedString aNewSectName = theSectionName;
1121 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
1122 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
1123 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
1126 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
1128 Handle(TDataStd_ExtStringList) aNamesList;
1129 Handle(TDataStd_IntegerList) aTypesList;
1130 Handle(TDataStd_BooleanList) aClosuresList;
1131 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1132 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
1133 return SECTION_POLYLINE;
1135 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
1136 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
1138 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
1141 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
1142 const SectionType theSectionType )
1144 Handle(TDataStd_ExtStringList) aNamesList;
1145 Handle(TDataStd_IntegerList) aTypesList;
1146 Handle(TDataStd_BooleanList) aClosuresList;
1147 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1148 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
1151 TColStd_ListOfInteger anOldTypesList;
1152 anOldTypesList = aTypesList->List();
1154 // Refill the existing list
1155 aTypesList->Clear();
1157 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
1158 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
1159 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
1164 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
1166 Handle(TDataStd_ExtStringList) aNamesList;
1167 Handle(TDataStd_IntegerList) aTypesList;
1168 Handle(TDataStd_BooleanList) aClosuresList;
1169 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1170 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
1173 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
1174 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
1176 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
1179 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
1180 const bool theIsClosed )
1182 Handle(TDataStd_ExtStringList) aNamesList;
1183 Handle(TDataStd_IntegerList) aTypesList;
1184 Handle(TDataStd_BooleanList) aClosuresList;
1185 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1186 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
1189 TDataStd_ListOfByte anOldClosuresList;
1190 anOldClosuresList = aClosuresList->List();
1192 // Refill the existing list
1193 aClosuresList->Clear();
1195 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
1196 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
1197 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
1202 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
1203 NCollection_Sequence<SectionType>& theSectTypes,
1204 NCollection_Sequence<bool>& theSectClosures ) const
1206 theSectNames.Clear();
1207 theSectTypes.Clear();
1208 theSectClosures.Clear();
1212 const_cast<HYDROData_PolylineXY*>( this )->Interpolate();
1215 Handle(TDataStd_ExtStringList) aNamesList;
1216 Handle(TDataStd_IntegerList) aTypesList;
1217 Handle(TDataStd_BooleanList) aClosuresList;
1218 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1219 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
1222 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
1223 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
1224 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
1225 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
1226 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
1228 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
1229 SectionType aSectType = (SectionType)aTypesIter.Value();
1230 bool aSectClosures = aClosuresIter.Value();
1232 theSectNames.Append( aSectName );
1233 theSectTypes.Append( aSectType );
1234 theSectClosures.Append( aSectClosures );
1238 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
1240 Handle(TDataStd_ExtStringList) aNamesList;
1241 Handle(TDataStd_IntegerList) aTypesList;
1242 Handle(TDataStd_BooleanList) aClosuresList;
1243 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1244 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1247 if ( aNamesList->Extent() == 1 )
1249 removeSectionsLists();
1250 removePointsLists();
1254 TDataStd_ListOfExtendedString anOldNamesList;
1255 anOldNamesList = aNamesList->List();
1257 TColStd_ListOfInteger anOldTypesList;
1258 anOldTypesList = aTypesList->List();
1260 TDataStd_ListOfByte anOldClosuresList;
1261 anOldClosuresList = aClosuresList->List();
1263 // Refill the existing lists
1264 aNamesList->Clear();
1265 aTypesList->Clear();
1266 aClosuresList->Clear();
1268 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
1269 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
1270 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
1271 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
1272 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
1274 if ( i == theSectionIndex )
1275 continue; // skip index to remove
1277 aNamesList->Append( aNamesIter.Value() );
1278 aTypesList->Append( aTypesIter.Value() );
1279 aClosuresList->Append( (bool)aClosuresIter.Value() );
1282 // Remove points that belongs to removed section
1283 removePointsLists( theSectionIndex );
1289 void HYDROData_PolylineXY::RemoveSections()
1291 removeSectionsLists();
1292 removePointsLists();
1296 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
1297 const Point& thePoint,
1298 const int thePointIndex )
1300 Handle(TDataStd_RealList) aListX, aListY;
1301 getPointsLists( theSectionIndex, aListX, aListY );
1303 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
1305 aListX->Append( thePoint.X() );
1306 aListY->Append( thePoint.Y() );
1310 TColStd_ListOfReal anOldListX;
1311 anOldListX = aListX->List();
1313 TColStd_ListOfReal anOldListY;
1314 anOldListY = aListY->List();
1316 // Refill the existing lists
1320 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1321 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1322 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1324 double aCoordX = anIterX.Value();
1325 double aCoordY = anIterY.Value();
1327 if ( i == thePointIndex )
1329 // Insert our new point
1330 aListX->Append( thePoint.X() );
1331 aListY->Append( thePoint.Y() );
1334 aListX->Append( aCoordX );
1335 aListY->Append( aCoordY );
1342 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
1343 const Point& thePoint,
1344 const int thePointIndex )
1346 Handle(TDataStd_RealList) aListX, aListY;
1347 getPointsLists( theSectionIndex, aListX, aListY );
1349 if ( thePointIndex < 0 )
1351 aListX->Prepend( thePoint.X() );
1352 aListY->Prepend( thePoint.Y() );
1354 else if ( thePointIndex >= aListX->Extent() )
1356 aListX->Append( thePoint.X() );
1357 aListY->Append( thePoint.Y() );
1361 TColStd_ListOfReal anOldListX;
1362 anOldListX = aListX->List();
1364 TColStd_ListOfReal anOldListY;
1365 anOldListY = aListY->List();
1367 // Refill the existing lists
1371 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1372 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1373 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1375 double aCoordX = anIterX.Value();
1376 double aCoordY = anIterY.Value();
1378 if ( i == thePointIndex )
1380 // Insert our new point instead of old one
1381 aCoordX = thePoint.X();
1382 aCoordY = thePoint.Y();
1385 aListX->Append( aCoordX );
1386 aListY->Append( aCoordY );
1393 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
1394 const PointsList& thePoints )
1396 Handle(TDataStd_RealList) aListX, aListY;
1397 getPointsLists( theSectionIndex, aListX, aListY );
1402 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1404 const Point& aPoint = thePoints.Value( i );
1405 aListX->Append( aPoint.X() );
1406 aListY->Append( aPoint.Y() );
1410 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
1411 const int thePointIndex )
1413 Handle(TDataStd_RealList) aListX, aListY;
1414 getPointsLists( theSectionIndex, aListX, aListY, false );
1415 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1418 if ( aListX->Extent() == 1 )
1420 removePointsLists( theSectionIndex );
1424 TColStd_ListOfReal anOldListX;
1425 anOldListX = aListX->List();
1427 TColStd_ListOfReal anOldListY;
1428 anOldListY = aListY->List();
1430 // Refill the existing lists
1434 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1435 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1436 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1438 if ( i == thePointIndex )
1439 continue; // skip index to remove
1441 aListX->Append( anIterX.Value() );
1442 aListY->Append( anIterY.Value() );
1449 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex, bool IsConvertToGlobal ) const
1451 PointsList aResList;
1455 const_cast<HYDROData_PolylineXY*>( this )->Interpolate();
1458 Handle(TDataStd_RealList) aListX, aListY;
1459 getPointsLists( theSectionIndex, aListX, aListY, false );
1460 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1463 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
1464 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
1465 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
1466 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
1468 Point aPoint( anIterX.Value(), anIterY.Value() );
1469 if (IsConvertToGlobal)
1470 aDoc->Transform( aPoint, false );
1471 aResList.Append( aPoint );
1477 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
1481 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1482 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1483 NCollection_Sequence<bool> aSectClosures;
1484 GetSections( aSectNames, aSectTypes, aSectClosures );
1486 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1488 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1489 SectionType aSectionType = aSectTypes.Value( aSectionId );
1490 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1492 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1493 if ( aSectPointsList.IsEmpty() )
1496 NCollection_Sequence<gp_XYZ> aPoints;
1497 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1499 const Point& aSectPoint = aSectPointsList.Value( i );
1501 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1502 aPoints.Append( aPoint );
1505 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );
1511 void HYDROData_PolylineXY::UpdateLocalCS( double theDx, double theDy )
1513 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1514 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1515 NCollection_Sequence<bool> aSectClosures;
1516 GetSections( aSectNames, aSectTypes, aSectClosures );
1518 gp_XY aDelta( theDx, theDy );
1519 for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ )
1521 PointsList aPoints = GetPoints( i );
1522 for( int j = 1, n = aPoints.Size(); j <= n; ++j )
1524 Point& aPoint = aPoints.ChangeValue( j );
1527 SetPoints( i, aPoints );
1532 void HYDROData_PolylineXY::Transform( const QTransform& theTrsf )
1534 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1535 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1536 NCollection_Sequence<bool> aSectClosures;
1537 GetSections( aSectNames, aSectTypes, aSectClosures );
1539 for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ ) {
1540 PointsList aPoints = GetPoints( i );
1541 for( int j = 1, n = aPoints.Size(); j <= n; ++j ) {
1542 Point& aPoint = aPoints.ChangeValue( j );
1544 QPointF aTrsfPoint = theTrsf.map( QPointF( aPoint.X(), aPoint.Y() ) );
1546 aPoint.SetX( aTrsfPoint.x() );
1547 aPoint.SetY( aTrsfPoint.y() );
1549 SetPoints( i, aPoints );
1555 bool HYDROData_PolylineXY::IsCustom() const
1557 if( myIsInCustomFlag )
1560 bool isNull = GetShape().IsNull();
1563 HYDROData_PolylineXY* aThat = const_cast<HYDROData_PolylineXY*>( this );
1564 aThat->myIsInCustomFlag = true;
1565 for( int i=0, n=NbSections(); i<n; i++ )
1566 aNbPoints += NbPoints( i );
1567 aThat->myIsInCustomFlag = false;
1569 return !isNull && aNbPoints == 0;
1572 bool HYDROData_PolylineXY::GetIsInCustomFlag() const
1574 return myIsInCustomFlag;
1577 void HYDROData_PolylineXY::SetIsInCustomFlag( bool theValue )
1579 myIsInCustomFlag = theValue;
1582 void HYDROData_PolylineXY::Interpolate()
1584 ImportShape( GetShape(), true, NULL );