1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <test_HYDROData_OperationsFactory.h>
21 #include <HYDROData_Document.h>
22 #include <HYDROData_Image.h>
23 #include <HYDROData_PolylineXY.h>
24 #include <HYDROData_OperationsFactory.h>
26 #include <ImageComposer_CropOperator.h>
32 void test_HYDROData_OperationsFactory::testCreate()
34 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
36 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
37 CPPUNIT_ASSERT(aFactory);
38 Handle(HYDROData_Image) anImage = aFactory->CreateImage(aDoc, NULL);
39 CPPUNIT_ASSERT(!anImage.IsNull());
40 CPPUNIT_ASSERT(anImage->Image().isNull());
45 static QImage TestImage() {
46 QImage aPic(50, 40, QImage::Format_RGB32);
48 QPainter aPainter(&aPic);
49 aPainter.drawEllipse(6, 7, 38, 30);
50 aPainter.drawLine(0, 40, 10, 0);
51 aPainter.drawLine(10, 0, 25, 35);
52 aPainter.drawLine(25, 35, 40, 0);
53 aPainter.drawLine(40, 0, 50, 40);
57 void test_HYDROData_OperationsFactory::testCrop()
59 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
60 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
62 // prepare the original image and crop-path
63 Handle(HYDROData_Image) anOriImage =
64 Handle(HYDROData_Image)::DownCast( aDoc->CreateObject( KIND_IMAGE ) );
66 QImage aTestImage = TestImage();
67 anOriImage->SetImage( aTestImage );
69 Handle(HYDROData_PolylineXY) aCropPolyline =
70 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
72 aCropPolyline->AddSection( "", HYDROData_PolylineXY::SECTION_POLYLINE, true );
74 aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 25, 0 ) );
75 aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 0, 20 ) );
76 aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 25, 40 ) );
77 aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 50, 20 ) );
79 // prepare Composer Operation
80 ImageComposer_Operator* aCropOp =
81 aFactory->Operator( ImageComposer_CropOperator::Type() );
83 CPPUNIT_ASSERT( aCropOp );
85 aCropOp->setArgs( Qt::red );
87 // create crop - image
88 Handle(HYDROData_Image) aCropImage = aFactory->CreateImage( aDoc, aCropOp );
89 CPPUNIT_ASSERT( !aCropImage.IsNull() );
91 aCropImage->AppendReference( anOriImage );
92 aCropImage->AppendReference( aCropPolyline );
95 // check crop operation was performed
96 CPPUNIT_ASSERT( !aCropImage->Image().isNull() );
97 CPPUNIT_ASSERT( aCropImage->Image() != aTestImage );