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>
74 #include <TDataStd_ExtStringArray.hxx>
76 #include <TopoDS_Iterator.hxx>
77 #include <TopTools_ListIteratorOfListOfShape.hxx>
78 #include <TopTools_HSequenceOfShape.hxx>
79 #include <TopExp_Explorer.hxx>
80 #include <ShapeAnalysis_FreeBounds.hxx>
84 #include <QPainterPath>
88 #include "HYDRO_trace.hxx"
89 #include <BRepTools.hxx>
93 static const Standard_GUID GUID_IS_UNEDITABLE("e5799736-9030-4051-91a4-2e58321fa153");
95 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
97 TCollection_AsciiString getUniqueSectionName( const NCollection_Sequence<TCollection_AsciiString>& theNamesSeq )
99 NCollection_Map<TCollection_AsciiString> aNamesMap;
101 for ( int i = 1, n = theNamesSeq.Size(); i <= n; ++i )
103 const TCollection_AsciiString& aSectName = theNamesSeq.Value( i );
104 aNamesMap.Add( aSectName );
107 TCollection_AsciiString aResName;
112 aResName = TCollection_AsciiString( "Section_" ) + aPrefIdx;
115 while ( aNamesMap.Contains( aResName ) );
120 TCollection_AsciiString getUniqueSectionName( const Handle(TDataStd_ExtStringList)& theNamesList )
122 NCollection_Sequence<TCollection_AsciiString> aNamesSeq;
124 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( theNamesList->List() );
125 for ( ; aNamesIter.More(); aNamesIter.Next() )
126 aNamesSeq.Append( aNamesIter.Value() );
128 return getUniqueSectionName( aNamesSeq );
131 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline)
133 HYDROData_PolylineXY::HYDROData_PolylineXY()
134 : HYDROData_IPolyline(),
135 myIsInCustomFlag( false )
139 HYDROData_PolylineXY::~HYDROData_PolylineXY()
143 QStringList HYDROData_PolylineXY::DumpToPython( const QString& thePyScriptPath,
144 MapOfTreatedObjects& theTreatedObjects ) const
146 QStringList aResList = dumpObjectCreation( theTreatedObjects );
147 QString aPolylineName = GetObjPyName();
149 // Set the wire color
150 QStringList aWireColorDef;
152 QColor aWireColor = GetWireColor();
153 setPythonObjectColor( aWireColorDef, aWireColor, DefaultWireColor(), "SetWireColor" );
155 if ( !aWireColorDef.isEmpty() )
157 aResList << aWireColorDef;
158 aResList << QString( "" );
161 bool anIsEditable = IsEditable();
164 // If polyline is not editable we try to import the shape from geom
165 TCollection_AsciiString aGeomObjectEntry = GetGeomObjectEntry();
166 if ( !aGeomObjectEntry.IsEmpty() )
168 QString aSalomeObjName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "polyline_sobj" );
169 aResList << QString( "%1 = salome.myStudy.FindObjectID( \"%2\" )" )
170 .arg( aSalomeObjName ).arg( aGeomObjectEntry.ToCString() );
172 aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() )" )
173 .arg( aPolylineName ).arg( aSalomeObjName );
175 aResList << QString( "%1.SetGeomObjectEntry( \"%2\" )" )
176 .arg( aPolylineName ).arg( aGeomObjectEntry.ToCString() );
182 NCollection_Sequence<TCollection_AsciiString> aSectNames;
183 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
184 NCollection_Sequence<bool> aSectClosures;
185 GetSections( aSectNames, aSectTypes, aSectClosures );
187 for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
189 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
190 const SectionType& aSectType = aSectTypes.Value( i );
191 bool aSectClosure = aSectClosures.Value( i );
193 aResList << QString( "%1.AddSection( \"%2\", %3, %4 )" ).arg( aPolylineName )
194 .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
196 HYDROData_IPolyline::PointsList aSectPointsList = GetPoints( i - 1 );
197 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
199 const Point& aSectPoint = aSectPointsList.Value( k );
201 QString anXStr = QString::number( aSectPoint.X(), 'f', 2 );
202 QString anYStr = QString::number( aSectPoint.Y(), 'f', 2 );
203 aResList << QString( "%1.AddPoint( %2, gp_XY( %3, %4 ) )" ).arg( aPolylineName )
204 .arg( i - 1 ).arg( anXStr ).arg( anYStr );
208 aResList << QString( "" );
209 aResList << QString( "%1.Update()" ).arg( aPolylineName );
210 aResList << QString( "" );
215 QVariant HYDROData_PolylineXY::GetDataVariant()
217 QPainterPath aPath = GetPainterPath();
220 aVarData.setValue<QPainterPath>( aPath );
225 QColor HYDROData_PolylineXY::DefaultWireColor()
227 return QColor( Qt::black );
230 bool HYDROData_PolylineXY::ImportFromGeomIOR( const TCollection_AsciiString& theIOR )
235 if ( theIOR.IsEmpty() )
238 TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() );
239 if ( aShape.IsNull() )
242 return ImportShape( aShape, false, NULL );
246 void HYDROData_PolylineXY::SetGeomObjectEntry( const TCollection_AsciiString& theEntry )
248 Handle(TDataStd_AsciiString) anAttr = TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), theEntry );
249 anAttr->SetID(TDataStd_AsciiString::GetID());
252 TCollection_AsciiString HYDROData_PolylineXY::GetGeomObjectEntry() const
254 TCollection_AsciiString aRes;
256 TDF_Label aLabel = myLab.FindChild( DataTag_GeomObjectEntry, false );
257 if ( !aLabel.IsNull() )
259 Handle(TDataStd_AsciiString) anAsciiStr;
260 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
261 aRes = anAsciiStr->Get();
267 bool convertEdgeToSection( const TopoDS_Edge& theEdge,
268 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
269 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
270 NCollection_Sequence<bool>& theSectClosures,
271 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
273 bool IsInterpolationAllowed,
274 double theDeflection )
276 Standard_Real aFirst = 0.0, aLast = 0.0;
277 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
278 if ( anEdgeGeomCurve.IsNull() )
281 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
282 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
284 HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
285 HYDROData_PolylineXY::PointsList aPointsList;
287 if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
289 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
291 gp_Pnt aFirstPoint, aLastPoint;
292 aGeomLine->D0( aFirst, aFirstPoint );
293 aGeomLine->D0( aLast, aLastPoint );
295 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
296 aPointsList.Append( aSectFirstPoint );
298 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
299 aPointsList.Append( aSectLastPoint );
301 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
303 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
305 BRepAdaptor_Curve anAdaptorCurve( theEdge );
306 GCPnts_QuasiUniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
307 //GCPnts_UniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
309 int aNbPoints = aDiscrete.NbPoints();
311 // Decrease the number of imported poles because of last one
312 // pole is the closing point which are the start point
313 if ( anIsEdgeClosed ) aNbPoints--;
315 for ( int i = 1; i <= aNbPoints; ++i )
317 const gp_Pnt& aPoint = aDiscrete.Value( i );
319 HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
320 aPointsList.Append( aSectPoint );
325 // Other curve types are not supported
329 if ( aPointsList.IsEmpty() )
332 theSectNames.Append( aSectName );
333 theSectTypes.Append( aSectionType );
334 theSectClosures.Append( anIsEdgeClosed );
335 theSectPoints.Append( aPointsList );
341 bool convertEdgesToSections( const TopoDS_Edge& theEdge,
342 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
343 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
344 NCollection_Sequence<bool>& theSectClosures,
345 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
347 bool IsInterpolationAllowed,
348 double theDeflection,
349 const Handle( HYDROData_PolylineXY )& theOldPolyline )
351 DEBTRACE("convertEdgesToSections")
352 Standard_Real aFirst = 0.0, aLast = 0.0;
353 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
354 if ( anEdgeGeomCurve.IsNull() )
357 bool isPrevious = (theSectTypes.Size() > 0);
358 DEBTRACE("nb sections: " << theSectTypes.Size());
359 HYDROData_PolylineXY::SectionType prevSectType = HYDROData_PolylineXY::SECTION_SPLINE;;
360 HYDROData_PolylineXY::PointsList prevPointList;
361 bool isPrevClosed = true;
364 prevSectType = theSectTypes.Last();
365 prevPointList = theSectPoints.Last();
366 isPrevClosed = theSectClosures.Last();
369 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
370 anIsEdgeClosed &= IsCanBeClosed; // on split, resulting edges are normally not closed...
371 HYDROData_PolylineXY::SectionType aSectionType ;
372 if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
374 aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
376 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
378 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
382 // Other curve types are not supported
386 bool isNewSection = !isPrevious || isPrevClosed || anIsEdgeClosed || prevSectType != aSectionType;
387 DEBTRACE(isNewSection <<": " << !isPrevious << " " << isPrevClosed << " " << anIsEdgeClosed << " " << (prevSectType != aSectionType));
389 HYDROData_PolylineXY::PointsList aPointsList;
392 aPointsList = prevPointList;
395 if( aSectionType == HYDROData_PolylineXY::SECTION_POLYLINE )
397 DEBTRACE("SECTION_POLYLINE");
398 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
400 gp_Pnt aFirstPoint, aLastPoint;
401 aGeomLine->D0( aFirst, aFirstPoint );
402 aGeomLine->D0( aLast, aLastPoint );
403 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
404 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
407 if (aSectFirstPoint == prevPointList.Last())
409 DEBTRACE("points shared: a");//aPointsList.Append( aSectFirstPoint );
410 aPointsList.Append( aSectLastPoint );
412 else if (aSectLastPoint == prevPointList.Last())
414 DEBTRACE("points shared: b");//aPointsList.Append( aSectLastPoint );
415 aPointsList.Append( aSectFirstPoint );
417 else if (aSectFirstPoint == prevPointList.First())
419 DEBTRACE("points shared: c");//aPointsList.Prepend( aSectFirstPoint );
420 aPointsList.Prepend( aSectLastPoint );
422 else if (aSectLastPoint == prevPointList.First())
424 DEBTRACE("points shared: d");//aPointsList.Prepend( aSectLastPoint );
425 aPointsList.Prepend( aSectFirstPoint );
429 DEBTRACE("no point shared")
430 isNewSection = true; // no point shared, new section
432 aPointsList.Append( aSectFirstPoint );
433 aPointsList.Append( aSectLastPoint );
438 DEBTRACE("new section");
439 aPointsList.Append( aSectFirstPoint );
440 aPointsList.Append( aSectLastPoint );
443 else // aSectionType == HYDROData_PolylineXY::SECTION_SPLINE
445 DEBTRACE("SECTION_SPLINE");
449 BRepAdaptor_Curve anAdaptorCurve(theEdge);
450 if (theOldPolyline.IsNull()) // --- no previous polyline: build a set of points from scratch for the spline
452 GCPnts_QuasiUniformDeflection aDiscrete(anAdaptorCurve, theDeflection);
454 int aNbPoints = aDiscrete.NbPoints();
456 // Decrease the number of imported poles because of last one
457 // pole is the closing point which are the start point
461 for (int i = 1; i <= aNbPoints; ++i)
463 const gp_Pnt& aPoint = aDiscrete.Value(i);
464 HYDROData_PolylineXY::Point aSectPoint(aPoint.X(), aPoint.Y());
465 aPointsList.Append(aSectPoint);
468 gp_Pnt endPts[] = {gp_Pnt(aPointsList.First().X(),aPointsList.First().Y(), 0),
469 gp_Pnt(aPointsList.Last().X(),aPointsList.Last().Y(), 0) };
470 DEBTRACE("curve start: "<< endPts[0].X() << " " << endPts[0].Y());
471 DEBTRACE("curve end: "<< endPts[1].X() << " " << endPts[1].Y());
473 else // --- split of a previous polyline: try to retrieve old sets of points and add intersection points
475 const gp_Pnt aEndPs[] = { anAdaptorCurve.Value(anAdaptorCurve.FirstParameter()).XYZ(),
476 anAdaptorCurve.Value(anAdaptorCurve.LastParameter()).XYZ() };
477 double midPar = (anAdaptorCurve.LastParameter() + anAdaptorCurve.FirstParameter())/2;
479 anAdaptorCurve.D0(midPar, midPnt);
480 DEBTRACE("curve first point: " << aEndPs[0].X() << " " << aEndPs[0].Y() << " " << aEndPs[0].Z());
481 DEBTRACE("curve last point: " << aEndPs[1].X() << " " << aEndPs[1].Y() << " " << aEndPs[1].Z());
482 DEBTRACE("curve mid point: " << midPnt.X() << " " << midPnt.Y() << " " << midPnt.Z());
484 std::vector<TopoDS_Wire> aCurves;
485 HYDROData_PolylineOperator::GetWires(theOldPolyline, aCurves);
487 int nbSections = theOldPolyline->NbSections();
488 DEBTRACE("nbSections: "<< nbSections << ", nbCurves: " << aCurves.size() );
489 for (int isec = 0; isec < nbSections; isec++)
491 DEBTRACE("section: "<< isec);
492 bool isOldSectionclosed = theOldPolyline->IsClosedSection(isec);
493 TopoDS_Wire aWire = aCurves[isec]; // we suppose sections and wires are in the same order
494 TopExp_Explorer anExp(aWire, TopAbs_EDGE);
495 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current()); // the first is OK: only one normally with splines
496 BRepAdaptor_Curve adaptorOldCurve(anEdge);
497 double pfirst = adaptorOldCurve.FirstParameter();
498 double plast = adaptorOldCurve.LastParameter();
499 DEBTRACE("previous curve first last : "<< pfirst << " " << plast);
500 double p[3] = {-1, -1};
501 double d0= ProjectPointToCurve(aEndPs[0].XYZ(), adaptorOldCurve,p[0]);
502 double d1= ProjectPointToCurve(aEndPs[1].XYZ(), adaptorOldCurve,p[1]);
503 double d2= ProjectPointToCurve(midPnt.XYZ(), adaptorOldCurve, p[2]);
504 DEBTRACE("d0: "<<d0<<" d1: "<<d1<<" d2: "<<d2<<" p0: "<<p[0]<<" p1: "<<p[1]<<" p2: "<<p[2]);
505 if ((d0 < 1.e-3) && (d1 < 1.e-3) && (d2 < 1.e-3)) // we got the good old curve (and the good section)
510 DEBTRACE("isOldSectionclosed: " << isOldSectionclosed);
511 if (!isOldSectionclosed) // no need to check first and last points on an open curve
520 else // old section closed: check if we use first or last points...
522 if((pmin < pmax) && ((std::abs(pmin - pfirst)> 1.e-3) && (std::abs(pmax - plast) >1.e-3))) // internal points forward
524 else if ((pmin > pmax) && ((std::abs(pmin - plast)> 1.e-3) && (std::abs(pmax - pfirst) >1.e-3))) // internal points reverse
530 else if ((std::abs(pmin - plast) <1.e-3) && (p[2] < pmax)) // forward, replace pmin par pfirst
532 else if ((std::abs(pmin - plast) <1.e-3) && (p[2] > pmax)) // reverse
538 else if ((std::abs(pmax - pfirst) <1.e-3) && (p[2] < pmin)) // reverse
544 else if ((std::abs(pmax - pfirst) <1.e-3) && (p[2] > pmin)) // forward, replace pmax par plast
547 DEBTRACE("forward: "<< forward << " pmin " << pmin << " pmax " << pmax);
548 HYDROData_PolylineXY::Point aFirstPoint, aLastPoint;
551 aFirstPoint = HYDROData_PolylineXY::Point(aEndPs[0].X(), aEndPs[0].Y());
552 aLastPoint = HYDROData_PolylineXY::Point(aEndPs[1].X(), aEndPs[1].Y());
556 aFirstPoint = HYDROData_PolylineXY::Point(aEndPs[1].X(), aEndPs[1].Y());
557 aLastPoint = HYDROData_PolylineXY::Point(aEndPs[0].X(), aEndPs[0].Y());
559 aPointsList.Append(aFirstPoint);
561 HYDROData_PolylineXY::PointsList aSectPoints = theOldPolyline->GetPoints(isec, false);
562 int nbPoints = aSectPoints.Length();
563 DEBTRACE("nbPoints " << nbPoints);
565 for (int i=1; i<=nbPoints; i++)
567 HYDROData_PolylineXY::Point aPoint = aSectPoints.Value(i);
568 gp_XYZ p(aPoint.X(), aPoint.Y(), 0);
570 double d = ProjectPointToCurve(p, adaptorOldCurve, param);
571 if ((param > pmin) && (param < pmax))
573 DEBTRACE("param: " << param);
574 aPointsList.Append(aPoint);
578 for (int i=nbPoints; i>0; i--)
580 HYDROData_PolylineXY::Point aPoint = aSectPoints.Value(i);
581 gp_XYZ p(aPoint.X(), aPoint.Y(), 0);
583 double d = ProjectPointToCurve(p, adaptorOldCurve, param);
584 if ((param > pmin) && (param < pmax))
586 DEBTRACE("param: " << param);
587 aPointsList.Append(aPoint);
591 aPointsList.Append(aLastPoint);
598 if ( aPointsList.IsEmpty() )
601 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
604 DEBTRACE("isNewSection");
605 theSectNames.Append( aSectName );
606 theSectTypes.Append( aSectionType );
607 theSectClosures.Append( anIsEdgeClosed );
608 theSectPoints.Append( aPointsList );
612 DEBTRACE("sameSection");
613 theSectPoints.SetValue(theSectPoints.Length(), aPointsList);
619 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape,
620 bool IsInterpolationAllowed,
621 const Handle( HYDROData_PolylineXY )& theOldPolyline,
622 bool IsClosureAllowed,
623 double theDeviation )
625 DEBTRACE("ImportShape");
626 if ( theShape.IsNull() )
629 //std::string brepName = this->GetName().toStdString();
630 //brepName += ".brep";
631 //BRepTools::Write( theShape, brepName.c_str() );
635 bool anIsCanBeImported = false;
637 NCollection_Sequence<TCollection_AsciiString> aSectNames;
638 NCollection_Sequence<SectionType> aSectTypes;
639 NCollection_Sequence<bool> aSectClosures;
640 NCollection_Sequence<PointsList> aSectPoints;
642 if ( theShape.ShapeType() == TopAbs_EDGE )
644 DEBTRACE("TopAbs_EDGE");
645 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
646 // anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes,
647 // aSectClosures, aSectPoints, true, IsInterpolationAllowed, theDeviation );
648 anIsCanBeImported = convertEdgesToSections( anEdge, aSectNames, aSectTypes, aSectClosures,
649 aSectPoints, IsClosureAllowed, IsInterpolationAllowed,
650 theDeviation, theOldPolyline );
652 else if ( theShape.ShapeType() == TopAbs_WIRE )
654 DEBTRACE("TopAbs_WIRE");
655 TopTools_SequenceOfShape anEdges;
656 HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
658 anIsCanBeImported = !anEdges.IsEmpty();
659 for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
661 TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
662 anIsCanBeImported = convertEdgesToSections( aWireEdge, aSectNames, aSectTypes, aSectClosures,
663 aSectPoints, IsClosureAllowed, IsInterpolationAllowed,
664 theDeviation, theOldPolyline );
668 if ( anIsCanBeImported )
670 for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
672 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
673 const SectionType& aSectType = aSectTypes.Value( i );
674 bool anIsSectionClosed = aSectClosures.Value( i );
675 const PointsList& aSectPointsList = aSectPoints( i );
677 AddSection( aSectName, aSectType, anIsSectionClosed );
678 SetPoints( i - 1, aSectPointsList );
683 TopoDS_Shape aShape = theShape;
685 if ( theShape.ShapeType() == TopAbs_EDGE )
687 // We make the wire from incoming edge because of other algorithms
688 // are waiting at least the wire from polyline
689 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
690 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
692 if ( aMakeWire.IsDone() )
693 aShape = aMakeWire.Wire();
696 gp_Pln aPlane( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
697 BRepBuilderAPI_MakeFace aMakeFace( aPlane );
699 BRepOffsetAPI_NormalProjection aProj( aMakeFace.Face() );
702 TopoDS_Shape aResult;
704 aResult = aProj.Shape();
709 setEditable( anIsCanBeImported );
714 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
715 const bool& theIsClosed,
716 const NCollection_Sequence<gp_XYZ>& thePoints )
719 if( theType == SECTION_POLYLINE )
721 int aNbPoints = thePoints.Length();
722 BRepBuilderAPI_MakePolygon aMakeWire;
723 for ( int i = 1, n = aNbPoints; i <= n ; ++i )
725 gp_XYZ aPoint = thePoints.Value( i );
726 gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
727 aMakeWire.Add( aPnt );
729 if( theIsClosed && ( aNbPoints > 2 ) )
732 if ( aMakeWire.IsDone() )
733 aWire = aMakeWire.Wire();
735 else //if( theType == PolylineSection::SECTION_SPLINE )
737 BRepBuilderAPI_MakeWire aMakeWire;
739 if ( thePoints.Size() > 1 )
741 Handle(Geom_BSplineCurve) aCurve =
742 HYDROData_BSplineOperation::ComputeCurve( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
744 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aCurve ).Edge();
745 aMakeWire.Add( anEdge );
748 if ( aMakeWire.IsDone() )
755 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
756 const SectionType& theType,
757 const bool& theIsClosed,
758 const NCollection_Sequence<gp_XYZ>& thePoints )
760 if ( thePoints.IsEmpty() )
763 if ( theType == SECTION_POLYLINE )
765 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
766 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
768 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
770 const gp_XYZ& aSectPoint = thePoints.Value( i );
772 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
776 thePath.closeSubpath();
780 Handle(Geom_BSplineCurve) aCurve =
781 HYDROData_BSplineOperation::ComputeCurve( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
782 HYDROData_BSplineOperation::ComputePath( aCurve, thePath );
786 void HYDROData_PolylineXY::Update()
790 // If polyline is not editable we no need to update it wire
795 HYDROData_IPolyline::Update();
797 NCollection_Sequence<TCollection_AsciiString> aSectNames;
798 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
799 NCollection_Sequence<bool> aSectClosures;
800 GetSections( aSectNames, aSectTypes, aSectClosures );
802 //BRepBuilderAPI_MakeWire aMakeWire;
804 TopTools_ListOfShape aSectionWiresList;
806 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
808 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
809 SectionType aSectionType = aSectTypes.Value( aSectionId );
810 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
812 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
813 if ( aSectPointsList.IsEmpty() )
816 NCollection_Sequence<gp_XYZ> aPoints;
817 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
819 const Point& aSectPoint = aSectPointsList.Value( i );
821 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
822 aPoints.Append( aPoint );
825 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
826 if ( !aSectionWire.IsNull() ) {
827 aSectionWiresList.Append( aSectionWire );
828 //aMakeWire.Add( aSectionWire );
831 // all input wires in the <aSectionWiresList>
832 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
833 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
834 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
835 for(;it.More();it.Next())
837 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
838 for(;it2.More();it2.Next())
839 aSeqEdges->Append(it2.Current());
843 TopoDS_Compound aCmp;
844 TopoDS_Shape aResult;
845 aBB.MakeCompound(aCmp);
846 if(aSeqEdges->Length() >1)
848 ShapeAnalysis_FreeBounds::ConnectEdgesToWires( aSeqEdges, 1E-5, Standard_True, aSeqWires );
850 if( aSeqWires->Length()==1 )
851 aResult = aSeqWires->Value( 1 );
854 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
856 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
862 else if (aSeqEdges->Length() == 1)
864 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
866 aResult = mkWire.Wire();
872 bool HYDROData_PolylineXY::IsHas2dPrs() const
877 bool HYDROData_PolylineXY::IsEditable() const
879 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
882 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
884 if ( !theIsEditable )
885 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
887 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
891 * Returns true if polyline is closed
893 bool HYDROData_PolylineXY::IsClosed(const bool theIsSimpleCheck) const
895 DEBTRACE("IsClosed " << theIsSimpleCheck << " " << GetName());
896 bool anIsClosed = false;
898 TopoDS_Shape aShape = GetShape();
902 TopTools_SequenceOfShape aWires;
903 HYDROData_ShapesTool::ExploreShapeToShapes(aShape, TopAbs_WIRE, aWires);
905 int aNbWires = aWires.Length();
906 if (theIsSimpleCheck)
908 anIsClosed = aNbWires > 0;
909 for (int i = 1; i <= aNbWires && anIsClosed; ++i)
911 const TopoDS_Shape& aWire = aWires.Value(i);
912 anIsClosed = BRep_Tool::IsClosed(aWire);
918 anIsClosed = BRep_Tool::IsClosed(aWires.First());
921 DEBTRACE("aNbWires " << aNbWires);
922 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
923 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
924 for (int i = 1; i <= aNbWires; ++i)
926 const TopoDS_Shape& aWire = aWires.Value(i);
927 TopExp_Explorer it2(aWire, TopAbs_EDGE);
928 for (; it2.More(); it2.Next())
929 aSeqEdges->Append(it2.Current());
931 if (aSeqEdges->Length() > 1)
933 DEBTRACE(aSeqEdges->Length());
934 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires);
935 if (aSeqWires->Length() == 1)
937 DEBTRACE(aSeqWires->Length());
938 const TopoDS_Wire& aPolylineWire = TopoDS::Wire(aSeqWires->Value(1));
939 anIsClosed = BRep_Tool::IsClosed(aPolylineWire);
948 int HYDROData_PolylineXY::GetNbConnectedWires(Handle(TopTools_HSequenceOfShape)& aConnectedWires) const
950 TopoDS_Shape aShape = GetShape();
953 int aNbconnectedWires = 0;
954 TopTools_SequenceOfShape aWires;
955 HYDROData_ShapesTool::ExploreShapeToShapes(aShape, TopAbs_WIRE, aWires);
956 int aNbWires = aWires.Length();
959 aNbconnectedWires = aNbWires;
960 aConnectedWires->Append(aWires.First());
964 DEBTRACE("aNbWires " << aNbWires);
965 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
966 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
967 for (int i = 1; i <= aNbWires; ++i)
969 const TopoDS_Shape& aWire = aWires.Value(i);
970 TopExp_Explorer it2(aWire, TopAbs_EDGE);
971 for (; it2.More(); it2.Next())
972 aSeqEdges->Append(it2.Current());
974 if (aSeqEdges->Length() > 1)
976 DEBTRACE(aSeqEdges->Length());
977 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires);
979 aConnectedWires = aSeqWires;
980 aNbconnectedWires = aConnectedWires->Length();
981 DEBTRACE("aNbconnectedWires " << aNbconnectedWires);
983 return aNbconnectedWires;
986 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
987 const int thePointIndex ) const
989 double aResDistance = -1;
990 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
993 if ( thePointIndex == 0 )
996 SectionType aSectionType = GetSectionType( theSectionIndex );
997 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
998 PointsList aSectPointsList = GetPoints( theSectionIndex );
999 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
1000 return aResDistance;
1002 if ( aSectionType == SECTION_POLYLINE )
1006 Point aPrevPoint = aSectPointsList.Value( 1 );
1007 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
1009 const Point& aSectPoint = aSectPointsList.Value( i );
1010 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
1011 aPrevPoint = aSectPoint;
1013 if ( thePointIndex == i - 1 )
1019 gp_XYZ aPointToTest;
1021 int aSectNbPoints = aSectPointsList.Size();
1022 NCollection_Sequence<gp_XYZ> aPoints;
1023 for( int i = 1 ; i <= aSectNbPoints; ++i )
1025 const Point& aSectPoint = aSectPointsList.Value( i );
1027 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1028 aPoints.Append( aPoint );
1030 if ( thePointIndex == i - 1 )
1031 aPointToTest = aPoint;
1034 Handle(Geom_BSplineCurve) aCurve =
1035 HYDROData_BSplineOperation::ComputeCurve( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
1037 Quantity_Parameter aFirstParam = aCurve->FirstParameter();
1038 Quantity_Parameter aSecondParam = aCurve->LastParameter();
1040 if ( thePointIndex != aSectNbPoints - 1 )
1042 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aCurve );
1043 aSecondParam = aProject.LowerDistanceParameter();
1046 GeomAdaptor_Curve anAdap( aCurve );
1048 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
1051 return aResDistance;
1054 int HYDROData_PolylineXY::NbSections() const
1056 Handle(TDataStd_ExtStringList) aNamesList;
1057 Handle(TDataStd_IntegerList) aTypesList;
1058 Handle(TDataStd_BooleanList) aClosuresList;
1059 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1061 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
1064 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
1065 const SectionType theSectionType,
1066 const bool theIsClosed )
1068 Handle(TDataStd_ExtStringList) aNamesList;
1069 Handle(TDataStd_IntegerList) aTypesList;
1070 Handle(TDataStd_BooleanList) aClosuresList;
1071 getSectionsLists( aNamesList, aTypesList, aClosuresList );
1073 TCollection_ExtendedString aSectName( theSectName );
1074 if ( aSectName.Length() <= 0 )
1075 aSectName = getUniqueSectionName( aNamesList );
1077 aNamesList->Append( aSectName );
1078 aTypesList->Append( theSectionType );
1079 aClosuresList->Append( theIsClosed );
1084 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
1086 TCollection_AsciiString aResName;
1088 Handle(TDataStd_ExtStringList) aNamesList;
1089 Handle(TDataStd_IntegerList) aTypesList;
1090 Handle(TDataStd_BooleanList) aClosuresList;
1091 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1092 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1095 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
1096 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
1098 if ( aNamesIter.More() )
1099 aResName = aNamesIter.Value();
1104 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
1105 const TCollection_AsciiString& theSectionName )
1107 Handle(TDataStd_ExtStringList) aNamesList;
1108 Handle(TDataStd_IntegerList) aTypesList;
1109 Handle(TDataStd_BooleanList) aClosuresList;
1110 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1111 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1114 TDataStd_ListOfExtendedString anOldNamesList;
1115 anOldNamesList = aNamesList->List();
1117 // Refill the existing list
1118 aNamesList->Clear();
1120 TCollection_ExtendedString aNewSectName = theSectionName;
1122 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
1123 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
1124 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
1127 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
1129 Handle(TDataStd_ExtStringList) aNamesList;
1130 Handle(TDataStd_IntegerList) aTypesList;
1131 Handle(TDataStd_BooleanList) aClosuresList;
1132 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1133 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
1134 return SECTION_POLYLINE;
1136 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
1137 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
1139 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
1142 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
1143 const SectionType theSectionType )
1145 Handle(TDataStd_ExtStringList) aNamesList;
1146 Handle(TDataStd_IntegerList) aTypesList;
1147 Handle(TDataStd_BooleanList) aClosuresList;
1148 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1149 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
1152 TColStd_ListOfInteger anOldTypesList;
1153 anOldTypesList = aTypesList->List();
1155 // Refill the existing list
1156 aTypesList->Clear();
1158 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
1159 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
1160 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
1165 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
1167 Handle(TDataStd_ExtStringList) aNamesList;
1168 Handle(TDataStd_IntegerList) aTypesList;
1169 Handle(TDataStd_BooleanList) aClosuresList;
1170 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1171 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
1174 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
1175 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
1177 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
1180 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
1181 const bool theIsClosed )
1183 Handle(TDataStd_ExtStringList) aNamesList;
1184 Handle(TDataStd_IntegerList) aTypesList;
1185 Handle(TDataStd_BooleanList) aClosuresList;
1186 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1187 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
1190 TDataStd_ListOfByte anOldClosuresList;
1191 anOldClosuresList = aClosuresList->List();
1193 // Refill the existing list
1194 aClosuresList->Clear();
1196 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
1197 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
1198 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
1203 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
1204 NCollection_Sequence<SectionType>& theSectTypes,
1205 NCollection_Sequence<bool>& theSectClosures ) const
1207 theSectNames.Clear();
1208 theSectTypes.Clear();
1209 theSectClosures.Clear();
1213 const_cast<HYDROData_PolylineXY*>( this )->Interpolate();
1216 Handle(TDataStd_ExtStringList) aNamesList;
1217 Handle(TDataStd_IntegerList) aTypesList;
1218 Handle(TDataStd_BooleanList) aClosuresList;
1219 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1220 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
1223 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
1224 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
1225 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
1226 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
1227 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
1229 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
1230 SectionType aSectType = (SectionType)aTypesIter.Value();
1231 bool aSectClosures = aClosuresIter.Value();
1233 theSectNames.Append( aSectName );
1234 theSectTypes.Append( aSectType );
1235 theSectClosures.Append( aSectClosures );
1239 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
1241 Handle(TDataStd_ExtStringList) aNamesList;
1242 Handle(TDataStd_IntegerList) aTypesList;
1243 Handle(TDataStd_BooleanList) aClosuresList;
1244 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1245 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1248 if ( aNamesList->Extent() == 1 )
1250 removeSectionsLists();
1251 removePointsLists();
1252 removeSectionColor();
1256 TDataStd_ListOfExtendedString anOldNamesList;
1257 anOldNamesList = aNamesList->List();
1259 TColStd_ListOfInteger anOldTypesList;
1260 anOldTypesList = aTypesList->List();
1262 TDataStd_ListOfByte anOldClosuresList;
1263 anOldClosuresList = aClosuresList->List();
1265 // Refill the existing lists
1266 aNamesList->Clear();
1267 aTypesList->Clear();
1268 aClosuresList->Clear();
1270 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
1271 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
1272 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
1273 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
1274 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
1276 if ( i == theSectionIndex )
1277 continue; // skip index to remove
1279 aNamesList->Append( aNamesIter.Value() );
1280 aTypesList->Append( aTypesIter.Value() );
1281 aClosuresList->Append( (bool)aClosuresIter.Value() );
1284 // Remove points that belongs to removed section
1285 removePointsLists( theSectionIndex );
1286 removeSectionColor (theSectionIndex);
1292 void HYDROData_PolylineXY::RemoveSections()
1294 removeSectionsLists();
1295 removePointsLists();
1299 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
1300 const Point& thePoint,
1301 const int thePointIndex )
1303 Handle(TDataStd_RealList) aListX, aListY;
1304 getPointsLists( theSectionIndex, aListX, aListY );
1306 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
1308 aListX->Append( thePoint.X() );
1309 aListY->Append( thePoint.Y() );
1313 TColStd_ListOfReal anOldListX;
1314 anOldListX = aListX->List();
1316 TColStd_ListOfReal anOldListY;
1317 anOldListY = aListY->List();
1319 // Refill the existing lists
1323 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1324 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1325 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1327 double aCoordX = anIterX.Value();
1328 double aCoordY = anIterY.Value();
1330 if ( i == thePointIndex )
1332 // Insert our new point
1333 aListX->Append( thePoint.X() );
1334 aListY->Append( thePoint.Y() );
1337 aListX->Append( aCoordX );
1338 aListY->Append( aCoordY );
1345 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
1346 const Point& thePoint,
1347 const int thePointIndex )
1349 Handle(TDataStd_RealList) aListX, aListY;
1350 getPointsLists( theSectionIndex, aListX, aListY );
1352 if ( thePointIndex < 0 )
1354 aListX->Prepend( thePoint.X() );
1355 aListY->Prepend( thePoint.Y() );
1357 else if ( thePointIndex >= aListX->Extent() )
1359 aListX->Append( thePoint.X() );
1360 aListY->Append( thePoint.Y() );
1364 TColStd_ListOfReal anOldListX;
1365 anOldListX = aListX->List();
1367 TColStd_ListOfReal anOldListY;
1368 anOldListY = aListY->List();
1370 // Refill the existing lists
1374 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1375 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1376 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1378 double aCoordX = anIterX.Value();
1379 double aCoordY = anIterY.Value();
1381 if ( i == thePointIndex )
1383 // Insert our new point instead of old one
1384 aCoordX = thePoint.X();
1385 aCoordY = thePoint.Y();
1388 aListX->Append( aCoordX );
1389 aListY->Append( aCoordY );
1396 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
1397 const PointsList& thePoints )
1399 Handle(TDataStd_RealList) aListX, aListY;
1400 getPointsLists( theSectionIndex, aListX, aListY );
1405 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1407 const Point& aPoint = thePoints.Value( i );
1408 aListX->Append( aPoint.X() );
1409 aListY->Append( aPoint.Y() );
1413 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
1414 const int thePointIndex )
1416 Handle(TDataStd_RealList) aListX, aListY;
1417 getPointsLists( theSectionIndex, aListX, aListY, false );
1418 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1421 if ( aListX->Extent() == 1 )
1423 removePointsLists( theSectionIndex );
1427 TColStd_ListOfReal anOldListX;
1428 anOldListX = aListX->List();
1430 TColStd_ListOfReal anOldListY;
1431 anOldListY = aListY->List();
1433 // Refill the existing lists
1437 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1438 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1439 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1441 if ( i == thePointIndex )
1442 continue; // skip index to remove
1444 aListX->Append( anIterX.Value() );
1445 aListY->Append( anIterY.Value() );
1452 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex, bool IsConvertToGlobal ) const
1454 PointsList aResList;
1458 const_cast<HYDROData_PolylineXY*>( this )->Interpolate();
1461 Handle(TDataStd_RealList) aListX, aListY;
1462 getPointsLists( theSectionIndex, aListX, aListY, false );
1463 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1466 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
1467 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
1468 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
1469 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
1471 Point aPoint( anIterX.Value(), anIterY.Value() );
1472 if (IsConvertToGlobal)
1473 aDoc->Transform( aPoint, false );
1474 aResList.Append( aPoint );
1480 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
1484 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1485 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1486 NCollection_Sequence<bool> aSectClosures;
1487 GetSections( aSectNames, aSectTypes, aSectClosures );
1489 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1491 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1492 SectionType aSectionType = aSectTypes.Value( aSectionId );
1493 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1495 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1496 if ( aSectPointsList.IsEmpty() )
1499 NCollection_Sequence<gp_XYZ> aPoints;
1500 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1502 const Point& aSectPoint = aSectPointsList.Value( i );
1504 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1505 aPoints.Append( aPoint );
1508 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );
1514 void HYDROData_PolylineXY::UpdateLocalCS( double theDx, double theDy )
1516 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1517 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1518 NCollection_Sequence<bool> aSectClosures;
1519 GetSections( aSectNames, aSectTypes, aSectClosures );
1521 gp_XY aDelta( theDx, theDy );
1522 for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ )
1524 PointsList aPoints = GetPoints( i );
1525 for( int j = 1, n = aPoints.Size(); j <= n; ++j )
1527 Point& aPoint = aPoints.ChangeValue( j );
1530 SetPoints( i, aPoints );
1535 void HYDROData_PolylineXY::Transform( const QTransform& theTrsf )
1537 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1538 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1539 NCollection_Sequence<bool> aSectClosures;
1540 GetSections( aSectNames, aSectTypes, aSectClosures );
1542 for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ ) {
1543 PointsList aPoints = GetPoints( i );
1544 for( int j = 1, n = aPoints.Size(); j <= n; ++j ) {
1545 Point& aPoint = aPoints.ChangeValue( j );
1547 QPointF aTrsfPoint = theTrsf.map( QPointF( aPoint.X(), aPoint.Y() ) );
1549 aPoint.SetX( aTrsfPoint.x() );
1550 aPoint.SetY( aTrsfPoint.y() );
1552 SetPoints( i, aPoints );
1558 bool HYDROData_PolylineXY::IsCustom() const
1560 if( myIsInCustomFlag )
1563 bool isNull = GetShape().IsNull();
1566 HYDROData_PolylineXY* aThat = const_cast<HYDROData_PolylineXY*>( this );
1567 aThat->myIsInCustomFlag = true;
1568 for( int i=0, n=NbSections(); i<n; i++ )
1569 aNbPoints += NbPoints( i );
1570 aThat->myIsInCustomFlag = false;
1572 return !isNull && aNbPoints == 0;
1575 bool HYDROData_PolylineXY::GetIsInCustomFlag() const
1577 return myIsInCustomFlag;
1580 void HYDROData_PolylineXY::SetIsInCustomFlag( bool theValue )
1582 myIsInCustomFlag = theValue;
1585 void HYDROData_PolylineXY::Interpolate()
1587 ImportShape( GetShape(), true, NULL );
1590 void HYDROData_PolylineXY::SetDBFInfo( const QStringList& theDBFTable )
1593 Handle_TDataStd_ExtStringArray TExtStrArr =
1594 TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_DBFTableInfo), 1, theDBFTable.size() );
1595 foreach (QString val, theDBFTable)
1597 std::string StdVal = val.toStdString();
1598 const char* aCVal = StdVal.c_str();
1599 TExtStrArr->SetValue(i, TCollection_ExtendedString(aCVal));
1604 bool HYDROData_PolylineXY::GetDBFInfo(QStringList& theDBFTable) const
1606 TDF_Label aLabel = myLab.FindChild( DataTag_DBFTableInfo, false );
1607 if ( !aLabel.IsNull() )
1609 Handle(TDataStd_ExtStringArray) anExtStrArr;
1610 if ( aLabel.FindAttribute( TDataStd_ExtStringArray::GetID(), anExtStrArr ) )
1612 for (int i = anExtStrArr->Lower(); i <= anExtStrArr->Upper(); i++ )
1614 Standard_ExtString str = anExtStrArr->Value(i).ToExtString();
1615 TCollection_AsciiString aText (str);
1616 theDBFTable << QString(aText.ToCString());