1 #include <test_HYDROData_OperationsFactory.h>
3 #include <HYDROData_Document.h>
4 #include <HYDROData_Image.h>
5 #include <HYDROData_PolylineXY.h>
6 #include <HYDROData_OperationsFactory.h>
8 #include <ImageComposer_CropOperator.h>
14 void test_HYDROData_OperationsFactory::testCreate()
16 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
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());
27 static QImage TestImage() {
28 QImage aPic(50, 40, QImage::Format_RGB32);
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);
39 void test_HYDROData_OperationsFactory::testCrop()
41 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
42 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
44 // prepare the original image and crop-path
45 Handle(HYDROData_Image) anOriImage =
46 Handle(HYDROData_Image)::DownCast( aDoc->CreateObject( KIND_IMAGE ) );
48 QImage aTestImage = TestImage();
49 anOriImage->SetImage( aTestImage );
51 Handle(HYDROData_PolylineXY) aCropPolyline =
52 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
54 aCropPolyline->AddSection( "", HYDROData_PolylineXY::SECTION_POLYLINE, true );
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 ) );
61 // prepare Composer Operation
62 ImageComposer_Operator* aCropOp =
63 aFactory->Operator( ImageComposer_CropOperator::Type() );
65 CPPUNIT_ASSERT( aCropOp );
67 aCropOp->setArgs( Qt::red );
69 // create crop - image
70 Handle(HYDROData_Image) aCropImage = aFactory->CreateImage( aDoc, aCropOp );
71 CPPUNIT_ASSERT( !aCropImage.IsNull() );
73 aCropImage->AppendReference( anOriImage );
74 aCropImage->AppendReference( aCropPolyline );
77 // check crop operation was performed
78 CPPUNIT_ASSERT( !aCropImage->Image().isNull() );
79 CPPUNIT_ASSERT( aCropImage->Image() != aTestImage );