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_Poly3DOp.h"
25 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_Tool.h"
27 #include "HYDROGUI_Poly3DDlg.h"
28 #include "HYDROGUI_UpdateFlags.h"
30 #include <HYDROData_Document.h>
31 #include <HYDROData_Polyline3D.h>
32 #include <HYDROData_Profile.h>
33 #include <HYDROData_PolylineXY.h>
35 #include <HYDROData_OperationsFactory.h>
37 HYDROGUI_Poly3DOp::HYDROGUI_Poly3DOp( HYDROGUI_Module* theModule,
38 const bool theIsEdit )
39 : HYDROGUI_Operation( theModule ),
40 myIsEdit( theIsEdit ),
43 setName( theIsEdit ? tr( "EDIT_POLYLINE_3D" ) : tr( "CREATE_POLYLINE_3D" ) );
46 HYDROGUI_Poly3DOp::~HYDROGUI_Poly3DOp()
50 HYDROGUI_InputPanel* HYDROGUI_Poly3DOp::createInputPanel() const
52 return new HYDROGUI_Poly3DDlg( module(), getName() );
55 void HYDROGUI_Poly3DOp::startOperation()
57 HYDROGUI_Operation::startOperation();
59 HYDROGUI_Poly3DDlg* aPanel = (HYDROGUI_Poly3DDlg*)inputPanel();
61 aPanel->setMode( myIsEdit );
66 myEditedObject = Handle(HYDROData_Polyline3D)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
67 if( !myEditedObject.IsNull() )
68 aPoly3DName = myEditedObject->GetName();
72 aPoly3DName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_POLYLINE_3D_NAME" ) );
74 aPanel->setResultName( aPoly3DName );
76 QString aSelectedName1, aSelectedName2;
77 if( myIsEdit && !myEditedObject.IsNull() )
79 Handle(HYDROData_Entity) anObject1 = myEditedObject->GetProfileUZ()->GetFatherObject();
80 if( !anObject1.IsNull() )
81 aSelectedName1 = anObject1->GetName();
82 Handle(HYDROData_Entity) anObject2 = myEditedObject->GetPolylineXY();
83 if( !anObject2.IsNull() )
84 aSelectedName2 = anObject2->GetName();
85 aPanel->setSelectedObjects( aSelectedName1, aSelectedName2 );
89 Handle(HYDROData_Profile) aSelectedProfile =
90 Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
91 if( !aSelectedProfile.IsNull() )
93 QString aSelectedName = aSelectedProfile->GetName();
94 aPanel->setPreselectedObject( aSelectedName );
99 bool HYDROGUI_Poly3DOp::processApply( int& theUpdateFlags,
100 QString& theErrorMsg )
102 HYDROGUI_Poly3DDlg* aPanel = dynamic_cast<HYDROGUI_Poly3DDlg*>( inputPanel() );
104 QString aResultName = aPanel->getResultName();
105 if( aResultName.isEmpty() )
108 QString aSelectedName1, aSelectedName2;
109 if( !aPanel->getSelectedObjects( aSelectedName1, aSelectedName2 ) )
112 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aResultName ) )
114 // check that there are no other objects with the same name in the document
115 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aResultName );
116 if( !anObject.IsNull() )
118 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aResultName );
123 Handle(HYDROData_Entity) anObject1 =
124 HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_PROFILE ) ;
125 Handle(HYDROData_Entity) anObject2 =
126 HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_POLYLINEXY );
127 if( anObject1.IsNull() || anObject2.IsNull() )
130 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( anObject1 );
131 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( anObject2 );
133 if( aProfile.IsNull() || aPolyline.IsNull() )
136 Handle(HYDROData_ProfileUZ) aProfileUZ = aProfile->GetProfileUZ();
137 if( aProfileUZ.IsNull() )
140 Handle(HYDROData_Polyline3D) aResult;
143 aResult = myEditedObject;
144 aResult->RemoveProfileUZ();
145 aResult->RemovePolylineXY();
149 aResult = Handle(HYDROData_Polyline3D)::DownCast( doc()->CreateObject( KIND_POLYLINE ) );
152 if( aResult.IsNull() )
155 aResult->SetName( aResultName );
156 aResult->SetProfileUZ( aProfileUZ );
157 aResult->SetPolylineXY( aPolyline );
163 size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
164 module()->setObjectVisible( aViewId, anObject1, false );
165 module()->setObjectVisible( aViewId, anObject2, false );
166 module()->setObjectVisible( aViewId, aResult, true );
169 theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;