1 // Copyright (C) 2007-2013 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.
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 "HYDROGUI_TwoImagesOp.h"
25 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_Tool.h"
27 #include "HYDROGUI_TwoImagesDlg.h"
28 #include "HYDROGUI_UpdateFlags.h"
30 #include <HYDROData_Document.h>
31 #include <HYDROData_Image.h>
33 #include <HYDROOperations_Factory.h>
35 #include <ImageComposer_CutOperator.h>
36 #include <ImageComposer_FuseOperator.h>
38 HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType )
39 : HYDROGUI_Operation( theModule ),
47 myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
48 if( !myEditedObject.IsNull() )
50 if( HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory() )
52 if( ImageComposer_Operator* anOperator = aFactory->Operator( myEditedObject ) )
54 if( dynamic_cast<ImageComposer_FuseOperator*>( anOperator ) )
56 else if( dynamic_cast<ImageComposer_CutOperator*>( anOperator ) )
66 case Fuse: aName = tr( "FUSE" ); break;
67 case Cut: aName = tr( "CUT" ); break;
73 HYDROGUI_TwoImagesOp::~HYDROGUI_TwoImagesOp()
77 HYDROGUI_InputPanel* HYDROGUI_TwoImagesOp::createInputPanel() const
79 return new HYDROGUI_TwoImagesDlg( module(), getName() );
82 void HYDROGUI_TwoImagesOp::startOperation()
84 HYDROGUI_Operation::startOperation();
86 HYDROGUI_TwoImagesDlg* aPanel = (HYDROGUI_TwoImagesDlg*)inputPanel();
92 if( !myEditedObject.IsNull() )
93 anImageName = myEditedObject->GetName();
96 anImageName = HYDROGUI_Tool::GenerateObjectName( module(), getName() );
97 aPanel->setImageName( anImageName );
99 QString aSelectedName1, aSelectedName2;
100 if( myIsEdit && !myEditedObject.IsNull() )
102 if( myEditedObject->NbReferences() > 0 )
104 Handle(HYDROData_Image) anImage1 = myEditedObject->Reference( 0 );
105 if( !anImage1.IsNull() )
106 aSelectedName1 = anImage1->GetName();
108 if( myEditedObject->NbReferences() > 1 )
110 Handle(HYDROData_Image) anImage2 = myEditedObject->Reference( 1 );
111 if( !anImage2.IsNull() )
112 aSelectedName2 = anImage2->GetName();
114 aPanel->setSelectedImages( aSelectedName1, aSelectedName2 );
118 bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
119 QString& theErrorMsg )
121 HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast<HYDROGUI_TwoImagesDlg*>( inputPanel() );
123 QString anImageName = aPanel->getImageName();
124 if( anImageName.isEmpty() )
127 QString aSelectedName1, aSelectedName2;
128 if( !aPanel->getSelectedImages( aSelectedName1, aSelectedName2 ) )
131 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
133 // check that there are no other objects with the same name in the document
134 Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
135 if( !anObject.IsNull() )
137 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
142 Handle(HYDROData_Image) anImage1 = Handle(HYDROData_Image)::DownCast(
143 HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_IMAGE ) );
144 Handle(HYDROData_Image) anImage2 = Handle(HYDROData_Image)::DownCast(
145 HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_IMAGE ) );
146 if( anImage1.IsNull() || anImage2.IsNull() )
149 HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
150 Handle(HYDROData_Image) aResult = 0;
153 aResult = myEditedObject;
154 aResult->ClearReferences();
158 ImageComposer_Operator* anOperator = 0;
161 case Fuse: anOperator = new ImageComposer_FuseOperator(); break;
162 case Cut: anOperator = new ImageComposer_CutOperator(); break;
169 aResult = aFactory->CreateImage( doc(), anOperator );
172 if( aResult.IsNull() )
175 aResult->SetName( anImageName );
176 aResult->AppendReference( anImage1 );
177 aResult->AppendReference( anImage2 );
178 aFactory->UpdateImage( doc(), aResult );
182 size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
183 module()->setObjectVisible( aViewId, anImage1, false );
184 module()->setObjectVisible( aViewId, anImage2, false );
185 module()->setObjectVisible( aViewId, aResult, true );
189 theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced;