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 int nbSec = NbSections();
156 for (int i = 0; i < nbSec; i++)
159 GetSectionColor(i, aColor);
160 setPythonPolylineSectionColor(aWireColorDef, i, aColor );
161 //aWireColorDef << "";
164 if ( !aWireColorDef.isEmpty() )
166 aResList << aWireColorDef;
167 aResList << QString( "" );
170 bool anIsEditable = IsEditable();
173 // If polyline is not editable we try to import the shape from geom
174 TCollection_AsciiString aGeomObjectEntry = GetGeomObjectEntry();
175 if ( !aGeomObjectEntry.IsEmpty() )
177 QString aSalomeObjName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "polyline_sobj" );
178 aResList << QString( "%1 = salome.myStudy.FindObjectID( \"%2\" )" )
179 .arg( aSalomeObjName ).arg( aGeomObjectEntry.ToCString() );
181 aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() )" )
182 .arg( aPolylineName ).arg( aSalomeObjName );
184 aResList << QString( "%1.SetGeomObjectEntry( \"%2\" )" )
185 .arg( aPolylineName ).arg( aGeomObjectEntry.ToCString() );
191 NCollection_Sequence<TCollection_AsciiString> aSectNames;
192 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
193 NCollection_Sequence<bool> aSectClosures;
194 GetSections( aSectNames, aSectTypes, aSectClosures );
196 for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
198 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
199 const SectionType& aSectType = aSectTypes.Value( i );
200 bool aSectClosure = aSectClosures.Value( i );
202 aResList << QString( "%1.AddSection( \"%2\", %3, %4 )" ).arg( aPolylineName )
203 .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
205 HYDROData_IPolyline::PointsList aSectPointsList = GetPoints( i - 1 );
206 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
208 const Point& aSectPoint = aSectPointsList.Value( k );
210 QString anXStr = QString::number( aSectPoint.X(), 'f', 2 );
211 QString anYStr = QString::number( aSectPoint.Y(), 'f', 2 );
212 aResList << QString( "%1.AddPoint( %2, gp_XY( %3, %4 ) )" ).arg( aPolylineName )
213 .arg( i - 1 ).arg( anXStr ).arg( anYStr );
217 aResList << QString( "" );
218 aResList << QString( "%1.Update()" ).arg( aPolylineName );
219 aResList << QString( "" );
224 QVariant HYDROData_PolylineXY::GetDataVariant()
226 QPainterPath aPath = GetPainterPath();
229 aVarData.setValue<QPainterPath>( aPath );
234 QColor HYDROData_PolylineXY::DefaultWireColor()
236 return QColor( Qt::black );
239 bool HYDROData_PolylineXY::ImportFromGeomIOR( const TCollection_AsciiString& theIOR )
244 if ( theIOR.IsEmpty() )
247 TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() );
248 if ( aShape.IsNull() )
251 return ImportShape( aShape, false, NULL );
255 void HYDROData_PolylineXY::SetGeomObjectEntry( const TCollection_AsciiString& theEntry )
257 Handle(TDataStd_AsciiString) anAttr = TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), theEntry );
258 anAttr->SetID(TDataStd_AsciiString::GetID());
261 TCollection_AsciiString HYDROData_PolylineXY::GetGeomObjectEntry() const
263 TCollection_AsciiString aRes;
265 TDF_Label aLabel = myLab.FindChild( DataTag_GeomObjectEntry, false );
266 if ( !aLabel.IsNull() )
268 Handle(TDataStd_AsciiString) anAsciiStr;
269 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
270 aRes = anAsciiStr->Get();
276 bool convertEdgeToSection( const TopoDS_Edge& theEdge,
277 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
278 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
279 NCollection_Sequence<bool>& theSectClosures,
280 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
282 bool IsInterpolationAllowed,
283 double theDeflection )
285 Standard_Real aFirst = 0.0, aLast = 0.0;
286 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
287 if ( anEdgeGeomCurve.IsNull() )
290 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
291 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
293 HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
294 HYDROData_PolylineXY::PointsList aPointsList;
296 if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
298 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
300 gp_Pnt aFirstPoint, aLastPoint;
301 aGeomLine->D0( aFirst, aFirstPoint );
302 aGeomLine->D0( aLast, aLastPoint );
304 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
305 aPointsList.Append( aSectFirstPoint );
307 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
308 aPointsList.Append( aSectLastPoint );
310 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
312 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
314 BRepAdaptor_Curve anAdaptorCurve( theEdge );
315 GCPnts_QuasiUniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
316 //GCPnts_UniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
318 int aNbPoints = aDiscrete.NbPoints();
320 // Decrease the number of imported poles because of last one
321 // pole is the closing point which are the start point
322 if ( anIsEdgeClosed ) aNbPoints--;
324 for ( int i = 1; i <= aNbPoints; ++i )
326 const gp_Pnt& aPoint = aDiscrete.Value( i );
328 HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
329 aPointsList.Append( aSectPoint );
334 // Other curve types are not supported
338 if ( aPointsList.IsEmpty() )
341 theSectNames.Append( aSectName );
342 theSectTypes.Append( aSectionType );
343 theSectClosures.Append( anIsEdgeClosed );
344 theSectPoints.Append( aPointsList );
350 bool convertEdgesToSections( const TopoDS_Edge& theEdge,
351 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
352 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
353 NCollection_Sequence<bool>& theSectClosures,
354 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
356 bool IsInterpolationAllowed,
357 double theDeflection,
358 const Handle( HYDROData_PolylineXY )& theOldPolyline )
360 DEBTRACE("convertEdgesToSections")
361 Standard_Real aFirst = 0.0, aLast = 0.0;
362 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
363 if ( anEdgeGeomCurve.IsNull() )
366 bool isPrevious = (theSectTypes.Size() > 0);
367 DEBTRACE("nb sections: " << theSectTypes.Size());
368 HYDROData_PolylineXY::SectionType prevSectType = HYDROData_PolylineXY::SECTION_SPLINE;;
369 HYDROData_PolylineXY::PointsList prevPointList;
370 bool isPrevClosed = true;
373 prevSectType = theSectTypes.Last();
374 prevPointList = theSectPoints.Last();
375 isPrevClosed = theSectClosures.Last();
378 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
379 anIsEdgeClosed &= IsCanBeClosed; // on split, resulting edges are normally not closed...
380 HYDROData_PolylineXY::SectionType aSectionType ;
381 if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
383 aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
385 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
387 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
391 // Other curve types are not supported
395 bool isNewSection = !isPrevious || isPrevClosed || anIsEdgeClosed || prevSectType != aSectionType;
396 DEBTRACE(isNewSection <<": " << !isPrevious << " " << isPrevClosed << " " << anIsEdgeClosed << " " << (prevSectType != aSectionType));
398 HYDROData_PolylineXY::PointsList aPointsList;
401 aPointsList = prevPointList;
404 if( aSectionType == HYDROData_PolylineXY::SECTION_POLYLINE )
406 DEBTRACE("SECTION_POLYLINE");
407 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
409 gp_Pnt aFirstPoint, aLastPoint;
410 aGeomLine->D0( aFirst, aFirstPoint );
411 aGeomLine->D0( aLast, aLastPoint );
412 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
413 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
416 if (aSectFirstPoint == prevPointList.Last())
418 DEBTRACE("points shared: a");//aPointsList.Append( aSectFirstPoint );
419 aPointsList.Append( aSectLastPoint );
421 else if (aSectLastPoint == prevPointList.Last())
423 DEBTRACE("points shared: b");//aPointsList.Append( aSectLastPoint );
424 aPointsList.Append( aSectFirstPoint );
426 else if (aSectFirstPoint == prevPointList.First())
428 DEBTRACE("points shared: c");//aPointsList.Prepend( aSectFirstPoint );
429 aPointsList.Prepend( aSectLastPoint );
431 else if (aSectLastPoint == prevPointList.First())
433 DEBTRACE("points shared: d");//aPointsList.Prepend( aSectLastPoint );
434 aPointsList.Prepend( aSectFirstPoint );
438 DEBTRACE("no point shared")
439 isNewSection = true; // no point shared, new section
441 aPointsList.Append( aSectFirstPoint );
442 aPointsList.Append( aSectLastPoint );
447 DEBTRACE("new section");
448 aPointsList.Append( aSectFirstPoint );
449 aPointsList.Append( aSectLastPoint );
452 else // aSectionType == HYDROData_PolylineXY::SECTION_SPLINE
454 DEBTRACE("SECTION_SPLINE");
458 BRepAdaptor_Curve anAdaptorCurve(theEdge);
459 if (theOldPolyline.IsNull()) // --- no previous polyline: build a set of points from scratch for the spline
461 GCPnts_QuasiUniformDeflection aDiscrete(anAdaptorCurve, theDeflection);
463 int aNbPoints = aDiscrete.NbPoints();
465 // Decrease the number of imported poles because of last one
466 // pole is the closing point which are the start point
470 for (int i = 1; i <= aNbPoints; ++i)
472 const gp_Pnt& aPoint = aDiscrete.Value(i);
473 HYDROData_PolylineXY::Point aSectPoint(aPoint.X(), aPoint.Y());
474 aPointsList.Append(aSectPoint);
477 gp_Pnt endPts[] = {gp_Pnt(aPointsList.First().X(),aPointsList.First().Y(), 0),
478 gp_Pnt(aPointsList.Last().X(),aPointsList.Last().Y(), 0) };
479 DEBTRACE("curve start: "<< endPts[0].X() << " " << endPts[0].Y());
480 DEBTRACE("curve end: "<< endPts[1].X() << " " << endPts[1].Y());
482 else // --- split of a previous polyline: try to retrieve old sets of points and add intersection points
484 const gp_Pnt aEndPs[] = { anAdaptorCurve.Value(anAdaptorCurve.FirstParameter()).XYZ(),
485 anAdaptorCurve.Value(anAdaptorCurve.LastParameter()).XYZ() };
486 double midPar = (anAdaptorCurve.LastParameter() + anAdaptorCurve.FirstParameter())/2;
488 anAdaptorCurve.D0(midPar, midPnt);
489 DEBTRACE("curve first point: " << aEndPs[0].X() << " " << aEndPs[0].Y() << " " << aEndPs[0].Z());
490 DEBTRACE("curve last point: " << aEndPs[1].X() << " " << aEndPs[1].Y() << " " << aEndPs[1].Z());
491 DEBTRACE("curve mid point: " << midPnt.X() << " " << midPnt.Y() << " " << midPnt.Z());
493 std::vector<TopoDS_Wire> aCurves;
494 HYDROData_PolylineOperator::GetWires(theOldPolyline, aCurves);
496 int nbSections = theOldPolyline->NbSections();
497 DEBTRACE("nbSections: "<< nbSections << ", nbCurves: " << aCurves.size() );
498 for (int isec = 0; isec < nbSections; isec++)
500 DEBTRACE("section: "<< isec);
501 bool isOldSectionclosed = theOldPolyline->IsClosedSection(isec);
502 TopoDS_Wire aWire = aCurves[isec]; // we suppose sections and wires are in the same order
503 TopExp_Explorer anExp(aWire, TopAbs_EDGE);
504 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current()); // the first is OK: only one normally with splines
505 BRepAdaptor_Curve adaptorOldCurve(anEdge);
506 double pfirst = adaptorOldCurve.FirstParameter();
507 double plast = adaptorOldCurve.LastParameter();
508 DEBTRACE("previous curve first last : "<< pfirst << " " << plast);
509 double p[3] = {-1, -1};
510 double d0= ProjectPointToCurve(aEndPs[0].XYZ(), adaptorOldCurve,p[0]);
511 double d1= ProjectPointToCurve(aEndPs[1].XYZ(), adaptorOldCurve,p[1]);
512 double d2= ProjectPointToCurve(midPnt.XYZ(), adaptorOldCurve, p[2]);
513 DEBTRACE("d0: "<<d0<<" d1: "<<d1<<" d2: "<<d2<<" p0: "<<p[0]<<" p1: "<<p[1]<<" p2: "<<p[2]);
514 if ((d0 < 1.e-3) && (d1 < 1.e-3) && (d2 < 1.e-3)) // we got the good old curve (and the good section)
519 DEBTRACE("isOldSectionclosed: " << isOldSectionclosed);
520 if (!isOldSectionclosed) // no need to check first and last points on an open curve
529 else // old section closed: check if we use first or last points...
531 if((pmin < pmax) && ((std::fabs(pmin - pfirst)> 1.e-3) && (std::fabs(pmax - plast) >1.e-3))) // internal points forward
533 else if ((pmin > pmax) && ((std::fabs(pmin - plast)> 1.e-3) && (std::fabs(pmax - pfirst) >1.e-3))) // internal points reverse
539 else if ((std::fabs(pmin - plast) <1.e-3) && (p[2] < pmax)) // forward, replace pmin par pfirst
541 else if ((std::fabs(pmin - plast) <1.e-3) && (p[2] > pmax)) // reverse
547 else if ((std::fabs(pmax - pfirst) <1.e-3) && (p[2] < pmin)) // reverse
553 else if ((std::fabs(pmax - pfirst) <1.e-3) && (p[2] > pmin)) // forward, replace pmax par plast
556 DEBTRACE("forward: "<< forward << " pmin " << pmin << " pmax " << pmax);
557 HYDROData_PolylineXY::Point aFirstPoint, aLastPoint;
560 aFirstPoint = HYDROData_PolylineXY::Point(aEndPs[0].X(), aEndPs[0].Y());
561 aLastPoint = HYDROData_PolylineXY::Point(aEndPs[1].X(), aEndPs[1].Y());
565 aFirstPoint = HYDROData_PolylineXY::Point(aEndPs[1].X(), aEndPs[1].Y());
566 aLastPoint = HYDROData_PolylineXY::Point(aEndPs[0].X(), aEndPs[0].Y());
568 aPointsList.Append(aFirstPoint);
570 HYDROData_PolylineXY::PointsList aSectPoints = theOldPolyline->GetPoints(isec, false);
571 int nbPoints = aSectPoints.Length();
572 DEBTRACE("nbPoints " << nbPoints);
574 for (int i=1; i<=nbPoints; i++)
576 HYDROData_PolylineXY::Point aPoint = aSectPoints.Value(i);
577 gp_XYZ p(aPoint.X(), aPoint.Y(), 0);
579 double d = ProjectPointToCurve(p, adaptorOldCurve, param);
580 if ((param > pmin) && (param < pmax))
582 DEBTRACE("param: " << param);
583 aPointsList.Append(aPoint);
587 for (int i=nbPoints; i>0; i--)
589 HYDROData_PolylineXY::Point aPoint = aSectPoints.Value(i);
590 gp_XYZ p(aPoint.X(), aPoint.Y(), 0);
592 double d = ProjectPointToCurve(p, adaptorOldCurve, param);
593 if ((param > pmin) && (param < pmax))
595 DEBTRACE("param: " << param);
596 aPointsList.Append(aPoint);
600 aPointsList.Append(aLastPoint);
607 if ( aPointsList.IsEmpty() )
610 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
613 DEBTRACE("isNewSection");
614 theSectNames.Append( aSectName );
615 theSectTypes.Append( aSectionType );
616 theSectClosures.Append( anIsEdgeClosed );
617 theSectPoints.Append( aPointsList );
621 DEBTRACE("sameSection");
622 theSectPoints.SetValue(theSectPoints.Length(), aPointsList);
628 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape,
629 bool IsInterpolationAllowed,
630 const Handle( HYDROData_PolylineXY )& theOldPolyline,
631 bool IsClosureAllowed,
632 double theDeviation )
634 DEBTRACE("ImportShape");
635 if ( theShape.IsNull() )
638 //std::string brepName = this->GetName().toStdString();
639 //brepName += ".brep";
640 //BRepTools::Write( theShape, brepName.c_str() );
644 bool anIsCanBeImported = false;
646 NCollection_Sequence<TCollection_AsciiString> aSectNames;
647 NCollection_Sequence<SectionType> aSectTypes;
648 NCollection_Sequence<bool> aSectClosures;
649 NCollection_Sequence<PointsList> aSectPoints;
651 if ( theShape.ShapeType() == TopAbs_EDGE )
653 DEBTRACE("TopAbs_EDGE");
654 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
655 // anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes,
656 // aSectClosures, aSectPoints, true, IsInterpolationAllowed, theDeviation );
657 anIsCanBeImported = convertEdgesToSections( anEdge, aSectNames, aSectTypes, aSectClosures,
658 aSectPoints, IsClosureAllowed, IsInterpolationAllowed,
659 theDeviation, theOldPolyline );
661 else if ( theShape.ShapeType() == TopAbs_WIRE )
663 DEBTRACE("TopAbs_WIRE");
664 TopTools_SequenceOfShape anEdges;
665 HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
667 anIsCanBeImported = !anEdges.IsEmpty();
668 for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
670 TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
671 anIsCanBeImported = convertEdgesToSections( aWireEdge, aSectNames, aSectTypes, aSectClosures,
672 aSectPoints, IsClosureAllowed, IsInterpolationAllowed,
673 theDeviation, theOldPolyline );
677 if ( anIsCanBeImported )
679 for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
681 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
682 const SectionType& aSectType = aSectTypes.Value( i );
683 bool anIsSectionClosed = aSectClosures.Value( i );
684 const PointsList& aSectPointsList = aSectPoints( i );
686 AddSection( aSectName, aSectType, anIsSectionClosed );
687 SetPoints( i - 1, aSectPointsList );
692 TopoDS_Shape aShape = theShape;
694 if ( theShape.ShapeType() == TopAbs_EDGE )
696 // We make the wire from incoming edge because of other algorithms
697 // are waiting at least the wire from polyline
698 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
699 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
701 if ( aMakeWire.IsDone() )
702 aShape = aMakeWire.Wire();
705 gp_Pln aPlane( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
706 BRepBuilderAPI_MakeFace aMakeFace( aPlane );
708 BRepOffsetAPI_NormalProjection aProj( aMakeFace.Face() );
711 TopoDS_Shape aResult;
713 aResult = aProj.Shape();
718 setEditable( anIsCanBeImported );
723 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
724 const bool& theIsClosed,
725 const NCollection_Sequence<gp_XYZ>& thePoints )
728 if( theType == SECTION_POLYLINE )
730 int aNbPoints = thePoints.Length();
731 BRepBuilderAPI_MakePolygon aMakeWire;
732 for ( int i = 1, n = aNbPoints; i <= n ; ++i )
734 gp_XYZ aPoint = thePoints.Value( i );
735 gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
736 aMakeWire.Add( aPnt );
738 if( theIsClosed && ( aNbPoints > 2 ) )
741 if ( aMakeWire.IsDone() )
742 aWire = aMakeWire.Wire();
744 else //if( theType == PolylineSection::SECTION_SPLINE )
746 BRepBuilderAPI_MakeWire aMakeWire;
748 if ( thePoints.Size() > 1 )
750 Handle(Geom_BSplineCurve) aCurve =
751 HYDROData_BSplineOperation::ComputeCurve( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
753 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aCurve ).Edge();
754 aMakeWire.Add( anEdge );
757 if ( aMakeWire.IsDone() )
764 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
765 const SectionType& theType,
766 const bool& theIsClosed,
767 const NCollection_Sequence<gp_XYZ>& thePoints )
769 if ( thePoints.IsEmpty() )
772 if ( theType == SECTION_POLYLINE )
774 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
775 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
777 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
779 const gp_XYZ& aSectPoint = thePoints.Value( i );
781 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
785 thePath.closeSubpath();
789 Handle(Geom_BSplineCurve) aCurve =
790 HYDROData_BSplineOperation::ComputeCurve( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
791 HYDROData_BSplineOperation::ComputePath( aCurve, thePath );
795 void HYDROData_PolylineXY::Update()
799 // If polyline is not editable we no need to update it wire
804 HYDROData_IPolyline::Update();
806 NCollection_Sequence<TCollection_AsciiString> aSectNames;
807 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
808 NCollection_Sequence<bool> aSectClosures;
809 GetSections( aSectNames, aSectTypes, aSectClosures );
811 //BRepBuilderAPI_MakeWire aMakeWire;
813 TopTools_ListOfShape aSectionWiresList;
815 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
817 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
818 SectionType aSectionType = aSectTypes.Value( aSectionId );
819 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
821 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
822 if ( aSectPointsList.IsEmpty() )
825 NCollection_Sequence<gp_XYZ> aPoints;
826 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
828 const Point& aSectPoint = aSectPointsList.Value( i );
830 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
831 aPoints.Append( aPoint );
834 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
835 if ( !aSectionWire.IsNull() ) {
836 aSectionWiresList.Append( aSectionWire );
837 //aMakeWire.Add( aSectionWire );
840 // all input wires in the <aSectionWiresList>
842 TopoDS_Shape aResult;
844 TopoDS_Compound aCmp;
845 aBB.MakeCompound(aCmp);
846 if (aSectionWiresList.Size() == 1)
847 aResult = aSectionWiresList.First();
848 else if (aSectionWiresList.Size() > 1)
850 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
851 for(;it.More();it.Next())
853 aBB.Add(aCmp, it.Value());
858 //Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
859 //Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
860 //TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
861 //for(;it.More();it.Next())
863 // TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
864 // for(;it2.More();it2.Next())
865 // aSeqEdges->Append(it2.Current());
869 //TopoDS_Compound aCmp;
870 //TopoDS_Shape aResult;
871 //aBB.MakeCompound(aCmp);
872 //if(aSeqEdges->Length() >1)
874 // ShapeAnalysis_FreeBounds::ConnectEdgesToWires( aSeqEdges, 1E-5, Standard_True, aSeqWires );
876 // if( aSeqWires->Length()==1 )
877 // aResult = aSeqWires->Value( 1 );
880 // for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
882 // const TopoDS_Shape& aS1 = aSeqWires->Value(i);
883 // aBB.Add(aCmp, aS1);
888 //else if (aSeqEdges->Length() == 1)
890 // BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
891 // if (mkWire.IsDone())
892 // aResult = mkWire.Wire();
898 bool HYDROData_PolylineXY::IsHas2dPrs() const
903 bool HYDROData_PolylineXY::IsEditable() const
905 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
908 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
910 if ( !theIsEditable )
911 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
913 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
917 * Returns true if polyline is closed
919 bool HYDROData_PolylineXY::IsClosed(const bool theIsSimpleCheck) const
921 DEBTRACE("IsClosed " << theIsSimpleCheck << " " << GetName());
922 bool anIsClosed = false;
924 TopoDS_Shape aShape = GetShape();
928 TopTools_SequenceOfShape aWires;
929 HYDROData_ShapesTool::ExploreShapeToShapes(aShape, TopAbs_WIRE, aWires);
931 int aNbWires = aWires.Length();
932 if (theIsSimpleCheck)
934 anIsClosed = aNbWires > 0;
935 for (int i = 1; i <= aNbWires && anIsClosed; ++i)
937 const TopoDS_Shape& aWire = aWires.Value(i);
938 anIsClosed = BRep_Tool::IsClosed(aWire);
944 anIsClosed = BRep_Tool::IsClosed(aWires.First());
947 DEBTRACE("aNbWires " << aNbWires);
948 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
949 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
950 for (int i = 1; i <= aNbWires; ++i)
952 const TopoDS_Shape& aWire = aWires.Value(i);
953 TopExp_Explorer it2(aWire, TopAbs_EDGE);
954 for (; it2.More(); it2.Next())
955 aSeqEdges->Append(it2.Current());
957 if (aSeqEdges->Length() > 1)
959 DEBTRACE(aSeqEdges->Length());
960 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires);
961 if (aSeqWires->Length() == 1)
963 DEBTRACE(aSeqWires->Length());
964 const TopoDS_Wire& aPolylineWire = TopoDS::Wire(aSeqWires->Value(1));
965 anIsClosed = BRep_Tool::IsClosed(aPolylineWire);
974 int HYDROData_PolylineXY::GetNbConnectedWires(Handle(TopTools_HSequenceOfShape)& aConnectedWires) const
976 TopoDS_Shape aShape = GetShape();
979 int aNbconnectedWires = 0;
980 TopTools_SequenceOfShape aWires;
981 HYDROData_ShapesTool::ExploreShapeToShapes(aShape, TopAbs_WIRE, aWires);
982 int aNbWires = aWires.Length();
985 aNbconnectedWires = aNbWires;
986 aConnectedWires->Append(aWires.First());
990 DEBTRACE("aNbWires " << aNbWires);
991 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
992 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
993 for (int i = 1; i <= aNbWires; ++i)
995 const TopoDS_Shape& aWire = aWires.Value(i);
996 TopExp_Explorer it2(aWire, TopAbs_EDGE);
997 for (; it2.More(); it2.Next())
998 aSeqEdges->Append(it2.Current());
1000 if (aSeqEdges->Length() > 1)
1002 DEBTRACE(aSeqEdges->Length());
1003 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires);
1005 aConnectedWires = aSeqWires;
1006 aNbconnectedWires = aConnectedWires->Length();
1007 DEBTRACE("aNbconnectedWires " << aNbconnectedWires);
1009 return aNbconnectedWires;
1012 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
1013 const int thePointIndex ) const
1015 double aResDistance = -1;
1016 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
1017 return aResDistance;
1019 if ( thePointIndex == 0 )
1022 SectionType aSectionType = GetSectionType( theSectionIndex );
1023 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
1024 PointsList aSectPointsList = GetPoints( theSectionIndex );
1025 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
1026 return aResDistance;
1028 if ( aSectionType == SECTION_POLYLINE )
1032 Point aPrevPoint = aSectPointsList.Value( 1 );
1033 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
1035 const Point& aSectPoint = aSectPointsList.Value( i );
1036 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
1037 aPrevPoint = aSectPoint;
1039 if ( thePointIndex == i - 1 )
1045 gp_XYZ aPointToTest;
1047 int aSectNbPoints = aSectPointsList.Size();
1048 NCollection_Sequence<gp_XYZ> aPoints;
1049 for( int i = 1 ; i <= aSectNbPoints; ++i )
1051 const Point& aSectPoint = aSectPointsList.Value( i );
1053 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1054 aPoints.Append( aPoint );
1056 if ( thePointIndex == i - 1 )
1057 aPointToTest = aPoint;
1060 Handle(Geom_BSplineCurve) aCurve =
1061 HYDROData_BSplineOperation::ComputeCurve( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
1063 Quantity_Parameter aFirstParam = aCurve->FirstParameter();
1064 Quantity_Parameter aSecondParam = aCurve->LastParameter();
1066 if ( thePointIndex != aSectNbPoints - 1 )
1068 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aCurve );
1069 aSecondParam = aProject.LowerDistanceParameter();
1072 GeomAdaptor_Curve anAdap( aCurve );
1074 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
1077 return aResDistance;
1080 int HYDROData_PolylineXY::NbSections() const
1082 Handle(TDataStd_ExtStringList) aNamesList;
1083 Handle(TDataStd_IntegerList) aTypesList;
1084 Handle(TDataStd_BooleanList) aClosuresList;
1085 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1087 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
1090 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
1091 const SectionType theSectionType,
1092 const bool theIsClosed )
1094 Handle(TDataStd_ExtStringList) aNamesList;
1095 Handle(TDataStd_IntegerList) aTypesList;
1096 Handle(TDataStd_BooleanList) aClosuresList;
1097 getSectionsLists( aNamesList, aTypesList, aClosuresList );
1099 TCollection_ExtendedString aSectName( theSectName );
1100 if ( aSectName.Length() <= 0 )
1101 aSectName = getUniqueSectionName( aNamesList );
1103 aNamesList->Append( aSectName );
1104 aTypesList->Append( theSectionType );
1105 aClosuresList->Append( theIsClosed );
1110 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
1112 TCollection_AsciiString aResName;
1114 Handle(TDataStd_ExtStringList) aNamesList;
1115 Handle(TDataStd_IntegerList) aTypesList;
1116 Handle(TDataStd_BooleanList) aClosuresList;
1117 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1118 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1121 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
1122 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
1124 if ( aNamesIter.More() )
1125 aResName = aNamesIter.Value();
1130 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
1131 const TCollection_AsciiString& theSectionName )
1133 Handle(TDataStd_ExtStringList) aNamesList;
1134 Handle(TDataStd_IntegerList) aTypesList;
1135 Handle(TDataStd_BooleanList) aClosuresList;
1136 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1137 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1140 TDataStd_ListOfExtendedString anOldNamesList;
1141 anOldNamesList = aNamesList->List();
1143 // Refill the existing list
1144 aNamesList->Clear();
1146 TCollection_ExtendedString aNewSectName = theSectionName;
1148 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
1149 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
1150 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
1153 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
1155 Handle(TDataStd_ExtStringList) aNamesList;
1156 Handle(TDataStd_IntegerList) aTypesList;
1157 Handle(TDataStd_BooleanList) aClosuresList;
1158 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1159 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
1160 return SECTION_POLYLINE;
1162 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
1163 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
1165 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
1168 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
1169 const SectionType theSectionType )
1171 Handle(TDataStd_ExtStringList) aNamesList;
1172 Handle(TDataStd_IntegerList) aTypesList;
1173 Handle(TDataStd_BooleanList) aClosuresList;
1174 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1175 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
1178 TColStd_ListOfInteger anOldTypesList;
1179 anOldTypesList = aTypesList->List();
1181 // Refill the existing list
1182 aTypesList->Clear();
1184 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
1185 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
1186 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
1191 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
1193 Handle(TDataStd_ExtStringList) aNamesList;
1194 Handle(TDataStd_IntegerList) aTypesList;
1195 Handle(TDataStd_BooleanList) aClosuresList;
1196 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1197 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
1200 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
1201 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
1203 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
1206 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
1207 const bool theIsClosed )
1209 Handle(TDataStd_ExtStringList) aNamesList;
1210 Handle(TDataStd_IntegerList) aTypesList;
1211 Handle(TDataStd_BooleanList) aClosuresList;
1212 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1213 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
1216 TDataStd_ListOfByte anOldClosuresList;
1217 anOldClosuresList = aClosuresList->List();
1219 // Refill the existing list
1220 aClosuresList->Clear();
1222 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
1223 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
1224 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
1229 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
1230 NCollection_Sequence<SectionType>& theSectTypes,
1231 NCollection_Sequence<bool>& theSectClosures ) const
1233 theSectNames.Clear();
1234 theSectTypes.Clear();
1235 theSectClosures.Clear();
1239 const_cast<HYDROData_PolylineXY*>( this )->Interpolate();
1242 Handle(TDataStd_ExtStringList) aNamesList;
1243 Handle(TDataStd_IntegerList) aTypesList;
1244 Handle(TDataStd_BooleanList) aClosuresList;
1245 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1246 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
1249 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
1250 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
1251 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
1252 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
1253 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
1255 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
1256 SectionType aSectType = (SectionType)aTypesIter.Value();
1257 bool aSectClosures = aClosuresIter.Value();
1259 theSectNames.Append( aSectName );
1260 theSectTypes.Append( aSectType );
1261 theSectClosures.Append( aSectClosures );
1265 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
1267 Handle(TDataStd_ExtStringList) aNamesList;
1268 Handle(TDataStd_IntegerList) aTypesList;
1269 Handle(TDataStd_BooleanList) aClosuresList;
1270 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
1271 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
1274 if ( aNamesList->Extent() == 1 )
1276 removeSectionsLists();
1277 removePointsLists();
1278 removeSectionColor();
1282 TDataStd_ListOfExtendedString anOldNamesList;
1283 anOldNamesList = aNamesList->List();
1285 TColStd_ListOfInteger anOldTypesList;
1286 anOldTypesList = aTypesList->List();
1288 TDataStd_ListOfByte anOldClosuresList;
1289 anOldClosuresList = aClosuresList->List();
1291 // Refill the existing lists
1292 aNamesList->Clear();
1293 aTypesList->Clear();
1294 aClosuresList->Clear();
1296 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
1297 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
1298 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
1299 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
1300 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
1302 if ( i == theSectionIndex )
1303 continue; // skip index to remove
1305 aNamesList->Append( aNamesIter.Value() );
1306 aTypesList->Append( aTypesIter.Value() );
1307 aClosuresList->Append( (bool)aClosuresIter.Value() );
1310 // Remove points that belongs to removed section
1311 removePointsLists( theSectionIndex );
1312 removeSectionColor (theSectionIndex);
1318 void HYDROData_PolylineXY::RemoveSections()
1320 removeSectionsLists();
1321 removePointsLists();
1325 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
1326 const Point& thePoint,
1327 const int thePointIndex )
1329 Handle(TDataStd_RealList) aListX, aListY;
1330 getPointsLists( theSectionIndex, aListX, aListY );
1332 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
1334 aListX->Append( thePoint.X() );
1335 aListY->Append( thePoint.Y() );
1339 TColStd_ListOfReal anOldListX;
1340 anOldListX = aListX->List();
1342 TColStd_ListOfReal anOldListY;
1343 anOldListY = aListY->List();
1345 // Refill the existing lists
1349 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1350 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1351 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1353 double aCoordX = anIterX.Value();
1354 double aCoordY = anIterY.Value();
1356 if ( i == thePointIndex )
1358 // Insert our new point
1359 aListX->Append( thePoint.X() );
1360 aListY->Append( thePoint.Y() );
1363 aListX->Append( aCoordX );
1364 aListY->Append( aCoordY );
1371 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
1372 const Point& thePoint,
1373 const int thePointIndex )
1375 Handle(TDataStd_RealList) aListX, aListY;
1376 getPointsLists( theSectionIndex, aListX, aListY );
1378 if ( thePointIndex < 0 )
1380 aListX->Prepend( thePoint.X() );
1381 aListY->Prepend( thePoint.Y() );
1383 else if ( thePointIndex >= aListX->Extent() )
1385 aListX->Append( thePoint.X() );
1386 aListY->Append( thePoint.Y() );
1390 TColStd_ListOfReal anOldListX;
1391 anOldListX = aListX->List();
1393 TColStd_ListOfReal anOldListY;
1394 anOldListY = aListY->List();
1396 // Refill the existing lists
1400 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1401 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1402 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1404 double aCoordX = anIterX.Value();
1405 double aCoordY = anIterY.Value();
1407 if ( i == thePointIndex )
1409 // Insert our new point instead of old one
1410 aCoordX = thePoint.X();
1411 aCoordY = thePoint.Y();
1414 aListX->Append( aCoordX );
1415 aListY->Append( aCoordY );
1422 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
1423 const PointsList& thePoints )
1425 Handle(TDataStd_RealList) aListX, aListY;
1426 getPointsLists( theSectionIndex, aListX, aListY );
1431 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1433 const Point& aPoint = thePoints.Value( i );
1434 aListX->Append( aPoint.X() );
1435 aListY->Append( aPoint.Y() );
1439 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
1440 const int thePointIndex )
1442 Handle(TDataStd_RealList) aListX, aListY;
1443 getPointsLists( theSectionIndex, aListX, aListY, false );
1444 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1447 if ( aListX->Extent() == 1 )
1449 removePointsLists( theSectionIndex );
1453 TColStd_ListOfReal anOldListX;
1454 anOldListX = aListX->List();
1456 TColStd_ListOfReal anOldListY;
1457 anOldListY = aListY->List();
1459 // Refill the existing lists
1463 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1464 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1465 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1467 if ( i == thePointIndex )
1468 continue; // skip index to remove
1470 aListX->Append( anIterX.Value() );
1471 aListY->Append( anIterY.Value() );
1478 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex, bool IsConvertToGlobal ) const
1480 PointsList aResList;
1484 const_cast<HYDROData_PolylineXY*>( this )->Interpolate();
1487 Handle(TDataStd_RealList) aListX, aListY;
1488 getPointsLists( theSectionIndex, aListX, aListY, false );
1489 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1492 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
1493 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
1494 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
1495 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
1497 Point aPoint( anIterX.Value(), anIterY.Value() );
1498 if (IsConvertToGlobal)
1499 aDoc->Transform( aPoint, false );
1500 aResList.Append( aPoint );
1506 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
1510 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1511 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1512 NCollection_Sequence<bool> aSectClosures;
1513 GetSections( aSectNames, aSectTypes, aSectClosures );
1515 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1517 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1518 SectionType aSectionType = aSectTypes.Value( aSectionId );
1519 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1521 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1522 if ( aSectPointsList.IsEmpty() )
1525 NCollection_Sequence<gp_XYZ> aPoints;
1526 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1528 const Point& aSectPoint = aSectPointsList.Value( i );
1530 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1531 aPoints.Append( aPoint );
1534 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );
1540 void HYDROData_PolylineXY::UpdateLocalCS( double theDx, double theDy )
1542 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1543 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1544 NCollection_Sequence<bool> aSectClosures;
1545 GetSections( aSectNames, aSectTypes, aSectClosures );
1547 gp_XY aDelta( theDx, theDy );
1548 for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ )
1550 PointsList aPoints = GetPoints( i );
1551 for( int j = 1, n = aPoints.Size(); j <= n; ++j )
1553 Point& aPoint = aPoints.ChangeValue( j );
1556 SetPoints( i, aPoints );
1561 void HYDROData_PolylineXY::Transform( const QTransform& theTrsf )
1563 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1564 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1565 NCollection_Sequence<bool> aSectClosures;
1566 GetSections( aSectNames, aSectTypes, aSectClosures );
1568 for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ ) {
1569 PointsList aPoints = GetPoints( i );
1570 for( int j = 1, n = aPoints.Size(); j <= n; ++j ) {
1571 Point& aPoint = aPoints.ChangeValue( j );
1573 QPointF aTrsfPoint = theTrsf.map( QPointF( aPoint.X(), aPoint.Y() ) );
1575 aPoint.SetX( aTrsfPoint.x() );
1576 aPoint.SetY( aTrsfPoint.y() );
1578 SetPoints( i, aPoints );
1584 bool HYDROData_PolylineXY::IsCustom() const
1586 if( myIsInCustomFlag )
1589 bool isNull = GetShape().IsNull();
1592 HYDROData_PolylineXY* aThat = const_cast<HYDROData_PolylineXY*>( this );
1593 aThat->myIsInCustomFlag = true;
1594 for( int i=0, n=NbSections(); i<n; i++ )
1595 aNbPoints += NbPoints( i );
1596 aThat->myIsInCustomFlag = false;
1598 return !isNull && aNbPoints == 0;
1601 bool HYDROData_PolylineXY::GetIsInCustomFlag() const
1603 return myIsInCustomFlag;
1606 void HYDROData_PolylineXY::SetIsInCustomFlag( bool theValue )
1608 myIsInCustomFlag = theValue;
1611 void HYDROData_PolylineXY::Interpolate()
1613 ImportShape( GetShape(), true, NULL );
1616 void HYDROData_PolylineXY::SetDBFInfo( const QStringList& theDBFTable )
1619 Handle_TDataStd_ExtStringArray TExtStrArr =
1620 TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_DBFTableInfo), 1, theDBFTable.size() );
1621 foreach (QString val, theDBFTable)
1623 std::string StdVal = val.toStdString();
1624 const char* aCVal = StdVal.c_str();
1625 TExtStrArr->SetValue(i, TCollection_ExtendedString(aCVal));
1630 bool HYDROData_PolylineXY::GetDBFInfo(QStringList& theDBFTable) const
1632 TDF_Label aLabel = myLab.FindChild( DataTag_DBFTableInfo, false );
1633 if ( !aLabel.IsNull() )
1635 Handle(TDataStd_ExtStringArray) anExtStrArr;
1636 if ( aLabel.FindAttribute( TDataStd_ExtStringArray::GetID(), anExtStrArr ) )
1638 for (int i = anExtStrArr->Lower(); i <= anExtStrArr->Upper(); i++ )
1640 Standard_ExtString str = anExtStrArr->Value(i).ToExtString();
1641 TCollection_AsciiString aText (str);
1642 theDBFTable << QString(aText.ToCString());