Salome HOME
Linux compilation.
[modules/hydro.git] / src / HYDROData / test_HYDROData_OperationsFactory.cxx
1 #include <test_HYDROData_OperationsFactory.h>
2
3 #include <HYDROData_Document.h>
4 #include <HYDROData_Image.h>
5 #include <HYDROData_Polyline.h>
6 #include <HYDROData_OperationsFactory.h>
7
8 #include <ImageComposer_CropOperator.h>
9
10 #include <QPainter>
11
12 void test_HYDROData_OperationsFactory::testCreate()
13 {
14   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
15   
16   HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
17   CPPUNIT_ASSERT(aFactory);
18   Handle(HYDROData_Image) anImage = aFactory->CreateImage(aDoc, NULL);
19   CPPUNIT_ASSERT(!anImage.IsNull());
20   CPPUNIT_ASSERT(anImage->Image().isNull());
21   
22   aDoc->Close();
23 }
24
25 static QImage TestImage() {
26   QImage aPic(50, 40, QImage::Format_RGB32);
27   aPic.fill(Qt::white);
28   QPainter aPainter(&aPic);
29   aPainter.drawEllipse(6, 7, 38, 30);
30   aPainter.drawLine(0, 40, 10, 0);
31   aPainter.drawLine(10, 0, 25, 35);
32   aPainter.drawLine(25, 35, 40, 0);
33   aPainter.drawLine(40, 0, 50, 40);
34   return aPic;
35 }
36
37 void test_HYDROData_OperationsFactory::testCrop()
38 {
39   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
40   HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
41   
42   // prepare the original image and crop-path
43   Handle(HYDROData_Image) anOriImage = 
44     Handle(HYDROData_Image)::DownCast( aDoc->CreateObject( KIND_IMAGE ) );
45
46   QImage aTestImage = TestImage();
47   anOriImage->SetImage( aTestImage );
48
49   Handle(HYDROData_Polyline) aCropPolyline = 
50     Handle(HYDROData_Polyline)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) );
51
52   HYDROData_Polyline::PolylineData aPolylineData;
53
54   PolylineSection aPolylineSect;
55
56   aPolylineSect.myCoords << 25 <<  0 << 0;
57   aPolylineSect.myCoords <<  0 << 20 << 0;
58   aPolylineSect.myCoords << 25 << 40 << 0;
59   aPolylineSect.myCoords << 50 << 20 << 0;
60
61   aPolylineData << aPolylineSect;
62
63   aCropPolyline->SetPolylineData( aPolylineData );
64
65   // prepare Composer Operation
66   ImageComposer_Operator* aCropOp = 
67     aFactory->Operator( ImageComposer_CropOperator::Type() );
68   
69   CPPUNIT_ASSERT( aCropOp );
70
71   aCropOp->setArgs( Qt::red );
72
73   // create crop - image 
74   Handle(HYDROData_Image) aCropImage = aFactory->CreateImage( aDoc, aCropOp );
75   CPPUNIT_ASSERT( !aCropImage.IsNull() );
76
77   aCropImage->AppendReference( anOriImage );
78   aCropImage->AppendReference( aCropPolyline );
79   aCropImage->Update();
80
81   // check crop operation was performed
82   CPPUNIT_ASSERT( !aCropImage->Image().isNull() );
83   CPPUNIT_ASSERT( aCropImage->Image() != aTestImage );
84   
85   aDoc->Close();
86 }