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"
30 #include "HYDROGUI_UpdateFlags.h"
32 #include <HYDROData_Obstacle.h>
33 #include <HYDROData_Iterator.h>
37 #include <SalomeApp_Study.h>
39 #include <LightApp_Application.h>
40 #include <LightApp_UpdateFlags.h>
42 HYDROGUI_ImportGeomObjectOp::HYDROGUI_ImportGeomObjectOp( HYDROGUI_Module* theModule,
44 const bool theIsToShowPanel )
45 : HYDROGUI_Operation( theModule ),
46 myOpType ( theOpType ),
47 myIsToShowPanel ( theIsToShowPanel )
49 setName( tr( "IMPORT_GEOM_OBJECT" ) );
52 HYDROGUI_ImportGeomObjectOp::~HYDROGUI_ImportGeomObjectOp()
56 void HYDROGUI_ImportGeomObjectOp::startOperation()
58 HYDROGUI_Operation::startOperation();
60 // Get GEOM objects to import
61 myGeomObjects.clear();
62 if ( myOpType == ImportCreated ) {
63 myGeomObjects = module()->GetGeomObjectsToImport();
64 } else if ( myOpType == ImportSelected ) {
65 myGeomObjects = HYDROGUI_Tool::GetSelectedGeomObjects( module() );
68 HYDROGUI_ObstacleDlg* aPanel = 0;
70 if ( myGeomObjects.count() == 1 ) {
72 aPanel = ::qobject_cast<HYDROGUI_ObstacleDlg*>( inputPanel() );
75 // Reset the panel state
79 SalomeApp_Study* aStudy =
80 dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
82 QString anEntry = myGeomObjects.first();
83 _PTR(SObject) aSObject( aStudy->studyDS()->FindObjectID( qPrintable(anEntry) ) );
85 aPanel->setDefaultName( QString::fromStdString(aSObject->GetName()) );
89 // Pass the existing obstacle names to the panel
90 QStringList anObstacles =
91 HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_OBSTACLE );
93 aPanel->setObstacleNames( anObstacles );
102 void HYDROGUI_ImportGeomObjectOp::abortOperation()
104 HYDROGUI_Operation::abortOperation();
107 void HYDROGUI_ImportGeomObjectOp::commitOperation()
109 HYDROGUI_Operation::commitOperation();
112 bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags,
113 QString& theErrorMsg )
115 // Get active SalomeApp_Study
116 SalomeApp_Study* aStudy =
117 dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
122 QString anObstacleName;
123 Handle(HYDROData_Obstacle) anObstacleToEdit;
125 if ( myGeomObjects.count() == 1 ) {
127 HYDROGUI_ObstacleDlg* aPanel = ::qobject_cast<HYDROGUI_ObstacleDlg*>( inputPanel() );
129 // Check obstacle name
130 anObstacleName = aPanel->getObstacleName().simplified();
131 if ( anObstacleName.isEmpty() ) {
132 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
136 // Get obstacle to edit
137 QString anEditedName = aPanel->getEditedObstacleName().simplified();
139 if ( !anEditedName.isEmpty() ) {
140 anObstacleToEdit = Handle(HYDROData_Obstacle)::DownCast(
141 HYDROGUI_Tool::FindObjectByName( module(), anEditedName, KIND_OBSTACLE ) );
145 if( anObstacleToEdit.IsNull() || anObstacleToEdit->GetName() != anObstacleName ) {
146 // check that there are no other objects with the same name in the document
147 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObstacleName );
148 if( !anObject.IsNull() ) {
149 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObstacleName );
157 // Get the created object as SObject
158 foreach ( const QString& anEntry, myGeomObjects ) {
159 _PTR(SObject) aSObject( aStudy->studyDS()->FindObjectID( qPrintable(anEntry)) );
161 // Get the corresponding TopoDS_Shape
162 TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( aSObject->GetIOR().c_str() );
163 if ( !aShape.IsNull() ) {
164 // Create/edit an obstacle object
165 Handle(HYDROData_Obstacle) anObstacle;
167 if ( anObstacleToEdit.IsNull() ) {
169 Handle(HYDROData_Obstacle)::DownCast( doc()->CreateObject(KIND_OBSTACLE) );
171 anObstacle = anObstacleToEdit;
175 if ( anObstacleName.isEmpty() ) {
176 QString aName = QString::fromStdString( aSObject->GetName() );
177 anObstacleName = HYDROGUI_Tool::GenerateObjectName(
178 module(), aName, QStringList(), true );
180 if ( anObstacle->GetName() != anObstacleName ) {
181 anObstacle->SetName( anObstacleName );
184 anObstacleName.clear();
187 anObstacle->SetShape3D( aShape );
189 // Set operation status
191 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
199 HYDROGUI_InputPanel* HYDROGUI_ImportGeomObjectOp::createInputPanel() const
201 HYDROGUI_InputPanel* aPanel = 0;
202 if ( myIsToShowPanel ) {
203 aPanel = new HYDROGUI_ObstacleDlg( module(), getName() );