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_ImportGeomObjectOp.h"
25 #include "HYDROGUI_ObstacleDlg.h"
27 #include "HYDROGUI_DataModel.h"
28 #include "HYDROGUI_Module.h"
29 #include "HYDROGUI_Tool.h"
31 #include <HYDROData_Obstacle.h>
32 #include <HYDROData_Iterator.h>
36 #include <SalomeApp_Study.h>
38 #include <LightApp_Application.h>
39 #include <LightApp_UpdateFlags.h>
41 HYDROGUI_ImportGeomObjectOp::HYDROGUI_ImportGeomObjectOp( HYDROGUI_Module* theModule,
43 const bool theIsToShowPanel )
44 : HYDROGUI_Operation( theModule ),
45 myOpType ( theOpType ),
46 myIsToShowPanel ( theIsToShowPanel )
48 setName( tr( "IMPORT_GEOM_OBJECT" ) );
51 HYDROGUI_ImportGeomObjectOp::~HYDROGUI_ImportGeomObjectOp()
55 void HYDROGUI_ImportGeomObjectOp::startOperation()
57 HYDROGUI_Operation::startOperation();
59 // Get GEOM objects to import
60 myGeomObjects.clear();
61 if ( myOpType == ImportCreated ) {
62 myGeomObjects = module()->GetGeomObjectsToImport();
63 } else if ( myOpType == ImportSelected ) {
64 myGeomObjects = HYDROGUI_Tool::GetSelectedGeomObjects( module() );
67 HYDROGUI_ObstacleDlg* aPanel = 0;
69 if ( myGeomObjects.count() == 1 ) {
71 aPanel = ::qobject_cast<HYDROGUI_ObstacleDlg*>( inputPanel() );
74 // Reset the panel state
77 // Pass the existing obstacle names to the panel
78 QStringList anObstacles =
79 HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_OBSTACLE );
81 aPanel->setObstacleNames( anObstacles );
90 void HYDROGUI_ImportGeomObjectOp::abortOperation()
92 HYDROGUI_Operation::abortOperation();
95 void HYDROGUI_ImportGeomObjectOp::commitOperation()
97 HYDROGUI_Operation::commitOperation();
100 bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags,
101 QString& theErrorMsg )
103 // Get active SalomeApp_Study
104 SalomeApp_Study* aStudy =
105 dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
110 QString anObstacleName;
111 Handle(HYDROData_Obstacle) anObstacleToEdit;
114 HYDROGUI_ObstacleDlg* aPanel = ::qobject_cast<HYDROGUI_ObstacleDlg*>( inputPanel() );
116 QString anEditedName = aPanel->getEditedObstacleName().simplified();
118 if ( !anEditedName.isEmpty() ) {
119 anObstacleToEdit = Handle(HYDROData_Obstacle)::DownCast(
120 HYDROGUI_Tool::FindObjectByName( module(), anEditedName, KIND_OBSTACLE ) );
123 anObstacleName = anEditedName; //TODO: aPanel->getObstacleName();
128 // Get the created object as SObject
129 foreach ( const QString& anEntry, myGeomObjects ) {
130 _PTR(SObject) aSObject( aStudy->studyDS()->FindObjectID( qPrintable(anEntry)) );
132 // Get the corresponding TopoDS_Shape
133 TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( aSObject->GetIOR().c_str() );
134 if ( !aShape.IsNull() ) {
135 // Create/edit an obstacle object
136 // TODO refactoring: get rid of obstacle from TopoDS_Shape creation code copy/paste
137 Handle(HYDROData_Obstacle) anObstacle;
139 if ( anObstacleToEdit.IsNull() ) {
141 Handle(HYDROData_Obstacle)::DownCast( doc()->CreateObject(KIND_OBSTACLE) );
143 anObstacle = anObstacleToEdit;
147 if ( anObstacleName.isEmpty() ) {
148 QString aName = QString::fromStdString( aSObject->GetName() );
149 anObstacleName = HYDROGUI_Tool::GenerateObjectName( module(), aName );
151 if ( anObstacle->GetName() != anObstacleName ) {
152 anObstacle->SetName( anObstacleName );
156 anObstacle->SetShape3D( aShape );
158 // Set operation status
160 theUpdateFlags = UF_Model;
168 HYDROGUI_InputPanel* HYDROGUI_ImportGeomObjectOp::createInputPanel() const
170 HYDROGUI_InputPanel* aPanel = 0;
171 if ( myIsToShowPanel ) {
172 aPanel = new HYDROGUI_ObstacleDlg( module(), getName() );