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"
42 #include "SALOMEGUI_Desktop.h"
44 #include "OCCViewer_Viewer3d.h"
45 #include "VTKViewer_ViewFrame.h"
46 #include "VTKViewer_RenderWindowInteractor.h"
48 #include "SALOME_ListIteratorOfListIO.hxx"
49 #include "SALOMEGUI_ImportOperation.h"
50 #include "SALOMEGUI_QtCatchCorbaException.hxx"
52 #include <qapplication.h>
55 #include "utilities.h"
59 GEOMToolsGUI* GEOMToolsGUI::myGUIObject = 0;
61 typedef QMap<QString, QString> FilterMap;
63 //=======================================================================
64 // function : getFileName
65 // purpose : Selection of a file name for Import/Export. Returns also
66 // the selected file type code through <filter> argument.
67 //=======================================================================
68 static QString getFileName( QWidget* parent,
69 const QString& initial,
70 const FilterMap& filterMap,
71 const QString& caption,
75 static QString lastUsedFilter;
77 for ( FilterMap::const_iterator it = filterMap.begin(); it != filterMap.end(); ++it )
78 filters.push_back( it.key() );
80 QAD_FileDlg* fd = new QAD_FileDlg( parent, open, true, true );
81 if ( !caption.isEmpty() )
82 fd->setCaption( caption );
84 if ( !initial.isEmpty() )
85 fd->setSelection( initial );
87 if ( !lastUsedFilter.isEmpty() && filterMap.contains( lastUsedFilter ) )
88 fd->setSelectedFilter( lastUsedFilter );
90 fd->setFilters( filters );
93 QString filename = fd->selectedFile();
94 format = filterMap[fd->selectedFilter()];
95 lastUsedFilter = fd->selectedFilter();
97 qApp->processEvents();
101 //=======================================================================
102 // function : GetGEOMToolsGUI()
103 // purpose : Get the only GEOMToolsGUI object [ static ]
104 //=======================================================================
105 GEOMToolsGUI* GEOMToolsGUI::GetGEOMToolsGUI()
107 if ( myGUIObject == 0 ) {
108 // init GEOMToolsGUI only once
109 myGUIObject = new GEOMToolsGUI();
114 //=======================================================================
115 // function : GEOMToolsGUI()
116 // purpose : Constructor
117 //=======================================================================
118 GEOMToolsGUI::GEOMToolsGUI() : GEOMGUI()
123 //=======================================================================
124 // function : ~GEOMToolsGUI()
125 // purpose : Destructor
126 //=======================================================================
127 GEOMToolsGUI::~GEOMToolsGUI()
132 //=======================================================================
133 // function : OnGUIEvent()
135 //=======================================================================
136 bool GEOMToolsGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
138 GeometryGUI::GetGeomGUI()->EmitSignalDeactivateDialog();
139 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
141 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
142 switch (theCommandID)
154 case 111: // IMPORT BREP
155 case 112: // IMPORT IGES
156 case 113: // IMPORT STEP
161 case 121: // EXPORT BREP
162 case 122: // EXPORT IGES
163 case 123: // EXPORT STEP
168 case 411: // SETTINGS - ADD IN STUDY
170 // SAN -- TO BE REMOVED !!!
173 case 412: // SETTINGS - SHADING COLOR
178 case 413: // SETTINGS - ISOS
183 case 414: // SETTINGS : STEP VALUE FOR SPIN BOXES
188 case 804: // ADD IN STUDY - POPUP VIEWER
190 // SAN -- TO BE REMOVED !!!!
198 case 5103: // CHECK GEOMETRY
203 case 5104: // LOAD SCRIPT
208 case 8032: // COLOR - POPUP VIEWER
213 case 8033: // TRANSPARENCY - POPUP VIEWER
218 case 8034: // ISOS - POPUP VIEWER
223 case 9024 : // OPEN - OBJBROSER POPUP
230 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
238 //===============================================================================
239 // function : OnEditDelete()
241 //===============================================================================
242 void GEOMToolsGUI::OnEditDelete()
244 SALOME_Selection* Sel = SALOME_Selection::Selection(
245 QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
247 if ( Sel->IObjectCount() == 0 )
250 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
252 bool aLocked = aStudy->GetProperties()->IsLocked();
254 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
255 QObject::tr("WRN_WARNING"),
256 QObject::tr("WRN_STUDY_LOCKED"),
257 QObject::tr("BUT_OK") );
261 // VSR 17/11/04: check if all objects selected belong to GEOM component --> start
262 QString aParentComponent = ((SALOMEGUI_Desktop*)QAD_Application::getDesktop())->getComponentFromSelection();
263 if ( aParentComponent != QAD_Application::getDesktop()->getActiveComponent() ) {
264 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
265 QObject::tr("ERR_ERROR"),
266 QObject::tr("NON_GEOM_OBJECTS_SELECTED").arg(QAD_Application::getDesktop()->getComponentUserName( "GEOM" )),
267 QObject::tr("BUT_OK") );
270 // VSR 17/11/04: check if all objects selected belong to GEOM component <-- finish
272 if ( QAD_MessageBox::warn2( QAD_Application::getDesktop(),
273 tr( "GEOM_WRN_WARNING" ),
274 tr( "GEOM_REALLY_DELETE" ),
275 tr( "GEOM_BUT_YES" ),
276 tr( "GEOM_BUT_NO" ), 1, 0, 0 ) != 1 )
279 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
281 Standard_Boolean found;
282 SALOMEDS::GenericAttribute_var anAttr;
283 SALOMEDS::AttributeIOR_var anIOR;
285 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
287 QAD_Operation* op = new SALOMEGUI_ImportOperation( QAD_Application::getDesktop()->getActiveStudy() );
291 Standard_Boolean deleted = false;
293 for ( ;It.More();It.Next() )
295 Handle( SALOME_InteractiveObject ) IObject = It.Value();
297 if ( !IObject->hasEntry() )
300 SALOMEDS::SObject_var SO = aStudy->FindObjectID( IObject->getEntry() );
302 /* Erase child graphical objects */
304 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( SO );
305 for ( ; it->More();it->Next() )
307 SALOMEDS::SObject_var CSO = it->Value();
309 if ( CSO->FindAttribute( anAttr, "AttributeIOR" ) )
311 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
313 // Delete child( s ) shape in Client :
315 const TCollection_AsciiString ASCior( anIOR->Value() ) ;
316 GeometryGUI::GetGeomGUI()->GetShapeReader().RemoveShapeFromBuffer( ASCior );
318 for ( int i = 0; i < nbSf; i++ )
320 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( CSO->GetObject() );
321 if ( !aGeomObj->_is_nil() )
322 GEOM_Displayer().Erase( aGeomObj, true );
327 /* Erase main graphical object */
329 for ( int i = 0; i < nbSf; i++ )
331 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame( i );
332 GEOM_Displayer().Erase( IObject, true );
335 /* Delete main shape in Client : */
337 if ( SO->FindAttribute( anAttr, "AttributeIOR" ) )
339 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
340 const TCollection_AsciiString ASCIor( anIOR->Value() ) ;
341 GeometryGUI::GetGeomGUI()->GetShapeReader().RemoveShapeFromBuffer( ASCIor );
344 /* Erase objects in Study */
346 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
347 if ( !obj->_is_nil() )
349 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
350 aStudyBuilder->RemoveObject( obj );
352 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( obj->GetObject() );
353 if ( !aGeomObj->_is_nil() )
354 GeometryGUI::GetGeomGUI()->GetGeomGen()->RemoveObject( aGeomObj );
365 /* Clear any previous selection */
366 Sel->ClearIObjects();
367 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
371 //==============================================================================
372 // function : OnEditCopy()
374 //==============================================================================
375 void GEOMToolsGUI::OnEditCopy()
378 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
379 GEOM::string_array_var listIOR = new GEOM::string_array;
381 const SALOME_ListIO& List = Sel->StoredIObjects();
383 myGeomBase->ConvertListOfIOInListOfIOR(List, listIOR);
385 Sel->ClearIObjects();
387 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
388 int aStudyID = aStudy->StudyId();
390 for (unsigned int ind = 0; ind < listIOR->length();ind++) {
391 GEOM::GEOM_Object_var aShapeInit = myGeom->GetIORFromString(listIOR[ind]);
393 GEOM::GEOM_IInsertOperations_var IOp = myGeom->GetIInsertOperations(aStudyID);
394 GEOM::GEOM_Object_var result = IOp->MakeCopy(aShapeInit) ;
395 myGeomBase->Display(result);
397 catch (const SALOME::SALOME_Exception& S_ex) {
398 QtCatchCorbaException(S_ex);
402 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_READY"));
407 //=====================================================================================
409 // purpose : BRep, Iges, Step
410 //=====================================================================================
411 bool GEOMToolsGUI::Import()
413 QAD_Study* aDoc = QAD_Application::getDesktop()->getActiveStudy();
414 SALOMEDS::Study_var aStudy = aDoc->getStudyDocument();
416 bool aLocked = aStudy->GetProperties()->IsLocked();
418 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
419 QObject::tr("WRN_WARNING"),
420 QObject::tr("WRN_STUDY_LOCKED"),
421 QObject::tr("BUT_OK") );
425 GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGUI()->GetGeomGen()->GetIInsertOperations( aStudy->StudyId() );
426 if ( aInsOp->_is_nil() )
429 GEOM::GEOM_Object_var anObj;
431 // Obtain a list of available import formats
433 GEOM::string_array_var aFormats, aPatterns;
434 aInsOp->ImportTranslators( aFormats, aPatterns );
435 for ( int i = 0, n = aFormats->length(); i < n; i++ )
436 aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
440 QString file = getFileName(QAD_Application::getDesktop(), "", aMap, tr("GEOM_MEN_IMPORT"), true, fileType );
441 if( file.isEmpty() || fileType.isEmpty() )
444 GEOM_Operation* anOp = new GEOM_Operation( aDoc, aInsOp.in() );
447 QAD_Application::getDesktop()->putInfo( tr("GEOM_PRP_LOADING").arg(QAD_Tools::getFileNameFromPath( file )) );
451 anObj = aInsOp->Import( file.latin1(), fileType.latin1() );
453 if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
454 anObj->SetName( GEOMBase::GetDefaultName( QObject::tr( "GEOM_IMPORT" ) ).latin1() );
455 QString aPublishObjName = GEOMBase::GetDefaultName( QAD_Tools::getFileNameFromPath( file ));
456 GeometryGUI::GetGeomGUI()->GetGeomGen()->PublishInStudy(
457 aStudy, SALOMEDS::SObject::_nil(), anObj, aPublishObjName );
459 GEOM_Displayer().Display( anObj.in() );
466 QAD_MessageBox::error1( QAD_Application::getDesktop(),
467 QObject::tr( "GEOM_ERROR" ),
468 QObject::tr("GEOM_PRP_ABORT") + "\n" + QString( aInsOp->GetErrorCode() ),
469 QObject::tr("BUT_OK") );
472 catch(const SALOME::SALOME_Exception& S_ex) {
473 QtCatchCorbaException(S_ex);
482 //=====================================================================================
484 // purpose : BRep, Iges, Step
485 //=====================================================================================
486 bool GEOMToolsGUI::Export()
488 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
489 GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGUI()->GetGeomGen()->GetIInsertOperations( aStudy->StudyId() );
490 if ( aInsOp->_is_nil() )
493 // Obtain a list of available export formats
495 GEOM::string_array_var aFormats, aPatterns;
496 aInsOp->ExportTranslators( aFormats, aPatterns );
497 for ( int i = 0, n = aFormats->length(); i < n; i++ )
498 aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
500 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
501 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
503 for(;It.More();It.Next()) {
504 Handle(SALOME_InteractiveObject) IObject = It.Value();
505 Standard_Boolean found;
506 GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject(IObject, found);
508 if ( !found || anObj->_is_nil() )
512 QString file = getFileName(QAD_Application::getDesktop(),
513 QString( IObject->getName() ),
515 tr("GEOM_MEN_EXPORT"),
519 // User has pressed "Cancel" --> stop the operation
520 if ( file.isEmpty() || fileType.isEmpty() )
523 // Standard_Boolean result = BRepTools::Write(Shape->Shape(), strdup(file.latin1()) );
526 aInsOp->Export( anObj, file, fileType.latin1() );
527 if ( !aInsOp->IsDone() ) {
529 QAD_MessageBox::error1( QAD_Application::getDesktop(),
530 QObject::tr( "GEOM_ERROR" ),
531 QObject::tr("GEOM_PRP_ABORT") + "\n" + QString( aInsOp->GetErrorCode() ),
532 QObject::tr("BUT_OK") );
536 catch (const SALOME::SALOME_Exception& S_ex) {
537 QtCatchCorbaException(S_ex);
545 //=====================================================================================
547 //=====================================================================================
552 return GEOMToolsGUI::GetGEOMToolsGUI();