From: mtn Date: Thu, 8 Aug 2013 04:53:17 +0000 (+0000) Subject: HYDROData_Polyline object was added X-Git-Tag: BR_hydro_v_0_1~128 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b58558f56e97ff01757710155cd9a8429b34ae46;p=modules%2Fhydro.git HYDROData_Polyline object was added --- diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index 8fb55d65..bf28f0d0 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -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) diff --git a/src/HYDROData/HYDROData_Iterator.cxx b/src/HYDROData/HYDROData_Iterator.cxx index 534cbd13..da22e5eb 100644 --- a/src/HYDROData/HYDROData_Iterator.cxx +++ b/src/HYDROData/HYDROData_Iterator.cxx @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -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); diff --git a/src/HYDROData/HYDROData_Object.h b/src/HYDROData/HYDROData_Object.h index e1e930e9..f448d70a 100644 --- a/src/HYDROData/HYDROData_Object.h +++ b/src/HYDROData/HYDROData_Object.h @@ -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 index 00000000..a0ec4f2d --- /dev/null +++ b/src/HYDROData/HYDROData_Polyline.cxx @@ -0,0 +1,101 @@ +#include +#include + +#include +#include +#include +#include + +// 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 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 aPointsArray = points(); + aPointsArray.append( thePoint ); + setPoints( aPointsArray ); +} + +bool HYDROData_Polyline::insertPoint( int theIndex, const QPointF& thePoint) +{ + QList aPointsArray = points(); + aPointsArray.insert( theIndex, thePoint ); + setPoints( aPointsArray ); +} + +bool HYDROData_Polyline::removePoint( int theIndex ) +{ + QList 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 HYDROData_Polyline::points() +{ + QList 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 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 index 00000000..61a22bbc --- /dev/null +++ b/src/HYDROData/HYDROData_Polyline.h @@ -0,0 +1,94 @@ +#ifndef HYDROData_Polyline_HeaderFile +#define HYDROData_Polyline_HeaderFile + +#include + +#include +#include +#include + +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 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 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 index 00000000..66f214f4 --- /dev/null +++ b/src/HYDROData/test_HYDROData_Polyline.cxx @@ -0,0 +1,81 @@ +#include + +#include +#include + +#include +#include + +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 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 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 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 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 index 00000000..30c8e893 --- /dev/null +++ b/src/HYDROData/test_HYDROData_Polyline.h @@ -0,0 +1,25 @@ +#include + +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");