#include <HYDROData_Document.h>
#include <HYDROData_Image.h>
+#include <HYDROData_Polyline.h>
#include <HYDROOperations_Factory.h>
-#include <QPainter>
#include <ImageComposer_CropOperator.h>
+#include <QPainter>
+
void test_HYDROOperations_Factory::testCreate()
{
Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
void test_HYDROOperations_Factory::testCrop()
{
- Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
- Handle(HYDROData_Image) anImage = aFactory->CreateImage(aDoc, NULL);
+
// prepare the original image and crop-path
- QImage aPic = TestImage();
- anImage->SetImage(aPic);
- QPainterPath aPath(QPointF(25, 0));
- aPath.lineTo(0, 20);
- aPath.lineTo(25, 40);
- aPath.lineTo(50, 20);
- aPath.closeSubpath();
+ Handle(HYDROData_Image) anOriImage =
+ Handle(HYDROData_Image)::DownCast( aDoc->CreateObject( KIND_IMAGE ) );
+
+ QImage aTestImage = TestImage();
+ anOriImage->SetImage( aTestImage );
+
+ Handle(HYDROData_Polyline) aCropPolyline =
+ Handle(HYDROData_Polyline)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) );
+
+ HYDROData_Polyline::PolylineData aPolylineData;
+
+ PolylineSection aPolylineSect;
+
+ aPolylineSect.myCoords << 25 << 0 << 0;
+ aPolylineSect.myCoords << 0 << 20 << 0;
+ aPolylineSect.myCoords << 25 << 40 << 0;
+ aPolylineSect.myCoords << 50 << 20 << 0;
+
+ aPolylineData << aPolylineSect;
+
+ aCropPolyline->setPolylineData( aPolylineData );
+
// prepare Composer Operation
- ImageComposer_CropOperator aCropOp;
- aCropOp.setArgs(Qt::red, aPath);
+ ImageComposer_Operator* aCropOp =
+ aFactory->Operator( ImageComposer_CropOperator::Type() );
+
+ CPPUNIT_ASSERT( aCropOp );
+
+ aCropOp->setArgs( Qt::red );
+
// create crop - image
- Handle(HYDROData_Image) aCrop = aFactory->CreateImage(aDoc, &aCropOp);
- CPPUNIT_ASSERT(!aCrop.IsNull());
- aCrop->AppendReference(anImage);
- aFactory->UpdateImage(aDoc, aCrop);
+ Handle(HYDROData_Image) aCropImage = aFactory->CreateImage( aDoc, aCropOp );
+ CPPUNIT_ASSERT( !aCropImage.IsNull() );
+
+ aCropImage->AppendReference( anOriImage );
+ aCropImage->AppendReference( aCropPolyline );
+ aCropImage->Update();
+
// check crop operation was performed
- CPPUNIT_ASSERT(!aCrop->Image().isNull());
- CPPUNIT_ASSERT(aCrop->Image() != aPic);
+ CPPUNIT_ASSERT( !aCropImage->Image().isNull() );
+ CPPUNIT_ASSERT( aCropImage->Image() != aTestImage );
aDoc->Close();
}