1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GEOMBase_Tools.cxx
25 // Author : Damien COQUERET
29 #include "GEOMToolsGUI.h"
30 #include "GeometryGUI.h"
31 #include "GEOM_Actor.h"
33 #include "GEOM_Operation.h"
34 #include "GEOM_Displayer.h"
36 #include "QAD_Desktop.h"
37 #include "QAD_FileDlg.h"
38 #include "QAD_Tools.h"
39 #include "QAD_MessageBox.h"
40 #include "QAD_RightFrame.h"
41 #include "QAD_WaitCursor.h"
43 #include "OCCViewer_Viewer3d.h"
44 #include "VTKViewer_ViewFrame.h"
45 #include "VTKViewer_RenderWindowInteractor.h"
47 #include "SALOME_ListIteratorOfListIO.hxx"
48 #include "SALOMEGUI_ImportOperation.h"
49 #include "SALOMEGUI_QtCatchCorbaException.hxx"
51 #include <qapplication.h>
54 #include "utilities.h"
58 GEOMToolsGUI* GEOMToolsGUI::myGUIObject = 0;
60 typedef QMap<QString, QString> FilterMap;
62 //=======================================================================
63 // function : getFileName
64 // purpose : Selection of a file name for Import/Export. Returns also
65 // the selected file type code through <filter> argument.
66 //=======================================================================
67 static QString getFileName( QWidget* parent,
68 const QString& initial,
69 const FilterMap& filterMap,
70 const QString& caption,
74 static QString lastUsedFilter;
76 for ( FilterMap::const_iterator it = filterMap.begin(); it != filterMap.end(); ++it )
77 filters.push_back( it.key() );
79 QAD_FileDlg* fd = new QAD_FileDlg( parent, open, true, true );
80 if ( !caption.isEmpty() )
81 fd->setCaption( caption );
83 if ( !initial.isEmpty() )
84 fd->setSelection( initial );
86 if ( !lastUsedFilter.isEmpty() && filterMap.contains( lastUsedFilter ) )
87 fd->setSelectedFilter( lastUsedFilter );
89 fd->setFilters( filters );
92 QString filename = fd->selectedFile();
93 format = filterMap[fd->selectedFilter()];
94 lastUsedFilter = fd->selectedFilter();
96 qApp->processEvents();
100 //=======================================================================
101 // function : GetGEOMToolsGUI()
102 // purpose : Get the only GEOMToolsGUI object [ static ]
103 //=======================================================================
104 GEOMToolsGUI* GEOMToolsGUI::GetGEOMToolsGUI()
106 if ( myGUIObject == 0 ) {
107 // init GEOMToolsGUI only once
108 myGUIObject = new GEOMToolsGUI();
113 //=======================================================================
114 // function : GEOMToolsGUI()
115 // purpose : Constructor
116 //=======================================================================
117 GEOMToolsGUI::GEOMToolsGUI() : GEOMGUI()
122 //=======================================================================
123 // function : ~GEOMToolsGUI()
124 // purpose : Destructor
125 //=======================================================================
126 GEOMToolsGUI::~GEOMToolsGUI()
131 //=======================================================================
132 // function : OnGUIEvent()
134 //=======================================================================
135 bool GEOMToolsGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
137 GeometryGUI::GetGeomGUI()->EmitSignalDeactivateDialog();
138 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
140 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
141 switch (theCommandID)
153 case 111: // IMPORT BREP
154 case 112: // IMPORT IGES
155 case 113: // IMPORT STEP
160 case 121: // EXPORT BREP
161 case 122: // EXPORT IGES
162 case 123: // EXPORT STEP
167 case 411: // SETTINGS - ADD IN STUDY
169 // SAN -- TO BE REMOVED !!!
172 case 412: // SETTINGS - SHADING COLOR
177 case 413: // SETTINGS - ISOS
182 case 414: // SETTINGS : STEP VALUE FOR SPIN BOXES
187 case 804: // ADD IN STUDY - POPUP VIEWER
189 // SAN -- TO BE REMOVED !!!!
197 case 5103: // CHECK GEOMETRY
202 case 5104: // LOAD SCRIPT
207 case 8032: // COLOR - POPUP VIEWER
212 case 8033: // TRANSPARENCY - POPUP VIEWER
217 case 8034: // ISOS - POPUP VIEWER
222 case 9024 : // OPEN - OBJBROSER POPUP
229 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
237 //===============================================================================
238 // function : OnEditDelete()
240 //===============================================================================
241 void GEOMToolsGUI::OnEditDelete()
243 SALOME_Selection* Sel = SALOME_Selection::Selection(
244 QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
246 if ( Sel->IObjectCount() == 0 )
249 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
251 bool aLocked = aStudy->GetProperties()->IsLocked();
253 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
254 QObject::tr("WRN_WARNING"),
255 QObject::tr("WRN_STUDY_LOCKED"),
256 QObject::tr("BUT_OK") );
260 if ( QAD_MessageBox::warn2( QAD_Application::getDesktop(),
261 tr( "GEOM_WRN_WARNING" ),
262 tr( "GEOM_REALLY_DELETE" ),
263 tr( "GEOM_BUT_YES" ),
264 tr( "GEOM_BUT_NO" ), 1, 0, 0 ) != 1 )
267 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
269 Standard_Boolean found;
270 SALOMEDS::GenericAttribute_var anAttr;
271 SALOMEDS::AttributeIOR_var anIOR;
273 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
275 QAD_Operation* op = new SALOMEGUI_ImportOperation( QAD_Application::getDesktop()->getActiveStudy() );
279 Standard_Boolean deleted = false;
281 for ( ;It.More();It.Next() )
283 Handle( SALOME_InteractiveObject ) IObject = It.Value();
285 if ( !IObject->hasEntry() )
288 SALOMEDS::SObject_var SO = aStudy->FindObjectID( IObject->getEntry() );
290 /* Erase child graphical objects */
292 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( SO );
293 for ( ; it->More();it->Next() )
295 SALOMEDS::SObject_var CSO = it->Value();
297 if ( CSO->FindAttribute( anAttr, "AttributeIOR" ) )
299 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
301 // Delete child( s ) shape in Client :
303 const TCollection_AsciiString ASCior( anIOR->Value() ) ;
304 GeometryGUI::GetGeomGUI()->GetShapeReader().RemoveShapeFromBuffer( ASCior );
306 for ( int i = 0; i < nbSf; i++ )
308 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( CSO->GetObject() );
309 if ( !aGeomObj->_is_nil() )
310 GEOM_Displayer().Erase( aGeomObj, true );
315 /* Erase main graphical object */
317 for ( int i = 0; i < nbSf; i++ )
319 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame( i );
320 GEOM_Displayer().Erase( IObject, true );
323 /* Delete main shape in Client : */
325 if ( SO->FindAttribute( anAttr, "AttributeIOR" ) )
327 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
328 const TCollection_AsciiString ASCIor( anIOR->Value() ) ;
329 GeometryGUI::GetGeomGUI()->GetShapeReader().RemoveShapeFromBuffer( ASCIor );
332 /* Erase objects in Study */
334 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
335 if ( !obj->_is_nil() )
337 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
338 aStudyBuilder->RemoveObject( obj );
340 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( obj->GetObject() );
341 if ( !aGeomObj->_is_nil() )
342 GeometryGUI::GetGeomGUI()->GetGeomGen()->RemoveObject( aGeomObj );
353 /* Clear any previous selection */
354 Sel->ClearIObjects();
355 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
359 //==============================================================================
360 // function : OnEditCopy()
362 //==============================================================================
363 void GEOMToolsGUI::OnEditCopy()
366 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
367 GEOM::string_array_var listIOR = new GEOM::string_array;
369 const SALOME_ListIO& List = Sel->StoredIObjects();
371 myGeomBase->ConvertListOfIOInListOfIOR(List, listIOR);
373 Sel->ClearIObjects();
375 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
376 int aStudyID = aStudy->StudyId();
378 for (unsigned int ind = 0; ind < listIOR->length();ind++) {
379 GEOM::GEOM_Object_var aShapeInit = myGeom->GetIORFromString(listIOR[ind]);
381 GEOM::GEOM_IInsertOperations_var IOp = myGeom->GetIInsertOperations(aStudyID);
382 GEOM::GEOM_Object_var result = IOp->MakeCopy(aShapeInit) ;
383 myGeomBase->Display(result);
385 catch (const SALOME::SALOME_Exception& S_ex) {
386 QtCatchCorbaException(S_ex);
390 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_READY"));
395 //=====================================================================================
397 // purpose : BRep, Iges, Step
398 //=====================================================================================
399 bool GEOMToolsGUI::Import()
401 QAD_Study* aDoc = QAD_Application::getDesktop()->getActiveStudy();
402 SALOMEDS::Study_var aStudy = aDoc->getStudyDocument();
404 bool aLocked = aStudy->GetProperties()->IsLocked();
406 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
407 QObject::tr("WRN_WARNING"),
408 QObject::tr("WRN_STUDY_LOCKED"),
409 QObject::tr("BUT_OK") );
413 GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGUI()->GetGeomGen()->GetIInsertOperations( aStudy->StudyId() );
414 if ( aInsOp->_is_nil() )
417 GEOM::GEOM_Object_var anObj;
419 // Obtain a list of available import formats
421 GEOM::string_array_var aFormats, aPatterns;
422 aInsOp->ImportTranslators( aFormats, aPatterns );
423 for ( int i = 0, n = aFormats->length(); i < n; i++ )
424 aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
428 QString file = getFileName(QAD_Application::getDesktop(), "", aMap, tr("GEOM_MEN_IMPORT"), true, fileType );
429 if( file.isEmpty() || fileType.isEmpty() )
432 GEOM_Operation* anOp = new GEOM_Operation( aDoc, aInsOp.in() );
435 QAD_Application::getDesktop()->putInfo( tr("GEOM_PRP_LOADING").arg(QAD_Tools::getFileNameFromPath( file )) );
439 anObj = aInsOp->Import( file.latin1(), fileType.latin1() );
441 if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
442 anObj->SetName( GEOMBase::GetDefaultName( QObject::tr( "GEOM_IMPORT" ) ).latin1() );
443 QString aPublishObjName = GEOMBase::GetDefaultName( QAD_Tools::getFileNameFromPath( file ));
444 GeometryGUI::GetGeomGUI()->GetGeomGen()->PublishInStudy(
445 aStudy, SALOMEDS::SObject::_nil(), anObj, aPublishObjName );
447 GEOM_Displayer().Display( anObj.in() );
454 QAD_MessageBox::error1( QAD_Application::getDesktop(),
455 QObject::tr( "GEOM_ERROR" ),
456 QObject::tr("GEOM_PRP_ABORT") + "\n" + QString( aInsOp->GetErrorCode() ),
457 QObject::tr("BUT_OK") );
460 catch(const SALOME::SALOME_Exception& S_ex) {
461 QtCatchCorbaException(S_ex);
470 //=====================================================================================
472 // purpose : BRep, Iges, Step
473 //=====================================================================================
474 bool GEOMToolsGUI::Export()
476 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
477 GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGUI()->GetGeomGen()->GetIInsertOperations( aStudy->StudyId() );
478 if ( aInsOp->_is_nil() )
481 // Obtain a list of available export formats
483 GEOM::string_array_var aFormats, aPatterns;
484 aInsOp->ExportTranslators( aFormats, aPatterns );
485 for ( int i = 0, n = aFormats->length(); i < n; i++ )
486 aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
488 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
489 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
491 for(;It.More();It.Next()) {
492 Handle(SALOME_InteractiveObject) IObject = It.Value();
493 Standard_Boolean found;
494 GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject(IObject, found);
496 if ( !found || anObj->_is_nil() )
500 QString file = getFileName(QAD_Application::getDesktop(),
501 QString( IObject->getName() ),
503 tr("GEOM_MEN_EXPORT"),
507 // User has pressed "Cancel" --> stop the operation
508 if ( file.isEmpty() || fileType.isEmpty() )
511 // Standard_Boolean result = BRepTools::Write(Shape->Shape(), strdup(file.latin1()) );
514 aInsOp->Export( anObj, file, fileType.latin1() );
515 if ( !aInsOp->IsDone() ) {
517 QAD_MessageBox::error1( QAD_Application::getDesktop(),
518 QObject::tr( "GEOM_ERROR" ),
519 QObject::tr("GEOM_PRP_ABORT") + "\n" + QString( aInsOp->GetErrorCode() ),
520 QObject::tr("BUT_OK") );
524 catch (const SALOME::SALOME_Exception& S_ex) {
525 QtCatchCorbaException(S_ex);
533 //=====================================================================================
535 //=====================================================================================
540 return GEOMToolsGUI::GetGEOMToolsGUI();