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
154 LightApp_Module( "HEXABLOCK" ),
162 _patternDataTreeView(0),
163 _patternBuilderTreeView(0),
164 _patternGeomTreeView(0),
165 _associationTreeView(0),
168 _treeViewDelegate(0),
170 moduleActivatedOnce(false),
179 _makeCylinderDiag(0),
181 _makeCylindersDiag(0),
189 _makeTransformationDiag(0),
190 _makeSymmetryDiag(0),
191 _performTransformationDiag(0),
192 _performSymmetryDiag(0),
201 _quadRevolutionDiag(0),
202 _makeHemiSphereDiag(0),
203 _modelInfoDiag(NULL),
207 DEBTRACE("HEXABLOCKGUI::HEXABLOCKGUI");
208 // _studyContextMap.clear();
209 graphicViewsHandler = new GraphicViewsHandler();
210 loadDocLastPath = new QDir();
211 saveDocLastPath = new QDir();
214 HEXABLOCKGUI::~HEXABLOCKGUI()
217 // disconnect( getApp(), SIGNAL(studyClosed()), _genericGui, SLOT (onCleanOnExit()));
221 SalomeApp_Study* HEXABLOCKGUI::activeStudy()
223 SUIT_Application* app = SUIT_Session::session()->activeApplication();
225 return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
231 // Gets an reference to the module's engine
232 HEXABLOCK_ORB::HEXABLOCK_Gen_ptr HEXABLOCKGUI::InitHEXABLOCKGen( SalomeApp_Application* app )
234 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer", "HEXABLOCK" );
235 HEXABLOCK_ORB::HEXABLOCK_Gen_ptr clr = HEXABLOCK_ORB::HEXABLOCK_Gen::_narrow(comp);
236 ASSERT(!CORBA::is_nil(clr));
240 // // Gets an reference to SMESH's engine CS_TO_DELETE
241 // SMESH::SMESH_Gen_ptr HEXABLOCKGUI::InitSMESHGen( SalomeApp_Application* app,
242 // const std::string& container )
244 // Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( container.c_str(), "SMESH" );
245 // SMESH::SMESH_Gen_ptr clr = SMESH::SMESH_Gen::_narrow(comp);
246 // ASSERT(!CORBA::is_nil(clr));
250 // // Gets an reference to GEOM's engine CS_TO_DELETE
251 GEOM::GEOM_Gen_ptr HEXABLOCKGUI::InitGEOMGen( SalomeApp_Application* app,
252 const std::string& container )
254 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( container.c_str(), "GEOM" );
255 GEOM::GEOM_Gen_ptr clr = GEOM::GEOM_Gen::_narrow(comp);
256 ASSERT(!CORBA::is_nil(clr));
261 void HEXABLOCKGUI::initialize( CAM_Application* app )
263 DEBTRACE("HEXABLOCKGUI::initialize");
264 SalomeApp_Module::initialize( app );
266 _hexaEngine = InitHEXABLOCKGen( dynamic_cast<SalomeApp_Application*>( app ) );
267 _geomEngine = InitGEOMGen( dynamic_cast<SalomeApp_Application*>( app ) );
269 DEBTRACE(app << " " << application() << " " << application()->desktop() << " " << aParent);
271 SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
272 setResource(aResourceMgr);
274 createAndFillDockWidget();
279 // add component to study
280 // if (createSComponent()) updateObjBrowser()
281 // createSComponent();
283 if (_dwInputPanel != NULL)
284 geomBaseHelper = new MyGEOMBase_Helper(dynamic_cast<SUIT_Desktop*>(_dwInputPanel->parent()));
287 void HEXABLOCKGUI::viewManagers( QStringList& list ) const
289 DEBTRACE("HEXABLOCKGUI::viewManagers");
290 // foreach (const QString &str, list)
291 // MESSAGE("HEXABLOCKGUI::viewManagers"<<str.toStdString() );
292 // list.append( QxScene_Viewer::Type() );
293 // list.append( OCCViewer_Viewer::Type() );
294 // list.append( SVTK_Viewer::Type() );
297 void HEXABLOCKGUI::restoreGraphicViews()
301 if (currentOccGView == NULL)
303 currentOccGView = new OccGraphicView(graphicViewsHandler->createOccWindow(),
304 application()->desktop());
305 currentOccGView->getViewWindow()->installEventFilter(this);
307 else if (currentOccGView->getViewWindow() == NULL)
309 currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
310 currentOccGView->getViewWindow()->installEventFilter(this);
315 if (currentDocGView == NULL)
317 else if (currentDocGView->getViewWindow() == NULL)
319 currentDocGView->setViewWindow(graphicViewsHandler->createVtkWindow());
320 currentDocGView->getViewWindow()->installEventFilter(this);
326 bool HEXABLOCKGUI::activateModule( SUIT_Study* theStudy )
328 DEBTRACE("HEXABLOCKGUI::activateModule");
330 /*HexaBlock can be launched in only one application*/
331 if (myApplication == NULL)
332 //remember the first application
333 myApplication = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
335 //application verification: if it's not the one known by HexaBlock,
336 //leave without activating
337 SalomeApp_Application* currentApplication = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
338 if (myApplication != currentApplication) return false;
340 bool bOk = SalomeApp_Module::activateModule( theStudy );
341 if ( !bOk ) return false;
343 // setMenuShown( true );
344 // setToolShown( true );
345 // showDockWidgets(false);
346 showDockWidgets(true);
348 connect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
349 this, SLOT(onWindowActivated( SUIT_ViewWindow* )), Qt::UniqueConnection );
350 connect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
351 this, SLOT( onObjectBrowserClick(const QModelIndex&) ), Qt::UniqueConnection );
352 // connect( getApp(), SIGNAL(studyClosed()), _genericGui,SLOT (onCleanOnExit()));
354 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
356 SUIT_ViewManager* vm;
357 ViewManagerList OCCViewManagers, VTKViewManagers;
359 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
360 QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
361 while ( itOCC.hasNext() && (vm = itOCC.next()) )
362 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
364 application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
365 QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
366 while ( itVTK.hasNext() && (vm = itVTK.next()) )
367 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
370 SALOME_ListIO selected;
371 sm->selectedObjects( selected );
374 // disable OCC selectors
375 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
376 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
377 while ( itOCCSel.hasNext() )
378 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
379 sr->setEnabled(true);
381 // disable VTK selectors
382 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
383 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
384 while ( itVTKSel.hasNext() )
385 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
386 sr->setEnabled(true);
388 sm->setSelectedObjects( selected, true ); //NPAL 19674
390 //connect close signal to vtk view manager
391 vm = getApp()->getViewManager(SVTK_Viewer::Type(), false);
394 connect( vm, SIGNAL( tryCloseView( SUIT_ViewWindow * ) ),
395 this, SLOT( onWindowClosed(SUIT_ViewWindow *) ), Qt::UniqueConnection );
398 //connect close signal to occ view manager
399 vm = getApp()->getViewManager(OCCViewer_Viewer::Type(), false);
402 connect( vm, SIGNAL( tryCloseView( SUIT_ViewWindow * ) ),
403 this, SLOT( onWindowClosed(SUIT_ViewWindow *) ), Qt::UniqueConnection );
406 _hexaEngine->SetCurrentStudy(SALOMEDS::Study::_nil());
407 if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( theStudy ))
408 if ( _PTR(Study) aStudy = s->studyDS()) {
409 //define _CAST(Class, shared_ptr_Obj) dynamic_cast<SALOMEDS_##Class*>(shared_ptr_Obj.get())
410 _hexaEngine->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
411 updateObjBrowser(); // objects can be removed
414 if (currentOccGView != NULL && currentOccGView->getViewWindow() != NULL)
415 currentOccGView->getViewWindow()->installEventFilter(this);
418 if (currentDocGView != NULL)
420 switchModel(currentDocGView);
423 if (currentDocGView->getViewWindow() != NULL)
424 currentDocGView->getViewWindow()->installEventFilter(this);
433 bool HEXABLOCKGUI::deactivateModule( SUIT_Study* theStudy )
435 disconnect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
436 this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
437 disconnect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
438 this, SLOT( onObjectBrowserClick(const QModelIndex&) ) );
439 // connect( getApp(), SIGNAL(studyClosed()), _genericGui,SLOT (onCleanOnExit()));
442 if ( currentDocGView != NULL && currentDocGView->getViewWindow() != NULL )
443 //default selectionMode in VTKView
444 currentDocGView->getViewWindow()->SetSelectionMode( ActorSelection );
446 if (currentOccGView != NULL && currentOccGView->getViewWindow() != NULL)
448 //defaut selectionMode in OccView
449 getApp()->selectionMgr()->clearSelected();
450 geomBaseHelper->globalSelection(currentOccGView->getViewWindow());
451 // geomBaseHelper->localSelection(GEOM::GEOM_Object::_nil(), TopAbs_SHAPE);
452 if (currentOccGView != NULL)
453 geomBaseHelper->localSelection(currentOccGView->getViewWindow(), TopAbs_SHAPE);
456 qDeleteAll(myOCCSelectors);
457 myOCCSelectors.clear();
458 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
460 qDeleteAll(myVTKSelectors);
461 myVTKSelectors.clear();
462 getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
464 bool bOk = SalomeApp_Module::deactivateModule( theStudy );
466 //Must be done for all views later
467 if (currentOccGView != NULL && currentOccGView->getViewWindow() != NULL)
468 currentOccGView->getViewWindow()->removeEventFilter(this);
470 if (currentDocGView != NULL && currentDocGView->getViewWindow() != NULL)
471 currentDocGView->getViewWindow()->removeEventFilter(this);
473 //switch off current document graphic view
474 switchOffGraphicView(currentDocGView);
477 setMenuShown( false );
478 setToolShown( false );
479 showDockWidgets( false );
480 if (_dwInputPanel) _dwInputPanel->close();
482 //hide the current document actor
488 QString HEXABLOCKGUI::addInStudy(QString& fileName)
490 QString objStudyEntry;
492 if ( !fileName.isEmpty() ) {
494 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication());
495 SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : NULL;
496 if(!appStudy) return objStudyEntry;
498 _PTR(Study) aStudy = appStudy->studyDS();
499 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy );
501 GEOM::GEOM_IInsertOperations_var aInsOp = _geomEngine->GetIInsertOperations( aStudy->StudyId() );
502 GEOM::GEOM_Object_var anObj = aInsOp->ImportFile(fileName.toStdString().c_str(), "BREP");
503 if ( !anObj->_is_nil() && aInsOp->IsDone() )
505 QStringList sList = fileName.split(".");
506 SALOMEDS::SObject_var aSO = _geomEngine->PublishInStudy( aDSStudy,
507 SALOMEDS::SObject::_nil(),
509 sList[0].toStdString().c_str() );
510 objStudyEntry = aSO->GetID();
513 return objStudyEntry;
516 bool HEXABLOCKGUI::renameAllowed( const QString& entry) const
518 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
519 SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
520 SalomeApp_DataObject* obj = appStudy ? dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry)) : 0;
522 return (app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference());
526 bool HEXABLOCKGUI::renameObject( const QString& entry, const QString& name)
530 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication());
531 SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
536 _PTR(Study) aStudy = appStudy->studyDS();
541 _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
542 _PTR(GenericAttribute) anAttr;
544 if ( obj->FindAttribute(anAttr, "AttributeName") ){
545 _PTR(AttributeName) aName (anAttr);
546 // GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
548 // HEXABLOCK_Gen_i::Document_var aDoc = HEXABLOCK_Gen_i::Document::_narrow( theIOR );
549 // if (!CORBA::is_nil(aDoc)) {
550 // aName->SetValue( name.toLatin1().data() ); // rename the SObject
551 // aDoc->setName( name.toLatin1().data() ); // Rename the corresponding GEOM_Object
552 DocumentModel* currentModel = getCurrentModel();
553 if (currentModel == NULL) return result;
554 currentModel->setName( name/*.toLatin1().data()*/ );
555 aName->SetValue( getCurrentModel()->getName().toLatin1().data() );
556 // _currentGraphicView->setWindowTitle( getCurrentModel()->getName() );
563 // --- Default windows
564 void HEXABLOCKGUI::windows( QMap<int, int>& theMap ) const
566 DEBTRACE("HEXABLOCKGUI::windows");
568 theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
569 theMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
573 // QString HEXABLOCKGUI::engineIOR() const
575 // DEBTRACE("HEXABLOCKGUI::engineIOR");
576 // // return getApp()->defaultEngineIOR();
580 QString HEXABLOCKGUI::engineIOR() const
582 DEBTRACE("HEXABLOCKGUI::engineIOR");
583 CORBA::ORB_var anORB = getApp()->orb();
584 CORBA::String_var anIOR = anORB->object_to_string(_hexaEngine);
585 return QString( anIOR.in() );
589 VtkDocumentGraphicView* HEXABLOCKGUI::getDocument(SalomeApp_DataObject* studyObject)
591 if (docs.count(studyObject->entry()) == 0)
593 //Object's document not acquired yet
594 VtkDocumentGraphicView* dgview;
595 HEXA_NS::Hex* directory = HEXA_NS::Hex::getInstance();
596 if (directory == NULL)
597 return NULL; //No working director found
599 //------------------ Load the document -----------------
600 HEXA_NS::Document* document = directory->findDocument(studyObject->name().toStdString());
601 if (document == NULL) return NULL; //No document found
603 DocumentModel* docModel = new DocumentModel(document, studyObject->entry(), this );
605 MESSAGE("Doc model creation failed!");
608 dgview = graphicViewsHandler->createDocumentGraphicView(
611 application()->desktop() );
612 if (dgview == NULL) return NULL;
614 //update the data tree
615 // dgview->loadDocument();
616 docs[studyObject->entry()] = dgview;
619 return docs[studyObject->entry()];
624 void HEXABLOCKGUI::onObjectBrowserClick(const QModelIndex& index)
626 DEBTRACE("HEXABLOCKGUI::onObjectBrowserClick");
627 // we want to switch automatically to the right view windows
628 // QWidget *viewWindow = NULL;
630 //first, find selected item
632 DataObjectList dol = getApp()->objectBrowser()->getSelected();
633 if (dol.isEmpty()) return;
634 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
635 if (!item || item->parent()->name().compare(tr("HEXABLOCK")) != 0) return;
636 VtkDocumentGraphicView* docGView = getDocument(item);
637 if (docGView == NULL)
639 // currentDocGView = NULL;
643 //Init OCC if necessary
644 if (currentOccGView == NULL)
646 currentOccGView = new OccGraphicView(graphicViewsHandler->createOccWindow(),
647 application()->desktop());
648 currentOccGView->getViewWindow()->installEventFilter(this);
650 else if (currentOccGView->getViewWindow() == NULL)
652 currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
653 currentOccGView->getViewWindow()->installEventFilter(this);
656 //Init the vtk view if necessary
657 if (docGView->getViewWindow() == NULL)
659 if (currentDocGView == NULL || currentDocGView->getViewWindow() == NULL)
661 docGView->setViewWindow(graphicViewsHandler->createVtkWindow());
662 docGView->getViewWindow()->installEventFilter(this);
665 docGView->setViewWindow(currentDocGView->getViewWindow());
667 if (docGView->getDocumentActor() == NULL) docGView->update();
670 // setOpen (const QModelIndex &theObject, const bool theOpen=true)
671 // updateTree (SUIT_DataObject *=0, const bool=true)
672 //update the current document
673 switchModel(docGView);
678 void HEXABLOCKGUI::onWindowActivated( SUIT_ViewWindow* svw)
680 DEBTRACE("HEXABLOCKGUI::onWindowActivated");
681 // OCCViewer_ViewWindow* anOccVw = dynamic_cast<OCCViewer_ViewWindow*>(svw);
683 //update the current occ view
684 // if (anOccVw != NULL)
685 // currentOccGView->getViewWindow() = anOccVw;
687 //set event filter for the occ view
688 // if (currentOccGView != NULL && currentOccGView->getViewWindow() != NULL)
689 // currentOccGView->getViewWindow()->installEventFilter(this);
691 // we want to switch automatically to the right model
693 // SVTK_ViewWindow* viewWindow = dynamic_cast<SVTK_ViewWindow*>(svw);
694 // if (viewWindow == NULL) return;
696 // if (getApp()->activeModule() && getApp()->activeModule()->moduleName().compare("HEXABLOCK") != 0) //CS_TODO?
697 // getApp()->activateModule("HEXABLOCK");
699 //update the current model and the current vtk view
700 // switchModel( viewWindow );
703 void HEXABLOCKGUI::onWindowClosed( SUIT_ViewWindow* svw)
705 DEBTRACE("HEXABLOCKGUI::onWindowClosed");
708 //Decharger le model correspondant (VTK)
709 SVTK_ViewWindow* window = dynamic_cast<SVTK_ViewWindow*>(svw);
714 if (currentDocGView != NULL && currentDocGView->getViewWindow() == window)
715 { //HexaBlock Vtk Window has been closed
717 if (currentDialog != NULL) currentDialog->close();
718 if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
719 if (currentDocGView != NULL)
720 currentDocGView->setViewWindow(NULL);
727 /*VtkDocumentGraphicView* dgview = graphicViewsHandler->getDocumentGraphicView(window);
728 if (dgview == NULL) return; //The window has no document to close
730 //Save the document? (Ask only if the document is not empty
731 int answerCode = SUIT_MessageBox::question(
734 tr("Save the document ?"),
735 SUIT_MessageBox::Yes | SUIT_MessageBox::Cancel,
736 SUIT_MessageBox::Cancel);
737 if ( answerCode == SUIT_MessageBox::Cancel) return; //abort closing
738 else if (answerCode == SUIT_MessageBox::Yes)
739 saveDocument(); //Save the document
741 // switchOffGraphicView(window); //disconnect all connected signals
742 // currentVtkView = NULL;
743 // graphicViewsHandler->closeDocumentGraphicView(window);
745 //create a new one (empty document)
747 // currentVtkView->setWindowTitle(tr("HEXABLOCK") + " : " + currentVtkView->windowTitle());
751 if (currentOccGView != NULL && svw == currentOccGView->getViewWindow())
753 if (_vertexAssocDiag != NULL) _vertexAssocDiag->clear();
754 if (_edgeAssocDiag != NULL) _edgeAssocDiag->clear();
755 if (_quadAssocDiag != NULL) _quadAssocDiag->clear();
756 if (currentDialog != NULL) currentDialog->close();
757 if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
759 currentOccGView->getViewWindow()->removeEventFilter(this);
760 currentOccGView->setViewWindow(NULL);
764 void HEXABLOCKGUI::onViewManagerAdded( SUIT_ViewManager* vm)
766 DEBTRACE("HEXABLOCKGUI::onViewManagerAdded");
768 connect( vm, SIGNAL( tryCloseView( SUIT_ViewWindow * ) ),
769 this, SLOT( onWindowClosed(SUIT_ViewWindow *) ), Qt::UniqueConnection );
771 if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
773 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
774 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
776 // disable OCC selectors
777 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
778 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
779 while ( itOCCSel.hasNext() )
780 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
781 sr->setEnabled(true);
783 else if ( vm->getType() == SVTK_Viewer::Type() )
785 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
786 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
788 // disable VTK selectors
789 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
790 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
791 while ( itVTKSel.hasNext() )
792 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
793 sr->setEnabled(true);
797 void HEXABLOCKGUI::onViewManagerRemoved( SUIT_ViewManager* vm)
799 DEBTRACE("HEXABLOCKGUI::::onViewManagerRemoved");
801 SUIT_ViewModel* viewer = vm->getViewModel();
802 if (vm != NULL && vm->getType() == SVTK_Viewer::Type())
804 //VTK View Manager removed
805 if (getApp()->activeModule()->moduleName().compare("HEXABLOCK") == 0)
807 //Process only if it's our view manager
808 SUIT_ViewManager* myVm = NULL;
809 if (currentDocGView != NULL && currentDocGView->getViewWindow() != NULL)
810 myVm = currentDocGView->getViewWindow()->getViewManager();
814 //close opened dialog
815 if (currentDialog != NULL) currentDialog->close();
816 if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
822 //remove its selector
823 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
824 while ( itVTKSel.hasNext() )
825 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
826 if ( sr->viewer() == viewer )
828 delete myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
835 if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
837 //OCC View removed: remove its selector
838 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
839 while ( itOCCSel.hasNext() )
840 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
841 if ( sr->viewer() == viewer )
843 delete myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
849 void HEXABLOCKGUI::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
851 QModelIndexList l = selected.indexes();
852 if ( l.count() == 0 ) return;
853 if ( !l[0].isValid() ) return;
854 VtkDocumentGraphicView* currentGraphicView = getCurrentVtkGraphicView();
855 if ( currentGraphicView == NULL) return;
857 QTreeView* theTree = NULL;
858 if ( sender() == currentGraphicView->getPatternDataSelectionModel() ){
859 theTree = _patternDataTreeView;
860 } else if ( sender() == currentGraphicView->getPatternBuilderSelectionModel() ){
861 theTree = _patternBuilderTreeView;
862 } else if ( sender() == currentGraphicView->getPatternGeomSelectionModel() ) {
863 theTree = _patternGeomTreeView;
865 else if ( sender() == currentGraphicView->getGroupsSelectionModel() ){
866 theTree = _groupsTreeView;
867 } else if ( sender() == currentGraphicView->getMeshSelectionModel() ){
868 theTree = _meshTreeView;
871 theTree->scrollTo ( l[0] );
875 // void HEXABLOCKGUI::onTryClose(bool &isClosed, QxScene_ViewWindow* window) //CS_TODO
877 // DEBTRACE("HEXABLOCKGUI::onTryClose");
878 // isClosed = _genericGui->closeContext(window);
881 // CAM_DataModel* HEXABLOCKGUI::createDataModel()
883 // DEBTRACE("HEXABLOCKGUI::createDataModel");
884 // return new HEXABLOCKGUI_DataModel(this);
888 bool HEXABLOCKGUI::createSComponent() //addComponent
890 DEBTRACE("HEXABLOCKGUI::createSComponent");
891 // --- Find or create (if not done yet) "HEXABLOCK" SComponent in the study
893 _PTR(Study) aStudy = (( SalomeApp_Study* )(getApp()->activeStudy()))->studyDS();
894 _PTR(StudyBuilder) aBuilder (aStudy->NewBuilder());
895 _PTR(GenericAttribute) anAttr;
896 _PTR(AttributeName) aName;
897 _PTR(AttributeGraphic) aGraphic;
899 _PTR(SComponent) aComponent = aStudy->FindComponent("HEXABLOCK");
900 if ( !aComponent ){ //Create hexablock component if there's not one yet
901 aComponent = aBuilder->NewComponent("HEXABLOCK");
902 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
903 aName = _PTR(AttributeName) (anAttr);
904 aName->SetValue(getApp()->moduleTitle("HEXABLOCK").toStdString());
906 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
907 _PTR(AttributePixMap) aPixmap(anAttr);
908 // aPixmap->SetPixMap("share/salome/resources/hexablock/ModuleHexablock.png");
909 aPixmap->SetPixMap(tr("ICO_MODULE_HEXABLOCK_SMALL").toStdString());
911 aBuilder->DefineComponentInstance(aComponent, engineIOR().toStdString());
912 DEBTRACE("HEXABLOCKGUI::createSComponent engineIOR=>"<<engineIOR().toStdString());
913 // aBuilder->DefineComponentInstance(aComponent, getApp()->defaultEngineIOR().toStdString());
914 // DEBTRACE("HEXABLOCKGUI::createSComponent defaultEngineIOR=>"<<getApp()->defaultEngineIOR().toStdString());
916 // SalomeApp_DataModel::synchronize( aComponent, HEXABLOCKGUI::activeStudy() );
922 // bool HEXABLOCKGUI::isSelectionCompatible()
924 // DEBTRACE("HEXABLOCKGUI::isSelectionCompatible");
926 // bool isCompatible = true;
927 // SALOME_ListIO selected;
928 // if ( LightApp_SelectionMgr *Sel = selectionMgr() )
929 // Sel->selectedObjects( selected );
931 // SALOME_ListIteratorOfListIO It( selected );
932 // for ( ; isCompatible && It.More(); It.Next())
934 // ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
935 // ( strcmp("HEXABLOCK", It.Value()->getComponentDataType()) == 0 );
937 // return isCompatible;
940 void HEXABLOCKGUI::setResource(SUIT_ResourceMgr* r)
942 DEBTRACE("HEXABLOCKGUI::setResource");
943 _myresource = new HEXABLOCKGUI_Resource(r);
944 _myresource->preferencesChanged();
947 void HEXABLOCKGUI::createPreferences()
949 DEBTRACE("HEXABLOCKGUI::createPreferences");
950 _myresource->createPreferences(this);
953 void HEXABLOCKGUI::preferencesChanged( const QString& sect, const QString& name )
955 DEBTRACE("HEXABLOCKGUI::preferencesChanged");
956 _myresource->preferencesChanged(sect, name);
957 if(name=="userCatalog")
959 // _genericGui->getCatalogWidget()->addCatalogFromFile(Resource::userCatalog.toStdString());
963 void HEXABLOCKGUI::studyActivated() //CS_TODO
965 int newStudyId = getApp()->activeStudy()->id();
966 DEBTRACE("HEXABLOCKGUI::studyActivated " << _oldStudyId << " " << newStudyId);
968 if (_oldStudyId != -1)
970 // _studyContextMap[_oldStudyId] = QtGuiContext::getQtCurrent();
971 // if (_studyContextMap.count(newStudyId))
973 // DEBTRACE("switch to valid context " << QtGuiContext::getQtCurrent() << " " << _studyContextMap[newStudyId]);
974 // QtGuiContext::setQtCurrent(_studyContextMap[newStudyId]);
978 // DEBTRACE("no switch to null context");
981 _oldStudyId = newStudyId;
986 void HEXABLOCKGUI::treeContextMenu(const QPoint& aPosition)
988 QModelIndex currentIndex = _patternDataTreeView->currentIndex();
989 QVariant currentAssocVariant;
990 QString currentAssocEntry;
992 currentAssocVariant = currentIndex.data( HEXA_ASSOC_ENTRY_ROLE );
993 currentAssocEntry = currentIndex.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
994 if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() ){
995 // getCurrentModel()->allowEdition();
996 QMenu menu( _patternDataTreeView );
998 QAction *clearAct = menu.addAction( "Remove association(s)" );
999 connect( clearAct, SIGNAL(triggered()), this, SLOT(clearAssociations()), Qt::UniqueConnection );
1000 menu.exec( _patternDataTreeView->mapToGlobal( aPosition) );
1004 VtkDocumentGraphicView* currentVtkGraphicView = getCurrentVtkGraphicView();
1005 if (currentVtkGraphicView == NULL) return;
1006 QStandardItem *item = currentVtkGraphicView->getPatternDataModel()->itemFromIndex(currentIndex);
1008 //We don't do anything for single items
1009 if ( item->type() == VERTEXITEM || item->type() == EDGEITEM ||
1010 item->type() == QUADITEM || item->type() == HEXAITEM)
1013 //No associations for HEXA
1014 QVariant treeVariant = currentIndex.data( HEXA_TREE_ROLE );
1015 if ( !treeVariant.isValid() ) return;
1016 int eltType = treeVariant.toInt();
1017 if (eltType == HEXA_DIR_TREE) return;
1018 QMenu menu( _patternDataTreeView );
1020 //Show association(s)
1021 QAction *showAssocAct = menu.addAction( "Show associations" );
1022 connect( showAssocAct, SIGNAL(triggered()), this, SLOT(showAssociations()), Qt::UniqueConnection );
1024 //Clear all associations
1025 QAction *clearAllAssocAct = menu.addAction( "Remove all associations" );
1026 connect( clearAllAssocAct, SIGNAL(triggered()), this, SLOT(clearAllAssociations()), Qt::UniqueConnection );
1028 menu.exec( _patternDataTreeView->mapToGlobal( aPosition) );
1033 void HEXABLOCKGUI::createAndFillDockWidget()
1035 QMainWindow *aParent = application()->desktop();
1037 // Create dock widget (3 dock)
1039 //1) *********** user input panel ( contain user's edit dialog box )
1040 _dwInputPanel = new QDockWidget(aParent);
1041 // QLayout* inputLayout = new QVBoxLayout(aParent);
1042 // _dwInputPanel->setLayout(inputLayout);
1043 // _dwInputPanel->setWindowFlags(Qt::FramelessWindowHint);
1044 // _dwInputPanel->setWindowFlags(Qt::WindowTitleHint);
1045 _dwInputPanel->setVisible(false);
1046 _dwInputPanel->setWindowTitle("Input Panel");
1047 // _dwInputPanel->setMinimumHeight(DWINPUT_MINIMUM_HEIGHT);
1048 _dwInputPanel->setMinimumWidth(DWINPUT_MINIMUM_WIDTH); // --- force a minimum until display
1049 // _dwInputPanel->raise();
1051 // _stacked = new QStackedWidget(_dwInputPanel);
1052 // _dwInputPanel->setWidget(_stacked);
1054 _treeViewDelegate = new DocumentDelegate(_dwInputPanel);
1056 //2) ************* document data ( Pattern, Association, Mesh ) in treeview representation
1058 _dwPattern = new QDockWidget(aParent);
1059 // _dwPattern->installEventFilter(this);
1060 _dwPattern->setVisible(false);
1061 _dwPattern->setWindowTitle("Model");
1062 _dwPattern->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
1064 QFrame* patternFrame = new QFrame(_dwPattern);
1065 patternFrame->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
1066 QVBoxLayout* patternLayout = new QVBoxLayout(patternFrame);
1067 patternLayout->setSizeConstraint(QLayout::SetMaximumSize);
1068 QSplitter *splitter = new QSplitter(Qt::Vertical,patternFrame);
1069 _patternDataTreeView = new QTreeView(patternFrame);//_dwPattern);
1070 _patternBuilderTreeView = new QTreeView(patternFrame);
1071 _patternGeomTreeView = new QTreeView(patternFrame);
1072 splitter->addWidget(_patternDataTreeView);
1073 splitter->addWidget(_patternBuilderTreeView);
1074 splitter->addWidget(_patternGeomTreeView);
1075 patternLayout->addWidget(splitter);
1076 // _patternDataTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
1078 _patternDataTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers/*QAbstractItemView::DoubleClicked*/);
1079 _patternDataTreeView->setSelectionMode(QAbstractItemView::SingleSelection/*QAbstractItemView::MultiSelection*/);//);//QAbstractItemView::DoubleClicked, QAbstractItemView::SelectedClicked)
1080 _patternDataTreeView->setItemDelegate(_treeViewDelegate);
1083 _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1084 _patternBuilderTreeView->setItemDelegate(_treeViewDelegate);
1086 _patternGeomTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1087 _patternGeomTreeView->setSelectionMode(QAbstractItemView::SingleSelection/*QAbstractItemView::MultiSelection*/);
1089 _dwPattern->setWidget(patternFrame);
1090 patternFrame->show();
1091 //_dwPattern->raise();
1094 _dwGroups = new QDockWidget(aParent);
1095 // _dwGroups->installEventFilter(this);
1097 _dwGroups->setVisible(false);
1098 _dwGroups->setWindowTitle("Groups");
1099 _dwGroups->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
1100 _groupsTreeView = new QTreeView(_dwGroups);
1101 // _associationTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
1102 _groupsTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1103 _groupsTreeView->setItemDelegate(_treeViewDelegate);
1104 _dwGroups->setWidget(_groupsTreeView);
1105 _groupsTreeView->show();
1108 _dwMesh = new QDockWidget(aParent);
1109 // _dwMesh->installEventFilter(this);
1110 _dwMesh->setVisible(false);
1111 _dwMesh->setWindowTitle("Mesh");
1112 _dwMesh->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
1113 _meshTreeView = new QTreeView(_dwMesh);
1114 // _meshTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
1115 _meshTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1116 _meshTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
1117 _meshTreeView->setItemDelegate(_treeViewDelegate);
1118 _dwMesh->setWidget(_meshTreeView);
1119 _meshTreeView->show();
1120 // _dwMesh->raise();
1124 //3) ************* documents ( salome objectbrowser )
1125 QDockWidget *_dwObjectBrowser = 0;
1126 QWidget* wid = getApp()->objectBrowser()->treeView();
1127 // QWidget *wid = application()->objectBrowser()->treeView();
1128 QWidget *w = wid->parentWidget();
1129 while ( w && !_dwObjectBrowser ) {
1130 _dwObjectBrowser = ::qobject_cast<QDockWidget*>( w );
1131 w = w->parentWidget();
1133 // _dwObjectBrowser->installEventFilter(this);
1134 // _dwObjectBrowser->setVisible(false);
1135 _dwObjectBrowser->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
1136 _dwObjectBrowser->setWindowTitle("Study");
1139 // dock widget position
1140 // aParent->addDockWidget(Qt::LeftDockWidgetArea, _dwPattern);
1141 // aParent->addDockWidget(Qt::RightDockWidgetArea, _dwInputPanel);
1142 // aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwPattern );
1143 aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwObjectBrowser );
1144 aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwInputPanel );
1146 aParent->tabifyDockWidget( _dwObjectBrowser, _dwPattern );
1147 // aParent->tabifyDockWidget( _dwPattern, /*_dwAssociation );
1148 // aParent->tabifyDockWidget( _dwAssociation, */_dwGroups );
1149 aParent->tabifyDockWidget( _dwPattern, _dwGroups );
1150 aParent->tabifyDockWidget( _dwGroups, _dwMesh );
1153 #if QT_VERSION >= 0x040500
1154 aParent->setTabPosition(Qt::AllDockWidgetAreas, Resource::tabPanelsUp? QTabWidget::North: QTabWidget::South);
1158 // connect( _dwPattern, SIGNAL( visibilityChanged(bool) ), this, SLOT( showPatternMenus(bool) ) );
1159 // // connect( _dwAssociation, SIGNAL( visibilityChanged(bool) ), this, SLOT( showAssociationMenus(bool) ) );
1160 // connect( _dwGroups, SIGNAL( visibilityChanged(bool) ), this, SLOT( showGroupsMenus(bool) ) );
1161 // connect( _dwMesh, SIGNAL( visibilityChanged(bool) ), this, SLOT( showMeshMenus(bool) ) );
1163 // popup menu on data tree view
1164 _patternDataTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
1165 connect(_patternDataTreeView,
1166 SIGNAL(customContextMenuRequested(const QPoint &)),
1168 SLOT(treeContextMenu(const QPoint &)), Qt::UniqueConnection);
1171 void HEXABLOCKGUI::createActions()
1173 QMainWindow *aParent = application()->desktop();
1174 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1177 _newAct = createAction(_menuId++,
1178 tr("Create a new document"),
1179 resMgr->loadPixmap("HEXABLOCK", tr("ICON_NEW_DOCUMENT")),
1181 tr("Create a new document"),
1182 0, aParent, false, this, SLOT(newDocument()));
1183 _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1185 _importAct = createAction(_menuId++,
1186 tr("Load a document"),
1187 resMgr->loadPixmap("HEXABLOCK", tr("ICON_LOAD_DOCUMENT")),
1188 tr("Load Document"),
1189 tr("Load a document"),
1190 0, aParent, false, this, SLOT(loadDocument()));
1191 _importAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_O); // --- QKeySequence::Open ambiguous in SALOME
1193 _saveAct = createAction(_menuId++,
1194 tr("Save the document"),
1195 resMgr->loadPixmap("HEXABLOCK", tr("ICON_SAVE_DOCUMENT")),
1196 tr("Save Document"),
1197 tr("Save the document"),
1198 0, aParent, false, this, SLOT(saveDocument()));
1200 // _testAct = createAction(_menuId++, tr("Test"), resMgr->loadPixmap("HEXABLOCK", tr("ICON_TEST")),
1201 // tr("Test"), tr("New test"),
1202 // 0, aParent, false, this, SLOT(test_association()));
1204 // Pattern Data creation
1205 _addVertex = createAction(_menuId++,
1206 tr("Create a vertex"),
1207 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_VERTEX")),
1209 tr("Create a new vertex"),
1210 0, aParent, false, this, SLOT(addVertex()));
1212 _addEdge = createAction(_menuId++,
1213 tr("Create an edge"),
1214 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_EDGE")),
1216 tr("Create a new edge"),
1217 0, aParent, false, this, SLOT(addEdge()));
1219 _addQuad = createAction(_menuId++,
1220 tr("Create a quadrangle"),
1221 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_QUAD")),
1222 tr("Add Quadrangle"),
1223 tr("Create a new quadrangle"),
1224 0, aParent, false, this, SLOT(addQuad()));
1226 _addHexa = createAction(_menuId++,
1227 tr("Create an hexahedron"),
1228 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_HEXA")),
1229 tr("Add Hexahedron"),
1230 tr("Create a new hexahedron"),
1231 0, aParent, false, this, SLOT(addHexa()));
1233 // Builder Data creation
1234 _addVector = createAction(_menuId++,
1235 tr("Create a vector"),
1236 resMgr->loadPixmap( "HEXABLOCK", tr("ICON_ADD_VECTOR")),
1238 tr("Create a new vector"),
1239 0, aParent, false, this, SLOT(addVector()));
1241 _addCylinder = createAction(_menuId++,
1242 tr("Create a cylinder"),
1243 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_CYLINDER")),
1245 tr("Create a new cylinder"),
1246 0, aParent, false, this, SLOT(addCylinder()));
1248 _addPipe = createAction(_menuId++,
1249 tr("Create a pipe"),
1250 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_PIPE")),
1252 tr("Create a new pipe"),
1253 0, aParent, false, this, SLOT(addPipe()));
1255 _makeGrid = createAction(_menuId++,
1257 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_GRID")),
1260 0, aParent, false, this, SLOT(makeGrid()));
1262 _makeCylinder = createAction(_menuId++,
1263 tr("Make a cylinder"),
1264 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDER")),
1265 tr("Make Cylinder"),
1266 tr("Make a cylinder"),
1267 0, aParent, false, this, SLOT(makeCylinder()));
1269 _makePipe = createAction(_menuId++,
1271 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPE")),
1274 0, aParent, false, this, SLOT(makePipe()));
1276 _makeCylinders = createAction(_menuId++,
1277 tr("Make cylinders"),
1278 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDERS")),
1279 tr("Make Cylinders"),
1280 tr("Make cylinders"),
1281 0, aParent, false, this, SLOT(makeCylinders()));
1283 _makePipes = createAction(_menuId++,
1285 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPES")),
1288 0, aParent, false, this, SLOT(makePipes()));
1290 // // _makeRind = createAction( _menuId++, tr("Make rind"), resMgr->loadPixmap( "HEXABLOCK", tr("ICON_MAKE_RIND")),
1291 // // tr("Make rind"), tr("Make rind"),
1292 // // 0, aParent, false, this, SLOT(makeRind()));
1294 _makeHemiSphere = createAction(_menuId++,
1295 tr("Make an hemisphere"),
1296 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_HEMISPHERE")),
1297 tr("Make Hemisphere"),
1298 tr("Make an hemisphere"),
1299 0, aParent, false, this, SLOT(makeHemiSphere()));
1301 // Pattern Data edition
1302 _removeHexa = createAction(_menuId++,
1303 tr("Remove hexahedra"),
1304 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_HEXA")),
1305 tr("Remove Hexahedra"),
1306 tr("Remove hexahedra"),
1307 0, aParent, false, this, SLOT(removeHexa()));
1309 _prismQuad = createAction(_menuId++,
1310 tr("Prism quadrangles"),
1311 resMgr->loadPixmap( "HEXABLOCK", tr("ICON_PRISM_QUAD")),
1312 tr("Prism Quadrangles"),
1313 tr("Prism quadrangles"),
1314 0, aParent, false, this, SLOT(prismQuad()));
1316 _joinQuad = createAction(_menuId++,
1317 tr("Join quadrangles"),
1318 resMgr->loadPixmap("HEXABLOCK", tr("ICON_JOIN_QUAD")),
1319 tr("Join Quadrangles"),
1320 tr("Join quadrangles with hexahedra"),
1321 0, aParent, false, this, SLOT(joinQuad()));
1323 _merge = createAction(_menuId++,
1325 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MERGE")),
1328 0, aParent, false, this, SLOT(merge()));
1330 _disconnect = createAction(_menuId++,
1332 resMgr->loadPixmap("HEXABLOCK", tr("ICON_DISCONNECT")),
1334 tr("Disconnect edges, vertexes or quadrangles"),
1335 0, aParent, false, this, SLOT(disconnectElts()));
1337 _cutEdge = createAction(_menuId++,
1339 resMgr->loadPixmap("HEXABLOCK", tr("ICON_CUT_EDGE")),
1342 0, aParent, false, this, SLOT(cutEdge()));
1344 _makeTransformation = createAction(_menuId++,
1345 tr("Make transformation"),
1346 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_TRANSFORMATION")),
1347 tr("Make Transformation"),
1348 tr("Make transformation"),
1349 0, aParent, false, this, SLOT(makeTransformation()));
1351 _makeSymmetry = createAction(_menuId++,
1352 tr("Make symmetry"),
1353 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_SYMMETRY")),
1354 tr("Make Symmetry"),
1355 tr("Make symmetry"),
1356 0, aParent, false, this, SLOT(makeSymmetry()));
1358 _performTransformation = createAction(_menuId++,
1359 tr("Perform transformation"),
1360 resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_TRANSFORMATION")),
1361 tr("Perform Transformation"),
1362 tr("Perform transformation"),
1363 0, aParent, false, this, SLOT(performTransformation()));
1365 _performSymmetry = createAction(_menuId++,
1366 tr("Perform symmetry"),
1367 resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_SYMMETRY")),
1368 tr("Perform Symmetry"),
1369 tr("Perform symmetry"),
1370 0, aParent, false, this, SLOT(performSymmetry()));
1372 _replaceHexa = createAction(_menuId++,
1373 tr("Replace hexahedron"),
1374 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REPLACE_HEXA")),
1375 tr("Replace Hexahedron"),
1376 tr("Replace hexahedron"),
1377 0, aParent, false, this, SLOT(replaceHexa()));
1379 _quadRevolution = createAction(_menuId++,
1380 tr("Quad revolution"),
1381 resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_REVOLUTION")),
1382 tr("Quad Revolution"),
1383 tr("Quad revolution"),
1384 0, aParent, false, this, SLOT(quadRevolution()));
1387 _assocVertex = createAction(_menuId++,
1388 tr("Make vertex association"),
1389 resMgr->loadPixmap("HEXABLOCK", tr("ICON_VERTEX_ASSOCIATION")),
1390 tr("Make Vertex association"),
1391 tr("Make vertex association"),
1392 0, aParent, false, this, SLOT(assocVertex()));
1394 _assocEdge = createAction(_menuId++,
1395 tr("Make edge association"),
1396 resMgr->loadPixmap("HEXABLOCK", tr("ICON_EDGE_ASSOCIATION")),
1397 tr("Make Edge Association"),
1398 tr("Make edge association"),
1399 0, aParent, false, this, SLOT(assocEdge()));
1401 _assocQuad = createAction(_menuId++,
1402 tr("Make quadrangle association"),
1403 resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_ASSOCIATION")),
1404 tr("Make Quadrangle Association"),
1405 tr("Make quadrangle association"),
1406 0, aParent, false, this, SLOT(assocQuad()));
1409 _addGroup = createAction(_menuId++,
1411 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_GROUP")),
1414 0, aParent, false, this, SLOT(addGroup()));
1416 _removeGroup = createAction(_menuId++,
1417 tr("Remove a group"),
1418 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_GROUP")),
1420 tr("Remove a group"),
1421 0, aParent, false, this, SLOT(removeGroup()));
1424 _addLaw = createAction(_menuId++,
1426 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_LAW")),
1429 0, aParent, false, this, SLOT(addLaw()));
1431 _removeLaw = createAction(_menuId++,
1433 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_LAW")),
1436 0, aParent, false, this, SLOT(removeLaw()));
1438 _setPropagation = createAction(_menuId++,
1439 tr("Set propagation"),
1440 resMgr->loadPixmap("HEXABLOCK", tr("ICON_SET_PROPAGATION")),
1441 tr("Set Propagation"),
1442 tr("Set propagation"),
1443 0, aParent, false, this, SLOT(setPropagation()));
1445 _computeMesh = createAction(_menuId++,
1447 resMgr->loadPixmap("HEXABLOCK", tr("ICON_COMPUTE_MESH")),
1450 0, aParent, false, this, SLOT(computeMesh()));
1453 _showModelInfoAct = createAction(_menuId++,
1454 tr("Show Model Info"),
1456 tr("MODEL_INFO"),//TODO: must be added in translation file
1458 0, aParent, false, this, SLOT(showModelInfo()));
1460 _addShapeAct = createAction(_menuId++,
1463 tr("ADD_SHAPE"),//TODO: must be added in translation file
1465 0, aParent, false, this, SLOT(addShape()));
1468 // _showAct = createAction(_menuId++,
1472 // tr("Show the actor"),
1473 // 0, aParent, false, this, SLOT(showActor()));
1475 // _hideAct = createAction(_menuId++,
1479 // tr("Hide the actor"),
1480 // 0, aParent, false, this, SLOT(hideActor()));
1483 // _showOnlyAct = createAction(_menuId++,
1487 // tr("Show only this actor"),
1488 // 0, aParent, false, this, SLOT(showOnlyActor()));
1491 // _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1492 // QAction* createAction(const int id,
1493 // const QString& toolTip,
1494 // const QIcon& icon,
1495 // const QString& menu,
1496 // const QString& status,
1497 // const int shortCut,
1498 // QObject* parent =0,
1499 // bool checkable = false,
1500 // QObject* receiver =0,
1501 // const char* member =0);
1505 void HEXABLOCKGUI::createMenus()
1507 int aMenuId, subMenuId;
1508 aMenuId = createMenu( tr("MEN_FILE"), -1, -1 );
1509 createMenu( separator(), aMenuId, -1, 10 );
1510 aMenuId = createMenu( tr("HEXABLOCK"), aMenuId, -1, 10 );
1511 createMenu( _newAct, aMenuId );
1512 createMenu( _importAct, aMenuId );
1513 createMenu( _saveAct, aMenuId );
1514 // createMenu( _testAct, aMenuId );
1516 // aMenuId = createMenu( tr( "HEXABLOCK" ), -1, -1, 30 );
1517 aMenuId = createMenu( tr( "Document" ), -1, -1, 30 );
1518 createMenu( _newAct, aMenuId );//, 10
1519 createMenu( _importAct, aMenuId );
1520 createMenu( _saveAct, aMenuId );
1521 // createMenu( _testAct, aMenuId );
1523 aMenuId = createMenu( tr("Model"), -1, -1, 30 );
1524 subMenuId = createMenu( tr( "Construction" ), aMenuId, -1 );
1525 createMenu( _addVertex, subMenuId );
1526 createMenu( _addEdge, subMenuId );
1527 createMenu( _addQuad, subMenuId );
1528 createMenu( _addHexa, subMenuId );
1529 createMenu( separator(), subMenuId );
1532 createMenu( _addVector, subMenuId );
1533 createMenu( _addCylinder, subMenuId );
1534 createMenu( _addPipe, subMenuId );
1535 createMenu( separator(), subMenuId);
1536 createMenu( _makeGrid, subMenuId ); //Cartesian, Cylindrical, Spherical
1537 createMenu( _makeHemiSphere,subMenuId );
1538 createMenu( separator(), subMenuId);
1539 createMenu( _makeCylinder, subMenuId );
1540 createMenu( _makePipe, subMenuId );
1541 createMenu( _makeCylinders,subMenuId );
1542 createMenu( _makePipes, subMenuId );
1543 // createMenu( _makeRind, aMenuId );
1545 // Pattern Data Edition
1546 subMenuId = createMenu( tr( "Operation" ), aMenuId, -1 );
1547 createMenu( _removeHexa, subMenuId );
1548 createMenu( _prismQuad, subMenuId );
1549 createMenu( _joinQuad, subMenuId );
1550 createMenu( _merge, subMenuId );// createMenu( _mergeVertices, aMenuId ); // createMenu( _mergeEdges, aMenuId );
1551 createMenu( _disconnect, subMenuId );
1552 createMenu( _cutEdge, subMenuId );
1553 createMenu( _makeTransformation, subMenuId ); // createMenu( _makeTranslation, aMenuId );
1554 createMenu( _makeSymmetry, subMenuId );
1555 createMenu( _performTransformation, subMenuId );
1556 createMenu( _performSymmetry, subMenuId );
1557 createMenu( _replaceHexa, subMenuId );
1558 createMenu( _quadRevolution, subMenuId );
1561 aMenuId = createMenu( tr("Association"), -1, -1, 30 );
1562 createMenu( _assocVertex, aMenuId );
1563 createMenu( _assocEdge, aMenuId );
1564 createMenu( _assocQuad, aMenuId );
1567 aMenuId = createMenu( tr("Groups"), -1, -1, 30 );
1568 createMenu( _addGroup, aMenuId );
1569 createMenu( _removeGroup, aMenuId ); //CS_TODO
1572 aMenuId = createMenu( tr("Mesh "), -1, -1, 30 );
1573 createMenu( _addLaw, aMenuId );
1574 createMenu( _removeLaw, aMenuId );
1575 createMenu( _setPropagation, aMenuId );
1576 createMenu( _computeMesh, aMenuId );
1578 //show model infomation menu
1579 QString aRule = "$component={'HEXABLOCK'}";
1580 popupMgr()->insert( _showModelInfoAct, -1, -1 ); // link the model information action to context menu
1581 popupMgr()->setRule( _showModelInfoAct, aRule);
1583 //associate shape to a document menu
1584 popupMgr()->insert( _addShapeAct, -1, -1 );
1585 popupMgr()->setRule( _addShapeAct, aRule );
1587 //-------------------------------------------------
1589 //-------------------------------------------------
1590 // QString lc = "$"; // VSR : instead of QtxPopupSelection::defEquality();
1591 // QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
1592 // QString isNotEmpty("numberOfNodes <> 0");
1593 // QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
1594 // QString aType = QString( "%1type in {%2}" ).arg( lc );
1595 //// aType = aType.arg( mesh_part );
1597 // aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
1598 // QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
1599 // QString aSelCount = QString( "%1 > 0" ).arg( dc );
1601 // popupMgr()->insert( separator(), -1, -1 );
1602 // QString aRule = "$component={'HEXABLOCK'}";/* and ( type='(" + aClient + " and " +
1603 // aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";*/
1604 // // MESSAGE("aClient = " << aClient.toStdString());
1605 // // MESSAGE("aType = " << aType.toStdString());
1606 // // MESSAGE("aSelCount = " << aSelCount.toStdString());
1607 // // MESSAGE("anActiveVTK = " << anActiveVTK.toStdString());
1608 // // MESSAGE("isNotEmpty = " << isNotEmpty.toStdString());
1609 // // MESSAGE("aRule = " << aRule.toStdString());
1610 // popupMgr()->insert( _showAct, -1, -1 ); // DISPLAY
1611 // popupMgr()->setRule( _showAct, aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
1613 // popupMgr()->insert( _hideAct, -1, -1 ); // ERASE
1614 // popupMgr()->setRule( _hideAct, aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
1616 // popupMgr()->insert( _showOnlyAct, -1, -1 ); // DISPLAY_ONLY
1617 // popupMgr()->setRule(_showOnlyAct, aRule.arg( "" ), QtxPopupMgr::VisibleRule );
1619 // popupMgr()->insert( separator(), -1, -1 );
1624 void HEXABLOCKGUI::createTools()
1628 aToolId = createTool ( tr( "HexaBlock Toolbar" ) );
1629 createTool( _newAct, aToolId );
1630 createTool( _importAct, aToolId );
1631 createTool( _saveAct, aToolId );
1632 // createTool( _testAct, aToolId );
1633 //createTool( separator(), aToolId );
1636 aToolId = createTool ( tr( "Construction" ) );
1637 createTool( _addVertex, aToolId );
1638 createTool( _addEdge, aToolId );
1639 createTool( _addQuad, aToolId );
1640 createTool( _addHexa, aToolId );
1641 createTool( separator(), aToolId );
1644 createTool( _addVector, aToolId );
1645 createTool( _addCylinder, aToolId );
1646 createTool( _addPipe, aToolId );
1647 createTool( separator(), aToolId );
1649 createTool( _makeGrid, aToolId );
1650 createTool( _makeHemiSphere, aToolId );
1651 createTool( separator(), aToolId );
1652 createTool( _makeCylinder, aToolId );
1653 createTool( _makePipe, aToolId );
1654 createTool( _makeCylinders,aToolId );
1655 createTool( _makePipes, aToolId );
1656 // createTool( _makeRind, aToolId);
1657 // createTool( separator(), aToolId );
1659 // Pattern Data Edition
1660 aToolId = createTool ( tr( "Operation" ) );
1661 createTool( _removeHexa, aToolId );
1662 createTool( _prismQuad, aToolId );
1663 createTool( _joinQuad, aToolId );
1664 createTool( _merge, aToolId );
1665 createTool( _disconnect, aToolId );
1666 createTool( _cutEdge, aToolId );
1667 createTool( _makeTransformation, aToolId );
1668 createTool( _makeSymmetry, aToolId );
1669 createTool( _performTransformation, aToolId );
1670 createTool( _performSymmetry, aToolId );
1671 createTool( _replaceHexa, aToolId );
1672 createTool( _quadRevolution, aToolId );
1673 //createTool( separator(), aToolId );
1676 aToolId = createTool ( tr( "Association" ) );
1677 createTool( _assocVertex, aToolId );
1678 createTool( _assocEdge, aToolId );
1679 createTool( _assocQuad, aToolId );
1680 //createTool( separator(), aToolId );
1683 aToolId = createTool ( tr( "Group" ) );
1684 createTool( _addGroup, aToolId );
1685 createTool( _removeGroup, aToolId ); //CS_TODO
1686 //createTool( separator(), aToolId );
1689 aToolId = createTool ( tr( "Mesh" ) );
1690 createTool( _addLaw, aToolId );
1691 createTool( _removeLaw, aToolId );
1692 createTool( _setPropagation, aToolId );
1693 createTool( _computeMesh, aToolId );
1697 void HEXABLOCKGUI::initialMenus()
1699 showDocumentMenus( true );
1700 showPatternMenus( false );
1701 showAssociationMenus( false );
1702 showGroupsMenus( false );
1703 showMeshMenus( false );
1706 void HEXABLOCKGUI::showAllMenus()
1708 showDocumentMenus( true );
1709 showPatternMenus( true );
1710 showAssociationMenus( true );
1711 showGroupsMenus( true );
1712 showMeshMenus( true );
1716 void HEXABLOCKGUI::showDocumentMenus(bool show)
1718 DEBTRACE("HEXABLOCKGUI::showDocumentMenus " << show);
1720 setMenuShown(_newAct, show);
1721 setToolShown(_newAct, show);
1722 setMenuShown(_importAct, show);
1723 setToolShown(_importAct, show);
1724 setMenuShown(_saveAct, show);
1725 setToolShown(_saveAct, show);
1726 // setMenuShown(_testAct, show);
1727 // setToolShown(_testAct, show);
1730 void HEXABLOCKGUI::showPatternMenus(bool show)
1732 DEBTRACE("HEXABLOCKGUI::showPatternMenus " << show);
1733 DEBTRACE("getCurrentModel() " << getCurrentModel() );
1734 if ( show && !getCurrentModel() ) return;
1736 setMenuShown(_addVertex, show );//true);
1737 setToolShown(_addVertex, show);
1738 setMenuShown(_addEdge, show );//true);
1739 setToolShown(_addEdge, show);
1740 setMenuShown(_addQuad, show );//true);
1741 setToolShown(_addQuad, show);
1742 setMenuShown(_addHexa, show );//true);
1743 setToolShown(_addHexa, show);
1746 setMenuShown( _addVector, show );//true);
1747 setToolShown( _addVector, show);
1748 setMenuShown( _addCylinder, show );//true);
1749 setToolShown( _addCylinder, show);
1750 setMenuShown( _addPipe, show );//true);
1751 setToolShown( _addPipe, show);
1752 setMenuShown( _makeGrid, show );//true);
1753 setToolShown( _makeGrid, show);
1754 setMenuShown( _makeCylinder, show );//true);
1755 setToolShown( _makeCylinder, show);
1756 setMenuShown( _makePipe, show );//true);
1757 setToolShown( _makePipe, show);
1758 setMenuShown( _makeCylinders, show );//true);
1759 setToolShown( _makeCylinders, show);
1760 setMenuShown( _makePipes, show );//true);
1761 setToolShown( _makePipes, show);
1762 // setMenuShown( _makeRind, show );//true);
1763 // setToolShown( _makeRind, show);
1764 setMenuShown( _makeHemiSphere, show );//true);
1765 setToolShown( _makeHemiSphere, show);
1767 // Pattern Data Edition
1768 setMenuShown( _removeHexa, show );//true);
1769 setToolShown( _removeHexa, show);
1770 setMenuShown( _prismQuad, show );//true);
1771 setToolShown( _prismQuad, show);
1772 setMenuShown( _joinQuad, show );//true);
1773 setToolShown( _joinQuad, show);
1774 setMenuShown( _merge, show );//true);
1775 setToolShown( _merge, show);
1776 setMenuShown( _disconnect, show );//true);
1777 setToolShown( _disconnect, show);
1778 setMenuShown( _cutEdge, show );//true);
1779 setToolShown( _cutEdge, show);
1780 setMenuShown( _makeTransformation, show );//true);
1781 setToolShown( _makeTransformation, show);
1782 setMenuShown( _makeSymmetry, show );//true);
1783 setToolShown( _makeSymmetry, show);
1784 setMenuShown( _performTransformation, show );//true);
1785 setToolShown( _performTransformation, show);
1786 setMenuShown( _performSymmetry, show );//true);
1787 setToolShown( _performSymmetry, show);
1788 setMenuShown( _replaceHexa, show );//true);
1789 setToolShown( _replaceHexa, show);
1790 setMenuShown( _quadRevolution, show );//true);
1791 setToolShown( _quadRevolution, show);
1796 void HEXABLOCKGUI::showAssociationMenus(bool show)
1798 DEBTRACE("HEXABLOCKGUI::showAssociationMenus" << show);
1799 if ( show && !getCurrentModel() ) return;
1801 // Association Edition
1802 setMenuShown( _assocVertex, show );
1803 setToolShown( _assocVertex, show);
1804 setMenuShown( _assocEdge, show );
1805 setToolShown( _assocEdge, show);
1806 setMenuShown( _assocQuad, show );
1807 setToolShown( _assocQuad, show);
1811 void HEXABLOCKGUI::showGroupsMenus(bool show)
1813 DEBTRACE("HEXABLOCKGUI::showGroupsMenus" << show);
1814 if ( show && !getCurrentModel() ) return;
1815 setMenuShown( _addGroup, show );//true);
1816 setToolShown( _addGroup, show);
1817 setMenuShown( _removeGroup , show );//true);
1818 setToolShown( _removeGroup , show);
1821 void HEXABLOCKGUI::showMeshMenus(bool show)
1823 DEBTRACE("HEXABLOCKGUI::showMeshMenus" << show);
1824 if ( show && !getCurrentModel() ) return;
1825 setMenuShown( _addLaw, show );//true);
1826 setToolShown( _addLaw, show);
1827 setMenuShown( _removeLaw, show );//true);
1828 setToolShown( _removeLaw, show);;
1829 setMenuShown( _setPropagation, show );//true);
1830 setToolShown( _setPropagation, show);
1831 setMenuShown( _computeMesh, show); //true);
1832 setToolShown( _computeMesh, show);
1835 void HEXABLOCKGUI::showActor()
1837 //TODO: Implement the real one (this is not show only actor, but show actor)
1838 VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1839 if (currentVtkGView == NULL || currentVtkGView->getViewWindow() == NULL ||
1840 currentVtkGView->isEmpty() || currentVtkGView->getDocumentActor() == NULL)
1843 currentVtkGView->getViewWindow()->setFocus();
1844 currentVtkGView->getViewWindow()->Display(currentVtkGView->getDocumentActor()->getIO());
1845 currentVtkGView->update();
1846 currentVtkGView->getViewWindow()->onFitAll();
1848 //update the visibility state now
1849 SalomeApp_Study* aStudy = HEXABLOCKGUI::activeStudy();
1850 SUIT_ViewManager* vman = currentVtkGView->getViewWindow()->getViewManager();
1851 if (aStudy == NULL || vman == NULL) return;
1853 Handle(SALOME_InteractiveObject) anIO = currentVtkGView->getDocumentActor()->getIO();
1854 aStudy->setObjectProperty(vman->getId(), anIO->getEntry(), VISIBILITY_PROP, 1 );
1855 displayer()->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
1858 void HEXABLOCKGUI::showOnlyActor()
1860 VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1861 if (currentVtkGView == NULL || currentVtkGView->getViewWindow() == NULL ||
1862 currentVtkGView->isEmpty() || currentVtkGView->getDocumentActor() == NULL)
1865 SALOME_Actor *actor = NULL;
1866 vtkActor *aVTKActor = NULL;
1867 Handle(SALOME_InteractiveObject) anIO;
1869 SUIT_ViewManager* vman = currentVtkGView->getViewWindow()->getViewManager();
1870 SalomeApp_Study* aStudy = HEXABLOCKGUI::activeStudy();
1871 vtkRenderer *aRenderer = currentDocGView->getViewWindow()->getRenderer();
1872 if (aStudy == NULL || vman == NULL || aRenderer == NULL) return;
1874 //update the visibility state for all actors -----------
1875 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1876 vtkActorCollection *aCollection = aCopy.GetActors();
1877 if (aCollection == NULL) return;
1878 aCollection->InitTraversal();
1880 while( aVTKActor = aCollection->GetNextActor() ){
1881 actor = dynamic_cast<SALOME_Actor*>( aVTKActor );
1882 if ( actor && actor->hasIO() ){
1883 anIO = actor->getIO();
1884 if( anIO->hasEntry())
1886 aStudy->setObjectProperty(vman->getId(), anIO->getEntry(), VISIBILITY_PROP, 0 );
1887 displayer()->setVisibilityState(anIO->getEntry(), Qtx::HiddenState);
1892 //show only the current actor -----------------
1893 currentVtkGView->getViewWindow()->setFocus();
1894 currentVtkGView->getViewWindow()->DisplayOnly(currentVtkGView->getDocumentActor()->getIO());
1895 currentVtkGView->update();
1896 currentVtkGView->getViewWindow()->onFitAll();
1897 anIO = currentVtkGView->getDocumentActor()->getIO();
1898 aStudy->setObjectProperty(vman->getId(), anIO->getEntry(), VISIBILITY_PROP, 1 );
1899 displayer()->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
1902 //showOnly in occ viewer -------------
1904 OCCViewer_ViewWindow* occView = currentOccGView == NULL ? NULL : currentOccGView->getViewWindow();
1905 DocumentModel* docModel = currentVtkGView->getDocumentModel();
1906 if (occView == NULL || docModel == NULL) return;
1907 SALOME_View* vf = dynamic_cast<SALOME_View*>(occView->getViewManager()->getViewModel());
1908 if (vf == NULL) return;
1910 GEOM_Displayer* disp = geomBaseHelper->getDisplayer();
1913 MESSAGE("Displayer IS NULL");
1916 _PTR(Study) aStudyDS = aStudy->studyDS();
1917 if (aStudyDS == NULL) return;
1919 //erase all shapes from the occ viewer
1920 disp->EraseAll(false, true, vf);
1922 //show only the shapes of the document
1923 QList<QString> entries = docModel->getShapesEntries();
1925 CORBA::Object_var aCorbaObj = CORBA::Object::_nil();
1926 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_nil();
1927 HEXABLOCKGUI::geomBaseHelper->erasePreview(true);
1929 foreach(const QString& entry, entries)
1931 if (!entry.isEmpty())
1933 _PTR(SObject) aSChild = aStudyDS->FindObjectID( entry.toStdString() );
1934 aCorbaObj = corbaObj( aSChild );
1935 aGeomObj = GEOM::GEOM_Object::_narrow( aCorbaObj );
1936 if ( !CORBA::is_nil(aGeomObj) ){
1937 geomBaseHelper->display(aGeomObj._retn());
1938 // QString objIOR = GEOMBase::GetIORFromObject( aGeomObj._retn() );
1939 // Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIORinGEOMAISShape( objIOR );//, true )
1940 // if ( !aSh.IsNull() )
1941 // disp->Display(aSh->getIO(), true, vf);
1944 // MESSAGE("aSh IS NULL");
1949 occView->onResetView ();
1952 void HEXABLOCKGUI::hideActor()
1954 VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1955 if (currentVtkGView == NULL || currentVtkGView->isEmpty() ||
1956 currentVtkGView->getViewWindow() == NULL ||
1957 currentVtkGView->getDocumentActor() == NULL) return;
1959 // currentVtkGView->getViewWindow()->setFocus();
1960 currentVtkGView->getViewWindow()->Erase(currentVtkGView->getDocumentActor()->getIO());
1961 currentVtkGView->getViewWindow()->onFitAll();
1963 //update the visibility state now
1964 SalomeApp_Study* aStudy = HEXABLOCKGUI::activeStudy();
1965 SUIT_ViewManager* vman = currentVtkGView->getViewWindow()->getViewManager();
1966 if (aStudy == NULL || vman == NULL) return;
1968 Handle(SALOME_InteractiveObject) anIO = currentVtkGView->getDocumentActor()->getIO();
1969 aStudy->setObjectProperty(vman->getId(), anIO->getEntry(), VISIBILITY_PROP, 0 );
1970 displayer()->setVisibilityState(anIO->getEntry(), Qtx::HiddenState);
1974 VtkDocumentGraphicView* HEXABLOCKGUI::getCurrentVtkGraphicView()
1976 // VtkDocumentGraphicView* gv = graphicViewsHandler->getDocumentGraphicView(currentVtkView);
1977 // return graphicViewsHandler->getDocumentGraphicView(currentVtkView);
1978 return currentDocGView;
1981 void HEXABLOCKGUI::showDockWidgets(bool isVisible)
1983 DEBTRACE("HEXABLOCKGUI::showDockWidgets " << isVisible);
1985 if (_dwObjectBrowser) _dwObjectBrowser->setVisible(isVisible);
1986 if (_dwObjectBrowser) _dwObjectBrowser->toggleViewAction()->setVisible(isVisible);
1988 if (_dwPattern) _dwPattern->setVisible(isVisible);
1989 if (_dwPattern) _dwPattern->toggleViewAction()->setVisible(isVisible);
1991 // if (_dwAssociation) _dwAssociation->setVisible(isVisible);
1992 // if (_dwAssociation) _dwAssociation->toggleViewAction()->setVisible(isVisible);
1994 if (_dwMesh) _dwMesh->setVisible(isVisible);
1995 if (_dwMesh) _dwMesh->toggleViewAction()->setVisible(isVisible);
1997 if (_dwGroups) _dwGroups->setVisible(isVisible);
1998 if (_dwGroups) _dwGroups->toggleViewAction()->setVisible(isVisible);
2000 // if (_dwInputPanel) _dwInputPanel->setVisible(isVisible);
2001 // if (_dwInputPanel) _dwInputPanel->toggleViewAction()->setVisible(isVisible);
2003 // QWidget* w = _dwInputPanel->widget();
2004 // if (w) w->show();
2005 // if ( isVisible ) _dwObjectBrowser->raise();//_dwPattern->raise();
2009 // void HEXABLOCKGUI::raiseStacked()
2011 // // if (_dwStacked) _dwStacked->raise();
2015 void HEXABLOCKGUI::testDocument()
2019 // QStandardItem *parentItem = getCurrentModel()->invisibleRootItem();
2020 // QStandardItem *myItem = new QStandardItem("MyItem");
2021 // parentItem->appendRow(myItem);
2023 // QModelIndex v0 = getCurrentModel()->addVertex(0., 0., 0.);
2024 // QModelIndex v1 = getCurrentModel()->addVertex(5., 0., 0.);
2025 // QModelIndex v2 = getCurrentModel()->addVertex(5., 5., 0.);
2026 // QModelIndex v3 = getCurrentModel()->addVertex(0., 5., 0.);
2027 // QModelIndex v4 = getCurrentModel()->addVertex(0., 0., 5.);
2028 // QModelIndex v5 = getCurrentModel()->addVertex(5., 0., 5.);
2029 // QModelIndex v6 = getCurrentModel()->addVertex(5., 5., 5.);
2030 // QModelIndex v7 = getCurrentModel()->addVertex(0., 5., 5.);
2033 // QModelIndex q0 = getCurrentModel()->addQuadVertices( v0, v1, v2, v3 );
2034 // QModelIndex q1 = getCurrentModel()->addQuadVertices( v4, v5, v6, v7 );
2035 // QModelIndex q2 = getCurrentModel()->addQuadVertices( v0, v3, v7, v4 );
2036 // QModelIndex q3 = getCurrentModel()->addQuadVertices( v1, v2, v6, v5 );
2037 // QModelIndex q4 = getCurrentModel()->addQuadVertices( v0, v1, v5, v4 );
2038 // QModelIndex q5 = getCurrentModel()->addQuadVertices( v3, v2, v6, v7 );
2040 // QModelIndex h0 = getCurrentModel()->addHexaQuad( q0, q1, q2, q3, q4, q5 );
2041 // QModelIndex vx = getCurrentModel()->addVector(1., 0., 0.);
2042 // QModelIndex vy = getCurrentModel()->addVector(0., 1., 0.);
2043 // QModelIndex vz = getCurrentModel()->addVector(0., 0., 1.);
2048 // // QModelIndex orig1 = getCurrentModel()->addVertex (0, 0,0);
2049 // // QModelIndex orig2 = getCurrentModel()->addVertex (50,0,0);
2050 // // QModelIndex vz = getCurrentModel()->addVector (0,0,1);
2051 // // QModelIndex vx = getCurrentModel()->addVector (1,0,0);
2059 // // QModelIndex cyl = getCurrentModel()->addCylinder (orig1, vz, nr, nl);
2060 // // QModelIndex pipe = getCurrentModel()->addPipe (orig2, vz, nri, nre, nl);
2062 // // getCurrentModel()->makeCylinder (cyl, vx, nr, na, nl);
2063 // // getCurrentModel()->makePipe(pipe, vx, nr, na, nl);
2067 // newMesh( "toto", 3, "FactoryServer");
2071 void HEXABLOCKGUI::test_make_cart_grid()
2073 QModelIndex orig1 = getCurrentModel()->addVertex( 0, 0, 0);
2074 QModelIndex orig2 = getCurrentModel()->addVertex( 10, 0, 0);
2075 QModelIndex orig3 = getCurrentModel()->addVertex( 0, 10, 0);
2076 QModelIndex orig4 = getCurrentModel()->addVertex( 10, 10, 0);
2077 QModelIndex orig5 = getCurrentModel()->addVertex( 0, 20, 0);
2078 QModelIndex orig6 = getCurrentModel()->addVertex( 10, 20, 0);
2080 QModelIndex vz = getCurrentModel()->addVector(0, 0, 1);
2081 QModelIndex vx = getCurrentModel()->addVector(1, 0, 0);
2088 // QModelIndex c1 = getCurrentModel()->makeCylindrical(orig1, vx, vz, dr, 360, dl, nr, 4, nl, true);
2089 // QModelIndex c2 = getCurrentModel()->makeCylindrical(orig2, vx, vz, dr, 360, dl, nr, 8, nl, true);
2090 // QModelIndex c3 = getCurrentModel()->makeCylindrical(orig3, vx, vz, dr, 270, dl, nr, 8, nl, true);
2091 // QModelIndex c4 = getCurrentModel()->makeCylindrical(orig4, vx, vz, dr, 270, dl, nr, 7, nl, true);
2092 // QModelIndex c5 = getCurrentModel()->makeCylindrical(orig5, vx, vz, dr, 360, dl, nr, 5, nl, true);
2093 // QModelIndex c6 = getCurrentModel()->makeCylindrical(orig6, vx, vz, dr, 360, dl, nr, 6, nl, true);
2098 void HEXABLOCKGUI::test_make_elmts_transform()
2105 QModelIndex orig = getCurrentModel()->addVertex(0, 0, 0);
2106 QModelIndex dirVr = getCurrentModel()->addVector(1, 1, 1);
2108 QModelIndex grid = getCurrentModel()->makeCartesian(orig, dirVr, size_x, size_y, size_z);//, 0, 0, 0);
2109 // orig.setScalar(2);
2111 // file_name = os.path.join(os.environ['TMP'], 'transfo0.vtk')
2112 // getCurrentModel()->saveVtk(file_name)
2114 QModelIndex devant = getCurrentModel()->addVector(5, 0, 0);
2115 QModelIndex grid2 = getCurrentModel()->makeTranslation(grid, devant);
2117 // file_name = os.path.join(os.environ['TMP'], 'transfo_translation.vtk')
2118 // getCurrentModel()->saveVtk(file_name)
2120 QModelIndex grid4 = getCurrentModel()->makeRotation(grid2, orig, dirVr, 45);
2123 // file_name = os.path.join(os.environ['TMP'], 'transfo_rotation.vtk');
2124 // getCurrentModel()->saveVtk(file_name);
2127 // print "...test make elements by transforming elements OK"
2131 void HEXABLOCKGUI::test()
2133 DEBTRACE("HEXABLOCKGUI::test");
2134 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2135 if (currentDGView == NULL) return;
2136 currentDGView->update();
2140 void HEXABLOCKGUI::test_association()
2142 DEBTRACE("HEXABLOCKGUI::test_association");
2145 QModelIndex v0, v1, v2, v3, e0, e1, q0;
2147 DocumentModel::GeomObj v0Assoc, v1Assoc, v2Assoc, v3Assoc;
2148 DocumentModel::GeomObj e0AssocA, e1AssocA, e1AssocB, e1AssocC;
2149 DocumentModel::GeomObj q0AssocA, q0AssocB;
2151 DocumentModel::GeomObj v0Assoc_test, v1Assoc_test, v2Assoc_test, v3Assoc_test;
2152 QList<DocumentModel::GeomObj> e1Assocs_test;
2153 DocumentModel::GeomObj q0Assoc_test;
2155 v0 = getCurrentModel()->addVertex(0, 0, 0);
2156 v1 = getCurrentModel()->addVertex(1, 0, 0);
2157 v2 = getCurrentModel()->addVertex(1, 1, 0);
2158 v3 = getCurrentModel()->addVertex(0, 1, 0);
2159 e0 = getCurrentModel()->addEdgeVertices(v0, v1);
2160 e1 = getCurrentModel()->addEdgeVertices(v1, v2);
2161 q0 = getCurrentModel()->addQuadVertices( v0, v1, v2, v3 );
2164 // >>> face3.GetEntry()'0:1:4'
2165 // >>> e1.GetEntry()'0:1:8'
2166 // >>> e2.GetEntry()'0:1:9'
2167 // >>> e3.GetEntry()'0:1:10'
2168 // >>> e4.GetEntry()'0:1:11'
2169 // >>> v1.GetEntry()'0:1:12'
2170 // >>> v2.GetEntry()'0:1:13'
2171 // >>> v3.GetEntry()'0:1:14'
2172 // >>> v4.GetEntry()'0:1:15'
2175 // v0Assoc.name = "geomV0";
2176 // v0Assoc.entry = "0:1:1:1:3:6";//"0:1:12";
2177 // v0Assoc.brep = "brepV0";
2178 // v1Assoc.name = "geomV1";
2179 // v1Assoc.entry = "0:1:1:1:3:7";//"0:1:13";
2180 // v1Assoc.brep = "brepV1";
2181 // v2Assoc.name = "geomV2";
2182 // v2Assoc.entry = "0:1:1:1:3:8";//"0:1:14";
2183 // v2Assoc.brep = "brepV2";
2184 // v3Assoc.name = "geomV3";
2185 // v3Assoc.entry = "0:1:1:1:3:9";//"0:1:15";
2186 // v3Assoc.brep = "brepV3";
2190 // e0AssocA.name = "geomE0a";
2191 // e0AssocA.entry = "0:1:1:1:3:5";//"0:1:8";
2192 // e0AssocA.brep = "brepE0a";
2193 // e0AssocA.start = 0.10;
2194 // e0AssocA.end = 0.95;
2198 // e1AssocA.name = "geomE1a";
2199 // e1AssocA.entry = "0:1:1:1:3:2";//"0:1:8";
2200 // e1AssocA.brep = "brepE1a";
2201 // e1AssocA.start = 0.12;
2202 // e1AssocA.end = 0.89;
2203 // e1AssocB.name = "geomE1b";
2204 // e1AssocB.entry = "0:1:1:1:3:3";//"0:1:9";
2205 // e1AssocB.brep = "brepE1b";
2206 // e1AssocB.start = 0.20;
2207 // e1AssocB.end = 0.80;
2208 // e1AssocC.name = "geomE1c";
2209 // e1AssocC.entry = "0:1:1:1:3:4";//"0:1:10";
2210 // e1AssocC.brep = "brepE1c";
2211 // e1AssocC.start = 0.16;
2212 // e1AssocC.end = 0.96;
2214 // q0AssocA.name = "geomQuad";
2215 // q0AssocA.entry = "0:1:1:1:3";
2216 // q0AssocA.brep = "brepq0";
2218 // q0AssocB.name = "geomQuad";
2219 // q0AssocB.entry = "0:1:1:1:4";
2220 // q0AssocB.brep = "brepq0";
2222 // getCurrentModel()->addAssociation( v0, v0Assoc );
2223 // getCurrentModel()->addAssociation( v1, v1Assoc );
2224 // getCurrentModel()->addAssociation( v2, v2Assoc );
2225 // getCurrentModel()->addAssociation( v3, v3Assoc );
2228 // getCurrentModel()->addAssociation( e0, e0AssocA );
2230 // getCurrentModel()->addAssociation( e1, e1AssocA );
2231 // getCurrentModel()->addAssociation( e1, e1AssocB );
2232 // getCurrentModel()->addAssociation( e1, e1AssocC );
2234 // getCurrentModel()->addAssociation( q0, q0AssocA );
2235 // getCurrentModel()->addAssociation( q0, q0AssocB );
2241 // v0Assoc_test = getCurrentModel()->getAssociations( v0 )[0];
2242 // v1Assoc_test = getCurrentModel()->getAssociations( v1 )[0];
2243 // v2Assoc_test = getCurrentModel()->getAssociations( v2 )[0];
2244 // v3Assoc_test = getCurrentModel()->getAssociations( v3 )[0];
2245 // ASSERT( v0Assoc.name == v0Assoc_test.name );
2246 // ASSERT( v1Assoc.name == v1Assoc_test.name );
2247 // ASSERT( v2Assoc.name == v2Assoc_test.name );
2248 // ASSERT( v3Assoc.name == v3Assoc_test.name );
2249 // ASSERT( v0Assoc.entry == v0Assoc_test.entry );
2250 // ASSERT( v1Assoc.entry == v1Assoc_test.entry );
2251 // ASSERT( v2Assoc.entry == v2Assoc_test.entry );
2252 // ASSERT( v3Assoc.entry == v3Assoc_test.entry );
2255 // e1Assocs_test = getCurrentModel()->getAssociations( e1 );
2256 // ASSERT( e1Assocs_test[0].name == e1AssocA.name );
2257 // ASSERT( e1Assocs_test[1].name == e1AssocB.name );
2258 // ASSERT( e1Assocs_test[2].name == e1AssocC.name );
2259 // ASSERT( e1Assocs_test[0].entry == e1AssocA.entry );
2260 // ASSERT( e1Assocs_test[1].entry == e1AssocB.entry );
2261 // ASSERT( e1Assocs_test[2].entry == e1AssocC.entry );
2262 // ASSERT( e1Assocs_test[0].start == e1AssocA.start );
2263 // ASSERT( e1Assocs_test[1].start == e1AssocB.start );
2264 // ASSERT( e1Assocs_test[2].start == e1AssocC.start );
2265 // ASSERT( e1Assocs_test[0].end == e1AssocA.end );
2266 // ASSERT( e1Assocs_test[1].end == e1AssocB.end );
2267 // ASSERT( e1Assocs_test[2].end == e1AssocC.end );
2269 // q0Assoc_test = getCurrentModel()->getAssociations( q0 )[0];
2270 // ASSERT( q0Assoc_test.name == q0Assoc.name );
2271 // ASSERT( q0Assoc_test.entry == q0Assoc.entry );
2274 DEBTRACE("HEXABLOCKGUI::test_association fin");
2277 //clear all used dialogs by the current model
2278 void HEXABLOCKGUI::clearDialogs()
2280 std::set<HexaBaseDialog*>::const_iterator debut (currentModelDialogs.begin()),
2281 fin (currentModelDialogs.end());
2282 for(;debut!=fin;++debut) (*debut)->clear();
2284 if (_vertexAssocDiag != NULL) _vertexAssocDiag->clear(); //not a subclass of HexaBaseDialog
2286 currentModelDialogs.clear(); //empty the used dialogs list
2289 HexaBaseDialog* HEXABLOCKGUI::getDlgBox(VtkDocumentGraphicView* dgview)
2291 if (!gViewDlgBox.contains(dgview)) return NULL;
2292 return gViewDlgBox[dgview];
2295 void HEXABLOCKGUI::switchOnGraphicView(VtkDocumentGraphicView* dgview)
2297 if (dgview == NULL) return;
2299 switchOffGraphicView(dgview, false); //to avoid double connect
2302 connect( selectionMgr(), SIGNAL( currentSelectionChanged() ),
2303 dgview->getPatternDataSelectionModel(), SLOT( salomeSelectionChanged() ), Qt::UniqueConnection );
2304 connect( dgview->getPatternDataSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2305 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2306 connect( dgview->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2307 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2308 connect( dgview->getPatternGeomSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2309 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2310 connect( dgview->getGroupsSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2311 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2312 connect( dgview->getMeshSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2313 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2315 if (currentDocGView != NULL)
2317 if (currentDocGView->getViewWindow() != NULL)
2318 dgview->setViewWindow(currentDocGView->getViewWindow());
2321 dgview->setViewWindow(graphicViewsHandler->createVtkWindow());
2322 dgview->getViewWindow()->installEventFilter(this);
2325 dgview->getViewWindow()->setFocus();
2328 //_showDialogBox(getDlgBox(dgview));
2331 void HEXABLOCKGUI::switchOffGraphicView(VtkDocumentGraphicView* dgview, bool saveCurrentDlg)
2333 if (dgview == NULL) return;
2335 //disconnect signals
2336 disconnect( selectionMgr(), SIGNAL( currentSelectionChanged() ),
2337 dgview->getPatternDataSelectionModel(), SLOT( salomeSelectionChanged() ) );
2338 disconnect( dgview->getPatternDataSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2339 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2340 disconnect( dgview->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2341 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2342 disconnect( dgview->getPatternGeomSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2343 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2344 disconnect( dgview->getGroupsSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2345 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2346 disconnect( dgview->getMeshSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2347 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2350 gViewDlgBox[dgview] = currentDialog;
2352 //close opened dialog
2353 if (currentDialog != NULL) currentDialog->close();
2354 if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
2360 void HEXABLOCKGUI::switchModel(VtkDocumentGraphicView* dgview)
2362 DEBTRACE("HEXABLOCKGUI::switchModel " << dgview);
2364 if (dgview == NULL /*|| dgview == currentDocGView*/ ) //Need to switch?
2366 MESSAGE("HEXABLOCKGUI::switchModel : no need to switch!");
2370 //switch off the current document graphic view (disconnect signals...)
2371 if (currentDocGView != NULL)
2373 //Hide current actor
2375 switchOffGraphicView(currentDocGView);
2378 //clear the dialogs used by the current model so they can be used by the new model
2379 if (currentDocGView != dgview) clearDialogs();
2382 _patternDataTreeView->setModel(dgview->getPatternDataModel());
2383 _patternBuilderTreeView->setModel(dgview->getPatternBuilderModel());
2384 _patternGeomTreeView->setModel(dgview->getPatternGeomModel());
2385 _groupsTreeView->setModel(dgview->getGroupsModel());
2386 _meshTreeView->setModel(dgview->getMeshModel());
2388 _patternDataTreeView->setSelectionModel(dgview->getPatternDataSelectionModel());
2389 _patternDataTreeView->setEditTriggers(/*QAbstractItemView::EditKeyPressed*/QAbstractItemView::AllEditTriggers /*QAbstractItemView::NoEditTriggers*/);
2391 _patternBuilderTreeView->setSelectionModel(dgview->getPatternBuilderSelectionModel());
2392 _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
2394 _patternGeomTreeView->setSelectionModel(dgview->getPatternGeomSelectionModel());
2395 _patternGeomTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
2397 _groupsTreeView->setSelectionModel(dgview->getGroupsSelectionModel());
2398 _groupsTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
2400 _meshTreeView->setSelectionModel(dgview->getMeshSelectionModel());
2401 _meshTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
2403 //switch on this graphic view (connect signals...)
2404 switchOnGraphicView(dgview);
2405 currentDocGView = dgview;
2406 if (_vertexAssocDiag != NULL)
2408 _vertexAssocDiag->setDocumentModel(getCurrentModel());
2409 _vertexAssocDiag->setPatternDataSelectionModel(currentDocGView->getPatternDataSelectionModel());
2411 currentDocGView->getViewWindow()->setFocus();
2413 currentDocGView->getDocumentModel()->refresh();
2417 // void detruitDialog() {
2418 // currentDialog = NULL;
2420 // if (_sdjfgjh) delete _sdjfgjh;
2427 DocumentModel* HEXABLOCKGUI::getCurrentModel()
2429 if (currentDocGView == NULL) return NULL;
2430 return currentDocGView->getDocumentModel();
2434 HEXABLOCKGUI::ViewType HEXABLOCKGUI::getActiveViewType()
2436 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2437 if (anApp == NULL) return UNKNOWN;
2438 SUIT_ViewManager* activeVm = anApp->activeViewManager();
2439 if (activeVm == NULL) return UNKNOWN;
2441 QString vmType = activeVm->getType();
2442 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
2444 else if ( vmType == OCCViewer_Viewer::Type() )
2450 pair <QString, HEXA_NS::Document*> HEXABLOCKGUI::newHexaDocument()
2452 // Create Document from HEXABLOCK ENGINE
2453 // WARNING : IN HEXABLOCK component, GUI and ENGINE share the same process
2454 HEXABLOCK_ORB::Document_ptr docIn = _hexaEngine->addDocument("default");
2456 HEXA_NS::Document* doc = NULL;
2459 // looking doc impl ( c++ )
2460 Document_impl* dServant = DownCast<Document_impl*>( docIn );
2462 if ( dServant) doc = dServant->GetImpl();
2464 // looking for docEntry
2465 if ( !CORBA::is_nil(docIn) ){
2466 CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( docIn );
2467 QString docIOR = anIOR.in();
2468 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
2469 if ( !docIOR.isEmpty() ) {
2470 _PTR(SObject) SO( study->studyDS()->FindObjectIOR( docIOR.toLatin1().constData() ) );
2472 docEntry = SO->GetID().c_str();
2475 DEBTRACE("HEXABLOCKGUI::newHexaDocument docEntry "<<docEntry.toStdString());
2477 return make_pair (docEntry, doc);
2481 void HEXABLOCKGUI::newDocument()
2483 DEBTRACE("HEXABLOCKGUI::newDocument");
2485 // MESSAGE("===== NEW DOCUMENT: je commence ! " << jepeux);
2488 QMainWindow *aParent = application()->desktop();
2489 QWidget *central = aParent->centralWidget();
2491 central->setFocus();
2493 DEBTRACE("No Central Widget");
2496 if (currentOccGView == NULL)
2498 currentOccGView = new OccGraphicView(graphicViewsHandler->createOccWindow(),
2499 application()->desktop());
2500 currentOccGView->getViewWindow()->installEventFilter(this);
2502 else if (currentOccGView->getViewWindow() == NULL)
2504 currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
2505 currentOccGView->getViewWindow()->installEventFilter(this);
2509 // Create Document from HEXABLOCK ENGINE
2510 pair <QString, HEXA_NS::Document*> docEntry_Doc ( newHexaDocument() );
2512 VtkDocumentGraphicView* newGraphicView;
2513 //One document at a time
2514 if (currentDocGView != NULL)
2516 if (currentDocGView->getViewWindow() == NULL)
2518 currentDocGView->setViewWindow(graphicViewsHandler->createVtkWindow());
2519 currentDocGView->getViewWindow()->installEventFilter(this);
2522 // Create a new document with the current window
2523 newGraphicView = graphicViewsHandler->createDocumentGraphicView(
2524 new DocumentModel( docEntry_Doc.second,
2525 docEntry_Doc.first, this ),
2526 currentDocGView->getViewWindow(),
2527 application()->desktop() );
2531 // Create the new Document Graphic View with a new window
2532 newGraphicView = graphicViewsHandler->createDocumentGraphicView(
2533 new DocumentModel( docEntry_Doc.second,
2534 docEntry_Doc.first, this ),
2535 graphicViewsHandler->createVtkWindow(),
2536 application()->desktop() );
2537 newGraphicView->getViewWindow()->installEventFilter(this);
2540 if (newGraphicView == NULL)
2541 //We couldn't create a new document graphic view
2542 //we'd better show a dialog box info to inform the user
2545 docs[docEntry_Doc.first] = newGraphicView;
2546 switchModel(newGraphicView); //select the corresponding document in the browser instead
2549 // _dwPattern->raise();
2551 // _PTR(Study) aStudy = (( SalomeApp_Study* )(getApp()->activeStudy()))->studyDS();
2552 // _PTR(SComponent) aComponent = aStudy->FindComponent("HEXABLOCK");
2553 // SalomeApp_DataModel::updateTree (aComponent, HEXABLOCKGUI::activeStudy());
2554 getApp()->updateObjectBrowser();
2557 // for (double i=0; i < 10000000000000000; ++i);
2559 // MESSAGE("===== NEW DOCUMENT: j'ai fini!");
2564 //Loads the model from the xmlFile in the current graphic view
2565 void HEXABLOCKGUI::loadDocument( const QString &inFile )
2567 DEBTRACE("HEXABLOCKGUI::loadDocument");
2570 QMainWindow *aParent = application()->desktop();
2571 QString selectedFile;
2573 if ( inFile.isNull() ){
2574 QFileDialog dialog( aParent, tr("Open HexaBlock Document") ,
2575 QString::null, tr( "XML-Files (*.xml);;All Files (*)" ) );
2576 dialog.setHistory( getQuickDirList() );
2578 //use the last path as default
2579 if (!(loadDocLastPath->absolutePath()).isEmpty())
2580 dialog.setDirectory(*loadDocLastPath);
2583 QStringList selectedFiles = dialog.selectedFiles();
2584 if (!selectedFiles.isEmpty())
2585 selectedFile = selectedFiles.first();
2587 //remember the selected path
2588 *loadDocLastPath = dialog.directory();
2591 selectedFile = inFile;
2593 if (! selectedFile.isEmpty())
2595 //we create a new document if necessary
2596 if (currentDocGView == NULL)
2597 //Need a new document
2599 else if (currentDocGView->getViewWindow() == NULL) //there's a document without a view
2601 currentDocGView->setViewWindow(graphicViewsHandler->createVtkWindow());
2602 currentDocGView->getViewWindow()->installEventFilter(this);
2605 if (!currentDocGView->isEmpty())
2606 //we can only have one document for a graphic view
2609 //we load the selected file in the current graphic view
2610 currentDocGView->loadDocument(selectedFile);
2611 DocumentModel* currentModel = getCurrentModel();
2612 renameObject( currentModel->documentEntry(), currentModel->getName() );
2614 // _PTR(Study) aStudy = (( SalomeApp_Study* )(getApp()->activeStudy()))->studyDS();
2615 // _PTR(SComponent) aComponent = aStudy->FindComponent("HEXABLOCK");
2616 // SalomeApp_DataModel::updateTree (aComponent, HEXABLOCKGUI::activeStudy());
2617 getApp()->updateObjectBrowser();
2622 void HEXABLOCKGUI::saveDocument()
2624 QMainWindow *aParent = application()->desktop();
2625 // QString anInitialPath = "";
2626 // if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
2627 // anInitialPath = QDir::currentPath();
2628 // QString aMeshName = anIO->getName();
2631 QString aDocName = "document", aFilename;
2633 filter.append( QObject::tr( "XML_FILES_FILTER" ) + " (*.xml)" );
2634 filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
2636 //use the last selected directory as default path for file selection
2637 aFilename = saveDocLastPath->absolutePath();
2638 if (!aFilename.isEmpty())
2639 aFilename += QString("/") + aDocName;
2641 //show the dialog for file selection
2642 aFilename = SUIT_FileDlg::getFileName( aParent,
2645 tr( "Save HexaBlock Document" ),
2648 //save the document in the selected file
2649 if ( !aFilename.isEmpty() ) {
2650 getCurrentVtkGraphicView()->saveDocument( aFilename );
2652 //Remember the path for next save
2653 QFileInfo fileInfo(aFilename);
2654 *saveDocLastPath = fileInfo.dir();
2660 void HEXABLOCKGUI::slot_modelChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
2662 //std::cout << "HHHHHHHHHHHHHHHHHH Model changed." << std::endl;
2663 //std::cout << "HHHHHHHHHHHHHHHHHH slot_modelChanged topLeft -> " << topLeft.data().toString().toStdString()<<std::endl;
2664 //std::cout << "HHHHHHHHHHHHHHHHHH slot_modelChanged bottomRight ->" << bottomRight.data().toString().toStdString()<<std::endl;
2666 _patternDataTreeView->openPersistentEditor( topLeft );
2668 // // Make the combo boxes always displayed.
2669 // for ( int i = 0; i < getCurrentModel()->rowCount(); ++i )
2671 // QModelIndex ind = getCurrentModel()->index(i);
2672 // _patternDataTreeView->openPersistentEditor( ind );
2673 // std::cout << "ind" << ind.data() << std::endl;
2677 void HEXABLOCKGUI::_showDialogBox( HexaBaseDialog* diag )
2679 if (diag == NULL || _dwInputPanel == NULL ||
2680 getCurrentVtkGraphicView() == NULL) return;
2682 //mark this dialog as used by the current model
2683 currentModelDialogs.insert(diag);
2685 //close the current dialog box info
2686 if (_treeViewDelegate != NULL)
2687 _treeViewDelegate->closeDialog();
2689 if (_dwInputPanel->widget())
2690 _dwInputPanel->widget()->close();
2692 //Temporary for debugging EdgeAssoc Faked InfoDialog
2693 if (diag == _edgeAssocDiag)
2694 diag->debugEdgeAssoc = true;
2696 diag->debugEdgeAssoc = false;
2698 if (diag == _quadAssocDiag || diag == _edgeAssocDiag || diag == _addShapeDiag)
2699 assocInProgress = true;
2701 assocInProgress = false;
2703 //show the dialog box in the dockwidget
2704 diag->resetSizeAndShow(_dwInputPanel);
2706 //clear the current selections
2707 if (HEXABLOCKGUI::selectionMgr() != NULL)
2708 HEXABLOCKGUI::selectionMgr()->clearSelected();
2710 currentDialog = diag;
2714 void HEXABLOCKGUI::addVertex()
2716 if ( !_vertexDiag ){
2717 _vertexDiag = new VertexDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2719 _showDialogBox( _vertexDiag );
2722 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2723 if (_vertexDiag != NULL && doc != NULL)
2724 _vertexDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_VERTEX).c_str());
2727 void HEXABLOCKGUI::addEdge()
2730 _edgeDiag = new EdgeDialog( _dwInputPanel, HexaBaseDialog::NEW_MODE);
2732 _showDialogBox( _edgeDiag );
2735 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2736 if (_edgeDiag != NULL && doc != NULL)
2737 _edgeDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_EDGE).c_str());
2740 void HEXABLOCKGUI::addQuad()
2743 _quadDiag = new QuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2746 _showDialogBox( _quadDiag );
2749 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2750 if (_quadDiag != NULL && doc != NULL)
2751 _quadDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_QUAD).c_str());
2754 void HEXABLOCKGUI::addHexa()
2757 _hexaDiag = new HexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2759 _showDialogBox( _hexaDiag );
2762 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2763 if (_hexaDiag != NULL && doc != NULL)
2764 _hexaDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_HEXA).c_str());
2767 void HEXABLOCKGUI::addVector()
2769 if ( !_vectorDiag ){
2770 _vectorDiag = new VectorDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2772 _showDialogBox( _vectorDiag );
2775 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2776 if (_vectorDiag != NULL && doc != NULL)
2777 _vectorDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_VECTOR).c_str());
2780 void HEXABLOCKGUI::addCylinder()
2782 if ( !_cylinderDiag ){
2783 _cylinderDiag = new CylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2785 _showDialogBox( _cylinderDiag );
2788 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2789 if (_cylinderDiag != NULL && doc != NULL)
2790 _cylinderDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_CYLINDER).c_str());
2794 void HEXABLOCKGUI::addPipe()
2797 _pipeDiag = new PipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2799 _showDialogBox( _pipeDiag );
2802 HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2803 if (_pipeDiag != NULL && doc != NULL)
2804 _pipeDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_CYLINDER).c_str());
2808 void HEXABLOCKGUI::makeGrid()
2810 if ( !_makeGridDiag ){
2811 _makeGridDiag = new MakeGridDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2813 _showDialogBox( _makeGridDiag );
2817 void HEXABLOCKGUI::makeCylinder()
2819 if ( !_makeCylinderDiag ){
2820 _makeCylinderDiag = new MakeCylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2822 _showDialogBox( _makeCylinderDiag );
2825 void HEXABLOCKGUI::makePipe()
2827 if ( !_makePipeDiag ){
2828 _makePipeDiag = new MakePipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2830 _showDialogBox( _makePipeDiag );
2833 void HEXABLOCKGUI::makeCylinders()
2835 if ( !_makeCylindersDiag ){
2836 _makeCylindersDiag = new MakeCylindersDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2838 _showDialogBox( _makeCylindersDiag );
2841 void HEXABLOCKGUI::makePipes()
2843 if ( !_makePipesDiag ){
2844 _makePipesDiag = new MakePipesDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2846 _showDialogBox( _makePipesDiag );
2850 void HEXABLOCKGUI::makeHemiSphere() // NEW HEXA3
2852 if ( !_makeHemiSphereDiag ){
2853 _makeHemiSphereDiag = new MakeHemiSphereDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2855 _showDialogBox( _makeHemiSphereDiag );
2859 void HEXABLOCKGUI::removeHexa()
2861 if ( !_removeHexaDiag ){
2862 _removeHexaDiag = new RemoveHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2864 _showDialogBox( _removeHexaDiag );
2868 void HEXABLOCKGUI::prismQuad()
2870 if ( !_prismQuadDiag ){
2871 _prismQuadDiag = new PrismQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2873 _showDialogBox( _prismQuadDiag );
2877 void HEXABLOCKGUI::joinQuad()
2879 if ( !_joinQuadDiag ){
2880 _joinQuadDiag = new JoinQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2882 _showDialogBox( _joinQuadDiag );
2885 void HEXABLOCKGUI::merge()
2888 _mergeDiag = new MergeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2890 _showDialogBox( _mergeDiag );
2893 void HEXABLOCKGUI::disconnectElts()
2895 if ( !_disconnectDiag ){
2896 _disconnectDiag = new DisconnectDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2898 _showDialogBox( _disconnectDiag );
2901 void HEXABLOCKGUI::cutEdge()
2903 if ( !_cutEdgeDiag ){
2904 _cutEdgeDiag = new CutEdgeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2906 _showDialogBox( _cutEdgeDiag );
2909 void HEXABLOCKGUI::makeTransformation()
2911 if ( !_makeTransformationDiag ){
2912 _makeTransformationDiag = new MakeTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2914 _showDialogBox( _makeTransformationDiag );
2918 void HEXABLOCKGUI::makeSymmetry()
2920 if ( !_makeSymmetryDiag ){
2921 _makeSymmetryDiag = new MakeSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2923 _showDialogBox( _makeSymmetryDiag );
2927 void HEXABLOCKGUI::performTransformation()
2929 if ( !_performTransformationDiag ){
2930 _performTransformationDiag = new PerformTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2932 _showDialogBox( _performTransformationDiag );
2936 void HEXABLOCKGUI::performSymmetry()
2938 if ( !_performSymmetryDiag ){
2939 _performSymmetryDiag = new PerformSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2941 _showDialogBox( _performSymmetryDiag );
2945 void HEXABLOCKGUI::replaceHexa() // NEW HEXA3
2947 if ( !_replaceHexaDiag ){
2948 _replaceHexaDiag = new ReplaceHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2950 _showDialogBox( _replaceHexaDiag );
2954 void HEXABLOCKGUI::quadRevolution() // NEW HEXA3
2956 if ( !_quadRevolutionDiag ){
2957 _quadRevolutionDiag = new QuadRevolutionDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2959 _showDialogBox( _quadRevolutionDiag );
2963 // void HEXABLOCKGUI::assocVertex()
2965 // if ( !_vertexAssocDiag ){
2966 // _vertexAssocDiag = new VertexAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2968 // _showDialogBox( vertexAssocDiag );
2972 void HEXABLOCKGUI::assocVertex()
2974 if (!_dwInputPanel) return;
2975 QWidget* d = dynamic_cast<SUIT_Desktop*>(_dwInputPanel->parent());
2977 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2978 if (currentDGView == NULL) return;
2980 if ( !_vertexAssocDiag ){
2981 _vertexAssocDiag = new VertexAssocDialog( NULL, d );
2982 if (!_vertexAssocDiag) return;
2984 _vertexAssocDiag->setDocumentModel(getCurrentModel());
2985 _vertexAssocDiag->setPatternDataSelectionModel(currentDGView->getPatternDataSelectionModel());
2987 //close current widget
2988 if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
2989 if (_dwInputPanel->widget()) _dwInputPanel->widget()->close();
2991 //add the vertex assoc dialog in the dockwidget
2992 if ( !_dwInputPanel->isVisible() ) _dwInputPanel->setVisible(true);
2993 _dwInputPanel->setWidget(_vertexAssocDiag);
2994 _dwInputPanel->setWindowTitle(_vertexAssocDiag->windowTitle());
2995 _vertexAssocDiag->adjustSize();
2996 assocInProgress = true;
2997 _vertexAssocDiag->show();
3002 void HEXABLOCKGUI::assocEdge()
3004 if ( !_edgeAssocDiag ){
3005 _edgeAssocDiag = new EdgeAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
3006 // _edgeAssocDiag->setGeomEngine( _geomEngine );
3008 _showDialogBox( _edgeAssocDiag );
3011 void HEXABLOCKGUI::assocQuad()
3013 if ( !_quadAssocDiag ){
3014 _quadAssocDiag = new QuadAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
3016 _showDialogBox( _quadAssocDiag );
3020 void HEXABLOCKGUI::addGroup()
3023 _groupDiag = new GroupDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
3025 _showDialogBox( _groupDiag );
3026 if (_groupDiag != NULL && getCurrentModel() != NULL)
3028 HEXA_NS::Document* doc = getCurrentModel()->getHexaDocument();
3029 if (doc == NULL) return;
3030 char defaultName[16];
3031 sprintf (defaultName, "g%04d", doc->countGroup());
3032 _groupDiag->name_le->setText(defaultName);
3036 void HEXABLOCKGUI::removeGroup()
3038 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3039 if (currentDGView == NULL) return;
3041 QItemSelectionModel *groupsSelectionModel = _groupsTreeView->selectionModel();
3042 QModelIndexList l = groupsSelectionModel->selectedIndexes();
3043 int nbGroupsRemoved = 0;
3046 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
3047 tr( "No group selected!" ) );
3051 foreach( QModelIndex selected, l ){
3052 if ( selected.data(HEXA_TREE_ROLE) == GROUP_TREE ){
3053 selected = currentDGView->getGroupsModel()->mapToSource( selected );
3054 Q_ASSERT(selected.isValid());
3056 //Confirm the deletion of the group
3057 if (SUIT_MessageBox::question(
3060 tr("Remove group : %1 ?").arg(selected.data().toString()),
3061 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
3062 SUIT_MessageBox::Cancel
3063 ) == SUIT_MessageBox::Cancel) return;
3065 bool removed = getCurrentModel()->removeGroup( selected );
3067 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
3068 tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
3074 if (!nbGroupsRemoved)
3075 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
3076 tr( "No group selected!" ) );
3079 void HEXABLOCKGUI::addLaw()
3082 _lawDiag = new LawDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
3084 _showDialogBox( _lawDiag );
3085 if (_lawDiag != NULL && getCurrentModel() != NULL)
3087 HEXA_NS::Document* doc = getCurrentModel()->getHexaDocument();
3088 if (doc == NULL) return;
3089 char defaultName[16];
3090 sprintf (defaultName, "l%04d", doc->countLaw());
3091 _lawDiag->name_le->setText(defaultName);
3095 void HEXABLOCKGUI::removeLaw()
3097 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3098 if (currentDGView == NULL) return;
3100 QModelIndexList l = currentDGView->getMeshSelectionModel()->selectedIndexes();
3101 int nbLawsRemoved = 0;
3104 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
3105 tr( "No law selected!" ) );
3109 foreach( QModelIndex selected, l ){
3110 if ( selected.data(HEXA_TREE_ROLE) == LAW_TREE ){
3111 selected = currentDGView->getMeshModel()->mapToSource( selected );
3112 Q_ASSERT(selected.isValid());
3114 //Confirm the deletion of the law
3115 if (SUIT_MessageBox::question(
3118 tr("Remove law : %1 ?\nAll propagations having this law will have the default law.").arg(selected.data().toString()),
3119 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
3120 SUIT_MessageBox::Cancel
3121 ) == SUIT_MessageBox::Cancel) return;
3123 bool removed = getCurrentModel()->removeLaw(selected);
3125 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
3126 tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
3133 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
3134 tr( "No law selected!" ) );
3139 void HEXABLOCKGUI::setPropagation()
3141 if ( !_propagationDiag ){
3142 _propagationDiag = new PropagationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
3144 _showDialogBox( _propagationDiag );
3148 // Dialog box to compute a mesh from a document
3149 // --------------------------------------------
3150 void HEXABLOCKGUI::computeMesh()
3152 if ( !_computeMeshDiag ){
3153 _computeMeshDiag = new ComputeMeshDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
3155 _computeMeshDiag->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
3156 _showDialogBox( _computeMeshDiag );
3159 void HEXABLOCKGUI::clearAssociations()
3161 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3162 if (currentDGView == NULL) return;
3164 // QMessageBox::warning( 0, "windowTitle()", "clearAssociations" );
3165 QModelIndex iDataModel = _patternDataTreeView->currentIndex();
3166 QModelIndex iModel = currentDGView->getPatternDataModel()->mapToSource(iDataModel);
3168 getCurrentModel()->clearEltAssociations(iModel);
3170 // SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
3173 void HEXABLOCKGUI::showModelInfo()
3175 //create the info dialog if not yet
3176 if (_modelInfoDiag == NULL)
3177 _modelInfoDiag = new ModelInfoDialog(_dwInputPanel);
3179 //show the model informations dialog
3180 _showDialogBox( _modelInfoDiag );
3183 void HEXABLOCKGUI::addShape()
3185 //create the info dialog if not yet
3186 if (_addShapeDiag == NULL)
3187 _addShapeDiag = new AddShapeDialog(_dwInputPanel);
3189 //show the model informations dialog
3190 _showDialogBox( _addShapeDiag );
3193 void HEXABLOCKGUI::clearAllAssociations()
3195 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3196 if (currentDGView == NULL) return;
3198 int currentChildIndex = 0;
3199 QModelIndex currentIndex = currentDGView->getPatternDataModel()->mapToSource(_patternDataTreeView->currentIndex());
3200 if (!currentIndex.isValid()) return;
3201 QVariant currentAssocVariant;
3202 QString currentAssocEntry;
3204 //Confirm the deletion of the associations
3205 QVariant treeVariant = currentIndex.data( HEXA_TREE_ROLE );
3206 if ( !treeVariant.isValid() ) return;
3207 int eltType = treeVariant.toInt();
3208 QString typeStr = "";
3209 HEXA_NS::EnumElt hexaType;
3210 if (eltType == VERTEX_DIR_TREE)
3212 typeStr = tr("TREE_ITEM_VERTEX").toUpper();
3213 hexaType = HEXA_NS::EL_VERTEX;
3215 else if (eltType == EDGE_DIR_TREE)
3217 typeStr = tr("TREE_ITEM_EDGE").toUpper();
3218 hexaType = HEXA_NS::EL_EDGE;
3220 else if (eltType == QUAD_DIR_TREE)
3222 typeStr = tr("TREE_ITEM_QUAD").toUpper();
3223 hexaType = HEXA_NS::EL_QUAD;
3226 if (SUIT_MessageBox::question(
3228 tr("CLEAR_ASSOCIATIONS"),
3229 tr("CLEAR_ALL_ASSOCIATIONS_ON") + " " + typeStr + "?",
3230 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
3231 SUIT_MessageBox::Cancel
3232 ) == SUIT_MessageBox::Cancel) return;
3235 DocumentModel* docModel = getCurrentModel();
3236 if (docModel == NULL) return;
3237 docModel->clearAssociation(hexaType);
3239 // QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
3240 // while( currentChild.isValid() ) {
3242 // currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
3243 // currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
3244 // if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
3245 // getCurrentModel()->clearEltAssociations(currentChild);
3247 // currentChild = currentChild.sibling(currentChildIndex++, 0);
3250 //SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
3253 void HEXABLOCKGUI::showAssociations()
3255 VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3256 if (currentDGView == NULL) return;
3258 QModelIndexList elts;
3259 int currentChildIndex = 0;
3260 QVariant currentAssocVariant;
3261 QString currentAssocEntry;
3262 QModelIndex currentIndex = _patternDataTreeView->currentIndex();
3263 QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
3265 while( currentChild.isValid() ) {
3267 currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
3268 currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
3269 if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
3270 elts << currentChild;
3272 currentChild = currentChild.sibling(currentChildIndex++, 0);
3274 currentDGView->getPatternDataSelectionModel()->highlightEltsWithAssocs(elts);
3278 LightApp_SelectionMgr* HEXABLOCKGUI::selectionMgr()
3280 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
3282 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
3287 bool HEXABLOCKGUI::eventFilter(QObject *obj, QEvent *event)
3289 if ( currentDialog == NULL ) return false;
3291 if ( event->type() == QEvent::Enter ){ // ENTER EVENT
3293 // The window acquire the focus when the cursor enter
3295 //OCC - window enter
3296 OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>(obj);
3297 if ( occWindow != NULL)
3299 if (!occWindow->hasFocus()) occWindow->setFocus();
3300 if (currentDialog != NULL && !currentDialog->isHidden())
3301 currentDialog->onWindowActivated(occWindow->getViewManager());
3305 SVTK_ViewWindow* vtkWindow = dynamic_cast<SVTK_ViewWindow*>(obj);
3306 if ( vtkWindow != NULL)
3308 if (!vtkWindow->hasFocus()) vtkWindow->setFocus();
3309 if (currentDialog != NULL && !currentDialog->isHidden())
3310 currentDialog->onWindowActivated(vtkWindow->getViewManager());
3313 //Don't pass the signal
3317 //standard event processing
3318 return QObject::eventFilter(obj, event);
3321 QStringList HEXABLOCKGUI::getQuickDirList()
3323 QStringList dirList;
3324 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
3326 dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
3333 // --- Export the module
3337 HEXABLOCKGUI_EXPORT CAM_Module* createModule()
3339 return new HEXABLOCKGUI();
3342 HEXABLOCKGUI_EXPORT char* getModuleVersion()
3344 return (char*)HEXABLOCK_VERSION_STR;
3349 // void HEXABLOCKGUI::newMesh( const std::string& meshName,
3351 // const std::string& container )
3354 // SalomeApp_Application* app = getApp();
3355 // int activeStudyId = app->activeStudy()->id();
3357 // if ( CORBA::is_nil(_hexaEngine) ) _hexaEngine = InitHEXABLOCKGen( app );
3358 // if ( CORBA::is_nil(_smeshEngine)) _smeshEngine = InitSMESHGen( app, container );
3359 // if ( CORBA::is_nil(_geomEngine) ) _geomEngine = InitGEOMGen( app, container );
3361 // std::cout << "_hexaEngine =>" << _hexaEngine << std::endl;
3362 // std::cout << "_smeshEngine =>" << _smeshEngine << std::endl;
3363 // std::cout << "_geomEngine =>" << _geomEngine << std::endl;
3365 // HEXA_NS::Document* docImpl = getCurrentModel()->documentImpl();
3366 // std::cout << "docImpl =>" << docImpl << std::endl;
3367 // std::cout << "docImpl->getFile() =>" << docImpl->getFile() << std::endl;
3368 // HEXABLOCK_ORB::Document_var anDocObj= _hexaEngine->loadDocument( docImpl->getFile() );
3369 // std::cout << "anDocObj =>" << anDocObj << std::endl;
3372 // GEOM::GEOM_I3DPrimOperations_var anGeomOper = _geomEngine->GetI3DPrimOperations( activeStudyId );
3373 // if ( CORBA::is_nil(anGeomOper) ) return; //!anGeomOper->_is_nil() ) {
3374 // std::cout << "anGeomOper =>" << anGeomOper << std::endl;
3375 // GEOM::GEOM_Object_var anGeomObj = anGeomOper->MakeBoxDXDYDZ( 5., 5., 5. );
3376 // std::cout << "anGeomObj =>" << anGeomObj << std::endl;
3379 // SALOMEDS::SObject _geomEngine->AddInStudy (in SALOMEDS::Study theStudy,
3380 // in GEOM_Object theObject,
3381 // in string theName,
3385 // // void GEOMBase::PublishSubObject( GEOM::GEOM_Object_ptr object )
3387 // SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
3388 // if ( study && !CORBA::is_nil( object ) ) {
3389 // _PTR(Study) studyDS = study->studyDS();
3390 // QString entry = GetEntry( object );
3391 // GEOM::GEOM_Object_var father = object->GetMainShape();
3392 // QString fatherEntry = GetEntry( father );
3393 // if ( entry.isEmpty() && !CORBA::is_nil( father ) && !fatherEntry.isEmpty() ) {
3394 // QString name = GetName( object );
3395 // GeometryGUI::GetGeomGen()->AddInStudy( GeometryGUI::ClientStudyToStudy( studyDS ),
3396 // object, name.toLatin1().data(), father.in() );
3402 // // geompy = smesh.geompy
3403 // // #fkl: shape = doc.getShape()
3404 // // shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
3405 // // geompy.addToStudy(shape, name)
3407 // // component = salome.lcc.FindOrLoadComponent(container, "SMESH")
3408 // // component.init_smesh(salome.myStudy, geompy.geom)
3409 // // mesh = component.Mesh(shape, name)
3411 // // so = "libHexaBlockEngine.so"
3413 // // algo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(component, "HEXABLOCK_3D", so)
3414 // SMESH::SMESH_Hypothesis_var algo = _smeshEngine->CreateHypothesis( "HEXABLOCK_3D", "libHexaBlockEngine.so");
3415 // // raises ( SALOME::SALOME_Exception );
3416 // // mesh.mesh.AddHypothesis(shape, algo)
3418 // // hypo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(component, "HEXABLOCK_Parameters", so)
3419 // //HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var
3420 // SMESH::SMESH_Hypothesis_var hypo = _smeshEngine->CreateHypothesis( "HEXABLOCK_Parameters", "libHexaBlockEngine.so");
3422 // HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var hexHypo = HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis::_narrow(hypo);
3423 // ASSERT(!CORBA::is_nil(hexHypo));
3425 // // mesh.mesh.AddHypothesis(shape, hypo)
3427 // // hexHypo->SetDocument(anDocObj);
3428 // // hexHypo->SetDimension(dim);
3430 // // mesh.Compute()
3438 // void newMesh( const std::string& meshName, int dim )// const std::string& container )
3441 // // _smeshEngine.init_smesh(salome.myStudy, geompy.geom)
3442 // SMESH::SMESH_var mesh = _smeshEngine->Mesh(shape, name);
3443 // SMESH::SMESH_Hypothesis_var algo = _smeshEngine->CreateHypothesis( "HEXABLOCK_3D", "libHexaBlockEngine.so");
3444 // SMESH::SMESH_Hypothesis_var hypo = _smeshEngine->CreateHypothesis( "HEXABLOCK_Parameters", "libHexaBlockEngine.so");
3445 // HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var hexHypo = HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis::_narrow(hypo);
3446 // hexHypo->SetDocument(anDocObj);
3447 // hexHypo->SetDimension(dim);
3451 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3453 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3454 if ( CORBA::is_nil( myComponentSMESH ) )
3456 SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3458 aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3459 return aGUI.myComponentSMESH;
3462 myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3463 return myComponentSMESH;
3468 // // throw SALOME_Exception(LOCALIZED("assocVertex"));
3469 // } catch ( SALOME::SALOME_Exception& exc ){
3470 // INFOS("Following exception was cought:\n\t"<<exc.details.text);
3471 // } catch( const std::exception& exc){
3472 // INFOS("Following exception was cought:\n\t"<<exc.what());
3473 // } catch (Standard_Failure& exc) {
3474 // MESSAGE("OCCT Exception in SMESH_Pattern: " << exc.GetMessageString());
3476 // MESSAGE("Unknown exception was cought !!!");