1 #include <test_HYDROData_OperationsFactory.h>
3 #include <HYDROData_Document.h>
4 #include <HYDROData_Image.h>
5 #include <HYDROData_Polyline.h>
6 #include <HYDROData_OperationsFactory.h>
8 #include <ImageComposer_CropOperator.h>
12 void test_HYDROData_OperationsFactory::testCreate()
14 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
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());
25 static QImage TestImage() {
26 QImage aPic(50, 40, QImage::Format_RGB32);
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);
37 void test_HYDROData_OperationsFactory::testCrop()
39 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
40 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
42 // prepare the original image and crop-path
43 Handle(HYDROData_Image) anOriImage =
44 Handle(HYDROData_Image)::DownCast( aDoc->CreateObject( KIND_IMAGE ) );
46 QImage aTestImage = TestImage();
47 anOriImage->SetImage( aTestImage );
49 Handle(HYDROData_Polyline) aCropPolyline =
50 Handle(HYDROData_Polyline)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) );
52 HYDROData_Polyline::PolylineData aPolylineData;
54 PolylineSection aPolylineSect;
56 aPolylineSect.myCoords << 25 << 0 << 0;
57 aPolylineSect.myCoords << 0 << 20 << 0;
58 aPolylineSect.myCoords << 25 << 40 << 0;
59 aPolylineSect.myCoords << 50 << 20 << 0;
61 aPolylineData << aPolylineSect;
63 aCropPolyline->SetPolylineData( aPolylineData );
65 // prepare Composer Operation
66 ImageComposer_Operator* aCropOp =
67 aFactory->Operator( ImageComposer_CropOperator::Type() );
69 CPPUNIT_ASSERT( aCropOp );
71 aCropOp->setArgs( Qt::red );
73 // create crop - image
74 Handle(HYDROData_Image) aCropImage = aFactory->CreateImage( aDoc, aCropOp );
75 CPPUNIT_ASSERT( !aCropImage.IsNull() );
77 aCropImage->AppendReference( anOriImage );
78 aCropImage->AppendReference( aCropPolyline );
81 // check crop operation was performed
82 CPPUNIT_ASSERT( !aCropImage->Image().isNull() );
83 CPPUNIT_ASSERT( aCropImage->Image() != aTestImage );