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 "HYDROGUI_TwoImagesOp.h"
25 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_Tool.h"
27 #include "HYDROGUI_TwoImagesDlg.h"
28 #include "HYDROGUI_UpdateFlags.h"
29 #include <HYDROGUI_DataObject.h>
31 #include <HYDROData_Document.h>
32 #include <HYDROData_Image.h>
34 #include <HYDROData_OperationsFactory.h>
36 #include <ImageComposer_CutOperator.h>
37 #include <ImageComposer_CropOperator.h>
38 #include <ImageComposer_FuseOperator.h>
40 #include <LightApp_Application.h>
41 #include <SUIT_Desktop.h>
42 #include <SUIT_MessageBox.h>
44 HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule,
46 const bool theIsEdit )
47 : HYDROGUI_Operation( theModule ),
49 myIsEdit( theIsEdit ),
55 case Fuse: aName = theIsEdit ? tr( "EDIT_FUSED_IMAGE" ) : tr( "FUSE_IMAGES" ); break;
56 case Cut: aName = theIsEdit ? tr( "EDIT_CUT_IMAGE" ) : tr( "CUT_IMAGES" ); break;
57 case Split: aName = theIsEdit ? tr( "EDIT_SPLITTED_IMAGE" ) : tr( "SPLIT_IMAGE" ); break;
63 HYDROGUI_TwoImagesOp::~HYDROGUI_TwoImagesOp()
67 HYDROGUI_InputPanel* HYDROGUI_TwoImagesOp::createInputPanel() const
69 return new HYDROGUI_TwoImagesDlg( module(), getName() );
72 void HYDROGUI_TwoImagesOp::startOperation()
74 HYDROGUI_Operation::startOperation();
76 HYDROGUI_TwoImagesDlg* aPanel = (HYDROGUI_TwoImagesDlg*)inputPanel();
81 aMode = HYDROGUI_TwoImagesDlg::TwoFuseImage;
83 aMode = HYDROGUI_TwoImagesDlg::TwoCutImage;
84 else if( myType == Split )
85 aMode = HYDROGUI_TwoImagesDlg::ImageAndPolyline;
86 aPanel->setMode( aMode, myIsEdit );
91 if ( isApplyAndClose() )
92 myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
93 if( !myEditedObject.IsNull() )
94 anImageName = myEditedObject->GetName();
101 case Fuse: aPrefix = tr( "FUSE" ); break;
102 case Cut: aPrefix = tr( "CUT" ); break;
103 case Split: aPrefix = tr( "SPLIT" ); break;
106 anImageName = HYDROGUI_Tool::GenerateObjectName( module(), aPrefix );
108 aPanel->setImageName( anImageName );
110 QString aSelectedName1, aSelectedName2;
111 if( myIsEdit && !myEditedObject.IsNull() )
113 if( myEditedObject->NbReferences() > 0 )
115 Handle(HYDROData_Entity) anObject1 = myEditedObject->Reference( 0 );
116 if( !anObject1.IsNull() )
117 aSelectedName1 = anObject1->GetName();
119 if( myEditedObject->NbReferences() > 1 )
121 Handle(HYDROData_Entity) anObject2 = myEditedObject->Reference( 1 );
122 if( !anObject2.IsNull() )
123 aSelectedName2 = anObject2->GetName();
125 aPanel->setSelectedObjects( aSelectedName1, aSelectedName2 );
127 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
128 if( ImageComposer_Operator* anOperator = aFactory->Operator( myEditedObject ) )
131 anOperator->getArgs( aColor );
132 aPanel->setColor( aColor );
137 Handle(HYDROData_Image) aSelectedImage =
138 Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
139 if( !aSelectedImage.IsNull() )
141 QString aSelectedName = aSelectedImage->GetName();
142 aPanel->setPreselectedObject( aSelectedName );
145 connect( aPanel, SIGNAL( alreadySelected( const QString& ) ), SLOT( onAlreadySelected( const QString& ) ) );
148 void HYDROGUI_TwoImagesOp::onAlreadySelected( const QString& theName )
150 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
151 QString aMessage = tr( "OBJECT_ALREADY_SELECTED" ).arg( theName );
152 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
155 bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
156 QString& theErrorMsg,
157 QStringList& theBrowseObjectsEntries )
159 HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast<HYDROGUI_TwoImagesDlg*>( inputPanel() );
161 bool anIsModifySelected = myType == Split && aPanel->isModifySelected();
163 QString anImageName = aPanel->getImageName();
164 if( !anIsModifySelected && anImageName.isEmpty() )
167 QString aSelectedName1, aSelectedName2;
168 if( !aPanel->getSelectedObjects( aSelectedName1, aSelectedName2 ) )
171 if( !anIsModifySelected &&
172 ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) ) )
174 // check that there are no other objects with the same name in the document
175 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
176 if( !anObject.IsNull() )
178 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
183 Handle(HYDROData_Entity) anObject1 =
184 HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_UNKNOWN ) ;
185 Handle(HYDROData_Entity) anObject2 =
186 HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_UNKNOWN );
187 if( anObject1.IsNull() || anObject2.IsNull() )
190 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
192 Handle(HYDROData_Image) aResult;
193 ImageComposer_Operator* anOperator = 0;
196 aResult = myEditedObject;
197 aResult->ClearReferences();
198 anOperator = aFactory->Operator( aResult );
202 QString anOperatorName;
205 case Fuse: anOperatorName = ImageComposer_FuseOperator::Type(); break;
206 case Cut: anOperatorName = ImageComposer_CutOperator::Type(); break;
207 case Split: anOperatorName = ImageComposer_CropOperator::Type(); break;
211 anOperator = aFactory->Operator( anOperatorName );
213 aResult = aFactory->CreateImage( doc(), anOperator );
214 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aResult );
215 theBrowseObjectsEntries.append( anEntry );
218 if( aResult.IsNull() || !anOperator )
221 // Setting the operator arguments
222 anOperator->setArgs( aPanel->getColor() );
223 aResult->SetArgs( anOperator->getBinArgs() );
225 aResult->SetName( anImageName );
226 aResult->AppendReference( anObject1 );
227 aResult->AppendReference( anObject2 );
231 if( anIsModifySelected )
233 Handle(HYDROData_Image) aSelectedImage = Handle(HYDROData_Image)::DownCast( anObject1 );
234 if( !aSelectedImage.IsNull() )
236 aSelectedImage->SetIsSelfSplitted( true );
237 aSelectedImage->SetImage( aResult->Image() );
238 aSelectedImage->SetTrsf( aResult->Trsf() );
243 if( !myIsEdit && !anIsModifySelected )
245 size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
246 module()->setObjectVisible( aViewId, anObject1, false );
247 module()->setObjectVisible( aViewId, anObject2, false );
248 module()->setObjectVisible( aViewId, aResult, true );
251 theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;