]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_Poly3DOp.cxx
Salome HOME
Merge branch 'BR_IMPROVEMENTS' of ssh://git.salome-platform.org/modules/hydro into...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Poly3DOp.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_Poly3DOp.h"
24
25 #include "HYDROGUI_Module.h"
26 #include <HYDROGUI_DataObject.h>
27 #include "HYDROGUI_Tool.h"
28 #include "HYDROGUI_Poly3DDlg.h"
29 #include "HYDROGUI_UpdateFlags.h"
30
31 #include <HYDROData_Document.h>
32 #include <HYDROData_Polyline3D.h>
33 #include <HYDROData_Profile.h>
34 #include <HYDROData_PolylineXY.h>
35 #include <HYDROData_Bathymetry.h>
36
37 #include <HYDROData_OperationsFactory.h>
38
39 HYDROGUI_Poly3DOp::HYDROGUI_Poly3DOp( HYDROGUI_Module* theModule,
40                                             const bool theIsEdit )
41 : HYDROGUI_Operation( theModule ),
42   myIsEdit( theIsEdit ),
43   myEditedObject( 0 )
44 {
45   setName( theIsEdit ? tr( "EDIT_POLYLINE_3D" ) : tr( "CREATE_POLYLINE_3D" ) );
46 }
47
48 HYDROGUI_Poly3DOp::~HYDROGUI_Poly3DOp()
49 {
50 }
51
52 HYDROGUI_InputPanel* HYDROGUI_Poly3DOp::createInputPanel() const
53 {
54   return new HYDROGUI_Poly3DDlg( module(), getName() );
55 }
56
57 void HYDROGUI_Poly3DOp::startOperation()
58 {
59   HYDROGUI_Operation::startOperation();
60
61   HYDROGUI_Poly3DDlg* aPanel = (HYDROGUI_Poly3DDlg*)inputPanel();
62   aPanel->reset();
63   aPanel->setMode( myIsEdit );
64
65   QString aPoly3DName;
66   if( myIsEdit )
67   {
68     if ( isApplyAndClose() )
69       myEditedObject = Handle(HYDROData_Polyline3D)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
70     if( !myEditedObject.IsNull() )
71       aPoly3DName = myEditedObject->GetName();
72   }
73   else
74   {
75     aPoly3DName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_POLYLINE_3D_NAME" ) );
76   }
77   aPanel->setResultName( aPoly3DName );
78
79   QString aPolyName, aProfileName, aBathName;
80   if( myIsEdit && !myEditedObject.IsNull() )
81   {
82     Handle(HYDROData_ProfileUZ) aProfileUZ = myEditedObject->GetProfileUZ();
83     if( !aProfileUZ.IsNull() )
84     {
85       Handle(HYDROData_Entity) aProfile = aProfileUZ->GetFatherObject();
86       if ( !aProfile.IsNull() )
87         aProfileName = aProfile->GetName();
88     }
89
90     Handle(HYDROData_Entity) aPoly = myEditedObject->GetPolylineXY();
91     if( !aPoly.IsNull() )
92       aPolyName = aPoly->GetName();
93
94     Handle(HYDROData_IAltitudeObject) anAltitudeObj = myEditedObject->GetAltitudeObject();
95     if( !anAltitudeObj.IsNull() )
96       aBathName = anAltitudeObj->GetName();
97
98     aPanel->setSelectedObjects( aPolyName, aProfileName, aBathName );
99   }
100   else if( !myIsEdit )
101   {
102     Handle(HYDROData_Profile) aSelectedProfile =
103       Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
104     if( !aSelectedProfile.IsNull() )
105     {
106       QString aSelectedName = aSelectedProfile->GetName();
107       aPanel->setPreselectedObject( aSelectedName );
108     }
109   }
110 }
111
112 bool HYDROGUI_Poly3DOp::processApply( int& theUpdateFlags,
113                                       QString& theErrorMsg,
114                                       QStringList& theBrowseObjectsEntries )
115 {
116   HYDROGUI_Poly3DDlg* aPanel = dynamic_cast<HYDROGUI_Poly3DDlg*>( inputPanel() );
117
118   QString aResultName = aPanel->getResultName();
119   if( aResultName.isEmpty() )
120     return false;
121
122   QString aPolyName, aProfileName, aBathName;
123   if( !aPanel->getSelectedObjects( aPolyName, aProfileName, aBathName ) )
124     return false;
125
126   if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aResultName ) )
127   {
128     // check that there are no other objects with the same name in the document
129     Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aResultName );
130     if( !anObject.IsNull() )
131     {
132       theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aResultName );
133       return false;
134     }
135   }
136
137   Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( 
138     HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
139   Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( 
140     HYDROGUI_Tool::FindObjectByName( module(), aPolyName, KIND_POLYLINEXY ) );
141   Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( 
142     HYDROGUI_Tool::FindObjectByName( module(), aBathName, KIND_BATHYMETRY ) );
143
144   if ( aPolyline.IsNull() || ( aProfile.IsNull() && aBath.IsNull() ) )
145     return false;
146
147   Handle(HYDROData_Polyline3D) aResult;
148   if( myIsEdit )
149   {
150     aResult = myEditedObject;
151   }
152   else
153   {
154     aResult = Handle(HYDROData_Polyline3D)::DownCast( doc()->CreateObject( KIND_POLYLINE ) );
155     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aResult );
156     theBrowseObjectsEntries.append( anEntry );
157   }
158
159   if( aResult.IsNull() )
160     return false;
161
162   aResult->SetName( aResultName );
163
164   aResult->SetPolylineXY( aPolyline, false );
165   if ( !aProfile.IsNull() )
166   {
167     Handle(HYDROData_ProfileUZ) aProfileUZ = aProfile->GetProfileUZ();
168     if( aProfileUZ.IsNull() )
169       return false;
170     
171     aResult->SetProfileUZ( aProfileUZ );
172   }
173   else
174   {
175     aResult->SetAltitudeObject( aBath );
176   }
177
178   if( !myIsEdit )
179   {
180     aResult->SetBorderColor( HYDROData_Polyline3D::DefaultBorderColor() );
181   }
182
183   aResult->Update();
184
185   if( !myIsEdit )
186   {
187     size_t aViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
188     module()->setObjectVisible( aViewId, aPolyline, false );
189     module()->setObjectVisible( aViewId, aProfile, false );
190     module()->setObjectVisible( aViewId, aResult, true );
191   }
192   module()->setIsToUpdate( aResult );
193
194   theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
195   return true;
196 }