]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
HYDROData_Polyline object was added
authormtn <mtn@opencascade.com>
Thu, 8 Aug 2013 04:53:17 +0000 (04:53 +0000)
committermtn <mtn@opencascade.com>
Thu, 8 Aug 2013 04:53:17 +0000 (04:53 +0000)
src/HYDROData/CMakeLists.txt
src/HYDROData/HYDROData_Iterator.cxx
src/HYDROData/HYDROData_Object.h
src/HYDROData/HYDROData_Polyline.cxx [new file with mode: 0755]
src/HYDROData/HYDROData_Polyline.h [new file with mode: 0755]
src/HYDROData/test_HYDROData_Polyline.cxx [new file with mode: 0755]
src/HYDROData/test_HYDROData_Polyline.h [new file with mode: 0755]

index 8fb55d65ecedd8cdf08eeefd13bc6719ad00c45d..bf28f0d0feb3fbf3f452715436fe4ce496145bab 100644 (file)
@@ -7,6 +7,7 @@ set(PROJECT_HEADERS
     HYDROData_Iterator.h
     HYDROData_Object.h
     HYDROData_Image.h
+    HYDROData_Polyline.h
 )
 
 set(PROJECT_SOURCES 
@@ -15,6 +16,7 @@ set(PROJECT_SOURCES
     HYDROData_Iterator.cxx
     HYDROData_Object.cxx
     HYDROData_Image.cxx
+    HYDROData_Polyline.cxx
 )
 
 add_definitions(
@@ -42,6 +44,7 @@ if(CPPUNIT_IS_OK)
     test_HYDROData_Object.h
     test_HYDROData_Iterator.h
     test_HYDROData_Image.h
+    test_HYDROData_Polyline.h
   )
 
   set(TEST_SOURCES 
@@ -50,6 +53,7 @@ if(CPPUNIT_IS_OK)
     test_HYDROData_Object.cxx
     test_HYDROData_Iterator.cxx
     test_HYDROData_Image.cxx
+    test_HYDROData_Polyline.cxx
   )
   
   set(TEST_EXE test_HYDROData)
index 534cbd13c62e6bdb60621dd497bee362a2cc7558..da22e5ebf0d41eb246e0869e667e8432d2caca77 100644 (file)
@@ -1,6 +1,7 @@
 #include <HYDROData_Iterator.h>
 
 #include <HYDROData_Image.h>
+#include <HYDROData_Polyline.h>
 
 #include <TDataStd_Name.hxx>
 #include <NCollection_DataMap.hxx>
@@ -54,6 +55,9 @@ Handle_HYDROData_Object HYDROData_Iterator::Object(const TDF_Label theLabel)
   case KIND_IMAGE:
     aResult = new HYDROData_Image();
     break;
+  case KIND_POLYLINE:
+    aResult = new HYDROData_Polyline();
+    break;
   }
   if (!aResult.IsNull())
     aResult->SetLabel(theLabel);
index e1e930e9d403a87560a95c5dc4dee9b9933af38c..f448d70a72f3a24c3320808061df257f84517c14 100644 (file)
@@ -12,6 +12,7 @@ typedef int ObjectKind;
 ///! Unrecognized object
 const ObjectKind KIND_UNKNOWN = 0;
 const ObjectKind KIND_IMAGE = 1;
+const ObjectKind KIND_POLYLINE = 2;
 
 DEFINE_STANDARD_HANDLE(HYDROData_Object, MMgt_TShared)
 
diff --git a/src/HYDROData/HYDROData_Polyline.cxx b/src/HYDROData/HYDROData_Polyline.cxx
new file mode 100755 (executable)
index 0000000..a0ec4f2
--- /dev/null
@@ -0,0 +1,101 @@
+#include <HYDROData_Polyline.h>
+#include <HYDROData_Iterator.h>
+
+#include <TDataStd_RealArray.hxx>
+#include <TDataStd_Name.hxx>
+#include <TDataStd_UAttribute.hxx>
+#include <TDF_ListIteratorOfLabelList.hxx>
+
+// tage of the child of my label that contains information about the operator
+static const Standard_GUID GUID_MUST_BE_UPDATED("80f2bb81-3873-4631-8ddd-940d2119f000");
+
+IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline, HYDROData_Object)
+IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline, HYDROData_Object)
+
+HYDROData_Polyline::HYDROData_Polyline()
+{
+}
+
+HYDROData_Polyline::~HYDROData_Polyline()
+{
+}
+
+void HYDROData_Polyline::setPoints( QList<QPointF> thePointsList )
+{
+  removeAllPoints();
+  if( thePointsList.isEmpty() )
+    return;
+  Handle(TDataStd_RealArray) anArray;
+  anArray = TDataStd_RealArray::Set( myLab, 0, thePointsList.size()*2-1 );
+  for( int i = 0 ; i < thePointsList.size() ; i++ ){
+    anArray->SetValue(i*2, thePointsList[i].x() );
+    anArray->SetValue(i*2+1, thePointsList[i].y() );
+  }
+}
+
+void HYDROData_Polyline::addPoint( const QPointF& thePoint )
+{
+  QList<QPointF> aPointsArray = points();
+  aPointsArray.append( thePoint );
+  setPoints( aPointsArray );
+}
+   
+bool HYDROData_Polyline::insertPoint( int theIndex, const QPointF& thePoint)
+{
+  QList<QPointF> aPointsArray = points();
+  aPointsArray.insert( theIndex, thePoint );
+  setPoints( aPointsArray );
+}
+
+bool HYDROData_Polyline::removePoint( int theIndex )
+{
+  QList<QPointF> aPointsArray = points();
+  aPointsArray.removeAt( theIndex );
+  setPoints( aPointsArray );
+}
+
+void HYDROData_Polyline::removeAllPoints()
+{
+  myLab.ForgetAttribute(TDataStd_RealArray::GetID());
+  return;
+}
+
+int HYDROData_Polyline::pointsCount()
+{
+  Handle(TDataStd_RealArray) anArray;
+  if(!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
+    return 0;
+  return anArray->Length()/2;
+}
+
+QList<QPointF> HYDROData_Polyline::points()
+{
+  QList<QPointF> aRes;
+  Handle(TDataStd_RealArray) anArray;
+  if(!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
+    return aRes;
+  int anArraySize = anArray->Length();
+  for( int i = 0 ; i < anArraySize/2 ; i++ ){
+    qreal anX = anArray->Value( i*2 );
+    qreal anY = anArray->Value( i*2 + 1 );
+    QPointF aPoint( anX, anY );
+    aRes.append( aPoint );
+  }
+  return aRes;
+}
+
+QPainterPath HYDROData_Polyline::painterPathLinear()
+{
+  QPainterPath aPath;
+  QList<QPointF> aPointsArray = points();
+  if( aPointsArray.size() == 0 )
+    return aPath;
+  aPath.moveTo( aPointsArray[0] );
+  for( int i = 0 ; i < aPointsArray.size() ; i++ ){
+    aPath.lineTo( aPointsArray[i] );
+  }
+  aPath.lineTo( aPointsArray[0] );
+//I dont know is it need or not ???
+  aPath.closeSubpath();
+  return aPath;
+}
diff --git a/src/HYDROData/HYDROData_Polyline.h b/src/HYDROData/HYDROData_Polyline.h
new file mode 100755 (executable)
index 0000000..61a22bb
--- /dev/null
@@ -0,0 +1,94 @@
+#ifndef HYDROData_Polyline_HeaderFile
+#define HYDROData_Polyline_HeaderFile
+
+#include <HYDROData_Object.h>
+
+#include <QPointF>
+#include <QPainterPath>
+#include <QList>
+
+DEFINE_STANDARD_HANDLE(HYDROData_Polyline, HYDROData_Object)
+
+/**\class HYDROData_Polyline
+ * \brief Class that stores/retreives information about the painter path.
+ *
+ * Keeps path as binary array of element type and coordinates
+ * of image with correspondent API for forkind wit hthese properties.
+ */
+class HYDROData_Polyline : public HYDROData_Object
+{
+public:
+  DEFINE_STANDARD_RTTI(HYDROData_Polyline);
+
+  /**
+   * Returns the kind of this object. Must be redefined in all objects of known type.
+   */
+  HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_POLYLINE;}
+
+  /**
+   * Replace current array by points list
+   * \param thePoint the point to add
+   */
+  HYDRODATA_EXPORT void setPoints( QList<QPointF> thePointsList );
+
+  /**
+   * Add point to the end of point list
+   * \param thePoint the point to add
+   */
+  HYDRODATA_EXPORT void addPoint( const QPointF& thePoint );
+   
+  /**
+   * Add point to the point list at the specified position
+   * \param theIndex the index of the list the point will insert after
+   */
+  HYDRODATA_EXPORT bool insertPoint( int theIndex, const QPointF& thePoint);
+
+  /**
+   * Remove point from polyline
+   * \param theIndex the point index
+   */
+  HYDRODATA_EXPORT bool removePoint( int theIndex );
+
+  /**
+   * Remove all points from polyline
+   * \param theIndex the point index
+   */
+  HYDRODATA_EXPORT void removeAllPoints();
+
+  /**
+   * Return list point count
+   * \return list point count
+   */
+  HYDRODATA_EXPORT int pointsCount();
+
+  /**
+   * Returns list of points
+   * \return list of points
+   */
+  HYDRODATA_EXPORT QList<QPointF> points();
+
+
+  /**
+   * Returns the painter path. The painter path is construct by lines
+   */
+  HYDRODATA_EXPORT QPainterPath painterPathLinear();
+
+
+protected:
+
+  friend class HYDROData_Iterator;
+
+  /**
+   * Creates new object in the internal data structure. Use higher level objects 
+   * to create objects with real content.
+   */
+  HYDROData_Polyline();
+
+  /**
+   * Destructs properties of the object and object itself, removes it from the document.
+   */
+  ~HYDROData_Polyline();
+
+};
+
+#endif
diff --git a/src/HYDROData/test_HYDROData_Polyline.cxx b/src/HYDROData/test_HYDROData_Polyline.cxx
new file mode 100755 (executable)
index 0000000..66f214f
--- /dev/null
@@ -0,0 +1,81 @@
+#include<test_HYDROData_Polyline.h>
+
+#include <HYDROData_Document.h>
+#include <HYDROData_Polyline.h>
+
+#include <QList>
+#include <QPointF>
+
+void test_HYDROData_Polyline::testPolyline()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+  Handle(HYDROData_Polyline) aPolyline = 
+    Handle(HYDROData_Polyline)::DownCast(aDoc->CreateObject(KIND_POLYLINE));
+  // empty image
+  QList<QPointF> aPoints = aPolyline->points();
+  CPPUNIT_ASSERT(aPoints.size() == 0 );
+
+  for( int i = 0 ; i < 10 ; i++ ){
+    double anX = ((double)i)*0.1;
+    double anY = ((double)(i-5))*10.;
+    QPointF aPoint(anX,anY);
+    aPoints.append(aPoint);
+  }
+
+  aPolyline->setPoints( aPoints );
+  
+  QList<QPointF> aRes = aPolyline->points();
+
+  CPPUNIT_ASSERT( aRes.size() == 10 );
+  
+  for( int i = 0 ; i < 10 ; i++ ){
+    double anX = aRes[i].x();
+    double anY = aRes[i].y();
+    double aRefX = ((double)i)*0.1;
+    double aRefY = ((double)(i-5))*10.;
+    CPPUNIT_ASSERT( anX == aRefX );
+    CPPUNIT_ASSERT( anY == aRefY );
+     
+  }
+  aDoc->Close();
+}
+
+
+void test_HYDROData_Polyline::testCopy()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+  Handle(HYDROData_Polyline) aPolyline1 = 
+    Handle(HYDROData_Polyline)::DownCast(aDoc->CreateObject(KIND_POLYLINE));
+
+  QList<QPointF> aPoints;
+  for( int i = 0 ; i < 10 ; i++ ){
+    double anX = ((double)i)*0.1;
+    double anY = ((double)(i-5))*10.;
+    QPointF aPoint(anX,anY);
+    aPoints.append(aPoint);
+  }
+
+  aPolyline1->setPoints(aPoints);
+
+  Handle(HYDROData_Polyline) aPolyline2 = 
+    Handle(HYDROData_Polyline)::DownCast(aDoc->CreateObject(KIND_POLYLINE));
+
+  aPolyline1->CopyTo(aPolyline2);
+
+  QList<QPointF> aRes = aPolyline2->points();
+
+  CPPUNIT_ASSERT( aRes.size() == 10 );
+  
+  for( int i = 0 ; i < 10 ; i++ ){
+    double anX = aRes[i].x();
+    double anY = aRes[i].y();
+    double aRefX = ((double)i)*0.1;
+    double aRefY = ((double)(i-5))*10.;
+    CPPUNIT_ASSERT( anX == aRefX );
+    CPPUNIT_ASSERT( anY == aRefY );
+     
+  }
+
+  aDoc->Close();
+}
diff --git a/src/HYDROData/test_HYDROData_Polyline.h b/src/HYDROData/test_HYDROData_Polyline.h
new file mode 100755 (executable)
index 0000000..30c8e89
--- /dev/null
@@ -0,0 +1,25 @@
+#include <cppunit/extensions/HelperMacros.h>
+
+class test_HYDROData_Polyline : public CppUnit::TestFixture {
+  CPPUNIT_TEST_SUITE(test_HYDROData_Polyline);
+  CPPUNIT_TEST(testPolyline);
+  CPPUNIT_TEST(testCopy);
+  CPPUNIT_TEST_SUITE_END();
+
+private:
+
+public:
+
+  void setUp() {}
+
+  void tearDown() {}
+
+  // checks save/restore QImages information
+  void testPolyline();
+
+  // checks the image properties copy/paste
+  void testCopy();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Polyline);
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_Polyline, "HYDROData_Polyline");