1 // Copyright (C) 2009-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // #include <Python.h>
27 // #include "klinkitemselectionmodel.h"
30 #include <QInputDialog>
32 #include <QStackedWidget>
36 #include <QtxTreeView.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_ViewManager.h>
42 #include <SUIT_ViewWindow.h>
43 #include <SUIT_DataObject.h>
44 #include <SUIT_DataBrowser.h>
45 #include <SUIT_FileDlg.h>
47 // #include <QxScene_ViewManager.h>
48 #include <SVTK_ViewManager.h>
49 #include <SVTK_ViewModel.h>
50 #include <SVTK_ViewWindow.h>
52 #include <VTKViewer_ViewModel.h>
54 #include <vtkActorCollection.h>
55 #include <VTKViewer_Algorithm.h>
56 #include <vtkRenderer.h>
60 #include <SOCC_ViewModel.h>
61 #include <SOCC_ViewWindow.h>
62 #include <OCCViewer_ViewWindow.h>
64 #include <GEOM_Constants.h>
67 // SALOME KERNEL includes
68 #include <SALOMEDS_Study.hxx>
69 #include <SALOMEDSClient_StudyBuilder.hxx>
70 #include <SALOMEDSClient_SComponent.hxx>
71 #include <SALOMEDSClient_ClientFactory.hxx>
72 #include <SALOMEDSClient_IParameters.hxx>
76 #include <SalomeApp_Study.h>
77 #include <SalomeApp_Module.h>
78 #include <SalomeApp_Application.h>
79 #include <SalomeApp_DataModel.h>
82 #include <SALOME_ListIO.hxx>
83 #include <SALOME_ListIteratorOfListIO.hxx>
86 #include <SALOME_LifeCycleCORBA.hxx>
88 #include <LightApp_VTKSelector.h>
90 #include <OCCViewer_ViewManager.h>
92 #include <GeometryGUI.h>
94 #include <QtxPopupMgr.h>
97 #include "Resource.hxx"
98 // #include "QtGuiContext.hxx"
100 #include "HEXABLOCKGUI.hxx"
101 #include "HEXABLOCKGUI_Export.hxx"
102 #include "HEXABLOCKGUI_Trace.hxx"
103 #include "HEXABLOCKGUI_Resource.hxx"
104 #include "GEOMBase.h"
105 // #include "HEXABLOCKGUI_DataModel.hxx"
107 #include "HEXABLOCKGUI_DocumentModel.hxx"
108 #include "HEXABLOCKGUI_DocumentSelectionModel.hxx"
109 #include "HEXABLOCKGUI_DocumentDelegate.hxx"
110 #include "HEXABLOCKGUI_DocumentPanel.hxx"
111 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
112 #include "HEXABLOCKGUI_OccGraphicView.hxx"
113 #include "HEXABLOCKGUI_GraphicViewsHandler.hxx"
115 #include <HEXABLOCK_version.h>
117 #include "MyBasicGUI_PointDlg.hxx"
119 // #include CORBA_CLIENT_HEADER(HEXABLOCKPlugin_Algorithm)
121 #include "HEXABLOCK.hxx"
122 #include "HexDocument_impl.hxx"
126 #define DW_MINIMUM_WIDTH 50
127 #define DWINPUT_MINIMUM_HEIGHT 50
128 #define DWINPUT_MINIMUM_WIDTH 50//255
131 using namespace HEXABLOCK::GUI;
133 int HEXABLOCKGUI::_oldStudyId = -1;
134 //bool jepeux = false;
136 HEXABLOCK_ORB::HEXABLOCK_Gen_var HEXABLOCKGUI::_hexaEngine = HEXABLOCK_ORB::HEXABLOCK_Gen::_nil();
137 // SMESH::SMESH_Gen_var HEXABLOCKGUI::_smeshEngine = SMESH::SMESH_Gen::_nil();
138 GEOM::GEOM_Gen_var HEXABLOCKGUI::_geomEngine = GEOM::GEOM_Gen::_nil();
140 // std::map<HEXABLOCK::GUI::DocumentModel*, SVTK_ViewWindow*> HEXABLOCKGUI::svtkViews;
141 // std::map<const QAbstractItemModel*, SVTK_ViewWindow*> HEXABLOCKGUI::svtkViews;
142 // std::map<const QAbstractItemModel*, SUIT_ViewWindow*> HEXABLOCKGUI::salomeViews;
143 // HEXABLOCK::GUI::DocumentModel *HEXABLOCKGUI::getCurrentModel() = NULL;
145 VtkDocumentGraphicView* HEXABLOCKGUI::currentDocGView = NULL;
146 OccGraphicView* HEXABLOCKGUI::currentOccGView = NULL;
147 MyGEOMBase_Helper* HEXABLOCKGUI::geomBaseHelper = NULL;
148 bool HEXABLOCKGUI::assocInProgress = false;
149 SalomeApp_Application* HEXABLOCKGUI::myApplication = NULL;
150 GEOMGUI_OCCSelector* HEXABLOCKGUI::currentOccSelector = NULL;
152 HEXABLOCKGUI::HEXABLOCKGUI() :
153 SalomeApp_Module( "HEXABLOCK" ), // default name
161 _patternDataTreeView(0),
162 _patternBuilderTreeView(0),
163 _patternGeomTreeView(0),
164 _associationTreeView(0),
167 _treeViewDelegate(0),
169 moduleActivatedOnce(false),
178 _makeCylinderDiag(0),
180 _makeCylindersDiag(0),
188 _makeTransformationDiag(0),
189 _makeSymmetryDiag(0),
190 _performTransformationDiag(0),
191 _performSymmetryDiag(0),
200 _quadRevolutionDiag(0),
201 _makeHemiSphereDiag(0),
202 _modelInfoDiag(NULL),
206 DEBTRACE("HEXABLOCKGUI::HEXABLOCKGUI");
207 // _studyContextMap.clear();
208 graphicViewsHandler = new GraphicViewsHandler();
209 loadDocLastPath = new QDir();
210 saveDocLastPath = new QDir();
213 HEXABLOCKGUI::~HEXABLOCKGUI()
216 // disconnect( getApp(), SIGNAL(studyClosed()), _genericGui, SLOT (onCleanOnExit()));
220 SalomeApp_Study* HEXABLOCKGUI::activeStudy()
222 SUIT_Application* app = SUIT_Session::session()->activeApplication();
224 return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
230 // Gets an reference to the module's engine
231 HEXABLOCK_ORB::HEXABLOCK_Gen_ptr HEXABLOCKGUI::InitHEXABLOCKGen( SalomeApp_Application* app )
233 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer", "HEXABLOCK" );
234 HEXABLOCK_ORB::HEXABLOCK_Gen_ptr clr = HEXABLOCK_ORB::HEXABLOCK_Gen::_narrow(comp);
235 ASSERT(!CORBA::is_nil(clr));
239 // // Gets an reference to SMESH's engine CS_TO_DELETE
240 // SMESH::SMESH_Gen_ptr HEXABLOCKGUI::InitSMESHGen( SalomeApp_Application* app,
241 // const std::string& container )
243 // Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( container.c_str(), "SMESH" );
244 // SMESH::SMESH_Gen_ptr clr = SMESH::SMESH_Gen::_narrow(comp);
245 // ASSERT(!CORBA::is_nil(clr));
249 // // Gets an reference to GEOM's engine CS_TO_DELETE
250 GEOM::GEOM_Gen_ptr HEXABLOCKGUI::InitGEOMGen( SalomeApp_Application* app,
251 const std::string& container )
253 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( container.c_str(), "GEOM" );
254 GEOM::GEOM_Gen_ptr clr = GEOM::GEOM_Gen::_narrow(comp);
255 ASSERT(!CORBA::is_nil(clr));
260 void HEXABLOCKGUI::initialize( CAM_Application* app )
262 DEBTRACE("HEXABLOCKGUI::initialize");
263 SalomeApp_Module::initialize( app );
265 _hexaEngine = InitHEXABLOCKGen( dynamic_cast<SalomeApp_Application*>( app ) );
266 _geomEngine = InitGEOMGen( dynamic_cast<SalomeApp_Application*>( app ) );
268 DEBTRACE(app << " " << application() << " " << application()->desktop() << " " << aParent);
270 SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
271 setResource(aResourceMgr);
273 createAndFillDockWidget();
278 // add component to study
279 // if (createSComponent()) updateObjBrowser()
280 // createSComponent();
282 if (_dwInputPanel != NULL)
283 geomBaseHelper = new MyGEOMBase_Helper(dynamic_cast<SUIT_Desktop*>(_dwInputPanel->parent()));
286 void HEXABLOCKGUI::viewManagers( QStringList& list ) const
288 DEBTRACE("HEXABLOCKGUI::viewManagers");
289 // foreach (const QString &str, list)
290 // MESSAGE("HEXABLOCKGUI::viewManagers"<<str.toStdString() );
291 // list.append( QxScene_Viewer::Type() );
292 // list.append( OCCViewer_Viewer::Type() );
293 // list.append( SVTK_Viewer::Type() );
296 void HEXABLOCKGUI::restoreGraphicViews()
300 if (currentOccGView == NULL)
302 currentOccGView = new OccGraphicView(graphicViewsHandler->createOccWindow(),
303 application()->desktop());
304 currentOccGView->getViewWindow()->installEventFilter(this);
306 else if (currentOccGView->getViewWindow() == NULL)
308 currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
309 currentOccGView->getViewWindow()->installEventFilter(this);
314 if (currentDocGView == NULL)
316 else if (currentDocGView->getViewWindow() == NULL)
318 currentDocGView->setViewWindow(graphicViewsHandler->createVtkWindow());
319 currentDocGView->getViewWindow()->installEventFilter(this);
325 bool HEXABLOCKGUI::activateModule( SUIT_Study* theStudy )
327 DEBTRACE("HEXABLOCKGUI::activateModule");
329 /*HexaBlock can be launched in only one application*/
330 if (myApplication == NULL)
331 //remember the first application
332 myApplication = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
334 //application verification: if it's not the one known by HexaBlock,
335 //leave without activating
336 SalomeApp_Application* currentApplication = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
337 if (myApplication != currentApplication) return false;
339 bool bOk = SalomeApp_Module::activateModule( theStudy );
340 if ( !bOk ) return false;
342 // setMenuShown( true );
343 // setToolShown( true );
344 // showDockWidgets(false);
345 showDockWidgets(true);
347 connect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
348 this, SLOT(onWindowActivated( SUIT_ViewWindow* )), Qt::UniqueConnection );
349 connect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
350 this, SLOT( onObjectBrowserClick(const QModelIndex&) ), Qt::UniqueConnection );
351 // connect( getApp(), SIGNAL(studyClosed()), _genericGui,SLOT (onCleanOnExit()));
353 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
355 SUIT_ViewManager* vm;
356 ViewManagerList OCCViewManagers, VTKViewManagers;
358 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
359 QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
360 while ( itOCC.hasNext() && (vm = itOCC.next()) )
361 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
363 application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
364 QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
365 while ( itVTK.hasNext() && (vm = itVTK.next()) )
366 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
369 SALOME_ListIO selected;
370 sm->selectedObjects( selected );
373 // disable OCC selectors
374 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
375 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
376 while ( itOCCSel.hasNext() )
377 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
378 sr->setEnabled(true);
380 // disable VTK selectors
381 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
382 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
383 while ( itVTKSel.hasNext() )
384 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
385 sr->setEnabled(true);
387 sm->setSelectedObjects( selected, true ); //NPAL 19674
389 //connect close signal to vtk view manager
390 vm = getApp()->getViewManager(SVTK_Viewer::Type(), false);
393 connect( vm, SIGNAL( tryCloseView( SUIT_ViewWindow * ) ),
394 this, SLOT( onWindowClosed(SUIT_ViewWindow *) ), Qt::UniqueConnection );
397 //connect close signal to occ view manager
398 vm = getApp()->getViewManager(OCCViewer_Viewer::Type(), false);
401 connect( vm, SIGNAL( tryCloseView( SUIT_ViewWindow * ) ),
402 this, SLOT( onWindowClosed(SUIT_ViewWindow *) ), Qt::UniqueConnection );
405 _hexaEngine->SetCurrentStudy(SALOMEDS::Study::_nil());
406 if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( theStudy ))
407 if ( _PTR(Study) aStudy = s->studyDS()) {
408 //define _CAST(Class, shared_ptr_Obj) dynamic_cast<SALOMEDS_##Class*>(shared_ptr_Obj.get())
409 _hexaEngine->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
410 updateObjBrowser(); // objects can be removed
413 if (currentOccGView != NULL && currentOccGView->getViewWindow() != NULL)
414 currentOccGView->getViewWindow()->installEventFilter(this);
417 if (currentDocGView != NULL)
419 switchModel(currentDocGView);
422 if (currentDocGView->getViewWindow() != NULL)
423 currentDocGView->getViewWindow()->installEventFilter(this);
432 bool HEXABLOCKGUI::deactivateModule( SUIT_Study* theStudy )
434 disconnect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
435 this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
436 disconnect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
437 this, SLOT( onObjectBrowserClick(const QModelIndex&) ) );
438 // connect( getApp(), SIGNAL(studyClosed()), _genericGui,SLOT (onCleanOnExit()));
441 if ( currentDocGView != NULL && currentDocGView->getViewWindow() != NULL )
442 //default selectionMode in VTKView
443 currentDocGView->getViewWindow()->SetSelectionMode( ActorSelection );
445 if (currentOccGView != NULL && currentOccGView->getViewWindow() != NULL)
447 //defaut selectionMode in OccView
448 getApp()->selectionMgr()->clearSelected();
449 geomBaseHelper->globalSelection(currentOccGView->getViewWindow());
450 // geomBaseHelper->localSelection(GEOM::GEOM_Object::_nil(), TopAbs_SHAPE);
451 if (currentOccGView != NULL)
452 geomBaseHelper->localSelection(currentOccGView->getViewWindow(), TopAbs_SHAPE);
455 qDeleteAll(myOCCSelectors);
456 myOCCSelectors.clear();
457 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
459 qDeleteAll(myVTKSelectors);
460 myVTKSelectors.clear();
461 getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
463 bool bOk = SalomeApp_Module::deactivateModule( theStudy );
465 //Must be done for all views later
466 if (currentOccGView != NULL && currentOccGView->getViewWindow() != NULL)
467 currentOccGView->getViewWindow()->removeEventFilter(this);
469 if (currentDocGView != NULL && currentDocGView->getViewWindow() != NULL)
470 currentDocGView->getViewWindow()->removeEventFilter(this);
472 //switch off current document graphic view
473 switchOffGraphicView(currentDocGView);
476 setMenuShown( false );
477 setToolShown( false );
478 showDockWidgets( false );
479 if (_dwInputPanel) _dwInputPanel->close();
481 //hide the current document actor
487 QString HEXABLOCKGUI::addInStudy(QString& fileName)
489 QString objStudyEntry;
491 if ( !fileName.isEmpty() ) {
493 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication());
494 SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : NULL;
495 if(!appStudy) return objStudyEntry;
497 _PTR(Study) aStudy = appStudy->studyDS();
498 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy );
500 GEOM::GEOM_IInsertOperations_var aInsOp = _geomEngine->GetIInsertOperations( aStudy->StudyId() );
501 GEOM::GEOM_Object_var anObj = aInsOp->ImportFile(fileName.toStdString().c_str(), "BREP");
502 if ( !anObj->_is_nil() && aInsOp->IsDone() )
504 QStringList sList = fileName.split(".");
505 SALOMEDS::SObject_var aSO = _geomEngine->PublishInStudy( aDSStudy,
506 SALOMEDS::SObject::_nil(),
508 sList[0].toStdString().c_str() );
509 objStudyEntry = aSO->GetID();
512 return objStudyEntry;
515 bool HEXABLOCKGUI::renameAllowed( const QString& entry) const
517 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
518 SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
519 SalomeApp_DataObject* obj = appStudy ? dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry)) : 0;
521 return (app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference());
525 bool HEXABLOCKGUI::renameObject( const QString& entry, const QString& name)
529 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication());
530 SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
535 _PTR(Study) aStudy = appStudy->studyDS();
540 _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
541 _PTR(GenericAttribute) anAttr;
543 if ( obj->FindAttribute(anAttr, "AttributeName") ){
544 _PTR(AttributeName) aName (anAttr);
545 // GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
547 // HEXABLOCK_Gen_i::Document_var aDoc = HEXABLOCK_Gen_i::Document::_narrow( theIOR );
548 // if (!CORBA::is_nil(aDoc)) {
549 // aName->SetValue( name.toLatin1().data() ); // rename the SObject
550 // aDoc->setName( name.toLatin1().data() ); // Rename the corresponding GEOM_Object
551 DocumentModel* currentModel = getCurrentModel();
552 if (currentModel == NULL) return result;
553 currentModel->setName( name/*.toLatin1().data()*/ );
554 aName->SetValue( getCurrentModel()->getName().toLatin1().data() );
555 // _currentGraphicView->setWindowTitle( getCurrentModel()->getName() );
562 // --- Default windows
563 void HEXABLOCKGUI::windows( QMap<int, int>& theMap ) const
565 DEBTRACE("HEXABLOCKGUI::windows");
567 theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
568 theMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
572 // QString HEXABLOCKGUI::engineIOR() const
574 // DEBTRACE("HEXABLOCKGUI::engineIOR");
575 // // return getApp()->defaultEngineIOR();
579 QString HEXABLOCKGUI::engineIOR() const
581 DEBTRACE("HEXABLOCKGUI::engineIOR");
582 CORBA::ORB_var anORB = getApp()->orb();
583 CORBA::String_var anIOR = anORB->object_to_string(_hexaEngine);
584 return QString( anIOR.in() );
588 VtkDocumentGraphicView* HEXABLOCKGUI::getDocument(SalomeApp_DataObject* studyObject)
590 if (docs.count(studyObject->entry()) == 0)
592 //Object's document not acquired yet
593 VtkDocumentGraphicView* dgview;
594 HEXA_NS::Hex* directory = HEXA_NS::Hex::getInstance();
595 if (directory == NULL)
596 return NULL; //No working director found
598 //------------------ Load the document -----------------
599 HEXA_NS::Document* document = directory->findDocument(studyObject->name().toStdString());
600 if (document == NULL) return NULL; //No document found
602 DocumentModel* docModel = new DocumentModel(document, studyObject->entry(), this );
604 MESSAGE("Doc model creation failed!");
607 dgview = graphicViewsHandler->createDocumentGraphicView(
610 application()->desktop() );
611 if (dgview == NULL) return NULL;
613 //update the data tree
614 // dgview->loadDocument();
615 docs[studyObject->entry()] = dgview;
618 return docs[studyObject->entry()];
623 void HEXABLOCKGUI::onObjectBrowserClick(const QModelIndex& index)
625 DEBTRACE("HEXABLOCKGUI::onObjectBrowserClick");
626 // we want to switch automatically to the right view windows
627 // QWidget *viewWindow = NULL;
629 //first, find selected item
631 DataObjectList dol = getApp()->objectBrowser()->getSelected();
632 if (dol.isEmpty()) return;
633 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
634 if (!item || item->parent()->name().compare(tr("HEXABLOCK")) != 0) return;
635 VtkDocumentGraphicView* docGView = getDocument(item);
636 if (docGView == NULL)
638 // currentDocGView = NULL;
642 //Init OCC if necessary
643 if (currentOccGView == NULL)
645 currentOccGView = new OccGraphicView(graphicViewsHandler->createOccWindow(),
646 application()->desktop());
647 currentOccGView->getViewWindow()->installEventFilter(this);
649 else if (currentOccGView->getViewWindow() == NULL)
651 currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
652 currentOccGView->getViewWindow()->installEventFilter(this);
655 //Init the vtk view if necessary
656 if (docGView->getViewWindow() == NULL)
658 if (currentDocGView == NULL || currentDocGView->getViewWindow() == NULL)
660 docGView->setViewWindow(graphicViewsHandler->createVtkWindow());
661 docGView->getViewWindow()->installEventFilter(this);
664 docGView->setViewWindow(currentDocGView->getViewWindow());
666 if (docGView->getDocumentActor() == NULL) docGView->update();
669 // setOpen (const QModelIndex &theObject, const bool theOpen=true)
670 // updateTree (SUIT_DataObject *=0, const bool=true)
671 //update the current document
672 switchModel(docGView);
677 void HEXABLOCKGUI::onWindowActivated( SUIT_ViewWindow* svw)
679 DEBTRACE("HEXABLOCKGUI::onWindowActivated");
680 // OCCViewer_ViewWindow* anOccVw = dynamic_cast<OCCViewer_ViewWindow*>(svw);
682 //update the current occ view
683 // if (anOccVw != NULL)
684 // currentOccGView->getViewWindow() = anOccVw;
686 //set event filter for the occ view
687 // if (currentOccGView != NULL && currentOccGView->getViewWindow() != NULL)
688 // currentOccGView->getViewWindow()->installEventFilter(this);
690 // we want to switch automatically to the right model
692 // SVTK_ViewWindow* viewWindow = dynamic_cast<SVTK_ViewWindow*>(svw);
693 // if (viewWindow == NULL) return;
695 // if (getApp()->activeModule() && getApp()->activeModule()->moduleName().compare("HEXABLOCK") != 0) //CS_TODO?
696 // getApp()->activateModule("HEXABLOCK");
698 //update the current model and the current vtk view
699 // switchModel( viewWindow );
702 void HEXABLOCKGUI::onWindowClosed( SUIT_ViewWindow* svw)
704 DEBTRACE("HEXABLOCKGUI::onWindowClosed");
707 //Decharger le model correspondant (VTK)
708 SVTK_ViewWindow* window = dynamic_cast<SVTK_ViewWindow*>(svw);
713 if (currentDocGView != NULL && currentDocGView->getViewWindow() == window)
714 { //HexaBlock Vtk Window has been closed
716 if (currentDialog != NULL) currentDialog->close();
717 if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
718 if (currentDocGView != NULL)
719 currentDocGView->setViewWindow(NULL);
726 /*VtkDocumentGraphicView* dgview = graphicViewsHandler->getDocumentGraphicView(window);
727 if (dgview == NULL) return; //The window has no document to close
729 //Save the document? (Ask only if the document is not empty
730 int answerCode = SUIT_MessageBox::question(
733 tr("Save the document ?"),
734 SUIT_MessageBox::Yes | SUIT_MessageBox::Cancel,
735 SUIT_MessageBox::Cancel);
736 if ( answerCode == SUIT_MessageBox::Cancel) return; //abort closing
737 else if (answerCode == SUIT_MessageBox::Yes)
738 saveDocument(); //Save the document
740 // switchOffGraphicView(window); //disconnect all connected signals
741 // currentVtkView = NULL;
742 // graphicViewsHandler->closeDocumentGraphicView(window);
744 //create a new one (empty document)
746 // currentVtkView->setWindowTitle(tr("HEXABLOCK") + " : " + currentVtkView->windowTitle());
750 if (currentOccGView != NULL && svw == currentOccGView->getViewWindow())
752 if (_vertexAssocDiag != NULL) _vertexAssocDiag->clear();
753 if (_edgeAssocDiag != NULL) _edgeAssocDiag->clear();
754 if (_quadAssocDiag != NULL) _quadAssocDiag->clear();
755 if (currentDialog != NULL) currentDialog->close();
756 if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
758 currentOccGView->getViewWindow()->removeEventFilter(this);
759 currentOccGView->setViewWindow(NULL);
763 void HEXABLOCKGUI::onViewManagerAdded( SUIT_ViewManager* vm)
765 DEBTRACE("HEXABLOCKGUI::onViewManagerAdded");
767 connect( vm, SIGNAL( tryCloseView( SUIT_ViewWindow * ) ),
768 this, SLOT( onWindowClosed(SUIT_ViewWindow *) ), Qt::UniqueConnection );
770 if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
772 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
773 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
775 // disable OCC selectors
776 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
777 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
778 while ( itOCCSel.hasNext() )
779 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
780 sr->setEnabled(true);
782 else if ( vm->getType() == SVTK_Viewer::Type() )
784 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
785 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
787 // disable VTK selectors
788 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
789 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
790 while ( itVTKSel.hasNext() )
791 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
792 sr->setEnabled(true);
796 void HEXABLOCKGUI::onViewManagerRemoved( SUIT_ViewManager* vm)
798 DEBTRACE("HEXABLOCKGUI::::onViewManagerRemoved");
800 SUIT_ViewModel* viewer = vm->getViewModel();
801 if (vm != NULL && vm->getType() == SVTK_Viewer::Type())
803 //VTK View Manager removed
804 if (getApp()->activeModule()->moduleName().compare("HEXABLOCK") == 0)
806 //Process only if it's our view manager
807 SUIT_ViewManager* myVm = NULL;
808 if (currentDocGView != NULL && currentDocGView->getViewWindow() != NULL)
809 myVm = currentDocGView->getViewWindow()->getViewManager();
813 //close opened dialog
814 if (currentDialog != NULL) currentDialog->close();
815 if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
821 //remove its selector
822 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
823 while ( itVTKSel.hasNext() )
824 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
825 if ( sr->viewer() == viewer )
827 delete myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
834 if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
836 //OCC View removed: remove its selector
837 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
838 while ( itOCCSel.hasNext() )
839 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
840 if ( sr->viewer() == viewer )
842 delete myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
848 void HEXABLOCKGUI::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
850 QModelIndexList l = selected.indexes();
851 if ( l.count() == 0 ) return;
852 if ( !l[0].isValid() ) return;
853 VtkDocumentGraphicView* currentGraphicView = getCurrentVtkGraphicView();
854 if ( currentGraphicView == NULL) return;
856 QTreeView* theTree = NULL;
857 if ( sender() == currentGraphicView->getPatternDataSelectionModel() ){
858 theTree = _patternDataTreeView;
859 } else if ( sender() == currentGraphicView->getPatternBuilderSelectionModel() ){
860 theTree = _patternBuilderTreeView;
861 } else if ( sender() == currentGraphicView->getPatternGeomSelectionModel() ) {
862 theTree = _patternGeomTreeView;
864 else if ( sender() == currentGraphicView->getGroupsSelectionModel() ){
865 theTree = _groupsTreeView;
866 } else if ( sender() == currentGraphicView->getMeshSelectionModel() ){
867 theTree = _meshTreeView;
870 theTree->scrollTo ( l[0] );
874 // void HEXABLOCKGUI::onTryClose(bool &isClosed, QxScene_ViewWindow* window) //CS_TODO
876 // DEBTRACE("HEXABLOCKGUI::onTryClose");
877 // isClosed = _genericGui->closeContext(window);
880 // CAM_DataModel* HEXABLOCKGUI::createDataModel()
882 // DEBTRACE("HEXABLOCKGUI::createDataModel");
883 // return new HEXABLOCKGUI_DataModel(this);
887 bool HEXABLOCKGUI::createSComponent() //addComponent
889 DEBTRACE("HEXABLOCKGUI::createSComponent");
890 // --- Find or create (if not done yet) "HEXABLOCK" SComponent in the study
892 _PTR(Study) aStudy = (( SalomeApp_Study* )(getApp()->activeStudy()))->studyDS();
893 _PTR(StudyBuilder) aBuilder (aStudy->NewBuilder());
894 _PTR(GenericAttribute) anAttr;
895 _PTR(AttributeName) aName;
896 _PTR(AttributeGraphic) aGraphic;
898 _PTR(SComponent) aComponent = aStudy->FindComponent("HEXABLOCK");
899 if ( !aComponent ){ //Create hexablock component if there's not one yet
900 aComponent = aBuilder->NewComponent("HEXABLOCK");
901 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
902 aName = _PTR(AttributeName) (anAttr);
903 aName->SetValue(getApp()->moduleTitle("HEXABLOCK").toStdString());
905 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
906 _PTR(AttributePixMap) aPixmap(anAttr);
907 // aPixmap->SetPixMap("share/salome/resources/hexablock/ModuleHexablock.png");
908 aPixmap->SetPixMap(tr("ICO_MODULE_HEXABLOCK_SMALL").toStdString());
910 aBuilder->DefineComponentInstance(aComponent, engineIOR().toStdString());
911 DEBTRACE("HEXABLOCKGUI::createSComponent engineIOR=>"<<engineIOR().toStdString());
912 // aBuilder->DefineComponentInstance(aComponent, getApp()->defaultEngineIOR().toStdString());
913 // DEBTRACE("HEXABLOCKGUI::createSComponent defaultEngineIOR=>"<<getApp()->defaultEngineIOR().toStdString());
915 // SalomeApp_DataModel::synchronize( aComponent, HEXABLOCKGUI::activeStudy() );
921 // bool HEXABLOCKGUI::isSelectionCompatible()
923 // DEBTRACE("HEXABLOCKGUI::isSelectionCompatible");
925 // bool isCompatible = true;
926 // SALOME_ListIO selected;
927 // if ( LightApp_SelectionMgr *Sel = selectionMgr() )
928 // Sel->selectedObjects( selected );
930 // SALOME_ListIteratorOfListIO It( selected );
931 // for ( ; isCompatible && It.More(); It.Next())
933 // ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
934 // ( strcmp("HEXABLOCK", It.Value()->getComponentDataType()) == 0 );
936 // return isCompatible;
939 void HEXABLOCKGUI::setResource(SUIT_ResourceMgr* r)
941 DEBTRACE("HEXABLOCKGUI::setResource");
942 _myresource = new HEXABLOCKGUI_Resource(r);
943 _myresource->preferencesChanged();
946 void HEXABLOCKGUI::createPreferences()
948 DEBTRACE("HEXABLOCKGUI::createPreferences");
949 _myresource->createPreferences(this);
952 void HEXABLOCKGUI::preferencesChanged( const QString& sect, const QString& name )
954 DEBTRACE("HEXABLOCKGUI::preferencesChanged");
955 _myresource->preferencesChanged(sect, name);
956 if(name=="userCatalog")
958 // _genericGui->getCatalogWidget()->addCatalogFromFile(Resource::userCatalog.toStdString());
962 void HEXABLOCKGUI::studyActivated() //CS_TODO
964 int newStudyId = getApp()->activeStudy()->id();
965 DEBTRACE("HEXABLOCKGUI::studyActivated " << _oldStudyId << " " << newStudyId);
967 if (_oldStudyId != -1)
969 // _studyContextMap[_oldStudyId] = QtGuiContext::getQtCurrent();
970 // if (_studyContextMap.count(newStudyId))
972 // DEBTRACE("switch to valid context " << QtGuiContext::getQtCurrent() << " " << _studyContextMap[newStudyId]);
973 // QtGuiContext::setQtCurrent(_studyContextMap[newStudyId]);
977 // DEBTRACE("no switch to null context");
980 _oldStudyId = newStudyId;
985 void HEXABLOCKGUI::treeContextMenu(const QPoint& aPosition)
987 QModelIndex currentIndex = _patternDataTreeView->currentIndex();
988 QVariant currentAssocVariant;
989 QString currentAssocEntry;
991 currentAssocVariant = currentIndex.data( HEXA_ASSOC_ENTRY_ROLE );
992 currentAssocEntry = currentIndex.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
993 if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() ){
994 // getCurrentModel()->allowEdition();
995 QMenu menu( _patternDataTreeView );
997 QAction *clearAct = menu.addAction( "Remove association(s)" );
998 connect( clearAct, SIGNAL(triggered()), this, SLOT(clearAssociations()), Qt::UniqueConnection );
999 menu.exec( _patternDataTreeView->mapToGlobal( aPosition) );
1003 VtkDocumentGraphicView* currentVtkGraphicView = getCurrentVtkGraphicView();
1004 if (currentVtkGraphicView == NULL) return;
1005 QStandardItem *item = currentVtkGraphicView->getPatternDataModel()->itemFromIndex(currentIndex);
1007 //We don't do anything for single items
1008 if ( item->type() == VERTEXITEM || item->type() == EDGEITEM ||
1009 item->type() == QUADITEM || item->type() == HEXAITEM)
1012 //No associations for HEXA
1013 QVariant treeVariant = currentIndex.data( HEXA_TREE_ROLE );
1014 if ( !treeVariant.isValid() ) return;
1015 int eltType = treeVariant.toInt();
1016 if (eltType == HEXA_DIR_TREE) return;
1017 QMenu menu( _patternDataTreeView );
1019 //Show association(s)
1020 QAction *showAssocAct = menu.addAction( "Show associations" );
1021 connect( showAssocAct, SIGNAL(triggered()), this, SLOT(showAssociations()), Qt::UniqueConnection );
1023 //Clear all associations
1024 QAction *clearAllAssocAct = menu.addAction( "Remove all associations" );
1025 connect( clearAllAssocAct, SIGNAL(triggered()), this, SLOT(clearAllAssociations()), Qt::UniqueConnection );
1027 menu.exec( _patternDataTreeView->mapToGlobal( aPosition) );
1032 void HEXABLOCKGUI::createAndFillDockWidget()
1034 QMainWindow *aParent = application()->desktop();
1036 // Create dock widget (3 dock)
1038 //1) *********** user input panel ( contain user's edit dialog box )
1039 _dwInputPanel = new QDockWidget(aParent);
1040 // QLayout* inputLayout = new QVBoxLayout(aParent);
1041 // _dwInputPanel->setLayout(inputLayout);
1042 // _dwInputPanel->setWindowFlags(Qt::FramelessWindowHint);
1043 // _dwInputPanel->setWindowFlags(Qt::WindowTitleHint);
1044 _dwInputPanel->setVisible(false);
1045 _dwInputPanel->setWindowTitle("Input Panel");
1046 // _dwInputPanel->setMinimumHeight(DWINPUT_MINIMUM_HEIGHT);
1047 _dwInputPanel->setMinimumWidth(DWINPUT_MINIMUM_WIDTH); // --- force a minimum until display
1048 // _dwInputPanel->raise();
1050 // _stacked = new QStackedWidget(_dwInputPanel);
1051 // _dwInputPanel->setWidget(_stacked);
1053 _treeViewDelegate = new DocumentDelegate(_dwInputPanel);
1055 //2) ************* document data ( Pattern, Association, Mesh ) in treeview representation
1057 _dwPattern = new QDockWidget(aParent);
1058 // _dwPattern->installEventFilter(this);
1059 _dwPattern->setVisible(false);
1060 _dwPattern->setWindowTitle("Model");
1061 _dwPattern->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
1063 QFrame* patternFrame = new QFrame(_dwPattern);
1064 patternFrame->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
1065 QVBoxLayout* patternLayout = new QVBoxLayout(patternFrame);
1066 patternLayout->setSizeConstraint(QLayout::SetMaximumSize);
1067 QSplitter *splitter = new QSplitter(Qt::Vertical,patternFrame);
1068 _patternDataTreeView = new QTreeView(patternFrame);//_dwPattern);
1069 _patternBuilderTreeView = new QTreeView(patternFrame);
1070 _patternGeomTreeView = new QTreeView(patternFrame);
1071 splitter->addWidget(_patternDataTreeView);
1072 splitter->addWidget(_patternBuilderTreeView);
1073 splitter->addWidget(_patternGeomTreeView);
1074 patternLayout->addWidget(splitter);
1075 // _patternDataTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
1077 _patternDataTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers/*QAbstractItemView::DoubleClicked*/);
1078 _patternDataTreeView->setSelectionMode(QAbstractItemView::SingleSelection/*QAbstractItemView::MultiSelection*/);//);//QAbstractItemView::DoubleClicked, QAbstractItemView::SelectedClicked)
1079 _patternDataTreeView->setItemDelegate(_treeViewDelegate);
1082 _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1083 _patternBuilderTreeView->setItemDelegate(_treeViewDelegate);
1085 _patternGeomTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1086 _patternGeomTreeView->setSelectionMode(QAbstractItemView::SingleSelection/*QAbstractItemView::MultiSelection*/);
1088 _dwPattern->setWidget(patternFrame);
1089 patternFrame->show();
1090 //_dwPattern->raise();
1093 _dwGroups = new QDockWidget(aParent);
1094 // _dwGroups->installEventFilter(this);
1096 _dwGroups->setVisible(false);
1097 _dwGroups->setWindowTitle("Groups");
1098 _dwGroups->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
1099 _groupsTreeView = new QTreeView(_dwGroups);
1100 // _associationTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
1101 _groupsTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1102 _groupsTreeView->setItemDelegate(_treeViewDelegate);
1103 _dwGroups->setWidget(_groupsTreeView);
1104 _groupsTreeView->show();
1107 _dwMesh = new QDockWidget(aParent);
1108 // _dwMesh->installEventFilter(this);
1109 _dwMesh->setVisible(false);
1110 _dwMesh->setWindowTitle("Mesh");
1111 _dwMesh->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
1112 _meshTreeView = new QTreeView(_dwMesh);
1113 // _meshTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
1114 _meshTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1115 _meshTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
1116 _meshTreeView->setItemDelegate(_treeViewDelegate);
1117 _dwMesh->setWidget(_meshTreeView);
1118 _meshTreeView->show();
1119 // _dwMesh->raise();
1123 //3) ************* documents ( salome objectbrowser )
1124 QDockWidget *_dwObjectBrowser = 0;
1125 QWidget* wid = getApp()->objectBrowser()->treeView();
1126 // QWidget *wid = application()->objectBrowser()->treeView();
1127 QWidget *w = wid->parentWidget();
1128 while ( w && !_dwObjectBrowser ) {
1129 _dwObjectBrowser = ::qobject_cast<QDockWidget*>( w );
1130 w = w->parentWidget();
1132 // _dwObjectBrowser->installEventFilter(this);
1133 // _dwObjectBrowser->setVisible(false);
1134 _dwObjectBrowser->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
1135 _dwObjectBrowser->setWindowTitle("Study");
1138 // dock widget position
1139 // aParent->addDockWidget(Qt::LeftDockWidgetArea, _dwPattern);
1140 // aParent->addDockWidget(Qt::RightDockWidgetArea, _dwInputPanel);
1141 // aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwPattern );
1142 aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwObjectBrowser );
1143 aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwInputPanel );
1145 aParent->tabifyDockWidget( _dwObjectBrowser, _dwPattern );
1146 // aParent->tabifyDockWidget( _dwPattern, /*_dwAssociation );
1147 // aParent->tabifyDockWidget( _dwAssociation, */_dwGroups );
1148 aParent->tabifyDockWidget( _dwPattern, _dwGroups );
1149 aParent->tabifyDockWidget( _dwGroups, _dwMesh );
1152 #if QT_VERSION >= 0x040500
1153 aParent->setTabPosition(Qt::AllDockWidgetAreas, Resource::tabPanelsUp? QTabWidget::North: QTabWidget::South);
1157 // connect( _dwPattern, SIGNAL( visibilityChanged(bool) ), this, SLOT( showPatternMenus(bool) ) );
1158 // // connect( _dwAssociation, SIGNAL( visibilityChanged(bool) ), this, SLOT( showAssociationMenus(bool) ) );
1159 // connect( _dwGroups, SIGNAL( visibilityChanged(bool) ), this, SLOT( showGroupsMenus(bool) ) );
1160 // connect( _dwMesh, SIGNAL( visibilityChanged(bool) ), this, SLOT( showMeshMenus(bool) ) );
1162 // popup menu on data tree view
1163 _patternDataTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
1164 connect(_patternDataTreeView,
1165 SIGNAL(customContextMenuRequested(const QPoint &)),
1167 SLOT(treeContextMenu(const QPoint &)), Qt::UniqueConnection);
1170 void HEXABLOCKGUI::createActions()
1172 QMainWindow *aParent = application()->desktop();
1173 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1176 _newAct = createAction(_menuId++,
1177 tr("Create a new document"),
1178 resMgr->loadPixmap("HEXABLOCK", tr("ICON_NEW_DOCUMENT")),
1180 tr("Create a new document"),
1181 0, aParent, false, this, SLOT(newDocument()));
1182 _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1184 _importAct = createAction(_menuId++,
1185 tr("Load a document"),
1186 resMgr->loadPixmap("HEXABLOCK", tr("ICON_LOAD_DOCUMENT")),
1187 tr("Load Document"),
1188 tr("Load a document"),
1189 0, aParent, false, this, SLOT(loadDocument()));
1190 _importAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_O); // --- QKeySequence::Open ambiguous in SALOME
1192 _saveAct = createAction(_menuId++,
1193 tr("Save the document"),
1194 resMgr->loadPixmap("HEXABLOCK", tr("ICON_SAVE_DOCUMENT")),
1195 tr("Save Document"),
1196 tr("Save the document"),
1197 0, aParent, false, this, SLOT(saveDocument()));
1199 // _testAct = createAction(_menuId++, tr("Test"), resMgr->loadPixmap("HEXABLOCK", tr("ICON_TEST")),
1200 // tr("Test"), tr("New test"),
1201 // 0, aParent, false, this, SLOT(test_association()));
1203 // Pattern Data creation
1204 _addVertex = createAction(_menuId++,
1205 tr("Create a vertex"),
1206 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_VERTEX")),
1208 tr("Create a new vertex"),
1209 0, aParent, false, this, SLOT(addVertex()));
1211 _addEdge = createAction(_menuId++,
1212 tr("Create an edge"),
1213 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_EDGE")),
1215 tr("Create a new edge"),
1216 0, aParent, false, this, SLOT(addEdge()));
1218 _addQuad = createAction(_menuId++,
1219 tr("Create a quadrangle"),
1220 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_QUAD")),
1221 tr("Add Quadrangle"),
1222 tr("Create a new quadrangle"),
1223 0, aParent, false, this, SLOT(addQuad()));
1225 _addHexa = createAction(_menuId++,
1226 tr("Create an hexahedron"),
1227 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_HEXA")),
1228 tr("Add Hexahedron"),
1229 tr("Create a new hexahedron"),
1230 0, aParent, false, this, SLOT(addHexa()));
1232 // Builder Data creation
1233 _addVector = createAction(_menuId++,
1234 tr("Create a vector"),
1235 resMgr->loadPixmap( "HEXABLOCK", tr("ICON_ADD_VECTOR")),
1237 tr("Create a new vector"),
1238 0, aParent, false, this, SLOT(addVector()));
1240 _addCylinder = createAction(_menuId++,
1241 tr("Create a cylinder"),
1242 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_CYLINDER")),
1244 tr("Create a new cylinder"),
1245 0, aParent, false, this, SLOT(addCylinder()));
1247 _addPipe = createAction(_menuId++,
1248 tr("Create a pipe"),
1249 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_PIPE")),
1251 tr("Create a new pipe"),
1252 0, aParent, false, this, SLOT(addPipe()));
1254 _makeGrid = createAction(_menuId++,
1256 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_GRID")),
1259 0, aParent, false, this, SLOT(makeGrid()));
1261 _makeCylinder = createAction(_menuId++,
1262 tr("Make a cylinder"),
1263 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDER")),
1264 tr("Make Cylinder"),
1265 tr("Make a cylinder"),
1266 0, aParent, false, this, SLOT(makeCylinder()));
1268 _makePipe = createAction(_menuId++,
1270 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPE")),
1273 0, aParent, false, this, SLOT(makePipe()));
1275 _makeCylinders = createAction(_menuId++,
1276 tr("Make cylinders"),
1277 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDERS")),
1278 tr("Make Cylinders"),
1279 tr("Make cylinders"),
1280 0, aParent, false, this, SLOT(makeCylinders()));
1282 _makePipes = createAction(_menuId++,
1284 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPES")),
1287 0, aParent, false, this, SLOT(makePipes()));
1289 // // _makeRind = createAction( _menuId++, tr("Make rind"), resMgr->loadPixmap( "HEXABLOCK", tr("ICON_MAKE_RIND")),
1290 // // tr("Make rind"), tr("Make rind"),
1291 // // 0, aParent, false, this, SLOT(makeRind()));
1293 _makeHemiSphere = createAction(_menuId++,
1294 tr("Make an hemisphere"),
1295 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_HEMISPHERE")),
1296 tr("Make Hemisphere"),
1297 tr("Make an hemisphere"),
1298 0, aParent, false, this, SLOT(makeHemiSphere()));
1300 // Pattern Data edition
1301 _removeHexa = createAction(_menuId++,
1302 tr("Remove hexahedra"),
1303 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_HEXA")),
1304 tr("Remove Hexahedra"),
1305 tr("Remove hexahedra"),
1306 0, aParent, false, this, SLOT(removeHexa()));
1308 _prismQuad = createAction(_menuId++,
1309 tr("Prism quadrangles"),
1310 resMgr->loadPixmap( "HEXABLOCK", tr("ICON_PRISM_QUAD")),
1311 tr("Prism Quadrangles"),
1312 tr("Prism quadrangles"),
1313 0, aParent, false, this, SLOT(prismQuad()));
1315 _joinQuad = createAction(_menuId++,
1316 tr("Join quadrangles"),
1317 resMgr->loadPixmap("HEXABLOCK", tr("ICON_JOIN_QUAD")),
1318 tr("Join Quadrangles"),
1319 tr("Join quadrangles with hexahedra"),
1320 0, aParent, false, this, SLOT(joinQuad()));
1322 _merge = createAction(_menuId++,
1324 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MERGE")),
1327 0, aParent, false, this, SLOT(merge()));
1329 _disconnect = createAction(_menuId++,
1331 resMgr->loadPixmap("HEXABLOCK", tr("ICON_DISCONNECT")),
1333 tr("Disconnect edges, vertexes or quadrangles"),
1334 0, aParent, false, this, SLOT(disconnectElts()));
1336 _cutEdge = createAction(_menuId++,
1338 resMgr->loadPixmap("HEXABLOCK", tr("ICON_CUT_EDGE")),
1341 0, aParent, false, this, SLOT(cutEdge()));
1343 _makeTransformation = createAction(_menuId++,
1344 tr("Make transformation"),
1345 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_TRANSFORMATION")),
1346 tr("Make Transformation"),
1347 tr("Make transformation"),
1348 0, aParent, false, this, SLOT(makeTransformation()));
1350 _makeSymmetry = createAction(_menuId++,
1351 tr("Make symmetry"),
1352 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_SYMMETRY")),
1353 tr("Make Symmetry"),
1354 tr("Make symmetry"),
1355 0, aParent, false, this, SLOT(makeSymmetry()));
1357 _performTransformation = createAction(_menuId++,
1358 tr("Perform transformation"),
1359 resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_TRANSFORMATION")),
1360 tr("Perform Transformation"),
1361 tr("Perform transformation"),
1362 0, aParent, false, this, SLOT(performTransformation()));
1364 _performSymmetry = createAction(_menuId++,
1365 tr("Perform symmetry"),
1366 resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_SYMMETRY")),
1367 tr("Perform Symmetry"),
1368 tr("Perform symmetry"),
1369 0, aParent, false, this, SLOT(performSymmetry()));
1371 _replaceHexa = createAction(_menuId++,
1372 tr("Replace hexahedron"),
1373 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REPLACE_HEXA")),
1374 tr("Replace Hexahedron"),
1375 tr("Replace hexahedron"),
1376 0, aParent, false, this, SLOT(replaceHexa()));
1378 _quadRevolution = createAction(_menuId++,
1379 tr("Quad revolution"),
1380 resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_REVOLUTION")),
1381 tr("Quad Revolution"),
1382 tr("Quad revolution"),
1383 0, aParent, false, this, SLOT(quadRevolution()));
1386 _assocVertex = createAction(_menuId++,
1387 tr("Make vertex association"),
1388 resMgr->loadPixmap("HEXABLOCK", tr("ICON_VERTEX_ASSOCIATION")),
1389 tr("Make Vertex association"),
1390 tr("Make vertex association"),
1391 0, aParent, false, this, SLOT(assocVertex()));
1393 _assocEdge = createAction(_menuId++,
1394 tr("Make edge association"),
1395 resMgr->loadPixmap("HEXABLOCK", tr("ICON_EDGE_ASSOCIATION")),
1396 tr("Make Edge Association"),
1397 tr("Make edge association"),
1398 0, aParent, false, this, SLOT(assocEdge()));
1400 _assocQuad = createAction(_menuId++,
1401 tr("Make quadrangle association"),
1402 resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_ASSOCIATION")),
1403 tr("Make Quadrangle Association"),
1404 tr("Make quadrangle association"),
1405 0, aParent, false, this, SLOT(assocQuad()));
1408 _addGroup = createAction(_menuId++,
1410 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_GROUP")),
1413 0, aParent, false, this, SLOT(addGroup()));
1415 _removeGroup = createAction(_menuId++,
1416 tr("Remove a group"),
1417 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_GROUP")),
1419 tr("Remove a group"),
1420 0, aParent, false, this, SLOT(removeGroup()));
1423 _addLaw = createAction(_menuId++,
1425 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_LAW")),
1428 0, aParent, false, this, SLOT(addLaw()));
1430 _removeLaw = createAction(_menuId++,
1432 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_LAW")),
1435 0, aParent, false, this, SLOT(removeLaw()));
1437 _setPropagation = createAction(_menuId++,
1438 tr("Set propagation"),
1439 resMgr->loadPixmap("HEXABLOCK", tr("ICON_SET_PROPAGATION")),
1440 tr("Set Propagation"),
1441 tr("Set propagation"),
1442 0, aParent, false, this, SLOT(setPropagation()));
1444 _computeMesh = createAction(_menuId++,
1446 resMgr->loadPixmap("HEXABLOCK", tr("ICON_COMPUTE_MESH")),
1449 0, aParent, false, this, SLOT(computeMesh()));
1452 _showModelInfoAct = createAction(_menuId++,
1453 tr("Show Model Info"),
1455 tr("MODEL_INFO"),//TODO: must be added in translation file
1457 0, aParent, false, this, SLOT(showModelInfo()));
1459 _addShapeAct = createAction(_menuId++,
1462 tr("ADD_SHAPE"),//TODO: must be added in translation file
1464 0, aParent, false, this, SLOT(addShape()));
1467 // _showAct = createAction(_menuId++,
1471 // tr("Show the actor"),
1472 // 0, aParent, false, this, SLOT(showActor()));
1474 // _hideAct = createAction(_menuId++,
1478 // tr("Hide the actor"),
1479 // 0, aParent, false, this, SLOT(hideActor()));
1482 // _showOnlyAct = createAction(_menuId++,
1486 // tr("Show only this actor"),
1487 // 0, aParent, false, this, SLOT(showOnlyActor()));
1490 // _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1491 // QAction* createAction(const int id,
1492 // const QString& toolTip,
1493 // const QIcon& icon,
1494 // const QString& menu,
1495 // const QString& status,
1496 // const int shortCut,
1497 // QObject* parent =0,
1498 // bool checkable = false,
1499 // QObject* receiver =0,
1500 // const char* member =0);
1504 void HEXABLOCKGUI::createMenus()
1506 int aMenuId, subMenuId;
1507 aMenuId = createMenu( tr("MEN_FILE"), -1, -1 );
1508 createMenu( separator(), aMenuId, -1, 10 );
1509 aMenuId = createMenu( tr("HEXABLOCK"), aMenuId, -1, 10 );
1510 createMenu( _newAct, aMenuId );
1511 createMenu( _importAct, aMenuId );
1512 createMenu( _saveAct, aMenuId );
1513 // createMenu( _testAct, aMenuId );
1515 // aMenuId = createMenu( tr( "HEXABLOCK" ), -1, -1, 30 );
1516 aMenuId = createMenu( tr( "Document" ), -1, -1, 30 );
1517 createMenu( _newAct, aMenuId );//, 10
1518 createMenu( _importAct, aMenuId );
1519 createMenu( _saveAct, aMenuId );
1520 // createMenu( _testAct, aMenuId );
1522 aMenuId = createMenu( tr("Model"), -1, -1, 30 );
1523 subMenuId = createMenu( tr( "Construction" ), aMenuId, -1 );
1524 createMenu( _addVertex, subMenuId );
1525 createMenu( _addEdge, subMenuId );
1526 createMenu( _addQuad, subMenuId );
1527 createMenu( _addHexa, subMenuId );
1528 createMenu( separator(), subMenuId );
1531 createMenu( _addVector, subMenuId );
1532 createMenu( _addCylinder, subMenuId );
1533 createMenu( _addPipe, subMenuId );
1534 createMenu( separator(), subMenuId);
1535 createMenu( _makeGrid, subMenuId ); //Cartesian, Cylindrical, Spherical
1536 createMenu( _makeHemiSphere,subMenuId );
1537 createMenu( separator(), subMenuId);
1538 createMenu( _makeCylinder, subMenuId );
1539 createMenu( _makePipe, subMenuId );
1540 createMenu( _makeCylinders,subMenuId );
1541 createMenu( _makePipes, subMenuId );
1542 // createMenu( _makeRind, aMenuId );
1544 // Pattern Data Edition
1545 subMenuId = createMenu( tr( "Operation" ), aMenuId, -1 );
1546 createMenu( _removeHexa, subMenuId );
1547 createMenu( _prismQuad, subMenuId );
1548 createMenu( _joinQuad, subMenuId );
1549 createMenu( _merge, subMenuId );// createMenu( _mergeVertices, aMenuId ); // createMenu( _mergeEdges, aMenuId );
1550 createMenu( _disconnect, subMenuId );
1551 createMenu( _cutEdge, subMenuId );
1552 createMenu( _makeTransformation, subMenuId ); // createMenu( _makeTranslation, aMenuId );
1553 createMenu( _makeSymmetry, subMenuId );
1554 createMenu( _performTransformation, subMenuId );
1555 createMenu( _performSymmetry, subMenuId );
1556 createMenu( _replaceHexa, subMenuId );
1557 createMenu( _quadRevolution, subMenuId );
1560 aMenuId = createMenu( tr("Association"), -1, -1, 30 );
1561 createMenu( _assocVertex, aMenuId );
1562 createMenu( _assocEdge, aMenuId );
1563 createMenu( _assocQuad, aMenuId );
1566 aMenuId = createMenu( tr("Groups"), -1, -1, 30 );
1567 createMenu( _addGroup, aMenuId );
1568 createMenu( _removeGroup, aMenuId ); //CS_TODO
1571 aMenuId = createMenu( tr("Mesh "), -1, -1, 30 );
1572 createMenu( _addLaw, aMenuId );
1573 createMenu( _removeLaw, aMenuId );
1574 createMenu( _setPropagation, aMenuId );
1575 createMenu( _computeMesh, aMenuId );
1577 //show model infomation menu
1578 QString aRule = "$component={'HEXABLOCK'}";
1579 popupMgr()->insert( _showModelInfoAct, -1, -1 ); // link the model information action to context menu
1580 popupMgr()->setRule( _showModelInfoAct, aRule);
1582 //associate shape to a document menu
1583 popupMgr()->insert( _addShapeAct, -1, -1 );
1584 popupMgr()->setRule( _addShapeAct, aRule );
1586 //-------------------------------------------------
1588 //-------------------------------------------------
1589 // QString lc = "$"; // VSR : instead of QtxPopupSelection::defEquality();
1590 // QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
1591 // QString isNotEmpty("numberOfNodes <> 0");
1592 // QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
1593 // QString aType = QString( "%1type in {%2}" ).arg( lc );
1594 //// aType = aType.arg( mesh_part );
1596 // aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
1597 // QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
1598 // QString aSelCount = QString( "%1 > 0" ).arg( dc );
1600 // popupMgr()->insert( separator(), -1, -1 );
1601 // QString aRule = "$component={'HEXABLOCK'}";/* and ( type='(" + aClient + " and " +
1602 // aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";*/
1603 // // MESSAGE("aClient = " << aClient.toStdString());
1604 // // MESSAGE("aType = " << aType.toStdString());
1605 // // MESSAGE("aSelCount = " << aSelCount.toStdString());
1606 // // MESSAGE("anActiveVTK = " << anActiveVTK.toStdString());
1607 // // MESSAGE("isNotEmpty = " << isNotEmpty.toStdString());
1608 // // MESSAGE("aRule = " << aRule.toStdString());
1609 // popupMgr()->insert( _showAct, -1, -1 ); // DISPLAY
1610 // popupMgr()->setRule( _showAct, aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
1612 // popupMgr()->insert( _hideAct, -1, -1 ); // ERASE
1613 // popupMgr()->setRule( _hideAct, aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
1615 // popupMgr()->insert( _showOnlyAct, -1, -1 ); // DISPLAY_ONLY
1616 // popupMgr()->setRule(_showOnlyAct, aRule.arg( "" ), QtxPopupMgr::VisibleRule );
1618 // popupMgr()->insert( separator(), -1, -1 );
1623 void HEXABLOCKGUI::createTools()
1627 aToolId = createTool ( tr( "HexaBlock Toolbar" ) );
1628 createTool( _newAct, aToolId );
1629 createTool( _importAct, aToolId );
1630 createTool( _saveAct, aToolId );
1631 // createTool( _testAct, aToolId );
1632 //createTool( separator(), aToolId );
1635 aToolId = createTool ( tr( "Construction" ) );
1636 createTool( _addVertex, aToolId );
1637 createTool( _addEdge, aToolId );
1638 createTool( _addQuad, aToolId );
1639 createTool( _addHexa, aToolId );
1640 createTool( separator(), aToolId );
1643 createTool( _addVector, aToolId );
1644 createTool( _addCylinder, aToolId );
1645 createTool( _addPipe, aToolId );
1646 createTool( separator(), aToolId );
1648 createTool( _makeGrid, aToolId );
1649 createTool( _makeHemiSphere, aToolId );
1650 createTool( separator(), aToolId );
1651 createTool( _makeCylinder, aToolId );
1652 createTool( _makePipe, aToolId );
1653 createTool( _makeCylinders,aToolId );
1654 createTool( _makePipes, aToolId );
1655 // createTool( _makeRind, aToolId);
1656 // createTool( separator(), aToolId );
1658 // Pattern Data Edition
1659 aToolId = createTool ( tr( "Operation" ) );
1660 createTool( _removeHexa, aToolId );
1661 createTool( _prismQuad, aToolId );
1662 createTool( _joinQuad, aToolId );
1663 createTool( _merge, aToolId );
1664 createTool( _disconnect, aToolId );
1665 createTool( _cutEdge, aToolId );
1666 createTool( _makeTransformation, aToolId );
1667 createTool( _makeSymmetry, aToolId );
1668 createTool( _performTransformation, aToolId );
1669 createTool( _performSymmetry, aToolId );
1670 createTool( _replaceHexa, aToolId );
1671 createTool( _quadRevolution, aToolId );
1672 //createTool( separator(), aToolId );
1675 aToolId = createTool ( tr( "Association" ) );
1676 createTool( _assocVertex, aToolId );
1677 createTool( _assocEdge, aToolId );
1678 createTool( _assocQuad, aToolId );
1679 //createTool( separator(), aToolId );
1682 aToolId = createTool ( tr( "Group" ) );
1683 createTool( _addGroup, aToolId );
1684 createTool( _removeGroup, aToolId ); //CS_TODO
1685 //createTool( separator(), aToolId );
1688 aToolId = createTool ( tr( "Mesh" ) );
1689 createTool( _addLaw, aToolId );
1690 createTool( _removeLaw, aToolId );
1691 createTool( _setPropagation, aToolId );
1692 createTool( _computeMesh, aToolId );
1696 void HEXABLOCKGUI::initialMenus()
1698 showDocumentMenus( true );
1699 showPatternMenus( false );
1700 showAssociationMenus( false );
1701 showGroupsMenus( false );
1702 showMeshMenus( false );
1705 void HEXABLOCKGUI::showAllMenus()
1707 showDocumentMenus( true );
1708 showPatternMenus( true );
1709 showAssociationMenus( true );
1710 showGroupsMenus( true );
1711 showMeshMenus( true );
1715 void HEXABLOCKGUI::showDocumentMenus(bool show)
1717 DEBTRACE("HEXABLOCKGUI::showDocumentMenus " << show);
1719 setMenuShown(_newAct, show);
1720 setToolShown(_newAct, show);
1721 setMenuShown(_importAct, show);
1722 setToolShown(_importAct, show);
1723 setMenuShown(_saveAct, show);
1724 setToolShown(_saveAct, show);
1725 // setMenuShown(_testAct, show);
1726 // setToolShown(_testAct, show);
1729 void HEXABLOCKGUI::showPatternMenus(bool show)
1731 DEBTRACE("HEXABLOCKGUI::showPatternMenus " << show);
1732 DEBTRACE("getCurrentModel() " << getCurrentModel() );
1733 if ( show && !getCurrentModel() ) return;
1735 setMenuShown(_addVertex, show );//true);
1736 setToolShown(_addVertex, show);
1737 setMenuShown(_addEdge, show );//true);
1738 setToolShown(_addEdge, show);
1739 setMenuShown(_addQuad, show );//true);
1740 setToolShown(_addQuad, show);
1741 setMenuShown(_addHexa, show );//true);
1742 setToolShown(_addHexa, show);
1745 setMenuShown( _addVector, show );//true);
1746 setToolShown( _addVector, show);
1747 setMenuShown( _addCylinder, show );//true);
1748 setToolShown( _addCylinder, show);
1749 setMenuShown( _addPipe, show );//true);
1750 setToolShown( _addPipe, show);
1751 setMenuShown( _makeGrid, show );//true);
1752 setToolShown( _makeGrid, show);
1753 setMenuShown( _makeCylinder, show );//true);
1754 setToolShown( _makeCylinder, show);
1755 setMenuShown( _makePipe, show );//true);
1756 setToolShown( _makePipe, show);
1757 setMenuShown( _makeCylinders, show );//true);
1758 setToolShown( _makeCylinders, show);
1759 setMenuShown( _makePipes, show );//true);
1760 setToolShown( _makePipes, show);
1761 // setMenuShown( _makeRind, show );//true);
1762 // setToolShown( _makeRind, show);
1763 setMenuShown( _makeHemiSphere, show );//true);
1764 setToolShown( _makeHemiSphere, show);
1766 // Pattern Data Edition
1767 setMenuShown( _removeHexa, show );//true);
1768 setToolShown( _removeHexa, show);
1769 setMenuShown( _prismQuad, show );//true);
1770 setToolShown( _prismQuad, show);
1771 setMenuShown( _joinQuad, show );//true);
1772 setToolShown( _joinQuad, show);
1773 setMenuShown( _merge, show );//true);
1774 setToolShown( _merge, show);
1775 setMenuShown( _disconnect, show );//true);
1776 setToolShown( _disconnect, show);
1777 setMenuShown( _cutEdge, show );//true);
1778 setToolShown( _cutEdge, show);
1779 setMenuShown( _makeTransformation, show );//true);
1780 setToolShown( _makeTransformation, show);
1781 setMenuShown( _makeSymmetry, show );//true);
1782 setToolShown( _makeSymmetry, show);
1783 setMenuShown( _performTransformation, show );//true);
1784 setToolShown( _performTransformation, show);
1785 setMenuShown( _performSymmetry, show );//true);
1786 setToolShown( _performSymmetry, show);
1787 setMenuShown( _replaceHexa, show );//true);
1788 setToolShown( _replaceHexa, show);
1789 setMenuShown( _quadRevolution, show );//true);
1790 setToolShown( _quadRevolution, show);
1795 void HEXABLOCKGUI::showAssociationMenus(bool show)
1797 DEBTRACE("HEXABLOCKGUI::showAssociationMenus" << show);
1798 if ( show && !getCurrentModel() ) return;
1800 // Association Edition
1801 setMenuShown( _assocVertex, show );
1802 setToolShown( _assocVertex, show);
1803 setMenuShown( _assocEdge, show );
1804 setToolShown( _assocEdge, show);
1805 setMenuShown( _assocQuad, show );
1806 setToolShown( _assocQuad, show);
1810 void HEXABLOCKGUI::showGroupsMenus(bool show)
1812 DEBTRACE("HEXABLOCKGUI::showGroupsMenus" << show);
1813 if ( show && !getCurrentModel() ) return;
1814 setMenuShown( _addGroup, show );//true);
1815 setToolShown( _addGroup, show);
1816 setMenuShown( _removeGroup , show );//true);
1817 setToolShown( _removeGroup , show);
1820 void HEXABLOCKGUI::showMeshMenus(bool show)
1822 DEBTRACE("HEXABLOCKGUI::showMeshMenus" << show);
1823 if ( show && !getCurrentModel() ) return;
1824 setMenuShown( _addLaw, show );//true);
1825 setToolShown( _addLaw, show);
1826 setMenuShown( _removeLaw, show );//true);
1827 setToolShown( _removeLaw, show);;
1828 setMenuShown( _setPropagation, show );//true);
1829 setToolShown( _setPropagation, show);
1830 setMenuShown( _computeMesh, show); //true);
1831 setToolShown( _computeMesh, show);
1834 void HEXABLOCKGUI::showActor()
1836 //TODO: Implement the real one (this is not show only actor, but show actor)
1837 VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1838 if (currentVtkGView == NULL || currentVtkGView->getViewWindow() == NULL ||
1839 currentVtkGView->isEmpty() || currentVtkGView->getDocumentActor() == NULL)
1842 currentVtkGView->getViewWindow()->setFocus();
1843 currentVtkGView->getViewWindow()->Display(currentVtkGView->getDocumentActor()->getIO());
1844 currentVtkGView->update();
1845 currentVtkGView->getViewWindow()->onFitAll();
1847 //update the visibility state now
1848 SalomeApp_Study* aStudy = HEXABLOCKGUI::activeStudy();
1849 SUIT_ViewManager* vman = currentVtkGView->getViewWindow()->getViewManager();
1850 if (aStudy == NULL || vman == NULL) return;
1852 Handle(SALOME_InteractiveObject) anIO = currentVtkGView->getDocumentActor()->getIO();
1853 aStudy->setObjectProperty(vman->getId(), anIO->getEntry(), GEOM::propertyName(GEOM::Visibility), 1 );
1854 displayer()->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
1857 void HEXABLOCKGUI::showOnlyActor()
1859 VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1860 if (currentVtkGView == NULL || currentVtkGView->getViewWindow() == NULL ||
1861 currentVtkGView->isEmpty() || currentVtkGView->getDocumentActor() == NULL)
1864 SALOME_Actor *actor = NULL;
1865 vtkActor *aVTKActor = NULL;
1866 Handle(SALOME_InteractiveObject) anIO;
1868 SUIT_ViewManager* vman = currentVtkGView->getViewWindow()->getViewManager();
1869 SalomeApp_Study* aStudy = HEXABLOCKGUI::activeStudy();
1870 vtkRenderer *aRenderer = currentDocGView->getViewWindow()->getRenderer();
1871 if (aStudy == NULL || vman == NULL || aRenderer == NULL) return;
1873 //update the visibility state for all actors -----------
1874 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1875 vtkActorCollection *aCollection = aCopy.GetActors();
1876 if (aCollection == NULL) return;
1877 aCollection->InitTraversal();
1879 while( aVTKActor = aCollection->GetNextActor() ){
1880 actor = dynamic_cast<SALOME_Actor*>( aVTKActor );
1881 if ( actor && actor->hasIO() ){
1882 anIO = actor->getIO();
1883 if( anIO->hasEntry())
1885 aStudy->setObjectProperty(vman->getId(), anIO->getEntry(), GEOM::propertyName(GEOM::Visibility), 0 );
1886 displayer()->setVisibilityState(anIO->getEntry(), Qtx::HiddenState);
1891 //show only the current actor -----------------
1892 currentVtkGView->getViewWindow()->setFocus();
1893 currentVtkGView->getViewWindow()->DisplayOnly(currentVtkGView->getDocumentActor()->getIO());
1894 currentVtkGView->update();
1895 currentVtkGView->getViewWindow()->onFitAll();
1896 anIO = currentVtkGView->getDocumentActor()->getIO();
1897 aStudy->setObjectProperty(vman->getId(), anIO->getEntry(), GEOM::propertyName(GEOM::Visibility), 1 );
1898 displayer()->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
1901 //showOnly in occ viewer -------------
1903 OCCViewer_ViewWindow* occView = currentOccGView == NULL ? NULL : currentOccGView->getViewWindow();
1904 DocumentModel* docModel = currentVtkGView->getDocumentModel();
1905 if (occView == NULL || docModel == NULL) return;
1906 SALOME_View* vf = dynamic_cast<SALOME_View*>(occView->getViewManager()->getViewModel());
1907 if (vf == NULL) return;
1909 GEOM_Displayer* disp = geomBaseHelper->getDisplayer();
1912 MESSAGE("Displayer IS NULL");
1915 _PTR(Study) aStudyDS = aStudy->studyDS();
1916 if (aStudyDS == NULL) return;
1918 //erase all shapes from the occ viewer
1919 disp->EraseAll(false, true, vf);
1921 //show only the shapes of the document
1922 QList<QString> entries = docModel->getShapesEntries();
1924 CORBA::Object_var aCorbaObj = CORBA::Object::_nil();
1925 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_nil();
1926 HEXABLOCKGUI::geomBaseHelper->erasePreview(true);
1928 foreach(const QString& entry, entries)
1930 if (!entry.isEmpty())
1932 _PTR(SObject) aSChild = aStudyDS->FindObjectID( entry.toStdString() );
1933 aCorbaObj = corbaObj( aSChild );
1934 aGeomObj = GEOM::GEOM_Object::_narrow( aCorbaObj );
1935 if ( !CORBA::is_nil(aGeomObj) ){
1936 geomBaseHelper->display(aGeomObj._retn());
1937 // QString objIOR = GEOMBase::GetIORFromObject( aGeomObj._retn() );
1938 // Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIORinGEOMAISShape( objIOR );//, true )
1939 // if ( !aSh.IsNull() )
1940 // disp->Display(aSh->getIO(), true, vf);
1943 // MESSAGE("aSh IS NULL");
1948 occView->onResetView ();
1951 void HEXABLOCKGUI::hideActor()
1953 VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1954 if (currentVtkGView == NULL || currentVtkGView->isEmpty() ||
1955 currentVtkGView->getViewWindow() == NULL ||
1956 currentVtkGView->getDocumentActor() == NULL) return;
1958 // currentVtkGView->getViewWindow()->setFocus();
1959 currentVtkGView->getViewWindow()->Erase(currentVtkGView->getDocumentActor()->getIO());
1960 currentVtkGView->getViewWindow()->onFitAll();
1962 //update the visibility state now
1963 SalomeApp_Study* aStudy = HEXABLOCKGUI::activeStudy();
1964 SUIT_ViewManager* vman = currentVtkGView->getViewWindow()->getViewManager();
1965 if (aStudy == NULL || vman == NULL) return;
1967 Handle(SALOME_InteractiveObject) anIO = currentVtkGView->getDocumentActor()->getIO();
1968 aStudy->setObjectProperty(vman->getId(), anIO->getEntry(), GEOM::propertyName(GEOM::Visibility), 0 );
1969 displayer()->setVisibilityState(anIO->getEntry(), Qtx::HiddenState);
1973 VtkDocumentGraphicView* HEXABLOCKGUI::getCurrentVtkGraphicView()
1975 // VtkDocumentGraphicView* gv = graphicViewsHandler->getDocumentGraphicView(currentVtkView);
1976 // return graphicViewsHandler->getDocumentGraphicView(currentVtkView);
1977 return currentDocGView;
1980 void HEXABLOCKGUI::showDockWidgets(bool isVisible)
1982 DEBTRACE("HEXABLOCKGUI::showDockWidgets " << isVisible);
1984 if (_dwObjectBrowser) _dwObjectBrowser->setVisible(isVisible);
1985 if (_dwObjectBrowser) _dwObjectBrowser->toggleViewAction()->setVisible(isVisible);
1987 if (_dwPattern) _dwPattern->setVisible(isVisible);
1988 if (_dwPattern) _dwPattern->toggleViewAction()->setVisible(isVisible);
1990 // if (_dwAssociation) _dwAssociation->setVisible(isVisible);
1991 // if (_dwAssociation) _dwAssociation->toggleViewAction()->setVisible(isVisible);
1993 if (_dwMesh) _dwMesh->setVisible(isVisible);
1994 if (_dwMesh) _dwMesh->toggleViewAction()->setVisible(isVisible);
1996 if (_dwGroups) _dwGroups->setVisible(isVisible);
1997 if (_dwGroups) _dwGroups->toggleViewAction()->setVisible(isVisible);
1999 // if (_dwInputPanel) _dwInputPanel->setVisible(isVisible);
2000 // if (_dwInputPanel) _dwInputPanel->toggleViewAction()->setVisible(isVisible);
2002 // QWidget* w = _dwInputPanel->widget();
2003 // if (w) w->show();
2004 // if ( isVisible ) _dwObjectBrowser->raise();//_dwPattern->raise();
2008 // void HEXABLOCKGUI::raiseStacked()
2010 // // if (_dwStacked) _dwStacked->raise();
2014 void HEXABLOCKGUI::testDocument()
2018 // QStandardItem *parentItem = getCurrentModel()->invisibleRootItem();
2019 // QStandardItem *myItem = new QStandardItem("MyItem");
2020 // parentItem->appendRow(myItem);
2022 // QModelIndex v0 = getCurrentModel()->addVertex(0., 0., 0.);
2023 // QModelIndex v1 = getCurrentModel()->addVertex(5., 0., 0.);
2024 // QModelIndex v2 = getCurrentModel()->addVertex(5., 5., 0.);
2025 // QModelIndex v3 = getCurrentModel()->addVertex(0., 5., 0.);
2026 // QModelIndex v4 = getCurrentModel()->addVertex(0., 0., 5.);
2027 // QModelIndex v5 = getCurrentModel()->addVertex(5., 0., 5.);
2028 // QModelIndex v6 = getCurrentModel()->addVertex(5., 5., 5.);
2029 // QModelIndex v7 = getCurrentModel()->addVertex(0., 5., 5.);
2032 // QModelIndex q0 = getCurrentModel()->addQuadVertices( v0, v1, v2, v3 );
2033 // QModelIndex q1 = getCurrentModel()->addQuadVertices( v4, v5, v6, v7 );
2034 // QModelIndex q2 = getCurrentModel()->addQuadVertices( v0, v3, v7, v4 );
2035 // QModelIndex q3 = getCurrentModel()->addQuadVertices( v1, v2, v6, v5 );
2036 // QModelIndex q4 = getCurrentModel()->addQuadVertices( v0, v1, v5, v4 );
2037 // QModelIndex q5 = getCurrentModel()->addQuadVertices( v3, v2, v6, v7 );
2039 // QModelIndex h0 = getCurrentModel()->addHexaQuad( q0, q1, q2, q3, q4, q5 );
2040 // QModelIndex vx = getCurrentModel()->addVector(1., 0., 0.);
2041 // QModelIndex vy = getCurrentModel()->addVector(0., 1., 0.);
2042 // QModelIndex vz = getCurrentModel()->addVector(0., 0., 1.);
2047 // // QModelIndex orig1 = getCurrentModel()->addVertex (0, 0,0);
2048 // // QModelIndex orig2 = getCurrentModel()->addVertex (50,0,0);
2049 // // QModelIndex vz = getCurrentModel()->addVector (0,0,1);
2050 // // QModelIndex vx = getCurrentModel()->addVector (1,0,0);
2058 // // QModelIndex cyl = getCurrentModel()->addCylinder (orig1, vz, nr, nl);
2059 // // QModelIndex pipe = getCurrentModel()->addPipe (orig2, vz, nri, nre, nl);
2061 // // getCurrentModel()->makeCylinder (cyl, vx, nr, na, nl);
2062 // // getCurrentModel()->makePipe(pipe, vx, nr, na, nl);
2066 // newMesh( "toto", 3, "FactoryServer");
2070 void HEXABLOCKGUI::test_make_cart_grid()
2072 QModelIndex orig1 = getCurrentModel()->addVertex( 0, 0, 0);
2073 QModelIndex orig2 = getCurrentModel()->addVertex( 10, 0, 0);
2074 QModelIndex orig3 = getCurrentModel()->addVertex( 0, 10, 0);
2075 QModelIndex orig4 = getCurrentModel()->addVertex( 10, 10, 0);
2076 QModelIndex orig5 = getCurrentModel()->addVertex( 0, 20, 0);
2077 QModelIndex orig6 = getCurrentModel()->addVertex( 10, 20, 0);
2079 QModelIndex vz = getCurrentModel()->addVector(0, 0, 1);
2080 QModelIndex vx = getCurrentModel()->addVector(1, 0, 0);
2087 // QModelIndex c1 = getCurrentModel()->makeCylindrical(orig1, vx, vz, dr, 360, dl, nr, 4, nl, true);
2088 // QModelIndex c2 = getCurrentModel()->makeCylindrical(orig2, vx, vz, dr, 360, dl, nr, 8, nl, true);
2089 // QModelIndex c3 = getCurrentModel()->makeCylindrical(orig3, vx, vz, dr, 270, dl, nr, 8, nl, true);
2090 // QModelIndex c4 = getCurrentModel()->makeCylindrical(orig4, vx, vz, dr, 270, dl, nr, 7, nl, true);
2091 // QModelIndex c5 = getCurrentModel()->makeCylindrical(orig5, vx, vz, dr, 360, dl, nr, 5, nl, true);
2092 // QModelIndex c6 = getCurrentModel()->makeCylindrical(orig6, vx, vz, dr, 360, dl, nr, 6, nl, true);
2097 void HEXABLOCKGUI::test_make_elmts_transform()
2104 QModelIndex orig = getCurrentModel()->addVertex(0, 0, 0);
2105 QModelIndex dirVr = getCurrentModel()->addVector(1, 1, 1);
2107 QModelIndex grid = getCurrentModel()->makeCartesian(orig, dirVr, size_x, size_y, size_z);//, 0, 0, 0);
2108 // orig.setScalar(2);
2110 // file_name = os.path.join(os.environ['TMP'], 'transfo0.vtk')
2111 // getCurrentModel()->saveVtk(file_name)
2113 QModelIndex devant = getCurrentModel()->addVector(5, 0, 0);
2114 QModelIndex grid2 = getCurrentModel()->makeTranslation(grid, devant);
2116 // file_name = os.path.join(os.environ['TMP'], 'transfo_translation.vtk')
2117 // getCurrentModel()->saveVtk(file_name)
2119 QModelIndex grid4 = getCurrentModel()->makeRotation(grid2, orig, dirVr, 45);
2122 // file_name = os.path.join(os.environ['TMP'], 'transfo_rotation.vtk');
2123 // getCurrentModel()->saveVtk(file_name);
2126 // print "...test make elements by transforming elements OK"
2130 void HEXABLOCKGUI::test()
2132 DEBTRACE("HEXABLOCKGUI::test");
2133 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2134 if (currentDGView == NULL) return;
2135 currentDGView->update();
2139 void HEXABLOCKGUI::test_association()
2141 DEBTRACE("HEXABLOCKGUI::test_association");
2144 QModelIndex v0, v1, v2, v3, e0, e1, q0;
2146 DocumentModel::GeomObj v0Assoc, v1Assoc, v2Assoc, v3Assoc;
2147 DocumentModel::GeomObj e0AssocA, e1AssocA, e1AssocB, e1AssocC;
2148 DocumentModel::GeomObj q0AssocA, q0AssocB;
2150 DocumentModel::GeomObj v0Assoc_test, v1Assoc_test, v2Assoc_test, v3Assoc_test;
2151 QList<DocumentModel::GeomObj> e1Assocs_test;
2152 DocumentModel::GeomObj q0Assoc_test;
2154 v0 = getCurrentModel()->addVertex(0, 0, 0);
2155 v1 = getCurrentModel()->addVertex(1, 0, 0);
2156 v2 = getCurrentModel()->addVertex(1, 1, 0);
2157 v3 = getCurrentModel()->addVertex(0, 1, 0);
2158 e0 = getCurrentModel()->addEdgeVertices(v0, v1);
2159 e1 = getCurrentModel()->addEdgeVertices(v1, v2);
2160 q0 = getCurrentModel()->addQuadVertices( v0, v1, v2, v3 );
2163 // >>> face3.GetEntry()'0:1:4'
2164 // >>> e1.GetEntry()'0:1:8'
2165 // >>> e2.GetEntry()'0:1:9'
2166 // >>> e3.GetEntry()'0:1:10'
2167 // >>> e4.GetEntry()'0:1:11'
2168 // >>> v1.GetEntry()'0:1:12'
2169 // >>> v2.GetEntry()'0:1:13'
2170 // >>> v3.GetEntry()'0:1:14'
2171 // >>> v4.GetEntry()'0:1:15'
2174 // v0Assoc.name = "geomV0";
2175 // v0Assoc.entry = "0:1:1:1:3:6";//"0:1:12";
2176 // v0Assoc.brep = "brepV0";
2177 // v1Assoc.name = "geomV1";
2178 // v1Assoc.entry = "0:1:1:1:3:7";//"0:1:13";
2179 // v1Assoc.brep = "brepV1";
2180 // v2Assoc.name = "geomV2";
2181 // v2Assoc.entry = "0:1:1:1:3:8";//"0:1:14";
2182 // v2Assoc.brep = "brepV2";
2183 // v3Assoc.name = "geomV3";
2184 // v3Assoc.entry = "0:1:1:1:3:9";//"0:1:15";
2185 // v3Assoc.brep = "brepV3";
2189 // e0AssocA.name = "geomE0a";
2190 // e0AssocA.entry = "0:1:1:1:3:5";//"0:1:8";
2191 // e0AssocA.brep = "brepE0a";
2192 // e0AssocA.start = 0.10;
2193 // e0AssocA.end = 0.95;
2197 // e1AssocA.name = "geomE1a";
2198 // e1AssocA.entry = "0:1:1:1:3:2";//"0:1:8";
2199 // e1AssocA.brep = "brepE1a";
2200 // e1AssocA.start = 0.12;
2201 // e1AssocA.end = 0.89;
2202 // e1AssocB.name = "geomE1b";
2203 // e1AssocB.entry = "0:1:1:1:3:3";//"0:1:9";
2204 // e1AssocB.brep = "brepE1b";
2205 // e1AssocB.start = 0.20;
2206 // e1AssocB.end = 0.80;
2207 // e1AssocC.name = "geomE1c";
2208 // e1AssocC.entry = "0:1:1:1:3:4";//"0:1:10";
2209 // e1AssocC.brep = "brepE1c";
2210 // e1AssocC.start = 0.16;
2211 // e1AssocC.end = 0.96;
2213 // q0AssocA.name = "geomQuad";
2214 // q0AssocA.entry = "0:1:1:1:3";
2215 // q0AssocA.brep = "brepq0";
2217 // q0AssocB.name = "geomQuad";
2218 // q0AssocB.entry = "0:1:1:1:4";
2219 // q0AssocB.brep = "brepq0";
2221 // getCurrentModel()->addAssociation( v0, v0Assoc );
2222 // getCurrentModel()->addAssociation( v1, v1Assoc );
2223 // getCurrentModel()->addAssociation( v2, v2Assoc );
2224 // getCurrentModel()->addAssociation( v3, v3Assoc );
2227 // getCurrentModel()->addAssociation( e0, e0AssocA );
2229 // getCurrentModel()->addAssociation( e1, e1AssocA );
2230 // getCurrentModel()->addAssociation( e1, e1AssocB );
2231 // getCurrentModel()->addAssociation( e1, e1AssocC );
2233 // getCurrentModel()->addAssociation( q0, q0AssocA );
2234 // getCurrentModel()->addAssociation( q0, q0AssocB );
2240 // v0Assoc_test = getCurrentModel()->getAssociations( v0 )[0];
2241 // v1Assoc_test = getCurrentModel()->getAssociations( v1 )[0];
2242 // v2Assoc_test = getCurrentModel()->getAssociations( v2 )[0];
2243 // v3Assoc_test = getCurrentModel()->getAssociations( v3 )[0];
2244 // ASSERT( v0Assoc.name == v0Assoc_test.name );
2245 // ASSERT( v1Assoc.name == v1Assoc_test.name );
2246 // ASSERT( v2Assoc.name == v2Assoc_test.name );
2247 // ASSERT( v3Assoc.name == v3Assoc_test.name );
2248 // ASSERT( v0Assoc.entry == v0Assoc_test.entry );
2249 // ASSERT( v1Assoc.entry == v1Assoc_test.entry );
2250 // ASSERT( v2Assoc.entry == v2Assoc_test.entry );
2251 // ASSERT( v3Assoc.entry == v3Assoc_test.entry );
2254 // e1Assocs_test = getCurrentModel()->getAssociations( e1 );
2255 // ASSERT( e1Assocs_test[0].name == e1AssocA.name );
2256 // ASSERT( e1Assocs_test[1].name == e1AssocB.name );
2257 // ASSERT( e1Assocs_test[2].name == e1AssocC.name );
2258 // ASSERT( e1Assocs_test[0].entry == e1AssocA.entry );
2259 // ASSERT( e1Assocs_test[1].entry == e1AssocB.entry );
2260 // ASSERT( e1Assocs_test[2].entry == e1AssocC.entry );
2261 // ASSERT( e1Assocs_test[0].start == e1AssocA.start );
2262 // ASSERT( e1Assocs_test[1].start == e1AssocB.start );
2263 // ASSERT( e1Assocs_test[2].start == e1AssocC.start );
2264 // ASSERT( e1Assocs_test[0].end == e1AssocA.end );
2265 // ASSERT( e1Assocs_test[1].end == e1AssocB.end );
2266 // ASSERT( e1Assocs_test[2].end == e1AssocC.end );
2268 // q0Assoc_test = getCurrentModel()->getAssociations( q0 )[0];
2269 // ASSERT( q0Assoc_test.name == q0Assoc.name );
2270 // ASSERT( q0Assoc_test.entry == q0Assoc.entry );
2273 DEBTRACE("HEXABLOCKGUI::test_association fin");
2276 //clear all used dialogs by the current model
2277 void HEXABLOCKGUI::clearDialogs()
2279 std::set<HexaBaseDialog*>::const_iterator debut (currentModelDialogs.begin()),
2280 fin (currentModelDialogs.end());
2281 for(;debut!=fin;++debut) (*debut)->clear();
2283 if (_vertexAssocDiag != NULL) _vertexAssocDiag->clear(); //not a subclass of HexaBaseDialog
2285 currentModelDialogs.clear(); //empty the used dialogs list
2288 HexaBaseDialog* HEXABLOCKGUI::getDlgBox(VtkDocumentGraphicView* dgview)
2290 if (!gViewDlgBox.contains(dgview)) return NULL;
2291 return gViewDlgBox[dgview];
2294 void HEXABLOCKGUI::switchOnGraphicView(VtkDocumentGraphicView* dgview)
2296 if (dgview == NULL) return;
2298 switchOffGraphicView(dgview, false); //to avoid double connect
2301 connect( selectionMgr(), SIGNAL( currentSelectionChanged() ),
2302 dgview->getPatternDataSelectionModel(), SLOT( salomeSelectionChanged() ), Qt::UniqueConnection );
2303 connect( dgview->getPatternDataSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2304 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2305 connect( dgview->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2306 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2307 connect( dgview->getPatternGeomSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2308 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2309 connect( dgview->getGroupsSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2310 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2311 connect( dgview->getMeshSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2312 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2314 if (currentDocGView != NULL)
2316 if (currentDocGView->getViewWindow() != NULL)
2317 dgview->setViewWindow(currentDocGView->getViewWindow());
2320 dgview->setViewWindow(graphicViewsHandler->createVtkWindow());
2321 dgview->getViewWindow()->installEventFilter(this);
2324 dgview->getViewWindow()->setFocus();
2327 //_showDialogBox(getDlgBox(dgview));
2330 void HEXABLOCKGUI::switchOffGraphicView(VtkDocumentGraphicView* dgview, bool saveCurrentDlg)
2332 if (dgview == NULL) return;
2334 //disconnect signals
2335 disconnect( selectionMgr(), SIGNAL( currentSelectionChanged() ),
2336 dgview->getPatternDataSelectionModel(), SLOT( salomeSelectionChanged() ) );
2337 disconnect( dgview->getPatternDataSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2338 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2339 disconnect( dgview->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2340 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2341 disconnect( dgview->getPatternGeomSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2342 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2343 disconnect( dgview->getGroupsSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2344 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2345 disconnect( dgview->getMeshSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2346 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2349 gViewDlgBox[dgview] = currentDialog;
2351 //close opened dialog
2352 if (currentDialog != NULL) currentDialog->close();
2353 if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
2359 void HEXABLOCKGUI::switchModel(VtkDocumentGraphicView* dgview)
2361 DEBTRACE("HEXABLOCKGUI::switchModel " << dgview);
2363 if (dgview == NULL /*|| dgview == currentDocGView*/ ) //Need to switch?
2365 MESSAGE("HEXABLOCKGUI::switchModel : no need to switch!");
2369 //switch off the current document graphic view (disconnect signals...)
2370 if (currentDocGView != NULL)
2372 //Hide current actor
2374 switchOffGraphicView(currentDocGView);
2377 //clear the dialogs used by the current model so they can be used by the new model
2378 if (currentDocGView != dgview) clearDialogs();
2381 _patternDataTreeView->setModel(dgview->getPatternDataModel());
2382 _patternBuilderTreeView->setModel(dgview->getPatternBuilderModel());
2383 _patternGeomTreeView->setModel(dgview->getPatternGeomModel());
2384 _groupsTreeView->setModel(dgview->getGroupsModel());
2385 _meshTreeView->setModel(dgview->getMeshModel());
2387 _patternDataTreeView->setSelectionModel(dgview->getPatternDataSelectionModel());
2388 _patternDataTreeView->setEditTriggers(/*QAbstractItemView::EditKeyPressed*/QAbstractItemView::AllEditTriggers /*QAbstractItemView::NoEditTriggers*/);
2390 _patternBuilderTreeView->setSelectionModel(dgview->getPatternBuilderSelectionModel());
2391 _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
2393 _patternGeomTreeView->setSelectionModel(dgview->getPatternGeomSelectionModel());
2394 _patternGeomTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
2396 _groupsTreeView->setSelectionModel(dgview->getGroupsSelectionModel());
2397 _groupsTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
2399 _meshTreeView->setSelectionModel(dgview->getMeshSelectionModel());
2400 _meshTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
2402 //switch on this graphic view (connect signals...)
2403 switchOnGraphicView(dgview);
2404 currentDocGView = dgview;
2405 if (_vertexAssocDiag != NULL)
2407 _vertexAssocDiag->setDocumentModel(getCurrentModel());
2408 _vertexAssocDiag->setPatternDataSelectionModel(currentDocGView->getPatternDataSelectionModel());
2410 currentDocGView->getViewWindow()->setFocus();
2412 currentDocGView->getDocumentModel()->refresh();
2416 // void detruitDialog() {
2417 // currentDialog = NULL;
2419 // if (_sdjfgjh) delete _sdjfgjh;
2426 DocumentModel* HEXABLOCKGUI::getCurrentModel()
2428 if (currentDocGView == NULL) return NULL;
2429 return currentDocGView->getDocumentModel();
2433 HEXABLOCKGUI::ViewType HEXABLOCKGUI::getActiveViewType()
2435 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2436 if (anApp == NULL) return UNKNOWN;
2437 SUIT_ViewManager* activeVm = anApp->activeViewManager();
2438 if (activeVm == NULL) return UNKNOWN;
2440 QString vmType = activeVm->getType();
2441 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
2443 else if ( vmType == OCCViewer_Viewer::Type() )
2449 pair <QString, HEXA_NS::Document*> HEXABLOCKGUI::newHexaDocument()
2451 // Create Document from HEXABLOCK ENGINE
2452 // WARNING : IN HEXABLOCK component, GUI and ENGINE share the same process
2453 HEXABLOCK_ORB::Document_ptr docIn = _hexaEngine->addDocument("default");
2455 HEXA_NS::Document* doc = NULL;
2458 // looking doc impl ( c++ )
2459 Document_impl* dServant = DownCast<Document_impl*>( docIn );
2461 if ( dServant) doc = dServant->GetImpl();
2463 // looking for docEntry
2464 if ( !CORBA::is_nil(docIn) ){
2465 CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( docIn );
2466 QString docIOR = anIOR.in();
2467 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
2468 if ( !docIOR.isEmpty() ) {
2469 _PTR(SObject) SO( study->studyDS()->FindObjectIOR( docIOR.toLatin1().constData() ) );
2471 docEntry = SO->GetID().c_str();
2474 DEBTRACE("HEXABLOCKGUI::newHexaDocument docEntry "<<docEntry.toStdString());
2476 return make_pair (docEntry, doc);
2480 void HEXABLOCKGUI::newDocument()
2482 DEBTRACE("HEXABLOCKGUI::newDocument");
2484 // MESSAGE("===== NEW DOCUMENT: je commence ! " << jepeux);
2487 QMainWindow *aParent = application()->desktop();
2488 QWidget *central = aParent->centralWidget();
2490 central->setFocus();
2492 DEBTRACE("No Central Widget");
2495 if (currentOccGView == NULL)
2497 currentOccGView = new OccGraphicView(graphicViewsHandler->createOccWindow(),
2498 application()->desktop());
2499 currentOccGView->getViewWindow()->installEventFilter(this);
2501 else if (currentOccGView->getViewWindow() == NULL)
2503 currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
2504 currentOccGView->getViewWindow()->installEventFilter(this);
2508 // Create Document from HEXABLOCK ENGINE
2509 pair <QString, HEXA_NS::Document*> docEntry_Doc ( newHexaDocument() );
2511 VtkDocumentGraphicView* newGraphicView;
2512 //One document at a time
2513 if (currentDocGView != NULL)
2515 if (currentDocGView->getViewWindow() == NULL)
2517 currentDocGView->setViewWindow(graphicViewsHandler->createVtkWindow());
2518 currentDocGView->getViewWindow()->installEventFilter(this);
2521 // Create a new document with the current window
2522 newGraphicView = graphicViewsHandler->createDocumentGraphicView(
2523 new DocumentModel( docEntry_Doc.second,
2524 docEntry_Doc.first, this ),
2525 currentDocGView->getViewWindow(),
2526 application()->desktop() );
2530 // Create the new Document Graphic View with a new window
2531 newGraphicView = graphicViewsHandler->createDocumentGraphicView(
2532 new DocumentModel( docEntry_Doc.second,
2533 docEntry_Doc.first, this ),
2534 graphicViewsHandler->createVtkWindow(),
2535 application()->desktop() );
2536 newGraphicView->getViewWindow()->installEventFilter(this);
2539 if (newGraphicView == NULL)
2540 //We couldn't create a new document graphic view
2541 //we'd better show a dialog box info to inform the user
2544 docs[docEntry_Doc.first] = newGraphicView;
2545 switchModel(newGraphicView); //select the corresponding document in the browser instead
2548 // _dwPattern->raise();
2550 // _PTR(Study) aStudy = (( SalomeApp_Study* )(getApp()->activeStudy()))->studyDS();
2551 // _PTR(SComponent) aComponent = aStudy->FindComponent("HEXABLOCK");
2552 // SalomeApp_DataModel::updateTree (aComponent, HEXABLOCKGUI::activeStudy());
2553 getApp()->updateObjectBrowser();
2556 // for (double i=0; i < 10000000000000000; ++i);
2558 // MESSAGE("===== NEW DOCUMENT: j'ai fini!");
2563 //Loads the model from the xmlFile in the current graphic view
2564 void HEXABLOCKGUI::loadDocument( const QString &inFile )
2566 DEBTRACE("HEXABLOCKGUI::loadDocument");
2569 QMainWindow *aParent = application()->desktop();
2570 QString selectedFile;
2572 if ( inFile.isNull() ){
2573 QFileDialog dialog( aParent, tr("Open HexaBlock Document") ,
2574 QString::null, tr( "XML-Files (*.xml);;All Files (*)" ) );
2575 dialog.setHistory( getQuickDirList() );
2577 //use the last path as default
2578 if (!(loadDocLastPath->absolutePath()).isEmpty())
2579 dialog.setDirectory(*loadDocLastPath);
2582 QStringList selectedFiles = dialog.selectedFiles();
2583 if (!selectedFiles.isEmpty())
2584 selectedFile = selectedFiles.first();
2586 //remember the selected path
2587 *loadDocLastPath = dialog.directory();
2590 selectedFile = inFile;
2592 if (! selectedFile.isEmpty())
2594 //we create a new document if necessary
2595 if (currentDocGView == NULL)
2596 //Need a new document
2598 else if (currentDocGView->getViewWindow() == NULL) //there's a document without a view
2600 currentDocGView->setViewWindow(graphicViewsHandler->createVtkWindow());
2601 currentDocGView->getViewWindow()->installEventFilter(this);
2604 if (!currentDocGView->isEmpty())
2605 //we can only have one document for a graphic view
2608 //we load the selected file in the current graphic view
2609 currentDocGView->loadDocument(selectedFile);
2610 DocumentModel* currentModel = getCurrentModel();
2611 renameObject( currentModel->documentEntry(), currentModel->getName() );
2613 // _PTR(Study) aStudy = (( SalomeApp_Study* )(getApp()->activeStudy()))->studyDS();
2614 // _PTR(SComponent) aComponent = aStudy->FindComponent("HEXABLOCK");
2615 // SalomeApp_DataModel::updateTree (aComponent, HEXABLOCKGUI::activeStudy());
2616 getApp()->updateObjectBrowser();
2621 void HEXABLOCKGUI::saveDocument()
2623 QMainWindow *aParent = application()->desktop();
2624 // QString anInitialPath = "";
2625 // if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
2626 // anInitialPath = QDir::currentPath();
2627 // QString aMeshName = anIO->getName();
2630 QString aDocName = "document", aFilename;
2632 filter.append( QObject::tr( "XML_FILES_FILTER" ) + " (*.xml)" );
2633 filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
2635 //use the last selected directory as default path for file selection
2636 aFilename = saveDocLastPath->absolutePath();
2637 if (!aFilename.isEmpty())
2638 aFilename += QString("/") + aDocName;
2640 //show the dialog for file selection
2641 aFilename = SUIT_FileDlg::getFileName( aParent,
2644 tr( "Save HexaBlock Document" ),
2647 //save the document in the selected file
2648 if ( !aFilename.isEmpty() ) {
2649 getCurrentVtkGraphicView()->saveDocument( aFilename );
2651 //Remember the path for next save
2652 QFileInfo fileInfo(aFilename);
2653 *saveDocLastPath = fileInfo.dir();
2659 void HEXABLOCKGUI::slot_modelChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
2661 //std::cout << "HHHHHHHHHHHHHHHHHH Model changed." << std::endl;
2662 //std::cout << "HHHHHHHHHHHHHHHHHH slot_modelChanged topLeft -> " << topLeft.data().toString().toStdString()<<std::endl;
2663 //std::cout << "HHHHHHHHHHHHHHHHHH slot_modelChanged bottomRight ->" << bottomRight.data().toString().toStdString()<<std::endl;
2665 _patternDataTreeView->openPersistentEditor( topLeft );
2667 // // Make the combo boxes always displayed.
2668 // for ( int i = 0; i < getCurrentModel()->rowCount(); ++i )
2670 // QModelIndex ind = getCurrentModel()->index(i);
2671 // _patternDataTreeView->openPersistentEditor( ind );
2672 // std::cout << "ind" << ind.data() << std::endl;
2676 void HEXABLOCKGUI::_showDialogBox( HexaBaseDialog* diag )
2678 if (diag == NULL || _dwInputPanel == NULL ||
2679 getCurrentVtkGraphicView() == NULL) return;
2681 //mark this dialog as used by the current model
2682 currentModelDialogs.insert(diag);
2684 //close the current dialog box info
2685 if (_treeViewDelegate != NULL)
2686 _treeViewDelegate->closeDialog();
2688 if (_dwInputPanel->widget())
2689 _dwInputPanel->widget()->close();
2691 //Temporary for debugging EdgeAssoc Faked InfoDialog
2692 if (diag == _edgeAssocDiag)
2693 diag->debugEdgeAssoc = true;
2695 diag->debugEdgeAssoc = false;
2697 if (diag == _quadAssocDiag || diag == _edgeAssocDiag || diag == _addShapeDiag)
2698 assocInProgress = true;
2700 assocInProgress = false;
2702 //show the dialog box in the dockwidget
2703 diag->resetSizeAndShow(_dwInputPanel);
2705 //clear the current selections
2706 if (HEXABLOCKGUI::selectionMgr() != NULL)
2707 HEXABLOCKGUI::selectionMgr()->clearSelected();
2709 currentDialog = diag;
2713 void HEXABLOCKGUI::addVertex()
2715 if ( !_vertexDiag ){
2716 _vertexDiag = new VertexDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2718 _showDialogBox( _vertexDiag );
2721 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2722 if (_vertexDiag != NULL && doc != NULL)
2723 _vertexDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_VERTEX).c_str());
2726 void HEXABLOCKGUI::addEdge()
2729 _edgeDiag = new EdgeDialog( _dwInputPanel, HexaBaseDialog::NEW_MODE);
2731 _showDialogBox( _edgeDiag );
2734 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2735 if (_edgeDiag != NULL && doc != NULL)
2736 _edgeDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_EDGE).c_str());
2739 void HEXABLOCKGUI::addQuad()
2742 _quadDiag = new QuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2745 _showDialogBox( _quadDiag );
2748 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2749 if (_quadDiag != NULL && doc != NULL)
2750 _quadDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_QUAD).c_str());
2753 void HEXABLOCKGUI::addHexa()
2756 _hexaDiag = new HexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2758 _showDialogBox( _hexaDiag );
2761 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2762 if (_hexaDiag != NULL && doc != NULL)
2763 _hexaDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_HEXA).c_str());
2766 void HEXABLOCKGUI::addVector()
2768 if ( !_vectorDiag ){
2769 _vectorDiag = new VectorDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2771 _showDialogBox( _vectorDiag );
2774 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2775 if (_vectorDiag != NULL && doc != NULL)
2776 _vectorDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_VECTOR).c_str());
2779 void HEXABLOCKGUI::addCylinder()
2781 if ( !_cylinderDiag ){
2782 _cylinderDiag = new CylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2784 _showDialogBox( _cylinderDiag );
2787 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2788 if (_cylinderDiag != NULL && doc != NULL)
2789 _cylinderDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_CYLINDER).c_str());
2793 void HEXABLOCKGUI::addPipe()
2796 _pipeDiag = new PipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2798 _showDialogBox( _pipeDiag );
2801 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2802 if (_pipeDiag != NULL && doc != NULL)
2803 _pipeDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_CYLINDER).c_str());
2807 void HEXABLOCKGUI::makeGrid()
2809 if ( !_makeGridDiag ){
2810 _makeGridDiag = new MakeGridDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2812 _showDialogBox( _makeGridDiag );
2816 void HEXABLOCKGUI::makeCylinder()
2818 if ( !_makeCylinderDiag ){
2819 _makeCylinderDiag = new MakeCylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2821 _showDialogBox( _makeCylinderDiag );
2824 void HEXABLOCKGUI::makePipe()
2826 if ( !_makePipeDiag ){
2827 _makePipeDiag = new MakePipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2829 _showDialogBox( _makePipeDiag );
2832 void HEXABLOCKGUI::makeCylinders()
2834 if ( !_makeCylindersDiag ){
2835 _makeCylindersDiag = new MakeCylindersDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2837 _showDialogBox( _makeCylindersDiag );
2840 void HEXABLOCKGUI::makePipes()
2842 if ( !_makePipesDiag ){
2843 _makePipesDiag = new MakePipesDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2845 _showDialogBox( _makePipesDiag );
2849 void HEXABLOCKGUI::makeHemiSphere() // NEW HEXA3
2851 if ( !_makeHemiSphereDiag ){
2852 _makeHemiSphereDiag = new MakeHemiSphereDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2854 _showDialogBox( _makeHemiSphereDiag );
2858 void HEXABLOCKGUI::removeHexa()
2860 if ( !_removeHexaDiag ){
2861 _removeHexaDiag = new RemoveHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2863 _showDialogBox( _removeHexaDiag );
2867 void HEXABLOCKGUI::prismQuad()
2869 if ( !_prismQuadDiag ){
2870 _prismQuadDiag = new PrismQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2872 _showDialogBox( _prismQuadDiag );
2876 void HEXABLOCKGUI::joinQuad()
2878 if ( !_joinQuadDiag ){
2879 _joinQuadDiag = new JoinQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2881 _showDialogBox( _joinQuadDiag );
2884 void HEXABLOCKGUI::merge()
2887 _mergeDiag = new MergeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2889 _showDialogBox( _mergeDiag );
2892 void HEXABLOCKGUI::disconnectElts()
2894 if ( !_disconnectDiag ){
2895 _disconnectDiag = new DisconnectDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2897 _showDialogBox( _disconnectDiag );
2900 void HEXABLOCKGUI::cutEdge()
2902 if ( !_cutEdgeDiag ){
2903 _cutEdgeDiag = new CutEdgeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2905 _showDialogBox( _cutEdgeDiag );
2908 void HEXABLOCKGUI::makeTransformation()
2910 if ( !_makeTransformationDiag ){
2911 _makeTransformationDiag = new MakeTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2913 _showDialogBox( _makeTransformationDiag );
2917 void HEXABLOCKGUI::makeSymmetry()
2919 if ( !_makeSymmetryDiag ){
2920 _makeSymmetryDiag = new MakeSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2922 _showDialogBox( _makeSymmetryDiag );
2926 void HEXABLOCKGUI::performTransformation()
2928 if ( !_performTransformationDiag ){
2929 _performTransformationDiag = new PerformTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2931 _showDialogBox( _performTransformationDiag );
2935 void HEXABLOCKGUI::performSymmetry()
2937 if ( !_performSymmetryDiag ){
2938 _performSymmetryDiag = new PerformSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2940 _showDialogBox( _performSymmetryDiag );
2944 void HEXABLOCKGUI::replaceHexa() // NEW HEXA3
2946 if ( !_replaceHexaDiag ){
2947 _replaceHexaDiag = new ReplaceHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2949 _showDialogBox( _replaceHexaDiag );
2953 void HEXABLOCKGUI::quadRevolution() // NEW HEXA3
2955 if ( !_quadRevolutionDiag ){
2956 _quadRevolutionDiag = new QuadRevolutionDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2958 _showDialogBox( _quadRevolutionDiag );
2962 // void HEXABLOCKGUI::assocVertex()
2964 // if ( !_vertexAssocDiag ){
2965 // _vertexAssocDiag = new VertexAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2967 // _showDialogBox( vertexAssocDiag );
2971 void HEXABLOCKGUI::assocVertex()
2973 if (!_dwInputPanel) return;
2974 QWidget* d = dynamic_cast<SUIT_Desktop*>(_dwInputPanel->parent());
2976 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2977 if (currentDGView == NULL) return;
2979 if ( !_vertexAssocDiag ){
2980 _vertexAssocDiag = new VertexAssocDialog( NULL, d );
2981 if (!_vertexAssocDiag) return;
2983 _vertexAssocDiag->setDocumentModel(getCurrentModel());
2984 _vertexAssocDiag->setPatternDataSelectionModel(currentDGView->getPatternDataSelectionModel());
2986 //close current widget
2987 if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
2988 if (_dwInputPanel->widget()) _dwInputPanel->widget()->close();
2990 //add the vertex assoc dialog in the dockwidget
2991 if ( !_dwInputPanel->isVisible() ) _dwInputPanel->setVisible(true);
2992 _dwInputPanel->setWidget(_vertexAssocDiag);
2993 _dwInputPanel->setWindowTitle(_vertexAssocDiag->windowTitle());
2994 _vertexAssocDiag->adjustSize();
2995 assocInProgress = true;
2996 _vertexAssocDiag->show();
3001 void HEXABLOCKGUI::assocEdge()
3003 if ( !_edgeAssocDiag ){
3004 _edgeAssocDiag = new EdgeAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
3005 // _edgeAssocDiag->setGeomEngine( _geomEngine );
3007 _showDialogBox( _edgeAssocDiag );
3010 void HEXABLOCKGUI::assocQuad()
3012 if ( !_quadAssocDiag ){
3013 _quadAssocDiag = new QuadAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
3015 _showDialogBox( _quadAssocDiag );
3019 void HEXABLOCKGUI::addGroup()
3022 _groupDiag = new GroupDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
3024 _showDialogBox( _groupDiag );
3025 if (_groupDiag != NULL && getCurrentModel() != NULL)
3027 HEXA_NS::Document* doc = getCurrentModel()->getHexaDocument();
3028 if (doc == NULL) return;
3029 char defaultName[16];
3030 sprintf (defaultName, "g%04d", doc->countGroup());
3031 _groupDiag->name_le->setText(defaultName);
3035 void HEXABLOCKGUI::removeGroup()
3037 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3038 if (currentDGView == NULL) return;
3040 QItemSelectionModel *groupsSelectionModel = _groupsTreeView->selectionModel();
3041 QModelIndexList l = groupsSelectionModel->selectedIndexes();
3042 int nbGroupsRemoved = 0;
3045 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
3046 tr( "No group selected!" ) );
3050 foreach( QModelIndex selected, l ){
3051 if ( selected.data(HEXA_TREE_ROLE) == GROUP_TREE ){
3052 selected = currentDGView->getGroupsModel()->mapToSource( selected );
3053 Q_ASSERT(selected.isValid());
3055 //Confirm the deletion of the group
3056 if (SUIT_MessageBox::question(
3059 tr("Remove group : %1 ?").arg(selected.data().toString()),
3060 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
3061 SUIT_MessageBox::Cancel
3062 ) == SUIT_MessageBox::Cancel) return;
3064 bool removed = getCurrentModel()->removeGroup( selected );
3066 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
3067 tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
3073 if (!nbGroupsRemoved)
3074 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
3075 tr( "No group selected!" ) );
3078 void HEXABLOCKGUI::addLaw()
3081 _lawDiag = new LawDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
3083 _showDialogBox( _lawDiag );
3084 if (_lawDiag != NULL && getCurrentModel() != NULL)
3086 HEXA_NS::Document* doc = getCurrentModel()->getHexaDocument();
3087 if (doc == NULL) return;
3088 char defaultName[16];
3089 sprintf (defaultName, "l%04d", doc->countLaw());
3090 _lawDiag->name_le->setText(defaultName);
3094 void HEXABLOCKGUI::removeLaw()
3096 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3097 if (currentDGView == NULL) return;
3099 QModelIndexList l = currentDGView->getMeshSelectionModel()->selectedIndexes();
3100 int nbLawsRemoved = 0;
3103 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
3104 tr( "No law selected!" ) );
3108 foreach( QModelIndex selected, l ){
3109 if ( selected.data(HEXA_TREE_ROLE) == LAW_TREE ){
3110 selected = currentDGView->getMeshModel()->mapToSource( selected );
3111 Q_ASSERT(selected.isValid());
3113 //Confirm the deletion of the law
3114 if (SUIT_MessageBox::question(
3117 tr("Remove law : %1 ?\nAll propagations having this law will have the default law.").arg(selected.data().toString()),
3118 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
3119 SUIT_MessageBox::Cancel
3120 ) == SUIT_MessageBox::Cancel) return;
3122 bool removed = getCurrentModel()->removeLaw(selected);
3124 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
3125 tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
3132 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
3133 tr( "No law selected!" ) );
3138 void HEXABLOCKGUI::setPropagation()
3140 if ( !_propagationDiag ){
3141 _propagationDiag = new PropagationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
3143 _showDialogBox( _propagationDiag );
3147 // Dialog box to compute a mesh from a document
3148 // --------------------------------------------
3149 void HEXABLOCKGUI::computeMesh()
3151 if ( !_computeMeshDiag ){
3152 _computeMeshDiag = new ComputeMeshDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
3154 _computeMeshDiag->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
3155 _showDialogBox( _computeMeshDiag );
3158 void HEXABLOCKGUI::clearAssociations()
3160 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3161 if (currentDGView == NULL) return;
3163 // QMessageBox::warning( 0, "windowTitle()", "clearAssociations" );
3164 QModelIndex iDataModel = _patternDataTreeView->currentIndex();
3165 QModelIndex iModel = currentDGView->getPatternDataModel()->mapToSource(iDataModel);
3167 getCurrentModel()->clearEltAssociations(iModel);
3169 // SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
3172 void HEXABLOCKGUI::showModelInfo()
3174 //create the info dialog if not yet
3175 if (_modelInfoDiag == NULL)
3176 _modelInfoDiag = new ModelInfoDialog(_dwInputPanel);
3178 //show the model informations dialog
3179 _showDialogBox( _modelInfoDiag );
3182 void HEXABLOCKGUI::addShape()
3184 //create the info dialog if not yet
3185 if (_addShapeDiag == NULL)
3186 _addShapeDiag = new AddShapeDialog(_dwInputPanel);
3188 //show the model informations dialog
3189 _showDialogBox( _addShapeDiag );
3192 void HEXABLOCKGUI::clearAllAssociations()
3194 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3195 if (currentDGView == NULL) return;
3197 int currentChildIndex = 0;
3198 QModelIndex currentIndex = currentDGView->getPatternDataModel()->mapToSource(_patternDataTreeView->currentIndex());
3199 if (!currentIndex.isValid()) return;
3200 QVariant currentAssocVariant;
3201 QString currentAssocEntry;
3203 //Confirm the deletion of the associations
3204 QVariant treeVariant = currentIndex.data( HEXA_TREE_ROLE );
3205 if ( !treeVariant.isValid() ) return;
3206 int eltType = treeVariant.toInt();
3207 QString typeStr = "";
3208 HEXA_NS::EnumElt hexaType;
3209 if (eltType == VERTEX_DIR_TREE)
3211 typeStr = tr("TREE_ITEM_VERTEX").toUpper();
3212 hexaType = HEXA_NS::EL_VERTEX;
3214 else if (eltType == EDGE_DIR_TREE)
3216 typeStr = tr("TREE_ITEM_EDGE").toUpper();
3217 hexaType = HEXA_NS::EL_EDGE;
3219 else if (eltType == QUAD_DIR_TREE)
3221 typeStr = tr("TREE_ITEM_QUAD").toUpper();
3222 hexaType = HEXA_NS::EL_QUAD;
3225 if (SUIT_MessageBox::question(
3227 tr("CLEAR_ASSOCIATIONS"),
3228 tr("CLEAR_ALL_ASSOCIATIONS_ON") + " " + typeStr + "?",
3229 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
3230 SUIT_MessageBox::Cancel
3231 ) == SUIT_MessageBox::Cancel) return;
3234 DocumentModel* docModel = getCurrentModel();
3235 if (docModel == NULL) return;
3236 docModel->clearAssociation(hexaType);
3238 // QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
3239 // while( currentChild.isValid() ) {
3241 // currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
3242 // currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
3243 // if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
3244 // getCurrentModel()->clearEltAssociations(currentChild);
3246 // currentChild = currentChild.sibling(currentChildIndex++, 0);
3249 //SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
3252 void HEXABLOCKGUI::showAssociations()
3254 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3255 if (currentDGView == NULL) return;
3257 QModelIndexList elts;
3258 int currentChildIndex = 0;
3259 QVariant currentAssocVariant;
3260 QString currentAssocEntry;
3261 QModelIndex currentIndex = _patternDataTreeView->currentIndex();
3262 QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
3264 while( currentChild.isValid() ) {
3266 currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
3267 currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
3268 if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
3269 elts << currentChild;
3271 currentChild = currentChild.sibling(currentChildIndex++, 0);
3273 currentDGView->getPatternDataSelectionModel()->highlightEltsWithAssocs(elts);
3277 LightApp_SelectionMgr* HEXABLOCKGUI::selectionMgr()
3279 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
3281 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
3286 bool HEXABLOCKGUI::eventFilter(QObject *obj, QEvent *event)
3288 if ( currentDialog == NULL ) return false;
3290 if ( event->type() == QEvent::Enter ){ // ENTER EVENT
3292 // The window acquire the focus when the cursor enter
3294 //OCC - window enter
3295 OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>(obj);
3296 if ( occWindow != NULL)
3298 if (!occWindow->hasFocus()) occWindow->setFocus();
3299 if (currentDialog != NULL && !currentDialog->isHidden())
3300 currentDialog->onWindowActivated(occWindow->getViewManager());
3304 SVTK_ViewWindow* vtkWindow = dynamic_cast<SVTK_ViewWindow*>(obj);
3305 if ( vtkWindow != NULL)
3307 if (!vtkWindow->hasFocus()) vtkWindow->setFocus();
3308 if (currentDialog != NULL && !currentDialog->isHidden())
3309 currentDialog->onWindowActivated(vtkWindow->getViewManager());
3312 //Don't pass the signal
3316 //standard event processing
3317 return QObject::eventFilter(obj, event);
3320 QStringList HEXABLOCKGUI::getQuickDirList()
3322 QStringList dirList;
3323 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
3325 dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
3332 // --- Export the module
3336 HEXABLOCKGUI_EXPORT CAM_Module* createModule()
3338 return new HEXABLOCKGUI();
3341 HEXABLOCKGUI_EXPORT char* getModuleVersion()
3343 return (char*)HEXABLOCK_VERSION_STR;
3348 // void HEXABLOCKGUI::newMesh( const std::string& meshName,
3350 // const std::string& container )
3353 // SalomeApp_Application* app = getApp();
3354 // int activeStudyId = app->activeStudy()->id();
3356 // if ( CORBA::is_nil(_hexaEngine) ) _hexaEngine = InitHEXABLOCKGen( app );
3357 // if ( CORBA::is_nil(_smeshEngine)) _smeshEngine = InitSMESHGen( app, container );
3358 // if ( CORBA::is_nil(_geomEngine) ) _geomEngine = InitGEOMGen( app, container );
3360 // std::cout << "_hexaEngine =>" << _hexaEngine << std::endl;
3361 // std::cout << "_smeshEngine =>" << _smeshEngine << std::endl;
3362 // std::cout << "_geomEngine =>" << _geomEngine << std::endl;
3364 // HEXA_NS::Document* docImpl = getCurrentModel()->documentImpl();
3365 // std::cout << "docImpl =>" << docImpl << std::endl;
3366 // std::cout << "docImpl->getFile() =>" << docImpl->getFile() << std::endl;
3367 // HEXABLOCK_ORB::Document_var anDocObj= _hexaEngine->loadDocument( docImpl->getFile() );
3368 // std::cout << "anDocObj =>" << anDocObj << std::endl;
3371 // GEOM::GEOM_I3DPrimOperations_var anGeomOper = _geomEngine->GetI3DPrimOperations( activeStudyId );
3372 // if ( CORBA::is_nil(anGeomOper) ) return; //!anGeomOper->_is_nil() ) {
3373 // std::cout << "anGeomOper =>" << anGeomOper << std::endl;
3374 // GEOM::GEOM_Object_var anGeomObj = anGeomOper->MakeBoxDXDYDZ( 5., 5., 5. );
3375 // std::cout << "anGeomObj =>" << anGeomObj << std::endl;
3378 // SALOMEDS::SObject _geomEngine->AddInStudy (in SALOMEDS::Study theStudy,
3379 // in GEOM_Object theObject,
3380 // in string theName,
3384 // // void GEOMBase::PublishSubObject( GEOM::GEOM_Object_ptr object )
3386 // SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
3387 // if ( study && !CORBA::is_nil( object ) ) {
3388 // _PTR(Study) studyDS = study->studyDS();
3389 // QString entry = GetEntry( object );
3390 // GEOM::GEOM_Object_var father = object->GetMainShape();
3391 // QString fatherEntry = GetEntry( father );
3392 // if ( entry.isEmpty() && !CORBA::is_nil( father ) && !fatherEntry.isEmpty() ) {
3393 // QString name = GetName( object );
3394 // GeometryGUI::GetGeomGen()->AddInStudy( GeometryGUI::ClientStudyToStudy( studyDS ),
3395 // object, name.toLatin1().data(), father.in() );
3401 // // geompy = smesh.geompy
3402 // // #fkl: shape = doc.getShape()
3403 // // shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
3404 // // geompy.addToStudy(shape, name)
3406 // // component = salome.lcc.FindOrLoadComponent(container, "SMESH")
3407 // // component.init_smesh(salome.myStudy, geompy.geom)
3408 // // mesh = component.Mesh(shape, name)
3410 // // so = "libHexaBlockEngine.so"
3412 // // algo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(component, "HEXABLOCK_3D", so)
3413 // SMESH::SMESH_Hypothesis_var algo = _smeshEngine->CreateHypothesis( "HEXABLOCK_3D", "libHexaBlockEngine.so");
3414 // // raises ( SALOME::SALOME_Exception );
3415 // // mesh.mesh.AddHypothesis(shape, algo)
3417 // // hypo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(component, "HEXABLOCK_Parameters", so)
3418 // //HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var
3419 // SMESH::SMESH_Hypothesis_var hypo = _smeshEngine->CreateHypothesis( "HEXABLOCK_Parameters", "libHexaBlockEngine.so");
3421 // HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var hexHypo = HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis::_narrow(hypo);
3422 // ASSERT(!CORBA::is_nil(hexHypo));
3424 // // mesh.mesh.AddHypothesis(shape, hypo)
3426 // // hexHypo->SetDocument(anDocObj);
3427 // // hexHypo->SetDimension(dim);
3429 // // mesh.Compute()
3437 // void newMesh( const std::string& meshName, int dim )// const std::string& container )
3440 // // _smeshEngine.init_smesh(salome.myStudy, geompy.geom)
3441 // SMESH::SMESH_var mesh = _smeshEngine->Mesh(shape, name);
3442 // SMESH::SMESH_Hypothesis_var algo = _smeshEngine->CreateHypothesis( "HEXABLOCK_3D", "libHexaBlockEngine.so");
3443 // SMESH::SMESH_Hypothesis_var hypo = _smeshEngine->CreateHypothesis( "HEXABLOCK_Parameters", "libHexaBlockEngine.so");
3444 // HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var hexHypo = HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis::_narrow(hypo);
3445 // hexHypo->SetDocument(anDocObj);
3446 // hexHypo->SetDimension(dim);
3450 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3452 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3453 if ( CORBA::is_nil( myComponentSMESH ) )
3455 SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3457 aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3458 return aGUI.myComponentSMESH;
3461 myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3462 return myComponentSMESH;
3467 // // throw SALOME_Exception(LOCALIZED("assocVertex"));
3468 // } catch ( SALOME::SALOME_Exception& exc ){
3469 // INFOS("Following exception was cought:\n\t"<<exc.details.text);
3470 // } catch( const std::exception& exc){
3471 // INFOS("Following exception was cought:\n\t"<<exc.what());
3472 // } catch (Standard_Failure& exc) {
3473 // MESSAGE("OCCT Exception in SMESH_Pattern: " << exc.GetMessageString());
3475 // MESSAGE("Unknown exception was cought !!!");