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>
32 #include <HYDROData_Polyline.h>
34 #include <HYDROData_OperationsFactory.h>
36 #include <ImageComposer_CutOperator.h>
37 #include <ImageComposer_CropOperator.h>
38 #include <ImageComposer_FuseOperator.h>
40 HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule,
42 const bool theIsEdit )
43 : HYDROGUI_Operation( theModule ),
45 myIsEdit( theIsEdit ),
51 case Fuse: aName = theIsEdit ? tr( "EDIT_FUSED_IMAGE" ) : tr( "FUSE_IMAGES" ); break;
52 case Cut: aName = theIsEdit ? tr( "EDIT_CUT_IMAGE" ) : tr( "CUT_IMAGES" ); break;
53 case Split: aName = theIsEdit ? tr( "EDIT_SPLITTED_IMAGE" ) : tr( "SPLIT_IMAGE" ); break;
59 HYDROGUI_TwoImagesOp::~HYDROGUI_TwoImagesOp()
63 HYDROGUI_InputPanel* HYDROGUI_TwoImagesOp::createInputPanel() const
65 return new HYDROGUI_TwoImagesDlg( module(), getName() );
68 void HYDROGUI_TwoImagesOp::startOperation()
70 HYDROGUI_Operation::startOperation();
72 HYDROGUI_TwoImagesDlg* aPanel = (HYDROGUI_TwoImagesDlg*)inputPanel();
75 if( myType == Fuse || myType == Cut )
76 aPanel->setMode( HYDROGUI_TwoImagesDlg::TwoImages, myIsEdit );
77 else if( myType == Split )
78 aPanel->setMode( HYDROGUI_TwoImagesDlg::ImageAndPolyline, myIsEdit );
83 myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
84 if( !myEditedObject.IsNull() )
85 anImageName = myEditedObject->GetName();
92 case Fuse: aPrefix = tr( "FUSE" ); break;
93 case Cut: aPrefix = tr( "CUT" ); break;
94 case Split: aPrefix = tr( "SPLIT" ); break;
97 anImageName = HYDROGUI_Tool::GenerateObjectName( module(), aPrefix );
99 aPanel->setImageName( anImageName );
101 QString aSelectedName1, aSelectedName2;
102 if( myIsEdit && !myEditedObject.IsNull() )
104 if( myEditedObject->NbReferences() > 0 )
106 Handle(HYDROData_Entity) anObject1 = myEditedObject->Reference( 0 );
107 if( !anObject1.IsNull() )
108 aSelectedName1 = anObject1->GetName();
110 if( myEditedObject->NbReferences() > 1 )
112 Handle(HYDROData_Entity) anObject2 = myEditedObject->Reference( 1 );
113 if( !anObject2.IsNull() )
114 aSelectedName2 = anObject2->GetName();
116 aPanel->setSelectedObjects( aSelectedName1, aSelectedName2 );
118 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
119 if( ImageComposer_Operator* anOperator = aFactory->Operator( myEditedObject ) )
122 anOperator->getArgs( aColor );
123 aPanel->setColor( aColor );
128 Handle(HYDROData_Image) aSelectedImage =
129 Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
130 if( !aSelectedImage.IsNull() )
132 QString aSelectedName = aSelectedImage->GetName();
133 aPanel->setPreselectedObject( aSelectedName );
138 bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
139 QString& theErrorMsg )
141 HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast<HYDROGUI_TwoImagesDlg*>( inputPanel() );
143 bool anIsModifySelected = myType == Split && aPanel->isModifySelected();
145 QString anImageName = aPanel->getImageName();
146 if( !anIsModifySelected && anImageName.isEmpty() )
149 QString aSelectedName1, aSelectedName2;
150 if( !aPanel->getSelectedObjects( aSelectedName1, aSelectedName2 ) )
153 if( !anIsModifySelected &&
154 ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) ) )
156 // check that there are no other objects with the same name in the document
157 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
158 if( !anObject.IsNull() )
160 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
165 Handle(HYDROData_Entity) anObject1 =
166 HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_UNKNOWN ) ;
167 Handle(HYDROData_Entity) anObject2 =
168 HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_UNKNOWN );
169 if( anObject1.IsNull() || anObject2.IsNull() )
172 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
174 Handle(HYDROData_Image) aResult;
175 ImageComposer_Operator* anOperator = 0;
178 aResult = myEditedObject;
179 aResult->ClearReferences();
180 anOperator = aFactory->Operator( aResult );
184 QString anOperatorName;
187 case Fuse: anOperatorName = ImageComposer_FuseOperator::Type(); break;
188 case Cut: anOperatorName = ImageComposer_CutOperator::Type(); break;
189 case Split: anOperatorName = ImageComposer_CropOperator::Type(); break;
193 anOperator = aFactory->Operator( anOperatorName );
195 aResult = aFactory->CreateImage( doc(), anOperator );
198 if( aResult.IsNull() || !anOperator )
201 // Setting the operator arguments
202 anOperator->setArgs( aPanel->getColor() );
203 aResult->SetArgs( anOperator->getBinArgs() );
205 aResult->SetName( anImageName );
206 aResult->AppendReference( anObject1 );
207 aResult->AppendReference( anObject2 );
211 if( anIsModifySelected )
213 Handle(HYDROData_Image) aSelectedImage = Handle(HYDROData_Image)::DownCast( anObject1 );
214 if( !aSelectedImage.IsNull() )
216 aSelectedImage->SetIsSelfSplitted( true );
217 aSelectedImage->SetImage( aResult->Image() );
218 aSelectedImage->SetTrsf( aResult->Trsf() );
223 if( !myIsEdit && !anIsModifySelected )
225 size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
226 module()->setObjectVisible( aViewId, anObject1, false );
227 module()->setObjectVisible( aViewId, anObject2, false );
228 module()->setObjectVisible( aViewId, aResult, true );
231 theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;