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 HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule,
41 const bool theIsEdit )
42 : HYDROGUI_Operation( theModule ),
44 myIsEdit( theIsEdit ),
50 case Fuse: aName = theIsEdit ? tr( "EDIT_FUSED_IMAGE" ) : tr( "FUSE_IMAGES" ); break;
51 case Cut: aName = theIsEdit ? tr( "EDIT_CUT_IMAGE" ) : tr( "CUT_IMAGES" ); break;
52 case Split: aName = theIsEdit ? tr( "EDIT_SPLITTED_IMAGE" ) : tr( "SPLIT_IMAGE" ); break;
58 HYDROGUI_TwoImagesOp::~HYDROGUI_TwoImagesOp()
62 HYDROGUI_InputPanel* HYDROGUI_TwoImagesOp::createInputPanel() const
64 return new HYDROGUI_TwoImagesDlg( module(), getName() );
67 void HYDROGUI_TwoImagesOp::startOperation()
69 HYDROGUI_Operation::startOperation();
71 HYDROGUI_TwoImagesDlg* aPanel = (HYDROGUI_TwoImagesDlg*)inputPanel();
74 if( myType == Fuse || myType == Cut )
75 aPanel->setMode( HYDROGUI_TwoImagesDlg::TwoImages, myIsEdit );
76 else if( myType == Split )
77 aPanel->setMode( HYDROGUI_TwoImagesDlg::ImageAndPolyline, myIsEdit );
82 myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
83 if( !myEditedObject.IsNull() )
84 anImageName = myEditedObject->GetName();
91 case Fuse: aPrefix = tr( "FUSE" ); break;
92 case Cut: aPrefix = tr( "CUT" ); break;
93 case Split: aPrefix = tr( "SPLIT" ); break;
96 anImageName = HYDROGUI_Tool::GenerateObjectName( module(), aPrefix );
98 aPanel->setImageName( anImageName );
100 QString aSelectedName1, aSelectedName2;
101 if( myIsEdit && !myEditedObject.IsNull() )
103 if( myEditedObject->NbReferences() > 0 )
105 Handle(HYDROData_Entity) anObject1 = myEditedObject->Reference( 0 );
106 if( !anObject1.IsNull() )
107 aSelectedName1 = anObject1->GetName();
109 if( myEditedObject->NbReferences() > 1 )
111 Handle(HYDROData_Entity) anObject2 = myEditedObject->Reference( 1 );
112 if( !anObject2.IsNull() )
113 aSelectedName2 = anObject2->GetName();
115 aPanel->setSelectedObjects( aSelectedName1, aSelectedName2 );
117 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
118 if( ImageComposer_Operator* anOperator = aFactory->Operator( myEditedObject ) )
121 anOperator->getArgs( aColor );
122 aPanel->setColor( aColor );
127 Handle(HYDROData_Image) aSelectedImage =
128 Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
129 if( !aSelectedImage.IsNull() )
131 QString aSelectedName = aSelectedImage->GetName();
132 aPanel->setPreselectedObject( aSelectedName );
137 bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
138 QString& theErrorMsg )
140 HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast<HYDROGUI_TwoImagesDlg*>( inputPanel() );
142 bool anIsModifySelected = myType == Split && aPanel->isModifySelected();
144 QString anImageName = aPanel->getImageName();
145 if( !anIsModifySelected && anImageName.isEmpty() )
148 QString aSelectedName1, aSelectedName2;
149 if( !aPanel->getSelectedObjects( aSelectedName1, aSelectedName2 ) )
152 if( !anIsModifySelected &&
153 ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) ) )
155 // check that there are no other objects with the same name in the document
156 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
157 if( !anObject.IsNull() )
159 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
164 Handle(HYDROData_Entity) anObject1 =
165 HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_UNKNOWN ) ;
166 Handle(HYDROData_Entity) anObject2 =
167 HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_UNKNOWN );
168 if( anObject1.IsNull() || anObject2.IsNull() )
171 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
173 Handle(HYDROData_Image) aResult;
174 ImageComposer_Operator* anOperator = 0;
177 aResult = myEditedObject;
178 aResult->ClearReferences();
179 anOperator = aFactory->Operator( aResult );
183 QString anOperatorName;
186 case Fuse: anOperatorName = ImageComposer_FuseOperator::Type(); break;
187 case Cut: anOperatorName = ImageComposer_CutOperator::Type(); break;
188 case Split: anOperatorName = ImageComposer_CropOperator::Type(); break;
192 anOperator = aFactory->Operator( anOperatorName );
194 aResult = aFactory->CreateImage( doc(), anOperator );
197 if( aResult.IsNull() || !anOperator )
200 // Setting the operator arguments
201 anOperator->setArgs( aPanel->getColor() );
202 aResult->SetArgs( anOperator->getBinArgs() );
204 aResult->SetName( anImageName );
205 aResult->AppendReference( anObject1 );
206 aResult->AppendReference( anObject2 );
210 if( anIsModifySelected )
212 Handle(HYDROData_Image) aSelectedImage = Handle(HYDROData_Image)::DownCast( anObject1 );
213 if( !aSelectedImage.IsNull() )
215 aSelectedImage->SetIsSelfSplitted( true );
216 aSelectedImage->SetImage( aResult->Image() );
217 aSelectedImage->SetTrsf( aResult->Trsf() );
222 if( !myIsEdit && !anIsModifySelected )
224 size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
225 module()->setObjectVisible( aViewId, anObject1, false );
226 module()->setObjectVisible( aViewId, anObject2, false );
227 module()->setObjectVisible( aViewId, aResult, true );
230 theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;