1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_Poly3DOp.h"
21 #include "HYDROGUI_Module.h"
22 #include <HYDROGUI_DataObject.h>
23 #include "HYDROGUI_Tool2.h"
24 #include "HYDROGUI_Poly3DDlg.h"
25 #include "HYDROGUI_UpdateFlags.h"
27 #include <HYDROData_Document.h>
28 #include <HYDROData_Polyline3D.h>
29 #include <HYDROData_Profile.h>
30 #include <HYDROData_PolylineXY.h>
31 #include <HYDROData_Bathymetry.h>
33 #include <HYDROData_OperationsFactory.h>
35 HYDROGUI_Poly3DOp::HYDROGUI_Poly3DOp( HYDROGUI_Module* theModule,
36 const bool theIsEdit )
37 : HYDROGUI_Operation( theModule ),
38 myIsEdit( theIsEdit ),
41 setName( theIsEdit ? tr( "EDIT_POLYLINE_3D" ) : tr( "CREATE_POLYLINE_3D" ) );
44 HYDROGUI_Poly3DOp::~HYDROGUI_Poly3DOp()
48 HYDROGUI_InputPanel* HYDROGUI_Poly3DOp::createInputPanel() const
50 return new HYDROGUI_Poly3DDlg( module(), getName() );
53 void HYDROGUI_Poly3DOp::startOperation()
55 HYDROGUI_Operation::startOperation();
57 HYDROGUI_Poly3DDlg* aPanel = (HYDROGUI_Poly3DDlg*)inputPanel();
59 aPanel->setMode( myIsEdit );
64 if ( isApplyAndClose() )
65 myEditedObject = Handle(HYDROData_Polyline3D)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
66 if( !myEditedObject.IsNull() )
67 aPoly3DName = myEditedObject->GetName();
71 aPoly3DName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_POLYLINE_3D_NAME" ) );
73 aPanel->setResultName( aPoly3DName );
75 QString aPolyName, aProfileName, aBathName;
76 if( myIsEdit && !myEditedObject.IsNull() )
78 Handle(HYDROData_ProfileUZ) aProfileUZ = myEditedObject->GetProfileUZ();
79 if( !aProfileUZ.IsNull() )
81 Handle(HYDROData_Entity) aProfile = aProfileUZ->GetFatherObject();
82 if ( !aProfile.IsNull() )
83 aProfileName = aProfile->GetName();
86 Handle(HYDROData_Entity) aPoly = myEditedObject->GetPolylineXY();
88 aPolyName = aPoly->GetName();
90 Handle(HYDROData_IAltitudeObject) anAltitudeObj = myEditedObject->GetAltitudeObject();
91 if( !anAltitudeObj.IsNull() )
92 aBathName = anAltitudeObj->GetName();
94 aPanel->setSelectedObjects( aPolyName, aProfileName, aBathName );
98 Handle(HYDROData_Profile) aSelectedProfile =
99 Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
100 if( !aSelectedProfile.IsNull() )
102 QString aSelectedName = aSelectedProfile->GetName();
103 aPanel->setPreselectedObject( aSelectedName );
108 bool HYDROGUI_Poly3DOp::processApply( int& theUpdateFlags,
109 QString& theErrorMsg,
110 QStringList& theBrowseObjectsEntries )
112 HYDROGUI_Poly3DDlg* aPanel = dynamic_cast<HYDROGUI_Poly3DDlg*>( inputPanel() );
114 QString aResultName = aPanel->getResultName();
115 if( aResultName.isEmpty() )
118 QString aPolyName, aProfileName, aBathName;
119 if( !aPanel->getSelectedObjects( aPolyName, aProfileName, aBathName ) )
122 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aResultName ) )
124 // check that there are no other objects with the same name in the document
125 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aResultName );
126 if( !anObject.IsNull() )
128 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aResultName );
133 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
134 HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
135 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast(
136 HYDROGUI_Tool::FindObjectByName( module(), aPolyName, KIND_POLYLINEXY ) );
137 Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast(
138 HYDROGUI_Tool::FindObjectByName( module(), aBathName, KIND_BATHYMETRY ) );
140 if ( aPolyline.IsNull() || ( aProfile.IsNull() && aBath.IsNull() ) )
143 Handle(HYDROData_Polyline3D) aResult;
146 aResult = myEditedObject;
150 aResult = Handle(HYDROData_Polyline3D)::DownCast( doc()->CreateObject( KIND_POLYLINE ) );
151 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aResult );
152 theBrowseObjectsEntries.append( anEntry );
155 if( aResult.IsNull() )
158 aResult->SetName( aResultName );
160 aResult->SetPolylineXY( aPolyline, false );
161 if ( !aProfile.IsNull() )
163 Handle(HYDROData_ProfileUZ) aProfileUZ = aProfile->GetProfileUZ();
164 if( aProfileUZ.IsNull() )
167 aResult->SetProfileUZ( aProfileUZ );
171 aResult->SetAltitudeObject( aBath );
176 aResult->SetBorderColor( aResult->DefaultBorderColor() );
183 size_t aViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
184 module()->setObjectVisible( aViewId, aPolyline, false );
185 module()->setObjectVisible( aViewId, aProfile, false );
186 module()->setObjectVisible( aViewId, aResult, true );
188 module()->setIsToUpdate( aResult );
190 theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;