1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <test_HYDROData_OperationsFactory.h>
25 #include <HYDROData_Document.h>
26 #include <HYDROData_Image.h>
27 #include <HYDROData_PolylineXY.h>
28 #include <HYDROData_OperationsFactory.h>
30 #include <ImageComposer_CropOperator.h>
36 void test_HYDROData_OperationsFactory::testCreate()
38 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
40 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
41 CPPUNIT_ASSERT(aFactory);
42 Handle(HYDROData_Image) anImage = aFactory->CreateImage(aDoc, NULL);
43 CPPUNIT_ASSERT(!anImage.IsNull());
44 CPPUNIT_ASSERT(anImage->Image().isNull());
49 static QImage TestImage() {
50 QImage aPic(50, 40, QImage::Format_RGB32);
52 QPainter aPainter(&aPic);
53 aPainter.drawEllipse(6, 7, 38, 30);
54 aPainter.drawLine(0, 40, 10, 0);
55 aPainter.drawLine(10, 0, 25, 35);
56 aPainter.drawLine(25, 35, 40, 0);
57 aPainter.drawLine(40, 0, 50, 40);
61 void test_HYDROData_OperationsFactory::testCrop()
63 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
64 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
66 // prepare the original image and crop-path
67 Handle(HYDROData_Image) anOriImage =
68 Handle(HYDROData_Image)::DownCast( aDoc->CreateObject( KIND_IMAGE ) );
70 QImage aTestImage = TestImage();
71 anOriImage->SetImage( aTestImage );
73 Handle(HYDROData_PolylineXY) aCropPolyline =
74 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
76 aCropPolyline->AddSection( "", HYDROData_PolylineXY::SECTION_POLYLINE, true );
78 aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 25, 0 ) );
79 aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 0, 20 ) );
80 aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 25, 40 ) );
81 aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 50, 20 ) );
83 // prepare Composer Operation
84 ImageComposer_Operator* aCropOp =
85 aFactory->Operator( ImageComposer_CropOperator::Type() );
87 CPPUNIT_ASSERT( aCropOp );
89 aCropOp->setArgs( Qt::red );
91 // create crop - image
92 Handle(HYDROData_Image) aCropImage = aFactory->CreateImage( aDoc, aCropOp );
93 CPPUNIT_ASSERT( !aCropImage.IsNull() );
95 aCropImage->AppendReference( anOriImage );
96 aCropImage->AppendReference( aCropPolyline );
99 // check crop operation was performed
100 CPPUNIT_ASSERT( !aCropImage->Image().isNull() );
101 CPPUNIT_ASSERT( aCropImage->Image() != aTestImage );