Salome HOME
Merge branch 'BR_H2018_3' into BR_2018_V8_5 HYDRO_V2_0_0
authorPaul RASCLE <paul.rascle@edf.fr>
Fri, 14 Dec 2018 08:53:05 +0000 (09:53 +0100)
committerPaul RASCLE <paul.rascle@edf.fr>
Fri, 14 Dec 2018 08:53:05 +0000 (09:53 +0100)
27 files changed:
src/HYDROData/HYDROData_IPolyline.cxx
src/HYDROData/HYDROData_IPolyline.h
src/HYDROData/HYDROData_PolylineOperator.cxx
src/HYDROData/HYDROData_PolylineOperator.h
src/HYDROData/HYDROData_PolylineXY.cxx
src/HYDROData/HYDROData_Tool.cxx
src/HYDROData/HYDROData_Tool.h
src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx
src/HYDROGUI/HYDROGUI_Polyline.cxx
src/HYDROGUI/HYDROGUI_Polyline.h
src/HYDROGUI/HYDROGUI_PolylineOp.cxx
src/HYDROGUI/HYDROGUI_SetColorOp.cxx
src/HYDROGUI/HYDROGUI_Shape.cxx
src/HYDROGUI/HYDROGUI_VTKPrsShape.cxx
src/HYDROGUI/resources/HYDROGUI_msg_en.ts
src/HYDROPy/HYDROData_IPolyline.sip
src/HYDRO_tests/reference_data/CMakeLists.txt
src/HYDRO_tests/reference_data/linux/Polyline_import_XY.png [new file with mode: 0644]
src/HYDRO_tests/reference_data/linux/Polyline_import_XYZ.png [new file with mode: 0644]
src/HYDRO_tests/reference_data/linux/Polyline_import_XYZ_3D.png [new file with mode: 0644]
src/HYDRO_tests/reference_data/linux/Split_Polylines_Colors.png
src/HYDRO_tests/reference_data/win32/Polyline_import_XY.png [new file with mode: 0644]
src/HYDRO_tests/reference_data/win32/Polyline_import_XYZ.png [new file with mode: 0644]
src/HYDRO_tests/reference_data/win32/Polyline_import_XYZ_3D.png [new file with mode: 0644]
src/HYDRO_tests/reference_data/win32/Split_Polylines_Colors.png
src/HYDRO_tests/test_HYDROData_PolylineXY.cxx
src/HYDRO_tests/test_HYDROData_PolylineXY.h

index 1ec97913a28b97a035e8b46d213c000c7c06389d..ddd6908aa381f9cb8f1993dbeaa05c0361fdb444 100644 (file)
@@ -41,7 +41,11 @@ HYDROData_IPolyline::~HYDROData_IPolyline()
 
 void HYDROData_IPolyline::SetWireColor( const QColor& theColor )
 {
-  SetColor( theColor, DataTag_WireColor );
+  //SetColor( theColor, DataTag_WireColor ); //DEPRECATED;
+  //set theColor for all sections
+  int nbSec = NbSections();
+  for (int i = 0; i < nbSec; i++)
+    SetSectionColor(i, theColor);
 }
 
 QColor HYDROData_IPolyline::GetWireColor() const
@@ -168,7 +172,7 @@ void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) const
   }
 }
 
-bool HYDROData_IPolyline::getSectionColor( const int theSectionIndex, QColor &theColor) const
+bool HYDROData_IPolyline::GetSectionColor( const int theSectionIndex, QColor &theColor) const
 {
   TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, false );
   if ( aLabel.IsNull() )
@@ -189,8 +193,8 @@ bool HYDROData_IPolyline::getSectionColor( const int theSectionIndex, QColor &th
   }
 }
 
-void HYDROData_IPolyline::setSectionColor( const int theSectionIndex,
-                                           const QColor& theColor ) const
+void HYDROData_IPolyline::SetSectionColor( const int theSectionIndex,
+                                           const QColor& theColor )
 {
   TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, true );
   if ( aLabel.IsNull() )
@@ -228,3 +232,14 @@ void HYDROData_IPolyline::removeSectionColor( const int theSectionIndex ) const
       aSectLabel.ForgetAllAttributes();
   }
 }
+
+ void HYDROData_IPolyline::setPythonPolylineSectionColor( QStringList&  theScript,
+                                                          const int     theSectIndex,
+                                                          const QColor& theColor ) const
+{
+  QString anObjName = GetObjPyName();
+  theScript << QString( "%1.SetSectionColor( %2, QColor( %3, %4, %5, %6 ) )" )
+              .arg( anObjName ).arg( theSectIndex )
+              .arg( theColor.red()  ).arg( theColor.green() )
+              .arg( theColor.blue() ).arg( theColor.alpha() );
+}
index c8916d4cc9ea78492e96c740c730dc816361d01a..5795ce4bfbd064cf3716c134e9a2426ed115722b 100644 (file)
@@ -51,7 +51,7 @@ protected:
     DataTag_Points,
     DataTag_Sections,
     DataTag_PolylineShape,
-    DataTag_WireColor,
+    DataTag_WireColor,  //DEPRECATED; DataTag_SectionColors for coloring of individual section of polyline
     DataTag_SectionColors,
   };
 
@@ -68,7 +68,7 @@ public:
   /**
    * Returns wire color of object.
    */
-  HYDRODATA_EXPORT virtual QColor GetWireColor() const;
+  HYDRODATA_EXPORT virtual QColor GetWireColor() const; //DEPRECATED
 
   /**
    * Returns default wire color for new object.
@@ -191,10 +191,9 @@ public:
   HYDRODATA_EXPORT TopoDS_Shape GetShape() const;
   HYDRODATA_EXPORT void SetShape( const TopoDS_Shape& theShape );
 
-  HYDRODATA_EXPORT void setSectionColor( const int theSectionIndex,
-                                         const QColor& theColor ) const;
+  HYDRODATA_EXPORT virtual void SetSectionColor( const int theSectionIndex, const QColor& theColor );
 
-  HYDRODATA_EXPORT bool getSectionColor( const int theSectionIndex, QColor &theColor) const;
+  HYDRODATA_EXPORT virtual bool GetSectionColor( const int theSectionIndex, QColor &theColor) const;
 
   HYDRODATA_EXPORT void removeSectionColor( const int theSectionIndex = -1 ) const;
 
@@ -215,6 +214,9 @@ protected:
 
   void removePointsLists( const int theSectionIndex = -1 ) const;
 
+  void setPythonPolylineSectionColor( QStringList&  theScript,
+                                      const int     theSectIndex,
+                                      const QColor& theColor ) const;
 
 
 protected:
index 41d0f7c831cb4731c3ae87b0c29783cb09de7814..1b0c898544cb53d7a2110672244d657c4d983cc7 100644 (file)
@@ -86,13 +86,40 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theD
   std::vector<TopoDS_Wire> aCurves;
   GetWires(thePolyline, aCurves);
   bool isOK = true;
+
+  std::vector<QColor> aSectColors;
+  int nbSec = thePolyline->NbSections();
+  for (int i = 0; i < nbSec; i++)
+  {
+    QColor aColor;
+    thePolyline->GetSectionColor(i, aColor);
+    aSectColors.push_back(aColor);
+  }
+
+  bool bsetColor = aCurves.size() == aSectColors.size();
   for( int i=0, n=aCurves.size(); i<n; i++ )
   {
     std::vector<TopoDS_Shape> aCurvesList;
     Split( aCurves[i], thePoint, theTolerance, aCurvesList );
-    bool isLocalOK = CreatePolylines( theDoc, thePolyline, aCurvesList, true );
+    NCollection_IndexedDataMap<Handle(HYDROData_PolylineXY), TopoDS_Shape> outPoly2Sh;
+    bool isLocalOK = CreatePolylines( theDoc, thePolyline, aCurvesList, true, outPoly2Sh );
     isOK = isOK && isLocalOK;
+    if (bsetColor)
+    {
+      QColor aColor = aSectColors[i];
+      if( aColor.isValid() )
+      {
+        for (int j=1;j<=outPoly2Sh.Extent();j++)
+        {
+          const Handle(HYDROData_PolylineXY)& Poly = outPoly2Sh.FindKey(j); 
+          int nbSec = Poly->NbSections();
+          for (int k = 0; k < nbSec; k++)
+            Poly->SetSectionColor(k, aColor);
+        }
+      }
+    }
   }
+
   return isOK;
 }
 
@@ -212,9 +239,27 @@ bool HYDROData_PolylineOperator::split( const Handle( HYDROData_Document )& theD
     return false;
   }
 
+  std::vector<QColor> aSectColors;
+  int nbSec = thePolyline->NbSections();
+
+
+
   const int aPSCount = aCurves.size();
   const int aTSCount = aToolCurves.size();
   std::vector<TopoDS_Shape> aResult;
+
+  bool bSetColor = aPSCount == nbSec;
+  if (bSetColor)
+  {
+    for (int i = 0; i < nbSec; i++)
+    {
+      QColor aColor;
+      thePolyline->GetSectionColor(i, aColor);
+      aSectColors.push_back(aColor);
+    }
+  }
+  NCollection_DataMap <TopoDS_Shape, QColor, TopTools_ShapeMapHasher> W2Color;
+
   for (int aPSI = 0; aPSI < aPSCount; ++aPSI)
   {
     HYDROData_TopoCurve aCurve;
@@ -238,16 +283,35 @@ bool HYDROData_PolylineOperator::split( const Handle( HYDROData_Document )& theD
       aSplitCurves.end();
     for (int iw=0; aCIt != aLastCIt; ++aCIt, iw++)
     {
-      std::stringstream brepName;
-      brepName << "theSplitWire_";
-      brepName << iw;
-      brepName << ".brep";
-      BRepTools::Write(aCIt->Wire() , brepName.str().c_str() );
-      aResult.push_back(aCIt->Wire());
+      //std::stringstream brepName;
+      //brepName << "theSplitWire_";
+      //brepName << iw;
+      //brepName << ".brep";
+      //BRepTools::Write(aCIt->Wire() , brepName.str().c_str() );
+      const TopoDS_Wire& aW = aCIt->Wire();
+      if (bSetColor)
+        W2Color.Bind(aW, aSectColors[aPSI]);
+      aResult.push_back(aW);
     }
   }
 
-  CreatePolylines( theDoc, thePolyline, aResult, true );
+  NCollection_IndexedDataMap<Handle(HYDROData_PolylineXY), TopoDS_Shape> outPoly2Sh;
+  CreatePolylines( theDoc, thePolyline, aResult, true, outPoly2Sh );
+  
+  for (int j=1;j<=outPoly2Sh.Extent();j++)
+  {
+    const Handle(HYDROData_PolylineXY)& Poly = outPoly2Sh.FindKey(j); 
+    const TopoDS_Shape& Sh = outPoly2Sh.FindFromIndex(j); 
+
+    int nbSec = Poly->NbSections();
+    for (int k = 0; k < nbSec; k++)
+    {
+      const QColor* color = W2Color.Seek(Sh);
+      if (color)
+        Poly->SetSectionColor(k, *color);
+    }
+  }
+  
   return true;
 }
 
@@ -301,7 +365,8 @@ void HYDROData_PolylineOperator::Split(
 bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc,
                                                   const Handle( HYDROData_PolylineXY )& theOldPolyline,
                                                   const std::vector<TopoDS_Shape>& theShapes,
-                                                  bool isUseIndices )
+                                                  bool isUseIndices,
+                                                  NCollection_IndexedDataMap<Handle(HYDROData_PolylineXY), TopoDS_Shape>& outPoly2Sh)
 {
   if( theDoc.IsNull() )
     return false;
@@ -309,7 +374,6 @@ bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Docume
   if ( theOldPolyline.IsNull() )
     return false;
   const QString& theNamePrefix = theOldPolyline->GetName();
-  const QColor& theColor = theOldPolyline->GetWireColor();
 
   int n = theShapes.size();
   DEBTRACE("theShapes.size() "<< n);
@@ -338,8 +402,7 @@ bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Docume
       aPolyline->SetName( theNamePrefix );
     }
 
-    if( theColor.isValid() )
-      aPolyline->SetWireColor( theColor );
+    outPoly2Sh.Add(aPolyline, theShapes[i]);
   }
   return true;
 }
index 6fea45128c56f22ef759fda3f9ccfaa00cd0d1d0..ff64142abf0bafff4d5334476938ebb6939ec83b 100644 (file)
@@ -23,6 +23,7 @@
 #include <Geom2d_Curve.hxx>
 #include <gp_Pnt2d.hxx>
 #include <vector>
+#include <NCollection_IndexedDataMap.hxx>
 
 class HYDROData_Document;
 class HYDROData_TopoCurve;
@@ -85,7 +86,8 @@ protected:
   static bool CreatePolylines( const Handle( HYDROData_Document )& theDoc,
                                const Handle( HYDROData_PolylineXY )& theOldPolyline,
                                const std::vector<TopoDS_Shape>& theShape,
-                               bool isUseIndices );
+                               bool isUseIndices,
+                               NCollection_IndexedDataMap<Handle(HYDROData_PolylineXY), TopoDS_Shape>& outPoly2Sh);
 };
 
 #endif
index cd7a710078d56bd9978b6eef4b1ff46dbdc19d05..54c418ac975ccdaab3a25de9d4e12d983f2d7304 100644 (file)
@@ -149,8 +149,17 @@ QStringList HYDROData_PolylineXY::DumpToPython( const QString&       thePyScript
   // Set the wire color
   QStringList aWireColorDef;
 
-  QColor aWireColor = GetWireColor();
-  setPythonObjectColor( aWireColorDef, aWireColor, DefaultWireColor(), "SetWireColor" );
+  //QColor aWireColor = GetWireColor();
+  //setPythonObjectColor( aWireColorDef, aWireColor, DefaultWireColor(), "SetWireColor" );
+
+  int nbSec = NbSections();
+  for (int i = 0; i < nbSec; i++)
+  {
+    QColor aColor;
+    GetSectionColor(i, aColor);
+    setPythonPolylineSectionColor(aWireColorDef, i, aColor );
+    //aWireColorDef << "";
+  }
   
   if ( !aWireColorDef.isEmpty() )
   {
@@ -829,42 +838,59 @@ void HYDROData_PolylineXY::Update()
     }
   }
 // all input wires in the <aSectionWiresList>
-  Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
-  Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
-  TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
-  for(;it.More();it.Next())
-  {
-    TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
-    for(;it2.More();it2.Next()) 
-      aSeqEdges->Append(it2.Current());
-  }
 
+  TopoDS_Shape aResult;
   BRep_Builder aBB;
   TopoDS_Compound aCmp;
-  TopoDS_Shape aResult;
   aBB.MakeCompound(aCmp);
-  if(aSeqEdges->Length() >1)
+  if (aSectionWiresList.Size() == 1)
+    aResult = aSectionWiresList.First();
+  else if (aSectionWiresList.Size() > 1)
   {
-    ShapeAnalysis_FreeBounds::ConnectEdgesToWires( aSeqEdges, 1E-5, Standard_True, aSeqWires );
-
-    if( aSeqWires->Length()==1 )
-      aResult = aSeqWires->Value( 1 );
-    else
+    TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
+    for(;it.More();it.Next())
     {
-      for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
-      {
-        const TopoDS_Shape& aS1 = aSeqWires->Value(i);
-        aBB.Add(aCmp, aS1);
-      }
-      aResult = aCmp;
+      aBB.Add(aCmp, it.Value());
     }
+    aResult = aCmp;
   }
-  else if (aSeqEdges->Length() == 1)
-  {
-    BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
-    if (mkWire.IsDone())
-      aResult = mkWire.Wire();
-  }
+
+  //Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
+  //Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
+  //TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
+  //for(;it.More();it.Next())
+  //{
+  //  TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
+  //  for(;it2.More();it2.Next()) 
+  //    aSeqEdges->Append(it2.Current());
+  //}
+  //
+  //BRep_Builder aBB;
+  //TopoDS_Compound aCmp;
+  //TopoDS_Shape aResult;
+  //aBB.MakeCompound(aCmp);
+  //if(aSeqEdges->Length() >1)
+  //{
+  //  ShapeAnalysis_FreeBounds::ConnectEdgesToWires( aSeqEdges, 1E-5, Standard_True, aSeqWires );
+  //
+  //  if( aSeqWires->Length()==1 )
+  //    aResult = aSeqWires->Value( 1 );
+  //  else
+  //  {
+  //    for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
+  //    {
+  //      const TopoDS_Shape& aS1 = aSeqWires->Value(i);
+  //      aBB.Add(aCmp, aS1);
+  //    }
+  //    aResult = aCmp;
+  //  }
+  //}
+  //else if (aSeqEdges->Length() == 1)
+  //{
+  //  BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
+  //  if (mkWire.IsDone())
+  //    aResult = mkWire.Wire();
+  //}
 
   SetShape( aResult );
 }
index f5f8d9e77df9fe165d036381260ac7b53ea84f9b..9ad6eccc7fcd662ab8365db5bc0ee51f1e6ee4c5 100755 (executable)
 #include <ShapeAnalysis.hxx>
 #include <ShapeAnalysis_FreeBounds.hxx>
 
+#include <HYDROData_PolylineXY.h>
+#include <HYDROData_Polyline3D.h>
+#include <HYDROData_Bathymetry.h>
+
+#include <QFileInfo>
+#define BLOCK_SIZE 10000
 
 HYDROData_Tool::ExecStatus HYDROData_Tool::myTriangulationStatus = ExecStatus::None;
 
@@ -684,6 +690,203 @@ const HYDROData_Tool::ExecStatus& HYDROData_Tool::GetTriangulationStatus()
   return myTriangulationStatus;
 }
 
+static bool AddXYZ(bool bImportXY, 
+                   double x,
+                   double y, 
+                   double z,
+                   std::vector<gp_XYZ>& thePointsXYZ,
+                   std::vector<gp_XY>& thePointsXY)
+{
+  if (!bImportXY)
+  {
+    if ( HYDROData_Tool::IsNan( x ) || HYDROData_Tool::IsInf( x ) ||
+      HYDROData_Tool::IsNan( y ) || HYDROData_Tool::IsInf( y ) ||
+      HYDROData_Tool::IsNan( z ) || HYDROData_Tool::IsInf( z ) )
+      return false;
+
+    if( thePointsXYZ.size()>=thePointsXYZ.capacity() )
+      thePointsXYZ.reserve( thePointsXYZ.size()+BLOCK_SIZE );
+
+    thePointsXYZ.push_back(gp_XYZ(x,y,z));
+  }
+  else
+  {
+    if ( HYDROData_Tool::IsNan( x ) || HYDROData_Tool::IsInf( x ) ||
+      HYDROData_Tool::IsNan( y ) || HYDROData_Tool::IsInf( y ) )
+      return false;
+
+    if( thePointsXY.size()>=thePointsXY.capacity() )
+      thePointsXY.reserve( thePointsXY.size()+BLOCK_SIZE );
+
+    thePointsXY.push_back(gp_XY(x,y));
+  }
+  return true;
+}
+
+bool HYDROData_Tool::importFromXYZ( QString& theFileName,  
+                                    bool bImportXY, 
+                                    std::vector<gp_XYZ>& thePointsXYZ,
+                                    std::vector<gp_XY>& thePointsXY)
+{
+  QFile aFile( theFileName );
+  if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) )
+    return false;
+
+  QString aFileSuf = QFileInfo( aFile ).suffix().toLower();
+
+  double x,y;
+  if ( aFileSuf == "xyz" )
+  {
+    double z;
+    while ( !aFile.atEnd() )
+    {
+      std::string aLine = aFile.readLine().simplified().toStdString();
+      if ( aLine.empty() )
+        continue;
+
+      x = 0;
+      y = 0;
+      z = 0;
+
+      if( sscanf( aLine.c_str(), "%lf %lf %lf", &x, &y, &z )!=3 )
+        return false;
+
+      if (!AddXYZ(bImportXY, x, y, z, thePointsXYZ, thePointsXY ))
+        return false;
+    }
+  }
+  else if (aFileSuf == "xy" )
+  {
+    while ( !aFile.atEnd() )
+    {
+      std::string aLine = aFile.readLine().simplified().toStdString();
+      if ( aLine.empty() )
+        continue;
+
+      x = 0;
+      y = 0;
+
+      if( sscanf( aLine.c_str(), "%lf %lf", &x, &y )!=2 )
+        return false;
+
+      if (!AddXYZ(true, x, y, 0, thePointsXYZ, thePointsXY ))
+        return false;
+    }
+  }
+
+  aFile.close();
+
+  return true;
+}
+
+bool HYDROData_Tool::importPolylineFromXYZ(QString aFileName, Handle(HYDROData_Document) theDocument, 
+  bool importXY, NCollection_Sequence<Handle(HYDROData_Entity)>& importedEntities)
+{
+  if (importXY)
+  {
+    std::vector<gp_XY> aPoints2d;
+    std::vector<gp_XYZ> aDPoints3d;
+
+    if (HYDROData_Tool::importFromXYZ(aFileName, importXY, aDPoints3d, aPoints2d))
+    {
+      QString basename = QFileInfo( aFileName ).baseName();
+
+      Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
+      HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;    
+      bool IsClosed = false;
+      if ((aPoints2d.front()-aPoints2d.back()).Modulus()<Precision::Confusion())
+      {
+        IsClosed = true;
+        aPolylineXY->AddSection( TCollection_AsciiString("poly_section"), aSectType, true);
+      }
+      else
+        aPolylineXY->AddSection( TCollection_AsciiString("poly_section"), aSectType, false);
+
+      int n = aPoints2d.size();
+      if (IsClosed)
+        n--;
+
+      for ( int i = 0; i < n; i++ )
+      {
+        gp_XY aSectPoint = aPoints2d[i];
+        theDocument->Transform(aSectPoint, true);
+        aPolylineXY->AddPoint( 0, aSectPoint );
+      }      
+
+      aPolylineXY->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
+      aPolylineXY->SetName( basename + "_PolyXY_" );
+      aPolylineXY->Update();
+      importedEntities.Append(aPolylineXY);
+      return true;
+    }
+    else 
+      return false;
+  }
+  else //xyz 
+  {
+    std::vector<gp_XY> aDPoints2d;
+    std::vector<gp_XYZ> aPoints3d;
+    if (HYDROData_Tool::importFromXYZ(aFileName, false, aPoints3d, aDPoints2d))
+    {
+      QString basename = QFileInfo( aFileName ).baseName();
+      Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
+      Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( theDocument->CreateObject( KIND_POLYLINE ) );
+      Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( theDocument->CreateObject( KIND_BATHYMETRY ) );
+      HYDROData_Bathymetry::AltitudePoints aAPoints;
+      HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;    
+      bool IsClosed = false;
+      if ((aPoints3d.front()-aPoints3d.back()).Modulus()<Precision::Confusion())
+      {
+        IsClosed = true;
+        aPolylineXY->AddSection( TCollection_AsciiString("poly_section"), aSectType, true);
+      }
+      else
+        aPolylineXY->AddSection( TCollection_AsciiString("poly_section"), aSectType, false);
+
+      int n = aPoints3d.size();
+      if (IsClosed)
+        n--;
+
+      for ( int i = 0; i < n; i++ )
+      {
+        gp_XY aSectPoint(aPoints3d[i].X(), aPoints3d[i].Y());
+        theDocument->Transform(aSectPoint, true);
+        aPolylineXY->AddPoint( 0, aSectPoint );
+        HYDROData_Bathymetry::AltitudePoint p;
+        p.X = aSectPoint.X();
+        p.Y = aSectPoint.Y();
+        p.Z = aPoints3d[i].Z();
+        aAPoints.push_back(p);
+      }
+
+      QString aBathName = basename + "_bath_";
+      QString aPolyXYName = basename + "_polyXY_";
+      QString aPoly3DName = basename + "_poly3D_";
+
+      aPolylineXY->SetName( aPolyXYName );
+      aPolylineXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor());
+      aPolylineXY->Update();
+
+      aBath->SetAltitudePoints(aAPoints);
+      aBath->SetName( aBathName );
+
+      aPolylineObj->SetPolylineXY (aPolylineXY, false);
+      aPolylineObj->SetAltitudeObject(aBath);
+
+      aPolylineObj->SetBorderColor( aPolylineObj->DefaultBorderColor() );
+      aPolylineObj->SetName( aPoly3DName );
+
+      aPolylineObj->Update();
+      importedEntities.Append(aPolylineXY);
+      importedEntities.Append(aPolylineObj);
+      return true;
+    }
+    else 
+      return false;
+  }
+}
+
+
 std::ostream& operator<<( std::ostream& theStream, const QString& theText )
 {
   theStream << theText.toStdString();
index 0047995a169da453dbf1672a338f20375ea8da49..c7bd4fe6a53831e8e96d7f98700f487726c90831 100755 (executable)
@@ -154,6 +154,13 @@ public:
 
   static TopoDS_Shape PolyXY2Face(const Handle(HYDROData_PolylineXY)& aPolyline);
 
+  static bool importFromXYZ( QString& theFileName, bool bImportXY, std::vector<gp_XYZ>& thePointsXYZ,
+                             std::vector<gp_XY>& thePointsXY);
+
+  static bool importPolylineFromXYZ(QString aFilename, Handle(HYDROData_Document) theDocument, 
+                                    bool importXY, NCollection_Sequence<Handle(HYDROData_Entity)>& importedEntities);
+  
+
   static void SetSIProgress(const Handle(Message_ProgressIndicator)& thePI);
   static const Handle(Message_ProgressIndicator)& GetSIProgress();
 
index bc83c0f2abe7506a9200f7a357e2a839c835c4f3..6697b42010576b0f68c513458fd002f654cf7009 100644 (file)
@@ -28,6 +28,7 @@
 #include <HYDROData_Bathymetry.h>
 #include <HYDROData_Iterator.h>
 #include <HYDROData_ShapeFile.h>
+#include <HYDROData_Tool.h>
 
 #include <HYDROData_Profile.h>
 
@@ -39,6 +40,7 @@
 #include <QFile>
 #include <QFileInfo>
 #include <SUIT_MessageBox.h>
+#include <gp_XY.hxx>
 
 
 HYDROGUI_ImportPolylineOp::HYDROGUI_ImportPolylineOp( HYDROGUI_Module* theModule )
@@ -77,7 +79,16 @@ NCollection_Sequence<Handle(HYDROData_Entity)> HYDROGUI_ImportPolylineOp::Import
       continue;
 
     QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
-
+    anExt.toLower();
+    bool importXY = false;
+    if (anExt == "xyz")
+    {
+      importXY = SUIT_MessageBox::question( module->getApp()->desktop(),
+        tr( "IMPORT_POLYLINE" ),
+        tr( "IMPORT_POLYLINE_XY_PART_ONLY" ),
+        QMessageBox::Yes | QMessageBox::No, 
+        SUIT_MessageBox::Yes) == SUIT_MessageBox::Yes;
+    }
     if (anExt == "shp")
     {
       HYDROData_ShapeFile anImporter;
@@ -186,6 +197,14 @@ NCollection_Sequence<Handle(HYDROData_Entity)> HYDROGUI_ImportPolylineOp::Import
       }
       importedEntities.Append(theEntities);
     }
+    else if ( anExt == "xy" || (importXY && anExt == "xyz"))
+    {
+      HYDROData_Tool::importPolylineFromXYZ(aFileName, theDocument, true, importedEntities);   
+    }
+    else if (anExt == "xyz")
+    {
+      HYDROData_Tool::importPolylineFromXYZ(aFileName, theDocument, false, importedEntities);
+    }
   }
   return importedEntities;
 }
index edc05ccc6b6b5dda2a1f2f6d1f0587e67f59e912..0119af16d3f9341e11ac1721549001fb5a3bee3d 100644 (file)
@@ -62,12 +62,28 @@ Handle( Graphic3d_ArrayOfPolylines ) BuildEdgePresentation( const TopoDS_Edge& t
   return anArray;
 }
 
+bool HYDROGUI_Polyline::GetColorOfSubShape(const TopoDS_Shape& SubShape, Quantity_Color& outColor)
+{
+  for (int i=1; i<=myShapeToColor.Extent();i++)
+  {
+    const TopoDS_Shape& aCurShape = myShapeToColor.FindKey(i);
+    TopTools_IndexedMapOfShape aSubShMap;
+    TopExp::MapShapes(aCurShape, aSubShMap);
+    if (aSubShMap.Contains(SubShape))
+    {
+      outColor = myShapeToColor(i);
+      return true;
+    }
+  }
+  return false;
+}
+
 void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
                             const Handle(Prs3d_Presentation)& aPrs,
                             const Standard_Integer aMode)
 {  
   //AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
-  //return;
+  // return;
 
   aPrs->Clear();
   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs );
@@ -78,7 +94,6 @@ void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre
   anWidth =2;
   Handle(Graphic3d_AspectLine3d) anAspect = new Graphic3d_AspectLine3d( aColor, aType, anWidth );
 
-  TopExp_Explorer Exp1 ( myshape, TopAbs_EDGE );
   Bnd_Box BB;
   BRepBndLib::AddClose(myshape, BB);
   double xmin, xmax, ymin, ymax, zmin, zmax;
@@ -89,14 +104,27 @@ void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre
     double minSide = Min(Abs(xmax - xmin), Abs(ymax - ymin));
     devCoeff = minSide > 50 ? 0.05 : minSide / 3000;
   }
-  for ( ; Exp1.More(); Exp1.Next() )
+
+  TopExp_Explorer Exp ( myshape, TopAbs_WIRE );
+  for ( ; Exp.More(); Exp.Next() )
   {
-    TopoDS_Edge anEdge = TopoDS::Edge( Exp1.Current() );
-    Handle( Graphic3d_ArrayOfPolylines ) anArray = BuildEdgePresentation( anEdge, devCoeff );
-    if( !anArray.IsNull() )
+    TopoDS_Shape W = Exp.Current();
+    TopExp_Explorer Exp1 (W, TopAbs_EDGE );
+    Quantity_Color aWCol = aColor; //from drawer
+    if (myShapeToColor.Contains(W))
+    {
+      Quantity_Color aWCol = myShapeToColor.FindFromKey(W);
+      anAspect = new Graphic3d_AspectLine3d( aWCol, aType, anWidth );
+    }
+    for ( ; Exp1.More(); Exp1.Next() )
     {
-      aGroup->SetPrimitivesAspect( anAspect );
-      aGroup->AddPrimitiveArray( anArray );
+      TopoDS_Edge anEdge = TopoDS::Edge( Exp1.Current() );
+      Handle( Graphic3d_ArrayOfPolylines ) anArray = BuildEdgePresentation( anEdge, devCoeff);
+      if( !anArray.IsNull() )
+      {
+        aGroup->SetPrimitivesAspect( anAspect );
+        aGroup->AddPrimitiveArray( anArray );
+      }
     }
   }
 }
@@ -107,7 +135,8 @@ QList<Handle(AIS_InteractiveObject)> HYDROGUI_Polyline::createPresentations
   QList<Handle(AIS_InteractiveObject)> shapes;
 
   // 1. Main shape
-  shapes.append( new HYDROGUI_Polyline( theShape ) );
+  Handle(HYDROGUI_Polyline) aMPoly = new HYDROGUI_Polyline( theShape );
+  shapes.append( aMPoly );
 
   // 2. Shapes for direction arrows on edges
   TopExp_Explorer Exp ( theShape, TopAbs_EDGE );
@@ -116,7 +145,7 @@ QList<Handle(AIS_InteractiveObject)> HYDROGUI_Polyline::createPresentations
     TopoDS_Edge anEdge = TopoDS::Edge(Exp.Current());
     if ( !anEdge.IsNull() ) 
     {
-      Handle(HYDROGUI_Arrow) arrow = new HYDROGUI_Arrow( anEdge );
+      Handle(HYDROGUI_Arrow) arrow = new HYDROGUI_Arrow( anEdge, aMPoly );
       if( theType>=0 )
         arrow->SetType( (HYDROGUI_Arrow::Type)theType );
       if( theSize>=0 )
@@ -149,8 +178,8 @@ void HYDROGUI_Polyline::update( const QList<Handle(AIS_InteractiveObject)>& theO
 IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_Arrow, AIS_Shape)
 
 
-HYDROGUI_Arrow::HYDROGUI_Arrow( const TopoDS_Edge& edge )
-  : AIS_Shape( edge ), myType( Cone ), mySize( 35 )
+  HYDROGUI_Arrow::HYDROGUI_Arrow( const TopoDS_Edge& edge, const Handle(HYDROGUI_Polyline)& polyline )
+  : AIS_Shape( edge ), myType( Cone ), mySize( 35 ), myParentPoly (polyline)
 {
 }
 
@@ -178,6 +207,11 @@ void HYDROGUI_Arrow::SetSize( int theSize )
   mySize = qMax( theSize, 0 );
 }
 
+const Handle(HYDROGUI_Polyline)& HYDROGUI_Arrow::getParentPolyline() const
+{
+  return myParentPoly;
+}
+
 void HYDROGUI_Arrow::BoundingBox (Bnd_Box& theBndBox)
 {
   //Nothing to change, we consider arrow as object with empty bounding box
@@ -239,6 +273,9 @@ void HYDROGUI_Arrow::Compute( const Handle(PrsMgr_PresentationManager3d)& aPrese
   Attributes()->LineAspect()->Aspect()->Values( aColor, aType, anWidth );
   anWidth = 1;
 
+  const Handle(HYDROGUI_Polyline)& aParentPoly = getParentPolyline();
+  aParentPoly->GetColorOfSubShape(anEdge, aColor);
+
   if( myType==Cone )
   {
     Handle(Graphic3d_AspectLine3d) anAspect = new Graphic3d_AspectLine3d( aColor, aType, anWidth );
index 06f2ec44b88072882f1f53fa736c8cdab7c00355..be993fe63c9c2b4e6150b8a0a157df4801397312 100644 (file)
@@ -21,6 +21,9 @@
 
 #include <AIS_Shape.hxx>
 #include <QList>
+#include <NCollection_IndexedDataMap.hxx>
+#include <Quantity_Color.hxx>
+#include <TopTools_ShapeMapHasher.hxx>
 
 class TopoDS_Shape;
 class TopoDS_Edge;
@@ -39,8 +42,13 @@ public:
     ( const TopoDS_Shape& theShape, int theType, int theSize );
   static void update( const QList<Handle(AIS_InteractiveObject)>&, int theType, int theSize );
 
+  NCollection_IndexedDataMap<TopoDS_Shape, Quantity_Color, TopTools_ShapeMapHasher> myShapeToColor;
+
+  bool GetColorOfSubShape(const TopoDS_Shape& SubShape, Quantity_Color& outColor);
+
 public:
   DEFINE_STANDARD_RTTIEXT(HYDROGUI_Polyline, AIS_Shape);
+
 };
 
 class HYDROGUI_Arrow : public AIS_Shape
@@ -48,7 +56,7 @@ class HYDROGUI_Arrow : public AIS_Shape
 public:
   enum Type { None, Triangle, Cone };
 
-  HYDROGUI_Arrow( const TopoDS_Edge& edge );
+  HYDROGUI_Arrow( const TopoDS_Edge& edge, const Handle(HYDROGUI_Polyline)& polyline );
   virtual ~HYDROGUI_Arrow();
 
   virtual void Compute( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
@@ -63,12 +71,15 @@ public:
   int  GetSize() const;
   void SetSize( int );
 
+  const Handle(HYDROGUI_Polyline)& getParentPolyline() const;
+
 public:
   DEFINE_STANDARD_RTTIEXT(HYDROGUI_Arrow, AIS_Shape);
 
 private:
   Type myType;
   int  mySize;
+  Handle(HYDROGUI_Polyline) myParentPoly;
 };
 
 #endif
index ff4205b1f9af7fa52fe67b5dcf393f9b33b6e5b0..9c3ffd7e27e52ea4b7fee172becc8913b0439f4f 100755 (executable)
@@ -185,7 +185,7 @@ void HYDROGUI_PolylineOp::startOperation()
 
         Quantity_Color aColor = CurveCreator_Utils::getRandColor();      
         QColor aQColor = CurveCreator_Utils::colorConv(aColor);
-        myEditedObject->getSectionColor(i-1, aQColor);
+        myEditedObject->GetSectionColor(i-1, aQColor);
 
         myCurve->addSectionInternal( aSectName.toStdString(),
           aCurveType, aSectClosure, aCurveCoords, CurveCreator_Utils::colorConv(aQColor) );
@@ -359,7 +359,7 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags,
     aPolylineObj->AddSection( aSectName, aSectType, aSectClosure );
 
     Quantity_Color aColor = myCurve->getColorSection(i);
-    aPolylineObj->setSectionColor(i, CurveCreator_Utils::colorConv(aColor));
+    aPolylineObj->SetSectionColor(i, CurveCreator_Utils::colorConv(aColor));
 
     // Add the points from section
     CurveCreator::Coordinates aCurveCoords = myCurve->getCoords( i );
@@ -382,10 +382,10 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags,
     }
   }
 
 if ( !myIsEdit )
 {
   aPolylineObj->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
 }
//if ( !myIsEdit )
//{
//  aPolylineObj->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
//}
 
   // Update the wire of polyline
   aPolylineObj->Update();
index 732635279f5e216e9a4f47c4645587ef7622f54b..eb52c47e5f1fc079185f9abbc9ffab304ac71e8a 100644 (file)
@@ -96,7 +96,12 @@ void HYDROGUI_SetColorOp::startOperation()
     Handle(HYDROData_IPolyline) aPolyObject =
       Handle(HYDROData_IPolyline)::DownCast( myEditedObject );
 
-    aFirstColor = aPolyObject->GetWireColor();
+    //aFirstColor = aPolyObject->GetWireColor();
+
+    if (aPolyObject->NbSections() > 0)
+      aPolyObject->GetSectionColor(0, aFirstColor);
+    else
+      aFirstColor = aPolyObject->GetWireColor();
 
     anIsOneColor = true;
   }
@@ -159,7 +164,15 @@ bool HYDROGUI_SetColorOp::processApply( int& theUpdateFlags,
     Handle(HYDROData_IPolyline) aPolyObject =
       Handle(HYDROData_IPolyline)::DownCast( myEditedObject );
 
-    aPolyObject->SetWireColor( aFirstColor );
+    //aPolyObject->SetWireColor( aFirstColor );
+    int nbSec = aPolyObject->NbSections();
+    if (nbSec > 0)
+    {
+      for (int i = 0; i < nbSec; i++)
+        aPolyObject->SetSectionColor(i, aFirstColor);
+    }
+    else
+      aPolyObject->SetWireColor( aFirstColor );
   }
   else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_LandCoverMap) ) )
   {
index 27568465b9f153e1bde9a5d0b206f4b8f628b01b..691581602fd92b506ca83efd43cb29ee673a4add 100644 (file)
@@ -42,6 +42,7 @@
 #include <TopoDS_Face.hxx>
 #include <TopoDS_Wire.hxx>
 #include <TopExp_Explorer.hxx>
+#include <TopExp.hxx>
 
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_Session.h>
@@ -185,8 +186,48 @@ void HYDROGUI_Shape::update( bool isUpdateViewer,
         }
       }
 
-      QColor aWireColor = aPolyline->GetWireColor();
-      setBorderColor( aWireColor, false, false );
+      //QColor aWireColor = aPolyline->GetWireColor();
+      std::vector<QColor> aSectColors;
+      //TODO backward comp. with old aWireColor??
+      int nbSec = aPolyline->NbSections();
+      for (int i = 0; i < nbSec; i++)
+      {
+        QColor aColor;
+        aPolyline->GetSectionColor(i, aColor);
+        aSectColors.push_back(aColor);
+      }         
+
+      //
+      //setBorderColor( aWireColor, false, false );
+
+      foreach( Handle(AIS_InteractiveObject) aShape, myShapes )
+      {
+        if( !myTopoShape.IsNull() )
+        {
+          Handle(HYDROGUI_Polyline) aPShape = Handle(HYDROGUI_Polyline)::DownCast( aShape );
+          bool WireOrCmp = myTopoShape.ShapeType() == TopAbs_WIRE || myTopoShape.ShapeType() == TopAbs_COMPOUND;
+          if ( !aPShape.IsNull() && WireOrCmp)
+          {
+            TopTools_IndexedMapOfShape MW;
+            TopExp::MapShapes(myTopoShape, TopAbs_WIRE, MW);
+            if (MW.Extent() == nbSec)
+            {
+              for (int i=0;i<nbSec;i++)
+              {
+                const TopoDS_Shape& CW = MW(i+1);
+                Quantity_Color aFColor( getQuantityColorVal( aSectColors[i].red() ), 
+                  getQuantityColorVal( aSectColors[i].green() ),
+                  getQuantityColorVal( aSectColors[i].blue() ),
+                  Quantity_TOC_RGB );
+                aPShape->myShapeToColor.Add(CW, aFColor);
+              }
+            }
+          }
+        }
+      }    
+
+      //if ( theToDisplay && isVisible() && !myContext.IsNull() )  
+      //  displayShape( false );
     }
     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) )
     {
index 487cc4703342558d7999fd18071161ace5bd69b1..ce016a554b6431e2f86fe9023f88072a3810dc6d 100644 (file)
@@ -148,7 +148,7 @@ void HYDROGUI_VTKPrsShape::buildShape()
         }
       }
 
-      QColor aWireColor = aPolyline->GetWireColor();
+      //QColor aWireColor = aPolyline->GetWireColor();
       //setBorderColor( aWireColor, false, false );
     }
     else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) )
index 0f46924bf5dd0198bca5eeae0aca98f15d6a69dc..3b654ee684a5f49ca59ae42fb6efef2a74770cf3 100755 (executable)
@@ -2554,7 +2554,11 @@ file cannot be correctly imported for an Obstacle definition.</translation>
     </message>\r
     <message>\r
       <source>POLYLINE_FILTER</source>\r
-      <translation>Shape files (*.shp)</translation>\r
+      <translation>Shape files (*.shp);;XY files(*.xy);;XYZ files(*.xyz)</translation>
+    </message>
+    <message>
+      <source>IMPORT_POLYLINE_XY_PART_ONLY</source>
+      <translation>Do you wish to import the XY part only? (Click 'Yes' to import as polylineXY and 'No' to import as Polyline3D)</translation>
     </message>\r
     <message>\r
       <source>BAD_IMPORTED_POLYLINE_FILES_TLT</source>\r
index cb455acd1a629d72370d2cca3c2fdc90728d3332..0960af1a495a4e4eb6b8a122ed6a538fcfb3501e 100644 (file)
@@ -68,6 +68,17 @@ public:
    */
   static QColor DefaultWireColor();
 
+  /**
+   * Sets color for section of polyline.
+   */
+  virtual void SetSectionColor( const int theSectionIndex, const QColor& theColor );
+
+  /**
+   * Returns color of section of polyline.
+   */
+  virtual bool GetSectionColor( const int theSectionIndex, QColor &theColor ) const;
+
+
 public:
 
   /**
index 6732da7866c8161986270bc889759dd5cdd16870..cb701d8b042a5e5b4cd37e2c75e11a64382959fa 100644 (file)
@@ -151,6 +151,9 @@ SET(REFERENCE_DATA
     bathy_prs_fit_selected.png
     zone_random_colors.png
     diff_image.png
+    Polyline_import_XY.png
+    Polyline_import_XYZ.png
+    Polyline_import_XYZ_3D.png
 )
 
 # Application tests
diff --git a/src/HYDRO_tests/reference_data/linux/Polyline_import_XY.png b/src/HYDRO_tests/reference_data/linux/Polyline_import_XY.png
new file mode 100644 (file)
index 0000000..c71b5b6
Binary files /dev/null and b/src/HYDRO_tests/reference_data/linux/Polyline_import_XY.png differ
diff --git a/src/HYDRO_tests/reference_data/linux/Polyline_import_XYZ.png b/src/HYDRO_tests/reference_data/linux/Polyline_import_XYZ.png
new file mode 100644 (file)
index 0000000..c71b5b6
Binary files /dev/null and b/src/HYDRO_tests/reference_data/linux/Polyline_import_XYZ.png differ
diff --git a/src/HYDRO_tests/reference_data/linux/Polyline_import_XYZ_3D.png b/src/HYDRO_tests/reference_data/linux/Polyline_import_XYZ_3D.png
new file mode 100644 (file)
index 0000000..c71b5b6
Binary files /dev/null and b/src/HYDRO_tests/reference_data/linux/Polyline_import_XYZ_3D.png differ
index 98177d9911e6dd0514467e35bd86356c74fcb622..eb2d07c69df5d77dc52f181398a2c66465b6111d 100644 (file)
Binary files a/src/HYDRO_tests/reference_data/linux/Split_Polylines_Colors.png and b/src/HYDRO_tests/reference_data/linux/Split_Polylines_Colors.png differ
diff --git a/src/HYDRO_tests/reference_data/win32/Polyline_import_XY.png b/src/HYDRO_tests/reference_data/win32/Polyline_import_XY.png
new file mode 100644 (file)
index 0000000..009410d
Binary files /dev/null and b/src/HYDRO_tests/reference_data/win32/Polyline_import_XY.png differ
diff --git a/src/HYDRO_tests/reference_data/win32/Polyline_import_XYZ.png b/src/HYDRO_tests/reference_data/win32/Polyline_import_XYZ.png
new file mode 100644 (file)
index 0000000..009410d
Binary files /dev/null and b/src/HYDRO_tests/reference_data/win32/Polyline_import_XYZ.png differ
diff --git a/src/HYDRO_tests/reference_data/win32/Polyline_import_XYZ_3D.png b/src/HYDRO_tests/reference_data/win32/Polyline_import_XYZ_3D.png
new file mode 100644 (file)
index 0000000..009410d
Binary files /dev/null and b/src/HYDRO_tests/reference_data/win32/Polyline_import_XYZ_3D.png differ
index 7bcb35d0d420488e27c60d70343cc11e83333191..fc98137fe370c36171509d2f970f32c0c095138c 100644 (file)
Binary files a/src/HYDRO_tests/reference_data/win32/Split_Polylines_Colors.png and b/src/HYDRO_tests/reference_data/win32/Split_Polylines_Colors.png differ
index abc72f651b6c4a3d99c16ceef37e5768c27e96e4..b804b1abad5b2b81a6518753bd4cb6ace287b316 100644 (file)
@@ -46,6 +46,9 @@
 #include <TopoDS_Vertex.hxx>
 #include <TopoDS_Wire.hxx>
 #include <gp_XY.hxx>
+#include <HYDROData_Tool.h>
+
+extern QString REF_DATA_PATH;
 
 void test_HYDROData_PolylineXY::test_polyline()
 {
@@ -300,9 +303,21 @@ void test_HYDROData_PolylineXY::test_split_refs_627()
     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
   aPolyline->SetName( "test" );
 
-  QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
-  TopoDS_Wire aWire = Wire2d( aCoords, false );
-  aPolyline->SetShape( aWire );
+
+  //QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
+  aPolyline->AddSection( "", HYDROData_PolylineXY::SECTION_POLYLINE, false );
+  aPolyline->AddPoint( 0, gp_XY( 10, 10  ) );
+  aPolyline->AddPoint( 0, gp_XY( 20, 10 ) );
+  aPolyline->AddPoint( 0, gp_XY( 20, 20 ) );
+  aPolyline->AddPoint( 0, gp_XY( 10, 20 ) );
+  aPolyline->Update();
+
+
+  //TopoDS_Wire aWire = Wire2d( aCoords, false );
+  //aPolyline->SetShape( aWire );
+  TopoDS_Shape aW = aPolyline->GetShape();
+  CPPUNIT_ASSERT (aW.ShapeType() == TopAbs_WIRE);
+
   aPolyline->SetWireColor( Qt::red );
 
   gp_Pnt2d aPnt( 20, 20 );
@@ -316,25 +331,34 @@ void test_HYDROData_PolylineXY::test_split_refs_627()
   {
     Handle(HYDROData_PolylineXY) anObj = Handle(HYDROData_PolylineXY)::DownCast( anIt.Current() );
     if( aPolyline->Label() != anObj->Label() )
-      TestViewer::show( anObj->GetShape(), 0, true, anObj->GetWireColor() );
+    {
+      QColor color;
+      anObj->GetSectionColor(0, color);
+      TestViewer::show( anObj->GetShape(), 0, true, color );
+    }
   }
   CPPUNIT_ASSERT_IMAGES
     
   HYDROData_Iterator anIt2( aDoc, KIND_POLYLINEXY );
   CPPUNIT_ASSERT_EQUAL( true, anIt2.More() );
   CPPUNIT_ASSERT_EQUAL( QString( "test" ), anIt2.Current()->GetName() );
-  CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ),
-    Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetWireColor() );
+
+  QColor color1, color2, color3;
+  Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetSectionColor(0, color1);
+
+  CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ), color1);
   anIt2.Next();
   CPPUNIT_ASSERT_EQUAL( true, anIt2.More() );
   CPPUNIT_ASSERT_EQUAL( QString( "test_1" ), anIt2.Current()->GetName() );
-  CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ), 
-    Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetWireColor() );
+
+  Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetSectionColor(0, color2);
+  CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ), color2 );
+
   anIt2.Next();
   CPPUNIT_ASSERT_EQUAL( true, anIt2.More() );
   CPPUNIT_ASSERT_EQUAL( QString( "test_2" ), anIt2.Current()->GetName() );
-  CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ), 
-    Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetWireColor() );
+  Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetSectionColor(0, color3);
+  CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ), color3 );
   anIt2.Next();
   CPPUNIT_ASSERT_EQUAL( false, anIt2.More() );
   anIt2.Next();
@@ -518,3 +542,33 @@ void test_HYDROData_PolylineXY::test_split_straight_refs_634()
 
   aDoc->Close();
 }
+
+void test_HYDROData_PolylineXY::test_import_from_xyz()
+{
+  NCollection_Sequence<Handle(HYDROData_Entity)> ents;
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
+  TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
+  fname += "/profiles1.xyz";
+
+  NCollection_Sequence<Handle(HYDROData_Entity)> importedEntities;
+  bool stat = HYDROData_Tool::importPolylineFromXYZ(QString(fname.ToCString()), aDoc, true, importedEntities);
+  CPPUNIT_ASSERT (stat);
+  Handle(HYDROData_PolylineXY) aPolyXY = Handle(HYDROData_PolylineXY)::DownCast(importedEntities.First());   
+  CPPUNIT_ASSERT_EQUAL (importedEntities.Size(), 1);
+  CPPUNIT_ASSERT (!aPolyXY.IsNull());
+  TestViewer::show( aPolyXY->GetShape(), 0, true, "Polyline_import_XY" );
+  CPPUNIT_ASSERT_IMAGES
+  importedEntities.Clear();
+
+  stat = HYDROData_Tool::importPolylineFromXYZ(QString(fname.ToCString()), aDoc, false, importedEntities);
+  CPPUNIT_ASSERT (stat);
+  CPPUNIT_ASSERT_EQUAL (importedEntities.Size(), 2);
+  Handle(HYDROData_Polyline3D) aPoly3D;
+  aPolyXY = Handle(HYDROData_PolylineXY)::DownCast(importedEntities.First());   
+  aPoly3D = Handle(HYDROData_Polyline3D)::DownCast(importedEntities.Last());
+  CPPUNIT_ASSERT (!aPolyXY.IsNull());
+  CPPUNIT_ASSERT (!aPoly3D.IsNull());
+  TestViewer::show( aPolyXY->GetShape(), 0, false, "Polyline_import_XYZ" );
+  TestViewer::show( aPoly3D->GetShape3D(), 0, false, "Polyline_import_XYZ_3D" );
+  CPPUNIT_ASSERT_IMAGES
+}
\ No newline at end of file
index d51b20f51f101aaf9bcb08cefe67c6ecbc286c8e..b03ac734eec5e16e32ad8f99007a34e91fccd32b 100644 (file)
@@ -30,6 +30,8 @@ class test_HYDROData_PolylineXY : public CppUnit::TestFixture {
   CPPUNIT_TEST( test_custom_polylines );
   CPPUNIT_TEST( test_merge_refs_630 );
   CPPUNIT_TEST( test_split_straight_refs_634 );
+  CPPUNIT_TEST( test_import_from_xyz );
+
   CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -55,6 +57,8 @@ public:
   void test_custom_polylines();
   void test_merge_refs_630();
   void test_split_straight_refs_634();
+  void test_import_from_xyz();
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_PolylineXY);