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_Tool.h>
20 #include <HYDROData_ArtificialObject.h>
21 #include <HYDROData_Document.h>
22 #include <HYDROData_Entity.h>
23 #include <HYDROData_Iterator.h>
24 #include <HYDROData_NaturalObject.h>
25 #include <HYDROData_ShapesGroup.h>
26 #include <HYDROData_PolylineXY.h>
29 #include <QStringList>
30 #include <QTextStream>
32 #include <BRep_Tool.hxx>
33 #include <BRepAdaptor_Surface.hxx>
34 #include <BRepTopAdaptor_FClass2d.hxx>
36 #include <Geom_Curve.hxx>
38 #include <Quantity_Color.hxx>
39 #include <TopExp_Explorer.hxx>
41 #include <TopoDS_Face.hxx>
42 #include <TopoDS_Shape.hxx>
43 #include <TopoDS_Wire.hxx>
48 #include <BRepTools.hxx>
49 #include <NCollection_Map.hxx>
50 #include <TopTools_ShapeMapHasher.hxx>
51 #include <BRep_Builder.hxx>
52 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
54 #include <NCollection_List.hxx>
55 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <BRepBuilderAPI_MakeFace.hxx>
59 #include <TopExp_Explorer.hxx>
60 #include <TopTools_ListIteratorOfListOfShape.hxx>
61 #include <TopTools_HSequenceOfShape.hxx>
63 #include <BRep_Builder.hxx>
64 #include <BRepAlgo_FaceRestrictor.hxx>
65 #include <BRepCheck_Analyzer.hxx>
67 #include <ShapeAnalysis.hxx>
68 #include <ShapeAnalysis_FreeBounds.hxx>
70 #include <HYDROData_PolylineXY.h>
71 #include <HYDROData_Polyline3D.h>
72 #include <HYDROData_Bathymetry.h>
75 #define BLOCK_SIZE 10000
77 HYDROData_Tool::ExecStatus HYDROData_Tool::myTriangulationStatus = ExecStatus::None;
79 static int aMaxNameId = INT_MAX;
80 static int aMaxColorNb = 92000;
81 void HYDROData_Tool::WriteStringsToFile( QFile& theFile,
82 const QStringList& theStrings,
83 const QString& theSep )
85 if ( !theFile.isOpen() || theStrings.isEmpty() )
88 QString aWriteStr = theStrings.join( theSep );
89 if ( aWriteStr.isEmpty() )
92 QTextStream anOutStream( &theFile );
93 anOutStream << aWriteStr.toUtf8() << theSep << theSep;
96 bool HYDROData_Tool::ExtractGeneratedObjectName(const QString& theName, int& outValue, QString& thePrefName)
98 QStringList aLs = theName.split('_');
100 QString last = aLs.last();
101 outValue = last.toInt(&ok);
104 int last_len = last.length();
105 int total_len = theName.length();
106 thePrefName = theName.left(total_len-last_len-1);
110 QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
111 const QString& thePrefix,
112 const QStringList& theUsedNames,
113 const bool theIsTryToUsePurePrefix )
115 QStringList aNamesList( theUsedNames );
117 // Collect all used names in the document
118 HYDROData_Iterator anIter( theDoc );
119 for( ; anIter.More(); anIter.Next() )
121 Handle(HYDROData_Entity) anObject = anIter.Current();
122 if( anObject.IsNull() )
125 QString anObjName = anObject->GetName();
126 if ( anObjName.isEmpty() )
129 aNamesList.append( anObjName );
134 if ( theIsTryToUsePurePrefix && !aNamesList.contains( thePrefix ) ) {
138 while( anId < aMaxNameId )
140 aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
142 // check that there are no other objects with the same name in the document
143 if ( !aNamesList.contains( aName ) )
151 bool HYDROData_Tool::IsGeometryObject( const Handle(HYDROData_Entity)& theObject )
153 if ( theObject.IsNull() )
156 return theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) ||
157 theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) );
160 void HYDROData_Tool::UpdateChildObjectName( const QString& theOldStr,
161 const QString& theNewStr,
162 const Handle(HYDROData_Entity)& theObject )
164 if ( theObject.IsNull() )
167 QString anObjName = theObject->GetName();
168 if ( theOldStr.isEmpty() )
170 while ( anObjName.startsWith( '_' ) )
171 anObjName.remove( 0, 1 );
173 anObjName.prepend( theNewStr + "_" );
175 else if ( anObjName.startsWith( theOldStr ) )
177 anObjName.replace( 0, theOldStr.length(), theNewStr );
182 theObject->SetName( anObjName );
185 QString HYDROData_Tool::GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
186 const QString& thePrefix )
188 QString aName = thePrefix;
189 if ( !theTreatedObjects.contains( aName ) )
193 while( anId < aMaxNameId )
195 aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
197 // check that there are no other objects with the same name
198 if ( !theTreatedObjects.contains( aName ) )
204 //======================================================================================================
205 TopAbs_State HYDROData_Tool::ComputePointState( const gp_XY& theXY, const TopoDS_Face& theFace )
207 TopAbs_State aState(TopAbs_UNKNOWN);
208 if(theFace.IsNull()) return aState;
209 Standard_Real aTol = BRep_Tool::Tolerance(theFace);
210 BRepAdaptor_Surface Ads ( theFace, Standard_False );
211 Standard_Real toluv = Min ( Ads.UResolution(aTol), Ads.VResolution(aTol) );
213 toluv = 0.01; // there is no need to be more precise than 1cm a any case !
214 // another solution could be to compute a tolerance related to the distance between the border nodes
215 const gp_Pln& aPlane = Ads.Surface().Plane();
216 gp_Pnt aPnt(theXY.X(), theXY.Y(), 0.);
217 Standard_Real aU1, aV1;
218 ElSLib::Parameters(aPlane,aPnt, aU1, aV1);
219 BRepTopAdaptor_FClass2d aClassifier( theFace, toluv );
220 aState = aClassifier.Perform( gp_Pnt2d(aU1, aV1), Standard_False );
224 double HYDROData_Tool::GetAltitudeForEdge( const TopoDS_Edge& theEdge,
225 const gp_XY& thePoint,
226 double theParameterTolerance,
227 double theSquareDistanceTolerance,
228 double theInvalidAltitude )
230 double aFirst, aLast;
231 Handle(Geom_Curve) aCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
232 if( aCurve.IsNull() )
233 return theInvalidAltitude;
235 gp_Pnt aFirstPnt, aLastPnt;
237 aCurve->D0( aFirst, aFirstPnt );
238 aCurve->D0( aLast, aLastPnt );
240 gp_Pnt2d aFirstPnt2d( aFirstPnt.X(), aFirstPnt.Y() );
241 gp_Pnt2d aLastPnt2d( aLastPnt.X(), aLastPnt.Y() );
243 double aFirstDist = 0;
244 double aLastDist = aFirstPnt2d.SquareDistance( aLastPnt2d );
245 double aNecDist = aFirstPnt2d.SquareDistance( thePoint );
247 while( fabs( aLast - aFirst ) > theParameterTolerance )
249 double aMid = ( aFirst + aLast ) / 2;
251 aCurve->D0( aMid, aMidPnt );
252 double aDist = aFirstPnt2d.SquareDistance( gp_Pnt2d( aMidPnt.X(), aMidPnt.Y() ) );
254 if( aDist < aNecDist )
260 double aMid = ( aFirst + aLast ) / 2;
262 aCurve->D0( aMid, aMidPnt );
264 gp_Pnt2d aMidPnt2d( aMidPnt.X(), aMidPnt.Y() );
265 if( aMidPnt2d.SquareDistance( thePoint ) < theSquareDistanceTolerance )
268 return theInvalidAltitude;
271 double HYDROData_Tool::GetAltitudeForWire( const TopoDS_Wire& theWire,
272 const gp_XY& thePoint,
273 double theParameterTolerance,
274 double theSquareDistanceTolerance,
275 double theInvalidAltitude )
277 TopExp_Explorer anExp( theWire, TopAbs_EDGE );
278 for( ; anExp.More(); anExp.Next() )
280 double anAltitude = GetAltitudeForEdge( TopoDS::Edge( anExp.Current() ), thePoint,
281 theParameterTolerance, theSquareDistanceTolerance, theInvalidAltitude );
282 if( anAltitude != theInvalidAltitude )
285 return theInvalidAltitude;
288 TopoDS_Shape HYDROData_Tool::getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
289 const int theGroupId )
291 TopoDS_Shape aResShape;
292 if ( theGroupId < 1 || theGroupId > theGroups.Length() )
295 Handle(HYDROData_ShapesGroup) aGroup =
296 Handle(HYDROData_ShapesGroup)::DownCast( theGroups.Value( theGroupId ) );
297 if ( aGroup.IsNull() )
300 TopTools_SequenceOfShape aGroupShapes;
301 aGroup->GetShapes( aGroupShapes );
303 if ( !aGroupShapes.IsEmpty() )
304 aResShape = aGroupShapes.First();
309 TCollection_ExtendedString HYDROData_Tool::toExtString( const QString& theStr )
311 TCollection_ExtendedString aRes;
312 if( !theStr.isEmpty() )
314 Standard_ExtString extStr = new Standard_ExtCharacter[ ( theStr.length() + 1 ) * 2 ];
315 memcpy( (void*)extStr, theStr.unicode(), theStr.length() * 2 );
316 ((short*)extStr)[theStr.length()] = '\0';
317 aRes = TCollection_ExtendedString( extStr );
323 QString HYDROData_Tool::toQString( const TCollection_ExtendedString& theStr )
325 return QString( (QChar*)theStr.ToExtString(), theStr.Length() );
328 Quantity_Color HYDROData_Tool::toOccColor( const QColor& theColor )
330 double r = theColor.red() / 255.0;
331 double g = theColor.green() / 255.0;
332 double b = theColor.blue() / 255.0;
334 return Quantity_Color( r, g, b, Quantity_TOC_RGB );
337 QColor HYDROData_Tool::toQtColor( const Quantity_Color& theColor )
339 int r = 255 * theColor.Red();
340 int g = 255 * theColor.Green();
341 int b = 255 * theColor.Blue();
342 return QColor( r, g, b );
345 QColor HYDROData_Tool::GenerateRandColor()
347 float aHue = ( rand()%1000 ) * 0.001f;
350 aColor.setHsl( (int)(aHue*255.), 200, 128 );
351 int r = aColor.red();
352 int g = aColor.green();
353 int b = aColor.blue();
354 return ( aColor.isValid() ? aColor : Qt::darkBlue );
357 void HYDROData_Tool::GenerateRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors)
359 for (int i = 1; i <= nbColorsToGen; i++)
360 theColors.append(HYDROData_Tool::GenerateRandColor());
363 bool HYDROData_Tool::GenerateNonRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors)
365 if (nbColorsToGen > aMaxColorNb)
376 if (Codes.contains(Code))
378 aColor.setHsl( H, S, 128 );
379 if (aColor.isValid())
381 theColors.append(aColor);
384 } while (theColors.size() <= nbColorsToGen);
389 bool HYDROData_Tool::IsNan( double theValue )
392 return _isnan( theValue );
394 return isnan( theValue );
398 bool HYDROData_Tool::IsInf( double theValue )
401 return (!_finite( theValue ) );
403 return isinf( theValue );
407 static void MakeShellG(const NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher>& FG,
411 NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher>::Iterator itFG(FG);
414 //face nb > 1 => make shell
415 TopoDS_Shell outShell;
416 bb.MakeShell(outShell);
417 for (;itFG.More();itFG.Next())
418 bb.Add(outShell, itFG.Value());
421 else if (FG.Extent() == 1)
423 outSh = itFG.Value(); //one face
427 TopoDS_Shape HYDROData_Tool::RebuildCmp(const TopoDS_Shape& in)
429 TopTools_IndexedDataMapOfShapeListOfShape mE2LF;
430 TopExp::MapShapesAndAncestors(in, TopAbs_EDGE, TopAbs_FACE, mE2LF);
432 return TopoDS_Shape();
433 NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher> dfm;
434 //TopExp::MapShapes(aFuseShape, TopAbs_FACE, dfm);
435 TopExp_Explorer expf(in, TopAbs_FACE);
436 for (;expf.More(); expf.Next())
437 dfm.Add(TopoDS::Face(expf.Current()));
439 int nbF = dfm.Extent();
440 TopExp_Explorer exp_f(in, TopAbs_FACE);
441 const TopoDS_Face& FF = TopoDS::Face(exp_f.Current());
442 NCollection_List<TopoDS_Face> CurrFS;
443 NCollection_List<TopoDS_Face> NeighFS;
444 NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher> PrF;
446 NCollection_List<NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher>> GL_F;
447 NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher> OneGr;
451 NCollection_List<TopoDS_Face>::Iterator it_currfs(CurrFS);
453 for (;it_currfs.More();it_currfs.Next())
455 const TopoDS_Face& CF = it_currfs.Value();
456 TopExp_Explorer exp_edge(CF, TopAbs_EDGE);
457 for (;exp_edge.More();exp_edge.Next())
459 const TopoDS_Shape& CE = exp_edge.Current();
460 const TopTools_ListOfShape& lsf = mE2LF.FindFromKey(CE);
461 TopTools_ListIteratorOfListOfShape ls_it(lsf); //always one face (since all faces are planar)
462 for (;ls_it.More();ls_it.Next())
464 const TopoDS_Face& F = TopoDS::Face(ls_it.Value());
467 if (!PrF.Contains(F))
478 if (NeighFS.IsEmpty())
487 NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher>::Iterator itDm(dfm);
488 const TopoDS_Face& nsh = itDm.Key();
497 if (GL_F.Extent() > 1)
500 NCollection_List<NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher>>::Iterator itGL_F(GL_F);
502 bb.MakeCompound(cmp);
503 for (;itGL_F.More();itGL_F.Next())
505 MakeShellG(itGL_F.Value(), sh);
511 else if (GL_F.Extent() == 1)
513 MakeShellG(GL_F.First(), sh);
519 TopoDS_Shape HYDROData_Tool::PolyXY2Face( const Handle(HYDROData_PolylineXY)& aPolyline )
521 //DEBTRACE("generateTopShape");
522 TopoDS_Face aResultFace = TopoDS_Face(); // --- result: default = null face
524 if (!aPolyline.IsNull())
526 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
528 std::string brepName = "imz.brep";
529 BRepTools::Write(aPolylineShape, brepName.c_str());
531 TopTools_ListOfShape aWiresList;
533 if (!aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE)
535 // --- only one wire: try to make a face
536 //DEBTRACE("one wire: try to build a face");
537 const TopoDS_Wire& aPolylineWire = TopoDS::Wire(aPolylineShape);
538 if (!aPolylineWire.IsNull())
540 BRepBuilderAPI_MakeFace aMakeFace(aPolylineWire, Standard_True);
542 if (aMakeFace.IsDone())
544 //DEBTRACE(" a face with the only wire given");
545 aResultFace = aMakeFace.Face();
551 // --- a list of wires ? inventory of wires and edges
552 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
553 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
554 TopExp_Explorer anExp(aPolylineShape, TopAbs_WIRE);
555 //DEBTRACE("list of wires ?");
556 for (; anExp.More(); anExp.Next())
558 if (!anExp.Current().IsNull())
560 const TopoDS_Wire& aWire = TopoDS::Wire(anExp.Current());
561 aWiresList.Append(aWire);
562 //DEBTRACE(" append wire");
563 TopExp_Explorer it2(aWire, TopAbs_EDGE);
564 for (; it2.More(); it2.Next())
565 aSeqEdges->Append(it2.Current());
568 if (aWiresList.IsEmpty())
569 return aResultFace; // --- no wires: null result
571 if (aSeqEdges->Length() > 1)
573 //DEBTRACE("try to connect all the edges together, build a unique wire and a face");
574 // --- try to create one wire by connecting edges with a distance tolerance (no necessity of sharing points)
575 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires);
577 if (aSeqWires->Length() == 1)
579 // --- one wire: try to make a face
580 const TopoDS_Wire& aPolylineWire = TopoDS::Wire(aSeqWires->Value(1));
581 if (!aPolylineWire.IsNull())
583 BRepBuilderAPI_MakeFace aMakeFace(aPolylineWire, Standard_True);
585 if (aMakeFace.IsDone())
587 //DEBTRACE(" a face from all the wires connected");
588 aResultFace = aMakeFace.Face();
594 if (aResultFace.IsNull())
596 //DEBTRACE("try to make a face with the first wire of the list and other wires as restrictions");
597 // --- try to make a face with the first wire of the list and other wires as restrictions
598 BRepAlgo_FaceRestrictor aFR;
599 TopoDS_Face aRefFace;
600 TopoDS_Shape aS = aWiresList.First();
601 BRepBuilderAPI_MakeFace aMakeFace(TopoDS::Wire(aWiresList.First()), Standard_True);
603 if (aMakeFace.IsDone())
605 //DEBTRACE(" a face with first wire");
606 aRefFace = aMakeFace.Face();
608 if (!aRefFace.IsNull())
610 aFR.Init(aRefFace, Standard_False, Standard_True);
611 TopTools_ListIteratorOfListOfShape anIt(aWiresList);
612 for (; anIt.More(); anIt.Next())
614 TopoDS_Wire& aWire = TopoDS::Wire(anIt.Value());
622 for (; aFR.More(); aFR.Next())
624 //DEBTRACE(" a restricted face");
625 aResultFace = aFR.Current();
634 if (aResultFace.IsNull())
637 //DEBTRACE("check the face");
638 BRepCheck_Analyzer anAnalyzer(aResultFace);
639 if (anAnalyzer.IsValid() && aResultFace.ShapeType() == TopAbs_FACE)
641 //DEBTRACE("face OK");
646 //DEBTRACE("bad face");
648 return TopoDS_Face();
651 void HYDROData_Tool::SetSIProgress(const Handle(Message_ProgressIndicator)& thePI)
653 StricklerInterpolationProgress() = thePI;
656 const Handle(Message_ProgressIndicator)& HYDROData_Tool::GetSIProgress()
658 return StricklerInterpolationProgress();
661 Handle(Message_ProgressIndicator)& HYDROData_Tool::StricklerInterpolationProgress()
663 static Handle(Message_ProgressIndicator) aPI = NULL;
667 void HYDROData_Tool::SetZIProgress(const Handle(Message_ProgressIndicator)& thePI)
669 BathymetryInterpolationProgress() = thePI;
672 const Handle(Message_ProgressIndicator)& HYDROData_Tool::GetZIProgress()
674 return BathymetryInterpolationProgress();
677 Handle(Message_ProgressIndicator)& HYDROData_Tool::BathymetryInterpolationProgress()
679 static Handle(Message_ProgressIndicator) aPI = NULL;
683 void HYDROData_Tool::SetTriangulationStatus(const ExecStatus& theStatus)
685 myTriangulationStatus = theStatus;
688 const HYDROData_Tool::ExecStatus& HYDROData_Tool::GetTriangulationStatus()
690 return myTriangulationStatus;
693 static bool AddXYZ(bool bImportXY,
697 std::vector<gp_XYZ>& thePointsXYZ,
698 std::vector<gp_XY>& thePointsXY)
702 if ( HYDROData_Tool::IsNan( x ) || HYDROData_Tool::IsInf( x ) ||
703 HYDROData_Tool::IsNan( y ) || HYDROData_Tool::IsInf( y ) ||
704 HYDROData_Tool::IsNan( z ) || HYDROData_Tool::IsInf( z ) )
707 if( thePointsXYZ.size()>=thePointsXYZ.capacity() )
708 thePointsXYZ.reserve( thePointsXYZ.size()+BLOCK_SIZE );
710 thePointsXYZ.push_back(gp_XYZ(x,y,z));
714 if ( HYDROData_Tool::IsNan( x ) || HYDROData_Tool::IsInf( x ) ||
715 HYDROData_Tool::IsNan( y ) || HYDROData_Tool::IsInf( y ) )
718 if( thePointsXY.size()>=thePointsXY.capacity() )
719 thePointsXY.reserve( thePointsXY.size()+BLOCK_SIZE );
721 thePointsXY.push_back(gp_XY(x,y));
726 bool HYDROData_Tool::importFromXYZ( QString& theFileName,
728 std::vector<gp_XYZ>& thePointsXYZ,
729 std::vector<gp_XY>& thePointsXY)
731 QFile aFile( theFileName );
732 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) )
735 QString aFileSuf = QFileInfo( aFile ).suffix().toLower();
738 if ( aFileSuf == "xyz" )
741 while ( !aFile.atEnd() )
743 std::string aLine = aFile.readLine().simplified().toStdString();
751 if( sscanf( aLine.c_str(), "%lf %lf %lf", &x, &y, &z )!=3 )
757 if (!AddXYZ(bImportXY, x, y, z, thePointsXYZ, thePointsXY ))
764 else if (aFileSuf == "xy" )
766 while ( !aFile.atEnd() )
768 std::string aLine = aFile.readLine().simplified().toStdString();
775 if( sscanf( aLine.c_str(), "%lf %lf", &x, &y )!=2 )
781 if (!AddXYZ(true, x, y, 0, thePointsXYZ, thePointsXY ))
794 bool HYDROData_Tool::importPolylineFromXYZ(QString aFileName, Handle(HYDROData_Document) theDocument,
795 bool importXY, NCollection_Sequence<Handle(HYDROData_Entity)>& importedEntities)
799 std::vector<gp_XY> aPoints2d;
800 std::vector<gp_XYZ> aDPoints3d;
802 if (HYDROData_Tool::importFromXYZ(aFileName, importXY, aDPoints3d, aPoints2d))
804 QString basename = QFileInfo( aFileName ).baseName();
806 Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
807 HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;
808 bool IsClosed = false;
809 if ((aPoints2d.front()-aPoints2d.back()).Modulus()<Precision::Confusion())
812 aPolylineXY->AddSection( TCollection_AsciiString("poly_section"), aSectType, true);
815 aPolylineXY->AddSection( TCollection_AsciiString("poly_section"), aSectType, false);
817 int n = aPoints2d.size();
821 for ( int i = 0; i < n; i++ )
823 gp_XY aSectPoint = aPoints2d[i];
824 theDocument->Transform(aSectPoint, true);
825 aPolylineXY->AddPoint( 0, aSectPoint );
828 aPolylineXY->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
829 aPolylineXY->SetName( basename + "_PolyXY_" );
830 aPolylineXY->Update();
831 importedEntities.Append(aPolylineXY);
839 std::vector<gp_XY> aDPoints2d;
840 std::vector<gp_XYZ> aPoints3d;
841 if (HYDROData_Tool::importFromXYZ(aFileName, false, aPoints3d, aDPoints2d))
843 QString basename = QFileInfo( aFileName ).baseName();
844 Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
845 Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( theDocument->CreateObject( KIND_POLYLINE ) );
846 Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( theDocument->CreateObject( KIND_BATHYMETRY ) );
847 HYDROData_Bathymetry::AltitudePoints aAPoints;
848 HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;
849 bool IsClosed = false;
850 if ((aPoints3d.front()-aPoints3d.back()).Modulus()<Precision::Confusion())
853 aPolylineXY->AddSection( TCollection_AsciiString("poly_section"), aSectType, true);
856 aPolylineXY->AddSection( TCollection_AsciiString("poly_section"), aSectType, false);
858 int n = aPoints3d.size();
862 for ( int i = 0; i < n; i++ )
864 gp_XY aSectPoint(aPoints3d[i].X(), aPoints3d[i].Y());
865 theDocument->Transform(aSectPoint, true);
866 aPolylineXY->AddPoint( 0, aSectPoint );
867 HYDROData_Bathymetry::AltitudePoint p;
868 p.X = aSectPoint.X();
869 p.Y = aSectPoint.Y();
870 p.Z = aPoints3d[i].Z();
871 aAPoints.push_back(p);
874 QString aBathName = basename + "_bath_";
875 QString aPolyXYName = basename + "_polyXY_";
876 QString aPoly3DName = basename + "_poly3D_";
878 aPolylineXY->SetName( aPolyXYName );
879 aPolylineXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor());
880 aPolylineXY->Update();
882 aBath->SetAltitudePoints(aAPoints);
883 aBath->SetName( aBathName );
885 aPolylineObj->SetPolylineXY (aPolylineXY, false);
886 aPolylineObj->SetAltitudeObject(aBath);
888 aPolylineObj->SetBorderColor( aPolylineObj->DefaultBorderColor() );
889 aPolylineObj->SetName( aPoly3DName );
891 aPolylineObj->Update();
892 importedEntities.Append(aPolylineXY);
893 importedEntities.Append(aPolylineObj);
902 std::ostream& operator<<( std::ostream& theStream, const QString& theText )
904 theStream << theText.toStdString();
908 std::ostream& operator<<( std::ostream& theStream, const QColor& theColor )
910 theStream << "[" << theColor.red() << ", " << theColor.green() << ", " << theColor.blue() << "]";
914 std::ostream& operator<<( std::ostream& theStream, const TopoDS_Shape& theShape )
916 theStream << "[" << theShape.TShape().operator->() << "]";
920 std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace )
922 theStream << "[" << theFace.TShape().operator->() << "]";
926 std::ostream& operator<<( std::ostream& theStream, const gp_XY& theXY )
928 theStream << "(" << theXY.X() << "; " << theXY.Y() << ")";
932 bool operator == ( const gp_XY& thePoint1, const gp_XY& thePoint2 )
934 const double EPS = 1E-3;
936 fabs( thePoint1.X() - thePoint2.X() ) < EPS &&
937 fabs( thePoint1.Y() - thePoint2.Y() ) < EPS;