Salome HOME
patch for correct compilation on Linux
[modules/hydro.git] / src / HYDROData / HYDROData_Polyline.cxx
index e133ee3e4724c8182ff728408aee34ea3d2a90af..3f561c5d302f3a090a7e2aebb6c8c4a17b36453d 100755 (executable)
@@ -1,7 +1,7 @@
 #include <HYDROData_Polyline.h>
 #include <HYDROData_Iterator.h>
 
-#include <HYDROOperations_BSpline.h>
+#include <HYDROData_BSplineOperation.h>
 
 #include <ImageComposer_MetaTypes.h>
 
 #include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Wire.hxx>
+#include <BRep_Builder.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 
 #include <QStringList>
 
-// tage of the child of my label that contains information about the operator
-static const Standard_GUID GUID_MUST_BE_UPDATED("6647e1f7-1971-4c5a-86c7-11ff0291452d");
-
 #define PYTHON_POLYLINE_ID "KIND_POLYLINE"
 
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline, HYDROData_Object)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline, HYDROData_Object)
 
 HYDROData_Polyline::HYDROData_Polyline()
+: HYDROData_Object()
 {
 }
 
@@ -42,6 +42,18 @@ HYDROData_Polyline::~HYDROData_Polyline()
 {
 }
 
+TopoDS_Shape HYDROData_Polyline::GetTopShape() const
+{
+  // TODO
+  return getTopShape();
+}
+
+TopoDS_Shape HYDROData_Polyline::GetShape3D() const
+{
+  // TODO
+  return getTopShape();
+}
+
 /**
  * Dump object to Python script representation.
  */
@@ -49,7 +61,7 @@ QStringList HYDROData_Polyline::DumpToPython( MapOfTreatedObjects& theTreatedObj
 {
   QStringList aResList;
 
-  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
   if ( aDocument.IsNull() )
     return aResList;
                              
@@ -64,13 +76,13 @@ QStringList HYDROData_Polyline::DumpToPython( MapOfTreatedObjects& theTreatedObj
 
   aResList << QString( "" );
 
-  int aDim = getDimension();
-  aResList << QString( "%1.setDimension( %2 );" )
+  int aDim = GetDimension();
+  aResList << QString( "%1.SetDimension( %2 );" )
               .arg( aPolylineName ).arg( aDim );
 
   // Set polilyne data
 
-  PolylineData aPolylineData = getPolylineData();
+  PolylineData aPolylineData = GetPolylineData();
   if ( !aPolylineData.isEmpty() )
   {
     QString aPolylineDataName = "polyline_data";
@@ -108,8 +120,9 @@ QStringList HYDROData_Polyline::DumpToPython( MapOfTreatedObjects& theTreatedObj
       aResList << QString( "%1.append( %2 );" )
                   .arg( aPolylineDataName ).arg( aPolylineSectName );
     }
+    aResList << QString( "" );
 
-    aResList << QString( "%1.setPolylineData( %2 );" )
+    aResList << QString( "%1.SetPolylineData( %2 );" )
                   .arg( aPolylineName ).arg( aPolylineDataName );
   }
 
@@ -118,7 +131,7 @@ QStringList HYDROData_Polyline::DumpToPython( MapOfTreatedObjects& theTreatedObj
 
 QVariant HYDROData_Polyline::GetDataVariant()
 {
-  QPainterPath aPath = painterPath();
+  QPainterPath aPath = GetPainterPath();
 
   QVariant aVarData;
   aVarData.setValue<QPainterPath>( aPath );
@@ -126,44 +139,18 @@ QVariant HYDROData_Polyline::GetDataVariant()
   return aVarData;
 }
 
-/**
- * Return polyline dimension
- * \return polyline dimension. 2 or 3 is valid. 0 is invalid.
- */
-int HYDROData_Polyline::getDimension() const
-{
-    Handle(TDataStd_Integer) aDim;
-    if(!myLab.FindAttribute(TDataStd_Integer::GetID(), aDim))
-      return 0;
-    return aDim->Get();
-}
-
-/**
- * Set polyline dimension. Should be 2 or 3.
- * \param theDimension the polyline dimension
- */
-void HYDROData_Polyline::setDimension( int theDimension )
-{
-    removeAll();
-    int aDim=0;
-    if( theDimension == 2 || theDimension == 3){
-        aDim = theDimension;
-    }
-    TDataStd_Integer::Set(myLab, aDim);
-}
-
 /**
  * Replace current polyline data by new sections list
  * \param theSections the sections list
  */
-void HYDROData_Polyline::setPolylineData( const PolylineData& theSections )
+void HYDROData_Polyline::SetPolylineData( const PolylineData& theSections )
 {
 //Keep dimension
-  int aDim = getDimension();
+  int aDim = GetDimension();
   if( aDim == 0 )
       return;
-  removeAll();
-  setDimension(aDim);
+  RemoveAll();
+  SetDimension(aDim);
 
   if( theSections.size() == 0 )
     return;
@@ -218,7 +205,7 @@ void HYDROData_Polyline::setPolylineData( const PolylineData& theSections )
  * Return polyline data
  * \return polyline section list
  */
-HYDROData_Polyline::PolylineData HYDROData_Polyline::getPolylineData() const
+HYDROData_Polyline::PolylineData HYDROData_Polyline::GetPolylineData() const
 {
   int aSectCnt;
   PolylineData aRes;
@@ -278,10 +265,10 @@ HYDROData_Polyline::PolylineData HYDROData_Polyline::getPolylineData() const
 /**
  * Returns true if polyline is closed
  */
-bool HYDROData_Polyline::isClosed() const
+bool HYDROData_Polyline::IsClosed() const
 {
-  int aDim = getDimension();
-  PolylineData aPolylineData = getPolylineData();
+  int aDim = GetDimension();
+  PolylineData aPolylineData = GetPolylineData();
 
   if ( aDim == 0 || aPolylineData.isEmpty() )
     return false;
@@ -297,10 +284,36 @@ bool HYDROData_Polyline::isClosed() const
   return true;
 }
 
+/**
+ * Return polyline dimension
+ * \return polyline dimension. 2 or 3 is valid. 0 is invalid.
+ */
+int HYDROData_Polyline::GetDimension() const
+{
+    Handle(TDataStd_Integer) aDim;
+    if(!myLab.FindAttribute(TDataStd_Integer::GetID(), aDim))
+      return 0;
+    return aDim->Get();
+}
+
+/**
+ * Set polyline dimension. Should be 2 or 3.
+ * \param theDimension the polyline dimension
+ */
+void HYDROData_Polyline::SetDimension( int theDimension )
+{
+    RemoveAll();
+    int aDim=0;
+    if( theDimension == 2 || theDimension == 3){
+        aDim = theDimension;
+    }
+    TDataStd_Integer::Set(myLab, aDim);
+}
+
 /**
  * Remove all polyline attributes except dimension.
  */
-void HYDROData_Polyline::removeAll()
+void HYDROData_Polyline::RemoveAll()
 {
 //Remove only section data
   TDF_Label aLab = myLab.FindChild( DataTag_SectionsSize );
@@ -321,14 +334,14 @@ void HYDROData_Polyline::removeAll()
  * Note: currently only the first section of the polyline data is taken into account.
  * \return polyline painter path.
  */
-QPainterPath HYDROData_Polyline::painterPath() const
+QPainterPath HYDROData_Polyline::GetPainterPath() const
 {
   QPainterPath aPath;
-  int aDim = getDimension();
+  int aDim = GetDimension();
   if( aDim != 2 && aDim != 3 )
     return aPath;
 
-  PolylineData aSects = getPolylineData();
+  PolylineData aSects = GetPolylineData();
   if( aSects.isEmpty() )
     return aPath;
 
@@ -356,7 +369,7 @@ QPainterPath HYDROData_Polyline::painterPath() const
       int anIndex = i * aDim;
       aPoints << aSection.myCoords[ anIndex ] << aSection.myCoords[ anIndex + 1 ];
     }
-    HYDROOperations_BSpline aBSpline( aPoints, 0, anIsSectionClosed );
+    HYDROData_BSplineOperation aBSpline( aPoints, 0, anIsSectionClosed );
     aPath = aBSpline.ComputePath();
   }
   return aPath;
@@ -375,28 +388,16 @@ double HYDROData_Polyline::ZValue() const
   return 0;
 }
 
-void HYDROData_Polyline::SetWire( const TopoDS_Wire& theWire )
-{
-  TNaming_Builder aBuilder( myLab );
-  aBuilder.Generated( theWire );
-}
-
-TopoDS_Wire HYDROData_Polyline::Wire() const
-{
-  Handle(TNaming_NamedShape) aNamedShape;
-  if( myLab.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
-    return TopoDS::Wire( aNamedShape->Get() );
-  return TopoDS_Wire();
-}
-
 void HYDROData_Polyline::UpdateWire( const PolylineData& theSections )
 {
   BRepBuilderAPI_MakeWire aMakeWire;
 
-  int aDim = getDimension();
+  int aDim = GetDimension();
 
   double aZValue = ZValue();
 
+  TopTools_ListOfShape aSectionWiresList;
+
   int aSectionCount = theSections.size();
   for( int aSectionId = 0; aSectionId < aSectionCount; aSectionId++ )
   {
@@ -439,15 +440,30 @@ void HYDROData_Polyline::UpdateWire( const PolylineData& theSections )
           aPoints << x << y;
         }
 
-        HYDROOperations_BSpline aBSpline( aPoints, aZValue, anIsSectionClosed );
+        HYDROData_BSplineOperation aBSpline( aPoints, aZValue, anIsSectionClosed );
         TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
         aMakeSectionWire.Add( anEdge );
       }
       TopoDS_Wire aSectionWire = aMakeSectionWire.Wire();
+      aSectionWiresList.Append( aSectionWire );
       aMakeWire.Add( aSectionWire );
     }
   }
 
-  TopoDS_Wire aWire = aMakeWire.Wire();
-  SetWire( aWire );
+  TopoDS_Shape aShape;
+  if ( aMakeWire.IsDone() ) {
+    aShape = aMakeWire.Shape();
+  } else {
+    // build compound
+    TopoDS_Compound aCompound;
+    BRep_Builder aBuilder;
+    aBuilder.MakeCompound( aCompound );
+    TopTools_ListIteratorOfListOfShape anIter( aSectionWiresList );
+    for ( ; anIter.More(); anIter.Next() ) {
+      aBuilder.Add( aCompound, anIter.Value() );
+    }
+    aShape = aCompound;
+  }
+
+  SetTopShape( aShape );
 }