Salome HOME
The code refactoring since the ImageComposer API has been changed (Feature #6).
[modules/hydro.git] / src / HYDROData / test_HYDROOperations_Factory.cxx
1 #include <test_HYDROOperations_Factory.h>
2
3 #include <HYDROData_Document.h>
4 #include <HYDROData_Image.h>
5 #include <HYDROOperations_Factory.h>
6
7 #include <QPainter>
8 #include <ImageComposer_CropOperator.h>
9
10 void test_HYDROOperations_Factory::testCreate()
11 {
12   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
13   
14   HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
15   CPPUNIT_ASSERT(aFactory);
16   Handle(HYDROData_Image) anImage = aFactory->CreateImage(aDoc, NULL);
17   CPPUNIT_ASSERT(!anImage.IsNull());
18   CPPUNIT_ASSERT(anImage->Image().isNull());
19   
20   aDoc->Close();
21 }
22
23 static QImage TestImage() {
24   QImage aPic(50, 40, QImage::Format_RGB32);
25   aPic.fill(Qt::white);
26   QPainter aPainter(&aPic);
27   aPainter.drawEllipse(6, 7, 38, 30);
28   aPainter.drawLine(0, 40, 10, 0);
29   aPainter.drawLine(10, 0, 25, 35);
30   aPainter.drawLine(25, 35, 40, 0);
31   aPainter.drawLine(40, 0, 50, 40);
32   return aPic;
33 }
34
35 void test_HYDROOperations_Factory::testCrop()
36 {
37   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
38   HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
39   Handle(HYDROData_Image) anImage = aFactory->CreateImage(aDoc, NULL);
40   // prepare the original image and crop-path
41   QImage aPic = TestImage();
42   anImage->SetImage(aPic);
43   QPainterPath aPath(QPointF(25, 0));
44   aPath.lineTo(0, 20);
45   aPath.lineTo(25, 40);
46   aPath.lineTo(50, 20);
47   aPath.closeSubpath();
48   // prepare Composer Operation
49   ImageComposer_CropOperator aCropOp;
50   aCropOp.setArgs(Qt::red, aPath);
51   // create crop - image 
52   Handle(HYDROData_Image) aCrop = aFactory->CreateImage(aDoc, &aCropOp);
53   CPPUNIT_ASSERT(!aCrop.IsNull());
54   aCrop->AppendReference(anImage);
55   aFactory->UpdateImage(aDoc, aCrop);
56   // check crop operation was performed
57   CPPUNIT_ASSERT(!aCrop->Image().isNull());
58   CPPUNIT_ASSERT(aCrop->Image() != aPic);
59   
60   aDoc->Close();
61 }