Salome HOME
Update mechanism is corrected (Bug #182).
[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_PolylineXY.h>
6 #include <HYDROData_OperationsFactory.h>
7
8 #include <ImageComposer_CropOperator.h>
9
10 #include <gp_XY.hxx>
11
12 #include <QPainter>
13
14 void test_HYDROData_OperationsFactory::testCreate()
15 {
16   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
17   
18   HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
19   CPPUNIT_ASSERT(aFactory);
20   Handle(HYDROData_Image) anImage = aFactory->CreateImage(aDoc, NULL);
21   CPPUNIT_ASSERT(!anImage.IsNull());
22   CPPUNIT_ASSERT(anImage->Image().isNull());
23   
24   aDoc->Close();
25 }
26
27 static QImage TestImage() {
28   QImage aPic(50, 40, QImage::Format_RGB32);
29   aPic.fill(Qt::white);
30   QPainter aPainter(&aPic);
31   aPainter.drawEllipse(6, 7, 38, 30);
32   aPainter.drawLine(0, 40, 10, 0);
33   aPainter.drawLine(10, 0, 25, 35);
34   aPainter.drawLine(25, 35, 40, 0);
35   aPainter.drawLine(40, 0, 50, 40);
36   return aPic;
37 }
38
39 void test_HYDROData_OperationsFactory::testCrop()
40 {
41   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
42   HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
43   
44   // prepare the original image and crop-path
45   Handle(HYDROData_Image) anOriImage = 
46     Handle(HYDROData_Image)::DownCast( aDoc->CreateObject( KIND_IMAGE ) );
47
48   QImage aTestImage = TestImage();
49   anOriImage->SetImage( aTestImage );
50
51   Handle(HYDROData_PolylineXY) aCropPolyline = 
52     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
53
54   aCropPolyline->AddSection( "", HYDROData_PolylineXY::SECTION_POLYLINE, true );
55
56   aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 25, 0  ) );
57   aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 0,  20 ) );
58   aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 25, 40 ) );
59   aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 50, 20 ) );
60
61   // prepare Composer Operation
62   ImageComposer_Operator* aCropOp = 
63     aFactory->Operator( ImageComposer_CropOperator::Type() );
64   
65   CPPUNIT_ASSERT( aCropOp );
66
67   aCropOp->setArgs( Qt::red );
68
69   // create crop - image 
70   Handle(HYDROData_Image) aCropImage = aFactory->CreateImage( aDoc, aCropOp );
71   CPPUNIT_ASSERT( !aCropImage.IsNull() );
72
73   aCropImage->AppendReference( anOriImage );
74   aCropImage->AppendReference( aCropPolyline );
75   aCropImage->Update();
76
77   // check crop operation was performed
78   CPPUNIT_ASSERT( !aCropImage->Image().isNull() );
79   CPPUNIT_ASSERT( aCropImage->Image() != aTestImage );
80   
81   aDoc->Close();
82 }