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_GeoreferencementOp.h"
25 #include "HYDROGUI_GeoreferencementDlg.h"
26 #include "HYDROGUI_DataModel.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_Tool.h"
29 #include "HYDROGUI_UpdateFlags.h"
31 #include <HYDROData_Profile.h>
32 #include <HYDROData_Iterator.h>
33 #include <HYDROData_Entity.h>
35 #include <LightApp_Application.h>
36 #include <LightApp_UpdateFlags.h>
40 HYDROGUI_GeoreferencementOp::HYDROGUI_GeoreferencementOp( HYDROGUI_Module* theModule, const int theInitialMode )
41 : HYDROGUI_Operation( theModule ),
42 myInitialMode( theInitialMode )
44 setName( tr( "PROFILES_GEOREFERENCEMENT" ) );
47 HYDROGUI_GeoreferencementOp::~HYDROGUI_GeoreferencementOp()
51 void HYDROGUI_GeoreferencementOp::startOperation()
53 HYDROGUI_Operation::startOperation();
55 HYDROGUI_GeoreferencementDlg* aPanel =
56 ::qobject_cast<HYDROGUI_GeoreferencementDlg*>( inputPanel() );
63 if ( myInitialMode == All ) {
64 int anAllMode = HYDROGUI_GeoreferencementDlg::AllProfiles;
65 aPanel->setMode( anAllMode );
66 onModeActivated( anAllMode );
67 } else if ( myInitialMode == Selected ) {
68 int aSelectionMode = HYDROGUI_GeoreferencementDlg::SelectedProfiles;
69 aPanel->setMode( aSelectionMode );
70 onModeActivated( aSelectionMode );
74 void HYDROGUI_GeoreferencementOp::abortOperation()
76 HYDROGUI_Operation::abortOperation();
79 void HYDROGUI_GeoreferencementOp::commitOperation()
81 HYDROGUI_Operation::commitOperation();
84 HYDROGUI_InputPanel* HYDROGUI_GeoreferencementOp::createInputPanel() const
86 HYDROGUI_InputPanel* aPanel = new HYDROGUI_GeoreferencementDlg( module(), getName() );
87 connect( aPanel, SIGNAL( modeActivated( int ) ), SLOT( onModeActivated( int ) ) );
92 bool HYDROGUI_GeoreferencementOp::processApply( int& theUpdateFlags,
93 QString& theErrorMsg )
95 HYDROGUI_GeoreferencementDlg* aPanel =
96 ::qobject_cast<HYDROGUI_GeoreferencementDlg*>( inputPanel() );
101 // Get georeferencement data from the panel
102 HYDROGUI_GeoreferencementDlg::ProfilesGeoDataMap aGeoDataMap;
103 aPanel->getData( aGeoDataMap );
106 foreach ( const QString& aProfileName, aGeoDataMap.keys() ) {
107 Handle(HYDROData_Profile) aProfile =
108 Handle(HYDROData_Profile)::DownCast(
109 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
110 if ( !aProfile.IsNull() ) {
111 HYDROGUI_GeoreferencementDlg::ProfileGeoData aGeoData =
112 aGeoDataMap.value( aProfileName );
113 if ( aGeoData.isValid ) {
114 aProfile->SetFirstPoint( gp_XY( aGeoData.Xg, aGeoData.Yg ) );
115 aProfile->SetLastPoint( gp_XY( aGeoData.Xd, aGeoData.Yd ) );
117 aProfile->Invalidate();
122 theUpdateFlags = UF_Model;
126 void HYDROGUI_GeoreferencementOp::onModeActivated( const int theActualMode )
128 HYDROGUI_GeoreferencementDlg* aPanel =
129 ::qobject_cast<HYDROGUI_GeoreferencementDlg*>( inputPanel() );
134 HYDROGUI_GeoreferencementDlg::ProfilesGeoDataMap aDataMap;
135 HYDROData_SequenceOfObjects aSeqOfProfiles;
137 if( theActualMode == HYDROGUI_GeoreferencementDlg::AllProfiles ) {
138 HYDROData_Iterator aProfilesIter( doc(), KIND_PROFILE );
139 while ( aProfilesIter.More() ) {
140 aSeqOfProfiles.Append( aProfilesIter.Current() );
141 aProfilesIter.Next();
143 } else if ( theActualMode == HYDROGUI_GeoreferencementDlg::SelectedProfiles ) {
144 aSeqOfProfiles = HYDROGUI_Tool::GetSelectedObjects( module() );
147 HYDROData_SequenceOfObjects::Iterator anIter( aSeqOfProfiles );
148 for ( ; anIter.More(); anIter.Next() ) {
149 Handle(HYDROData_Profile) aProfile =
150 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
151 if ( aProfile.IsNull() ) {
155 HYDROGUI_GeoreferencementDlg::ProfileGeoData aGeoData;
157 gp_XY aFirstPoint, aLastPoint;
158 if ( aProfile->GetFirstPoint( aFirstPoint ) && aProfile->GetLastPoint( aLastPoint ) ) {
160 HYDROGUI_GeoreferencementDlg::ProfileGeoData( aFirstPoint.X(), aFirstPoint.Y(),
161 aLastPoint.X(), aLastPoint.Y() );
164 aDataMap.insert( aProfile->GetName(), aGeoData );
167 aPanel->setData( aDataMap );