HYDROData_Iterator.h
HYDROData_Object.h
HYDROData_Image.h
+ HYDROData_Polyline.h
)
set(PROJECT_SOURCES
HYDROData_Iterator.cxx
HYDROData_Object.cxx
HYDROData_Image.cxx
+ HYDROData_Polyline.cxx
)
add_definitions(
test_HYDROData_Object.h
test_HYDROData_Iterator.h
test_HYDROData_Image.h
+ test_HYDROData_Polyline.h
)
set(TEST_SOURCES
test_HYDROData_Object.cxx
test_HYDROData_Iterator.cxx
test_HYDROData_Image.cxx
+ test_HYDROData_Polyline.cxx
)
set(TEST_EXE test_HYDROData)
#include <HYDROData_Iterator.h>
#include <HYDROData_Image.h>
+#include <HYDROData_Polyline.h>
#include <TDataStd_Name.hxx>
#include <NCollection_DataMap.hxx>
case KIND_IMAGE:
aResult = new HYDROData_Image();
break;
+ case KIND_POLYLINE:
+ aResult = new HYDROData_Polyline();
+ break;
}
if (!aResult.IsNull())
aResult->SetLabel(theLabel);
///! Unrecognized object
const ObjectKind KIND_UNKNOWN = 0;
const ObjectKind KIND_IMAGE = 1;
+const ObjectKind KIND_POLYLINE = 2;
DEFINE_STANDARD_HANDLE(HYDROData_Object, MMgt_TShared)
--- /dev/null
+#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;
+}
--- /dev/null
+#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
--- /dev/null
+#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();
+}
--- /dev/null
+#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");