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 <HYDROData_OperationsFactory.h>
35 #include <ImageComposer_CutOperator.h>
36 #include <ImageComposer_CropOperator.h>
37 #include <ImageComposer_FuseOperator.h>
39 #include <LightApp_Application.h>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_MessageBox.h>
43 HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule,
45 const bool theIsEdit )
46 : HYDROGUI_Operation( theModule ),
48 myIsEdit( theIsEdit ),
54 case Fuse: aName = theIsEdit ? tr( "EDIT_FUSED_IMAGE" ) : tr( "FUSE_IMAGES" ); break;
55 case Cut: aName = theIsEdit ? tr( "EDIT_CUT_IMAGE" ) : tr( "CUT_IMAGES" ); break;
56 case Split: aName = theIsEdit ? tr( "EDIT_SPLITTED_IMAGE" ) : tr( "SPLIT_IMAGE" ); break;
62 HYDROGUI_TwoImagesOp::~HYDROGUI_TwoImagesOp()
66 HYDROGUI_InputPanel* HYDROGUI_TwoImagesOp::createInputPanel() const
68 return new HYDROGUI_TwoImagesDlg( module(), getName() );
71 void HYDROGUI_TwoImagesOp::startOperation()
73 HYDROGUI_Operation::startOperation();
75 HYDROGUI_TwoImagesDlg* aPanel = (HYDROGUI_TwoImagesDlg*)inputPanel();
80 aMode = HYDROGUI_TwoImagesDlg::TwoFuseImage;
82 aMode = HYDROGUI_TwoImagesDlg::TwoCutImage;
83 else if( myType == Split )
84 aMode = HYDROGUI_TwoImagesDlg::ImageAndPolyline;
85 aPanel->setMode( aMode, myIsEdit );
90 myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
91 if( !myEditedObject.IsNull() )
92 anImageName = myEditedObject->GetName();
99 case Fuse: aPrefix = tr( "FUSE" ); break;
100 case Cut: aPrefix = tr( "CUT" ); break;
101 case Split: aPrefix = tr( "SPLIT" ); break;
104 anImageName = HYDROGUI_Tool::GenerateObjectName( module(), aPrefix );
106 aPanel->setImageName( anImageName );
108 QString aSelectedName1, aSelectedName2;
109 if( myIsEdit && !myEditedObject.IsNull() )
111 if( myEditedObject->NbReferences() > 0 )
113 Handle(HYDROData_Entity) anObject1 = myEditedObject->Reference( 0 );
114 if( !anObject1.IsNull() )
115 aSelectedName1 = anObject1->GetName();
117 if( myEditedObject->NbReferences() > 1 )
119 Handle(HYDROData_Entity) anObject2 = myEditedObject->Reference( 1 );
120 if( !anObject2.IsNull() )
121 aSelectedName2 = anObject2->GetName();
123 aPanel->setSelectedObjects( aSelectedName1, aSelectedName2 );
125 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
126 if( ImageComposer_Operator* anOperator = aFactory->Operator( myEditedObject ) )
129 anOperator->getArgs( aColor );
130 aPanel->setColor( aColor );
135 Handle(HYDROData_Image) aSelectedImage =
136 Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
137 if( !aSelectedImage.IsNull() )
139 QString aSelectedName = aSelectedImage->GetName();
140 aPanel->setPreselectedObject( aSelectedName );
143 connect( aPanel, SIGNAL( alreadySelected( const QString& ) ), SLOT( onAlreadySelected( const QString& ) ) );
146 void HYDROGUI_TwoImagesOp::onAlreadySelected( const QString& theName )
148 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
149 QString aMessage = tr( "OBJECT_ALREADY_SELECTED" ).arg( theName );
150 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
153 bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
154 QString& theErrorMsg )
156 HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast<HYDROGUI_TwoImagesDlg*>( inputPanel() );
158 bool anIsModifySelected = myType == Split && aPanel->isModifySelected();
160 QString anImageName = aPanel->getImageName();
161 if( !anIsModifySelected && anImageName.isEmpty() )
164 QString aSelectedName1, aSelectedName2;
165 if( !aPanel->getSelectedObjects( aSelectedName1, aSelectedName2 ) )
168 if( !anIsModifySelected &&
169 ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) ) )
171 // check that there are no other objects with the same name in the document
172 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
173 if( !anObject.IsNull() )
175 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
180 Handle(HYDROData_Entity) anObject1 =
181 HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_UNKNOWN ) ;
182 Handle(HYDROData_Entity) anObject2 =
183 HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_UNKNOWN );
184 if( anObject1.IsNull() || anObject2.IsNull() )
187 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
189 Handle(HYDROData_Image) aResult;
190 ImageComposer_Operator* anOperator = 0;
193 aResult = myEditedObject;
194 aResult->ClearReferences();
195 anOperator = aFactory->Operator( aResult );
199 QString anOperatorName;
202 case Fuse: anOperatorName = ImageComposer_FuseOperator::Type(); break;
203 case Cut: anOperatorName = ImageComposer_CutOperator::Type(); break;
204 case Split: anOperatorName = ImageComposer_CropOperator::Type(); break;
208 anOperator = aFactory->Operator( anOperatorName );
210 aResult = aFactory->CreateImage( doc(), anOperator );
213 if( aResult.IsNull() || !anOperator )
216 // Setting the operator arguments
217 anOperator->setArgs( aPanel->getColor() );
218 aResult->SetArgs( anOperator->getBinArgs() );
220 aResult->SetName( anImageName );
221 aResult->AppendReference( anObject1 );
222 aResult->AppendReference( anObject2 );
226 if( anIsModifySelected )
228 Handle(HYDROData_Image) aSelectedImage = Handle(HYDROData_Image)::DownCast( anObject1 );
229 if( !aSelectedImage.IsNull() )
231 aSelectedImage->SetIsSelfSplitted( true );
232 aSelectedImage->SetImage( aResult->Image() );
233 aSelectedImage->SetTrsf( aResult->Trsf() );
238 if( !myIsEdit && !anIsModifySelected )
240 size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
241 module()->setObjectVisible( aViewId, anObject1, false );
242 module()->setObjectVisible( aViewId, anObject2, false );
243 module()->setObjectVisible( aViewId, aResult, true );
246 theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;