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>
56 #include <SOCC_ViewModel.h>
57 #include <SOCC_ViewWindow.h>
58 #include <OCCViewer_ViewWindow.h>
62 // SALOME KERNEL includes
63 #include <SALOMEDS_Study.hxx>
64 #include <SALOMEDSClient_StudyBuilder.hxx>
65 #include <SALOMEDSClient_SComponent.hxx>
66 #include <SALOMEDSClient_ClientFactory.hxx>
67 #include <SALOMEDSClient_IParameters.hxx>
71 #include <SalomeApp_DataObject.h>
72 #include <SalomeApp_Study.h>
73 #include <SalomeApp_Module.h>
74 #include <SalomeApp_Application.h>
75 #include <SalomeApp_DataModel.h>
78 #include <SALOME_ListIO.hxx>
79 #include <SALOME_ListIteratorOfListIO.hxx>
82 #include <SALOME_LifeCycleCORBA.hxx>
84 #include <LightApp_VTKSelector.h>
86 #include <OCCViewer_ViewManager.h>
89 #include <QtxPopupMgr.h>
92 #include "Resource.hxx"
93 // #include "QtGuiContext.hxx"
95 #include "HEXABLOCKGUI.hxx"
96 #include "HEXABLOCKGUI_Export.hxx"
97 #include "HEXABLOCKGUI_Trace.hxx"
98 #include "HEXABLOCKGUI_Resource.hxx"
99 // #include "HEXABLOCKGUI_DataModel.hxx"
100 #include "HEXABLOCKGUI_DocumentGraphicView.hxx"
101 #include "HEXABLOCKGUI_DocumentModel.hxx"
102 #include "HEXABLOCKGUI_DocumentSelectionModel.hxx"
103 #include "HEXABLOCKGUI_DocumentDelegate.hxx"
104 #include "HEXABLOCKGUI_DocumentPanel.hxx"
106 #include <HEXABLOCK_version.h>
108 #include "MyBasicGUI_PointDlg.hxx"
110 // #include CORBA_CLIENT_HEADER(HEXABLOCKPlugin_Algorithm)
112 #include "HEXABLOCK.hxx"
113 #include "HexDocument_impl.hxx"
116 #define DW_MINIMUM_WIDTH 50
117 #define DWINPUT_MINIMUM_HEIGHT 50
118 #define DWINPUT_MINIMUM_WIDTH 255
121 using namespace HEXABLOCK::GUI;
123 int HEXABLOCKGUI::_oldStudyId = -1;
125 HEXABLOCK_ORB::HEXABLOCK_Gen_var HEXABLOCKGUI::_hexaEngine = HEXABLOCK_ORB::HEXABLOCK_Gen::_nil();
126 // SMESH::SMESH_Gen_var HEXABLOCKGUI::_smeshEngine = SMESH::SMESH_Gen::_nil();
127 GEOM::GEOM_Gen_var HEXABLOCKGUI::_geomEngine = GEOM::GEOM_Gen::_nil();
129 // std::map<HEXABLOCK::GUI::DocumentModel*, SVTK_ViewWindow*> HEXABLOCKGUI::svtkViews;
130 // std::map<const QAbstractItemModel*, SVTK_ViewWindow*> HEXABLOCKGUI::svtkViews;
131 // std::map<const QAbstractItemModel*, SUIT_ViewWindow*> HEXABLOCKGUI::salomeViews;
132 // HEXABLOCK::GUI::DocumentModel *HEXABLOCKGUI::_currentModel = NULL;
134 SVTK_ViewWindow* HEXABLOCKGUI::currentVtkView = NULL;
135 OCCViewer_ViewWindow* HEXABLOCKGUI::currentOccView = NULL;
136 bool HEXABLOCKGUI::assocInProgress = false;
138 HEXABLOCKGUI::HEXABLOCKGUI() :
139 SalomeApp_Module( "HEXABLOCK" ), // default name
140 LightApp_Module( "HEXABLOCK" ),
149 _patternDataModel(0),
150 _patternBuilderModel(0),
151 _patternDataTreeView(0),
152 _patternBuilderTreeView(0),
153 _associationTreeView(0),
156 _currentGraphicView(0),
157 _treeViewDelegate(0),
158 _patternDataSelectionModel(0),
159 _patternBuilderSelectionModel(0),
160 _meshSelectionModel(0),
161 _groupsSelectionModel(0),
164 moduleActivatedOnce(false),
165 vtkViewManager(0),//,
167 // _selectFromTree( false )
176 _makeCylinderDiag(0),
178 _makeCylindersDiag(0),
186 _makeTransformationDiag(0),
187 _makeSymmetryDiag(0),
188 _performTransformationDiag(0),
189 _performSymmetryDiag(0),
198 _quadRevolutionDiag(0),
199 _makeHemiSphereDiag(0),
202 DEBTRACE("HEXABLOCKGUI::HEXABLOCKGUI");
203 // _studyContextMap.clear();
206 HEXABLOCKGUI::~HEXABLOCKGUI()
209 // disconnect( getApp(), SIGNAL(studyClosed()), _genericGui, SLOT (onCleanOnExit()));
213 SalomeApp_Study* HEXABLOCKGUI::activeStudy()
215 SUIT_Application* app = SUIT_Session::session()->activeApplication();
217 return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
223 // Gets an reference to the module's engine
224 HEXABLOCK_ORB::HEXABLOCK_Gen_ptr HEXABLOCKGUI::InitHEXABLOCKGen( SalomeApp_Application* app )
226 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer", "HEXABLOCK" );
227 HEXABLOCK_ORB::HEXABLOCK_Gen_ptr clr = HEXABLOCK_ORB::HEXABLOCK_Gen::_narrow(comp);
228 ASSERT(!CORBA::is_nil(clr));
232 // // Gets an reference to SMESH's engine CS_TO_DELETE
233 // SMESH::SMESH_Gen_ptr HEXABLOCKGUI::InitSMESHGen( SalomeApp_Application* app,
234 // const std::string& container )
236 // Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( container.c_str(), "SMESH" );
237 // SMESH::SMESH_Gen_ptr clr = SMESH::SMESH_Gen::_narrow(comp);
238 // ASSERT(!CORBA::is_nil(clr));
242 // // Gets an reference to GEOM's engine CS_TO_DELETE
243 GEOM::GEOM_Gen_ptr HEXABLOCKGUI::InitGEOMGen( SalomeApp_Application* app,
244 const std::string& container )
246 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( container.c_str(), "GEOM" );
247 MESSAGE("INITINITINITINIT comp : " << comp);
248 GEOM::GEOM_Gen_ptr clr = GEOM::GEOM_Gen::_narrow(comp);
249 MESSAGE("INITINITINITINIT clr 1: " << clr);
250 ASSERT(!CORBA::is_nil(clr));
255 void HEXABLOCKGUI::initialize( CAM_Application* app )
257 DEBTRACE("HEXABLOCKGUI::initialize");
258 SalomeApp_Module::initialize( app );
260 _hexaEngine = InitHEXABLOCKGen( dynamic_cast<SalomeApp_Application*>( app ) );
261 _geomEngine = InitGEOMGen( dynamic_cast<SalomeApp_Application*>( app ) );
262 MESSAGE("INITINITINITINIT clr 2: " << _geomEngine);
264 QWidget* aParent = application()->desktop();
265 DEBTRACE(app << " " << application() << " " << application()->desktop() << " " << aParent);
267 SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
268 setResource(aResourceMgr);
270 // if ( app && app->desktop() ){
271 // connect( app->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
272 // this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
273 // connect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
274 // this, SLOT( onObjectBrowserClick(const QModelIndex&) ) );
275 // // connect( getApp(), SIGNAL(studyClosed()), _genericGui,SLOT (onCleanOnExit()));
279 // QGraphicsScene* scene = new QGraphicsScene;
280 // scene->addText("Hello, philou!");
281 // QGraphicsView* view = new QGraphicsView(scene);
283 // app->desktop()->setCentralWidget(view);
286 createAndFillDockWidget();
291 // add component to study
292 if (createSComponent()) updateObjBrowser();
295 void HEXABLOCKGUI::viewManagers( QStringList& list ) const
297 DEBTRACE("HEXABLOCKGUI::viewManagers");
298 MESSAGE("HEXABLOCKGUI::viewManagers");
299 // foreach (const QString &str, list)
300 // MESSAGE("HEXABLOCKGUI::viewManagers"<<str.toStdString() );
301 // list.append( QxScene_Viewer::Type() );
302 // list.append( OCCViewer_Viewer::Type() );
303 // list.append( SVTK_Viewer::Type() );
307 bool HEXABLOCKGUI::activateModule( SUIT_Study* theStudy )
309 DEBTRACE("HEXABLOCKGUI::activateModule");
310 bool bOk = SalomeApp_Module::activateModule( theStudy );
311 if ( !bOk ) return false;
313 // setMenuShown( true );
314 // setToolShown( true );
315 if ( _currentModel == 0 )
320 // showDockWidgets(false);
321 showDockWidgets(true);
322 if (_dwInputPanel) _dwInputPanel->close();
324 // // import Python module that manages HEXABLOCK plugins (need to be here because SalomePyQt API uses active module)
325 // PyGILState_STATE gstate = PyGILState_Ensure();
326 // PyObject* pluginsmanager=PyImport_ImportModule((char*)"salome_pluginsmanager");
327 // if(pluginsmanager==NULL)
331 // PyObject* result=PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"hexablock","HEXABLOCK","Plugins");
334 // Py_XDECREF(result);
336 // PyGILState_Release(gstate);
337 // // end of HEXABLOCK plugins loading
339 connect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
340 this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
341 connect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
342 this, SLOT( onObjectBrowserClick(const QModelIndex&) ) );
343 // connect( getApp(), SIGNAL(studyClosed()), _genericGui,SLOT (onCleanOnExit()));
346 // vtkViewManager = getApp()->getViewManager(SVTK_Viewer::Type(), true); //create the view manager if it doesn't exist
347 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
349 SUIT_ViewManager* vm;
350 ViewManagerList OCCViewManagers, VTKViewManagers;
352 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
353 QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
354 while ( itOCC.hasNext() && (vm = itOCC.next()) )
355 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
357 application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
358 QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
359 while ( itVTK.hasNext() && (vm = itVTK.next()) )
360 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
363 SALOME_ListIO selected;
364 sm->selectedObjects( selected );
367 // disable OCC selectors
368 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
369 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
370 while ( itOCCSel.hasNext() )
371 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
372 sr->setEnabled(true);
374 // disable VTK selectors
375 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
376 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
377 while ( itVTKSel.hasNext() )
378 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
379 sr->setEnabled(true);
381 sm->setSelectedObjects( selected, true ); //NPAL 19674
384 _hexaEngine->SetCurrentStudy(SALOMEDS::Study::_nil());
385 if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( theStudy ))
386 if ( _PTR(Study) aStudy = s->studyDS()) {
387 //define _CAST(Class, shared_ptr_Obj) dynamic_cast<SALOMEDS_##Class*>(shared_ptr_Obj.get())
388 _hexaEngine->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
389 updateObjBrowser(); // objects can be removed
392 if (vtkViewManager==NULL || !vtkViewManager->getViewsCount()) newDocument();
393 if (_currentGraphicView != NULL)
394 _currentGraphicView->get_SUIT_ViewWindow()->setFocus();
401 bool HEXABLOCKGUI::deactivateModule( SUIT_Study* theStudy )
403 MESSAGE("HEXABLOCKGUI::deactivateModule");
405 setMenuShown( false );
406 setToolShown( false );
407 if (_dwInputPanel) _dwInputPanel->close();
408 showDockWidgets( false );
409 // QtGuiContext *context = QtGuiContext::getQtCurrent();
410 // _studyContextMap[theStudy->id()] = context;
411 // DEBTRACE("_studyContextMap[theStudy] " << theStudy << " " << context);
413 disconnect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
414 this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
415 disconnect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
416 this, SLOT( onObjectBrowserClick(const QModelIndex&) ) );
417 // connect( getApp(), SIGNAL(studyClosed()), _genericGui,SLOT (onCleanOnExit()));
420 if ( HEXABLOCKGUI::currentVtkView ){
421 HEXABLOCKGUI::currentVtkView->SetSelectionMode( ActorSelection ); //default selectionMode in VTKView
424 if (HEXABLOCKGUI::currentOccView != NULL)
426 getApp()->selectionMgr()->clearSelected();
427 //defaut selectionMode in OccView
428 if (currentDialog != NULL)
430 currentDialog->globalSelection();
431 currentDialog->localSelection(GEOM::GEOM_Object::_nil(), TopAbs_SHAPE);
436 // if ( _patternDataSelectionModel ){
437 // delete _patternDataSelectionModel;
438 // _patternDataSelectionModel = NULL;
440 // if ( _patternBuilderSelectionModel ){
441 // delete _patternBuilderSelectionModel;
442 // _patternBuilderSelectionModel = NULL;
445 qDeleteAll(myOCCSelectors);
446 myOCCSelectors.clear();
447 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
449 qDeleteAll(myVTKSelectors);
450 myVTKSelectors.clear();
451 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
453 return SalomeApp_Module::deactivateModule( theStudy );
457 bool HEXABLOCKGUI::renameAllowed( const QString& entry) const
459 // MESSAGE("HEXABLOCKGUI::renameAllowed");
460 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
461 SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
462 SalomeApp_DataObject* obj = appStudy ? dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry)) : 0;
464 bool res = app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference();
465 return (app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference());
469 bool HEXABLOCKGUI::renameObject( const QString& entry, const QString& name)
471 MESSAGE("HEXABLOCKGUI::renameObject");
472 // bool appRes = SalomeApp_Module::renameObject(entry,name);
473 // MESSAGE("appRes"<<appRes);
478 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
479 SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
484 _PTR(Study) aStudy = appStudy->studyDS();
489 _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
490 _PTR(GenericAttribute) anAttr;
492 if ( obj->FindAttribute(anAttr, "AttributeName") ){
493 _PTR(AttributeName) aName (anAttr);
494 // GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
496 // HEXABLOCK_Gen_i::Document_var aDoc = HEXABLOCK_Gen_i::Document::_narrow( theIOR );
497 // if (!CORBA::is_nil(aDoc)) {
498 aName->SetValue( name.toLatin1().data() ); // rename the SObject
499 // aDoc->setName( name.toLatin1().data() ); // Rename the corresponding GEOM_Object
500 _currentModel->setName( name/*.toLatin1().data()*/ );
501 // _currentGraphicView->setWindowTitle( _currentModel->getName() );
508 // --- Default windows
509 void HEXABLOCKGUI::windows( QMap<int, int>& theMap ) const
511 DEBTRACE("HEXABLOCKGUI::windows");
513 theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
514 theMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
517 // LightApp_Displayer* HEXABLOCKGUI::displayer()
519 // DEBTRACE("HEXABLOCKGUI::displayer");
520 // return _currentGraphicView;
524 // QString HEXABLOCKGUI::engineIOR() const
526 // DEBTRACE("HEXABLOCKGUI::engineIOR");
527 // // return getApp()->defaultEngineIOR();
531 QString HEXABLOCKGUI::engineIOR() const
533 DEBTRACE("HEXABLOCKGUI::engineIOR");
534 CORBA::ORB_var anORB = getApp()->orb();
535 CORBA::String_var anIOR = anORB->object_to_string(_hexaEngine);
536 return QString( anIOR.in() );
541 void HEXABLOCKGUI::onObjectBrowserClick(const QModelIndex& index)
543 DEBTRACE("HEXABLOCKGUI::onObjectBrowserClick");
544 // we want to switch automatically to the right view windows
545 QWidget *viewWindow = NULL;
547 //first, find entry of item selected
549 DataObjectList dol = getApp()->objectBrowser()->getSelected();
550 if (dol.isEmpty()) return;
551 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
553 itemEntry = item->entry();
555 // DEBTRACE("HEXABLOCKGUI::onClick index.data() => "<<index.data().toString().toStdString());
556 // DEBTRACE("HEXABLOCKGUI::onClick index.model() => "<<index.model());
557 // DEBTRACE("HEXABLOCKGUI::onClick item->name(). => "<<item->name().toStdString());
558 // DEBTRACE("HEXABLOCKGUI::onClick itemEntry =>"<<itemEntry.toStdString());
560 if ( !_salomeViewWindows.count( itemEntry ) ) return;
561 viewWindow = _salomeViewWindows[ itemEntry ];
562 if ( !viewWindow ) return;
563 // _selectFromTree = true;
564 viewWindow->setFocus();
565 _currentGraphicView->update(); //CS_TEST
566 // _selectFromTree = false;
568 // if (getApp()->activeModule()->moduleName().compare("HEXABLOCK") != 0)
569 // getApp()->activateModule("HEXABLOCK");
576 void HEXABLOCKGUI::onWindowActivated( SUIT_ViewWindow* svw)
578 DEBTRACE("HEXABLOCKGUI::onWindowActivated");
579 MESSAGE("HEXABLOCKGUI::onWindowActivated");
580 OCCViewer_ViewWindow* anOccVw = dynamic_cast<OCCViewer_ViewWindow*>(svw);
582 if ( anOccVw != NULL)
584 currentOccView->installEventFilter(this);
585 if (anOccVw != currentOccView)
586 currentOccView = anOccVw;
589 // we want to switch automatically to the right model
591 SVTK_ViewWindow* viewWindow = dynamic_cast<SVTK_ViewWindow*>(svw);
592 if (!viewWindow) return;
594 if (getApp()->activeModule() && getApp()->activeModule()->moduleName().compare("HEXABLOCK") != 0) //CS_TODO?
595 getApp()->activateModule("HEXABLOCK");
597 if (viewWindow != currentVtkView)
599 switchModel( viewWindow );
600 currentVtkView = viewWindow;
604 void HEXABLOCKGUI::onWindowClosed( SUIT_ViewWindow* svw)
606 DEBTRACE("HEXABLOCKGUI::onWindowClosed");
609 void HEXABLOCKGUI::onViewManagerAdded( SUIT_ViewManager* vm)
611 DEBTRACE("HEXABLOCKGUI::onViewManagerAdded");
612 if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
614 // qDebug( "connect" );
615 // // connect( vm, SIGNAL( keyPress ( SUIT_ViewWindow*, QKeyEvent* ) ),
616 // // this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
617 // // connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
618 // // this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
619 // connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
620 // this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
621 // LightApp_SelectionMgr* sm = getApp()->selectionMgr();
622 // myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
624 // // disable OCC selectors
625 // getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
626 // QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
627 // while ( itOCCSel.hasNext() )
628 // if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() ){
629 // sr->setEnabled(true);
630 // std::cout<<"HEXABLOCKGUI::onViewManagerAdded sr"<<sr;
633 DEBTRACE("HEXABLOCKGUI::onViewManagerAdded");
636 void HEXABLOCKGUI::onViewManagerRemoved( SUIT_ViewManager* vm)
638 DEBTRACE("HEXABLOCKGUI::::onViewManagerRemoved");
641 void HEXABLOCKGUI::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
643 QModelIndexList l = selected.indexes();
644 if ( l.count() == 0 ) return;
645 if ( !l[0].isValid() ) return;
647 QTreeView* theTree = NULL;
648 if ( sender() == _patternDataSelectionModel ){
649 theTree = _patternDataTreeView;
650 } else if ( sender() == _patternBuilderSelectionModel ){
651 theTree = _patternBuilderTreeView;
652 } else if ( sender() == _groupsSelectionModel ){
653 theTree = _groupsTreeView;
654 } else if ( sender() == _meshSelectionModel ){
655 theTree = _meshTreeView;
658 theTree->scrollTo ( l[0] );
662 // void HEXABLOCKGUI::onTryClose(bool &isClosed, QxScene_ViewWindow* window) //CS_TODO
664 // DEBTRACE("HEXABLOCKGUI::onTryClose");
665 // isClosed = _genericGui->closeContext(window);
668 // CAM_DataModel* HEXABLOCKGUI::createDataModel()
670 // DEBTRACE("HEXABLOCKGUI::createDataModel");
671 // return new HEXABLOCKGUI_DataModel(this);
675 bool HEXABLOCKGUI::createSComponent() //addComponent
677 DEBTRACE("HEXABLOCKGUI::createSComponent");
678 // --- Find or create "HEXABLOCK" SComponent in the study
680 _PTR(Study) aStudy = (( SalomeApp_Study* )(getApp()->activeStudy()))->studyDS();
681 _PTR(StudyBuilder) aBuilder (aStudy->NewBuilder());
682 _PTR(GenericAttribute) anAttr;
683 _PTR(AttributeName) aName;
685 _PTR(SComponent) aComponent = aStudy->FindComponent("HEXABLOCK");
687 aComponent = aBuilder->NewComponent("HEXABLOCK");
688 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
689 aName = _PTR(AttributeName) (anAttr);
690 aName->SetValue(getApp()->moduleTitle("HEXABLOCK").toStdString());
692 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
693 _PTR(AttributePixMap) aPixmap(anAttr);
694 aPixmap->SetPixMap("share/salome/resources/hexablock/ModuleHexablock.png");
696 aBuilder->DefineComponentInstance(aComponent, engineIOR().toStdString());
697 DEBTRACE("HEXABLOCKGUI::createSComponent engineIOR=>"<<engineIOR().toStdString());
698 // aBuilder->DefineComponentInstance(aComponent, getApp()->defaultEngineIOR().toStdString());
699 // DEBTRACE("HEXABLOCKGUI::createSComponent defaultEngineIOR=>"<<getApp()->defaultEngineIOR().toStdString());
701 // SalomeApp_DataModel::synchronize( aComponent, HEXABLOCKGUI::activeStudy() );
709 // bool HEXABLOCKGUI::isSelectionCompatible()
711 // DEBTRACE("HEXABLOCKGUI::isSelectionCompatible");
713 // bool isCompatible = true;
714 // SALOME_ListIO selected;
715 // if ( LightApp_SelectionMgr *Sel = selectionMgr() )
716 // Sel->selectedObjects( selected );
718 // SALOME_ListIteratorOfListIO It( selected );
719 // for ( ; isCompatible && It.More(); It.Next())
721 // ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
722 // ( strcmp("HEXABLOCK", It.Value()->getComponentDataType()) == 0 );
724 // return isCompatible;
727 void HEXABLOCKGUI::setResource(SUIT_ResourceMgr* r)
729 DEBTRACE("HEXABLOCKGUI::setResource");
730 _myresource = new HEXABLOCKGUI_Resource(r);
731 _myresource->preferencesChanged();
734 void HEXABLOCKGUI::createPreferences()
736 DEBTRACE("HEXABLOCKGUI::createPreferences");
737 _myresource->createPreferences(this);
740 void HEXABLOCKGUI::preferencesChanged( const QString& sect, const QString& name )
742 DEBTRACE("HEXABLOCKGUI::preferencesChanged");
743 _myresource->preferencesChanged(sect, name);
744 if(name=="userCatalog")
746 // _genericGui->getCatalogWidget()->addCatalogFromFile(Resource::userCatalog.toStdString());
750 void HEXABLOCKGUI::studyActivated() //CS_TODO
752 int newStudyId = getApp()->activeStudy()->id();
753 DEBTRACE("HEXABLOCKGUI::studyActivated " << _oldStudyId << " " << newStudyId);
755 if (_oldStudyId != -1)
757 // _studyContextMap[_oldStudyId] = QtGuiContext::getQtCurrent();
758 // if (_studyContextMap.count(newStudyId))
760 // DEBTRACE("switch to valid context " << QtGuiContext::getQtCurrent() << " " << _studyContextMap[newStudyId]);
761 // QtGuiContext::setQtCurrent(_studyContextMap[newStudyId]);
765 // DEBTRACE("no switch to null context");
768 _oldStudyId = newStudyId;
773 void HEXABLOCKGUI::treeContextMenu(const QPoint& aPosition)
775 QModelIndex currentIndex = _patternDataTreeView->currentIndex();
776 QVariant currentAssocVariant;
777 QString currentAssocEntry;
779 currentAssocVariant = currentIndex.data( HEXA_ASSOC_ENTRY_ROLE );
780 currentAssocEntry = currentIndex.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
781 if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() ){
782 // _currentModel->allowEdition();
783 QMenu menu( _patternDataTreeView );
785 QAction *clearAct = menu.addAction( "Remove association(s)" );
786 connect( clearAct, SIGNAL(triggered()), this, SLOT(clearAssociations()) );
787 menu.exec( _patternDataTreeView->mapToGlobal( aPosition) );
791 QStandardItem *item = _patternDataModel->itemFromIndex ( currentIndex );
793 //We don't do anything for single items
794 if ( item->type() == VERTEXITEM || item->type() == EDGEITEM ||
795 item->type() == QUADITEM || item->type() == HEXAITEM)
798 //No associations for HEXA
799 QVariant treeVariant = currentIndex.data( HEXA_TREE_ROLE );
800 if ( !treeVariant.isValid() ) return;
801 int eltType = treeVariant.toInt();
802 if (eltType == HEXA_DIR_TREE) return;
803 QMenu menu( _patternDataTreeView );
805 //Show association(s)
806 QAction *showAssocAct = menu.addAction( "Show associations" );
807 connect( showAssocAct, SIGNAL(triggered()), this, SLOT(showAssociations()) );
809 //Clear all associations
810 QAction *clearAllAssocAct = menu.addAction( "Remove all associations" );
811 connect( clearAllAssocAct, SIGNAL(triggered()), this, SLOT(clearAllAssociations()) );
813 menu.exec( _patternDataTreeView->mapToGlobal( aPosition) );
818 void HEXABLOCKGUI::createAndFillDockWidget()
820 QMainWindow *aParent = application()->desktop();
822 // Create dock widget (3 dock)
824 //1) *********** user input panel ( contain user's edit dialog box )
825 _dwInputPanel = new QDockWidget(aParent);
826 // QLayout* inputLayout = new QVBoxLayout(aParent);
827 // _dwInputPanel->setLayout(inputLayout);
828 // _dwInputPanel->setWindowFlags(Qt::FramelessWindowHint);
829 // _dwInputPanel->setWindowFlags(Qt::WindowTitleHint);
830 _dwInputPanel->setVisible(false);
831 _dwInputPanel->setWindowTitle("Input Panel");
832 // _dwInputPanel->setMinimumHeight(DWINPUT_MINIMUM_HEIGHT);
833 _dwInputPanel->setMinimumWidth(DWINPUT_MINIMUM_WIDTH); // --- force a minimum until display
834 _dwInputPanel->raise();
836 // _stacked = new QStackedWidget(_dwInputPanel);
837 // _dwInputPanel->setWidget(_stacked);
839 _treeViewDelegate = new DocumentDelegate(_dwInputPanel);
841 //2) ************* document data ( Pattern, Association, Mesh ) in treeview representation
843 _dwPattern = new QDockWidget(aParent);
844 // _dwPattern->installEventFilter(this);
845 _dwPattern->setVisible(false);
846 _dwPattern->setWindowTitle("Model");
847 _dwPattern->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
849 QFrame* patternFrame = new QFrame(_dwPattern);
850 patternFrame->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
851 QVBoxLayout* patternLayout = new QVBoxLayout(patternFrame);
852 patternLayout->setSizeConstraint(QLayout::SetMaximumSize);
853 QSplitter *splitter = new QSplitter(Qt::Vertical,patternFrame);
854 _patternDataTreeView = new QTreeView(patternFrame);//_dwPattern);
855 _patternBuilderTreeView = new QTreeView(patternFrame);
856 splitter->addWidget(_patternDataTreeView);
857 splitter->addWidget(_patternBuilderTreeView);
858 patternLayout->addWidget(splitter);
859 // _patternDataTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
861 _patternDataTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers/*QAbstractItemView::DoubleClicked*/);
862 _patternDataTreeView->setSelectionMode(QAbstractItemView::SingleSelection/*QAbstractItemView::MultiSelection*/);//);//QAbstractItemView::DoubleClicked, QAbstractItemView::SelectedClicked)
863 _patternDataTreeView->setItemDelegate(_treeViewDelegate);
866 _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
867 _patternBuilderTreeView->setItemDelegate(_treeViewDelegate);
868 _dwPattern->setWidget(patternFrame);
869 patternFrame->show();
870 //_dwPattern->raise();
873 _dwGroups = new QDockWidget(aParent);
874 // _dwGroups->installEventFilter(this);
876 _dwGroups->setVisible(false);
877 _dwGroups->setWindowTitle("Groups");
878 _dwGroups->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
879 _groupsTreeView = new QTreeView(_dwGroups);
880 // _associationTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
881 _groupsTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
882 _groupsTreeView->setItemDelegate(_treeViewDelegate);
883 _dwGroups->setWidget(_groupsTreeView);
884 _groupsTreeView->show();
887 _dwMesh = new QDockWidget(aParent);
888 // _dwMesh->installEventFilter(this);
889 _dwMesh->setVisible(false);
890 _dwMesh->setWindowTitle("Mesh");
891 _dwMesh->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
892 _meshTreeView = new QTreeView(_dwMesh);
893 // _meshTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
894 _meshTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
895 _meshTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
896 _meshTreeView->setItemDelegate(_treeViewDelegate);
897 _dwMesh->setWidget(_meshTreeView);
898 _meshTreeView->show();
903 //3) ************* documents ( salome objectbrowser )
904 QDockWidget *_dwObjectBrowser = 0;
905 QWidget* wid = getApp()->objectBrowser()->treeView();
906 // QWidget *wid = application()->objectBrowser()->treeView();
907 QWidget *w = wid->parentWidget();
908 while ( w && !_dwObjectBrowser ) {
909 _dwObjectBrowser = ::qobject_cast<QDockWidget*>( w );
910 w = w->parentWidget();
912 // _dwObjectBrowser->installEventFilter(this);
913 // _dwObjectBrowser->setVisible(false);
914 _dwObjectBrowser->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
915 _dwObjectBrowser->setWindowTitle("Study");
918 // dock widget position
919 // aParent->addDockWidget(Qt::LeftDockWidgetArea, _dwPattern);
920 // aParent->addDockWidget(Qt::RightDockWidgetArea, _dwInputPanel);
921 // aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwPattern );
922 aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwObjectBrowser );
923 aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwInputPanel );
925 aParent->tabifyDockWidget( _dwObjectBrowser, _dwPattern );
926 // aParent->tabifyDockWidget( _dwPattern, /*_dwAssociation );
927 // aParent->tabifyDockWidget( _dwAssociation, */_dwGroups );
928 aParent->tabifyDockWidget( _dwPattern, _dwGroups );
929 aParent->tabifyDockWidget( _dwGroups, _dwMesh );
932 #if QT_VERSION >= 0x040500
933 aParent->setTabPosition(Qt::AllDockWidgetAreas, Resource::tabPanelsUp? QTabWidget::North: QTabWidget::South);
937 // connect( _dwPattern, SIGNAL( visibilityChanged(bool) ), this, SLOT( showPatternMenus(bool) ) );
938 // // connect( _dwAssociation, SIGNAL( visibilityChanged(bool) ), this, SLOT( showAssociationMenus(bool) ) );
939 // connect( _dwGroups, SIGNAL( visibilityChanged(bool) ), this, SLOT( showGroupsMenus(bool) ) );
940 // connect( _dwMesh, SIGNAL( visibilityChanged(bool) ), this, SLOT( showMeshMenus(bool) ) );
942 // popup menu on data tree view
943 _patternDataTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
944 connect(_patternDataTreeView,
945 SIGNAL(customContextMenuRequested(const QPoint &)),
947 SLOT(treeContextMenu(const QPoint &)));
950 void HEXABLOCKGUI::createActions()
952 QMainWindow *aParent = application()->desktop();
953 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
956 _newAct = createAction(_menuId++,
957 tr("Create a new document"),
958 resMgr->loadPixmap("HEXABLOCK", tr("ICON_NEW_DOCUMENT")),
960 tr("Create a new document"),
961 0, aParent, false, this, SLOT(newDocument()));
962 _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
964 _importAct = createAction(_menuId++,
965 tr("Load a document"),
966 resMgr->loadPixmap("HEXABLOCK", tr("ICON_LOAD_DOCUMENT")),
968 tr("Load a document"),
969 0, aParent, false, this, SLOT(loadDocument()));
970 _importAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_O); // --- QKeySequence::Open ambiguous in SALOME
972 _saveAct = createAction(_menuId++,
973 tr("Save the document"),
974 resMgr->loadPixmap("HEXABLOCK", tr("ICON_SAVE_DOCUMENT")),
976 tr("Save the document"),
977 0, aParent, false, this, SLOT(saveDocument()));
979 // _testAct = createAction(_menuId++, tr("Test"), resMgr->loadPixmap("HEXABLOCK", tr("ICON_TEST")),
980 // tr("Test"), tr("New test"),
981 // 0, aParent, false, this, SLOT(test_association()));
983 // Pattern Data creation
984 _addVertex = createAction(_menuId++,
985 tr("Create a vertex"),
986 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_VERTEX")),
988 tr("Create a new vertex"),
989 0, aParent, false, this, SLOT(addVertex()));
991 _addEdge = createAction(_menuId++,
992 tr("Create an edge"),
993 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_EDGE")),
995 tr("Create a new edge"),
996 0, aParent, false, this, SLOT(addEdge()));
998 _addQuad = createAction(_menuId++,
999 tr("Create a quadrangle"),
1000 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_QUAD")),
1001 tr("Add Quadrangle"),
1002 tr("Create a new quadrangle"),
1003 0, aParent, false, this, SLOT(addQuad()));
1005 _addHexa = createAction(_menuId++,
1006 tr("Create an hexahedron"),
1007 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_HEXA")),
1008 tr("Add Hexahedron"),
1009 tr("Create a new hexahedron"),
1010 0, aParent, false, this, SLOT(addHexa()));
1012 // Builder Data creation
1013 _addVector = createAction(_menuId++,
1014 tr("Create a vector"),
1015 resMgr->loadPixmap( "HEXABLOCK", tr("ICON_ADD_VECTOR")),
1017 tr("Create a new vector"),
1018 0, aParent, false, this, SLOT(addVector()));
1020 _addCylinder = createAction(_menuId++,
1021 tr("Create a cylinder"),
1022 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_CYLINDER")),
1024 tr("Create a new cylinder"),
1025 0, aParent, false, this, SLOT(addCylinder()));
1027 _addPipe = createAction(_menuId++,
1028 tr("Create a pipe"),
1029 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_PIPE")),
1031 tr("Create a new pipe"),
1032 0, aParent, false, this, SLOT(addPipe()));
1034 _makeGrid = createAction(_menuId++,
1036 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_GRID")),
1039 0, aParent, false, this, SLOT(makeGrid()));
1041 _makeCylinder = createAction(_menuId++,
1042 tr("Make a cylinder"),
1043 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDER")),
1044 tr("Make Cylinder"),
1045 tr("Make a cylinder"),
1046 0, aParent, false, this, SLOT(makeCylinder()));
1048 _makePipe = createAction(_menuId++,
1050 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPE")),
1053 0, aParent, false, this, SLOT(makePipe()));
1055 _makeCylinders = createAction(_menuId++,
1056 tr("Make cylinders"),
1057 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDERS")),
1058 tr("Make Cylinders"),
1059 tr("Make cylinders"),
1060 0, aParent, false, this, SLOT(makeCylinders()));
1062 _makePipes = createAction(_menuId++,
1064 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPES")),
1067 0, aParent, false, this, SLOT(makePipes()));
1069 // // _makeRind = createAction( _menuId++, tr("Make rind"), resMgr->loadPixmap( "HEXABLOCK", tr("ICON_MAKE_RIND")),
1070 // // tr("Make rind"), tr("Make rind"),
1071 // // 0, aParent, false, this, SLOT(makeRind()));
1073 _makeHemiSphere = createAction(_menuId++,
1074 tr("Make an hemisphere"),
1075 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_HEMISPHERE")),
1076 tr("Make Hemisphere"),
1077 tr("Make an hemisphere"),
1078 0, aParent, false, this, SLOT(makeHemiSphere()));
1080 // Pattern Data edition
1081 _removeHexa = createAction(_menuId++,
1082 tr("Remove hexahedra"),
1083 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_HEXA")),
1084 tr("Remove Hexahedra"),
1085 tr("Remove hexahedra"),
1086 0, aParent, false, this, SLOT(removeHexa()));
1088 _prismQuad = createAction(_menuId++,
1089 tr("Prism quadrangles"),
1090 resMgr->loadPixmap( "HEXABLOCK", tr("ICON_PRISM_QUAD")),
1091 tr("Prism Quadrangles"),
1092 tr("Prism quadrangles"),
1093 0, aParent, false, this, SLOT(prismQuad()));
1095 _joinQuad = createAction(_menuId++,
1096 tr("Join quadrangles"),
1097 resMgr->loadPixmap("HEXABLOCK", tr("ICON_JOIN_QUAD")),
1098 tr("Join Quadrangles"),
1099 tr("Join quadrangles with hexahedra"),
1100 0, aParent, false, this, SLOT(joinQuad()));
1102 _merge = createAction(_menuId++,
1104 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MERGE")),
1107 0, aParent, false, this, SLOT(merge()));
1109 _disconnect = createAction(_menuId++,
1111 resMgr->loadPixmap("HEXABLOCK", tr("ICON_DISCONNECT")),
1113 tr("Disconnect edges, vertexes or quadrangles"),
1114 0, aParent, false, this, SLOT(disconnectElts()));
1116 _cutEdge = createAction(_menuId++,
1118 resMgr->loadPixmap("HEXABLOCK", tr("ICON_CUT_EDGE")),
1121 0, aParent, false, this, SLOT(cutEdge()));
1123 _makeTransformation = createAction(_menuId++,
1124 tr("Make transformation"),
1125 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_TRANSFORMATION")),
1126 tr("Make Transformation"),
1127 tr("Make transformation"),
1128 0, aParent, false, this, SLOT(makeTransformation()));
1130 _makeSymmetry = createAction(_menuId++,
1131 tr("Make symmetry"),
1132 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_SYMMETRY")),
1133 tr("Make Symmetry"),
1134 tr("Make symmetry"),
1135 0, aParent, false, this, SLOT(makeSymmetry()));
1137 _performTransformation = createAction(_menuId++,
1138 tr("Perform transformation"),
1139 resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_TRANSFORMATION")),
1140 tr("Perform Transformation"),
1141 tr("Perform transformation"),
1142 0, aParent, false, this, SLOT(performTransformation()));
1144 _performSymmetry = createAction(_menuId++,
1145 tr("Perform symmetry"),
1146 resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_SYMMETRY")),
1147 tr("Perform Symmetry"),
1148 tr("Perform symmetry"),
1149 0, aParent, false, this, SLOT(performSymmetry()));
1151 _replaceHexa = createAction(_menuId++,
1152 tr("Replace hexahedron"),
1153 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REPLACE_HEXA")),
1154 tr("Replace Hexahedron"),
1155 tr("Replace hexahedron"),
1156 0, aParent, false, this, SLOT(replaceHexa()));
1158 _quadRevolution = createAction(_menuId++,
1159 tr("Quad revolution"),
1160 resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_REVOLUTION")),
1161 tr("Quad Revolution"),
1162 tr("Quad revolution"),
1163 0, aParent, false, this, SLOT(quadRevolution()));
1166 _assocVertex = createAction(_menuId++,
1167 tr("Make vertex association"),
1168 resMgr->loadPixmap("HEXABLOCK", tr("ICON_VERTEX_ASSOCIATION")),
1169 tr("Make Vertex association"),
1170 tr("Make vertex association"),
1171 0, aParent, false, this, SLOT(assocVertex()));
1173 _assocEdge = createAction(_menuId++,
1174 tr("Make edge association"),
1175 resMgr->loadPixmap("HEXABLOCK", tr("ICON_EDGE_ASSOCIATION")),
1176 tr("Make Edge Association"),
1177 tr("Make edge association"),
1178 0, aParent, false, this, SLOT(assocEdge()));
1180 _assocQuad = createAction(_menuId++,
1181 tr("Make quadrangle association"),
1182 resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_ASSOCIATION")),
1183 tr("Make Quadrangle Association"),
1184 tr("Make quadrangle association"),
1185 0, aParent, false, this, SLOT(assocQuad()));
1188 _addGroup = createAction(_menuId++,
1190 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_GROUP")),
1193 0, aParent, false, this, SLOT(addGroup()));
1195 _removeGroup = createAction(_menuId++,
1196 tr("Remove a group"),
1197 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_GROUP")),
1199 tr("Remove a group"),
1200 0, aParent, false, this, SLOT(removeGroup()));
1203 _addLaw = createAction(_menuId++,
1205 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_LAW")),
1208 0, aParent, false, this, SLOT(addLaw()));
1210 _removeLaw = createAction(_menuId++,
1212 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_LAW")),
1215 0, aParent, false, this, SLOT(removeLaw()));
1217 _setPropagation = createAction(_menuId++,
1218 tr("Set propagation"),
1219 resMgr->loadPixmap("HEXABLOCK", tr("ICON_SET_PROPAGATION")),
1220 tr("Set Propagation"),
1221 tr("Set propagation"),
1222 0, aParent, false, this, SLOT(setPropagation()));
1224 _computeMesh = createAction(_menuId++,
1226 resMgr->loadPixmap("HEXABLOCK", tr("ICON_COMPUTE_MESH")),
1229 0, aParent, false, this, SLOT(computeMesh()));
1232 // _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1233 // QAction* createAction(const int id,
1234 // const QString& toolTip,
1235 // const QIcon& icon,
1236 // const QString& menu,
1237 // const QString& status,
1238 // const int shortCut,
1239 // QObject* parent =0,
1240 // bool checkable = false,
1241 // QObject* receiver =0,
1242 // const char* member =0);
1246 void HEXABLOCKGUI::createMenus()
1248 int aMenuId, subMenuId;
1249 aMenuId = createMenu( tr("MEN_FILE"), -1, -1 );
1250 createMenu( separator(), aMenuId, -1, 10 );
1251 aMenuId = createMenu( tr("HEXABLOCK"), aMenuId, -1, 10 );
1252 createMenu( _newAct, aMenuId );
1253 createMenu( _importAct, aMenuId );
1254 createMenu( _saveAct, aMenuId );
1255 // createMenu( _testAct, aMenuId );
1257 // aMenuId = createMenu( tr( "HEXABLOCK" ), -1, -1, 30 );
1258 aMenuId = createMenu( tr( "Document" ), -1, -1, 30 );
1259 createMenu( _newAct, aMenuId );//, 10
1260 createMenu( _importAct, aMenuId );
1261 createMenu( _saveAct, aMenuId );
1262 // createMenu( _testAct, aMenuId );
1264 aMenuId = createMenu( tr("Model"), -1, -1, 30 );
1265 subMenuId = createMenu( tr( "Construction" ), aMenuId, -1 );
1266 createMenu( _addVertex, subMenuId );
1267 createMenu( _addEdge, subMenuId );
1268 createMenu( _addQuad, subMenuId );
1269 createMenu( _addHexa, subMenuId );
1270 //createMenu( separator(), aMenuId);
1273 createMenu( _addVector, subMenuId );
1274 createMenu( _addCylinder, subMenuId );
1275 createMenu( _addPipe, subMenuId );
1276 //createMenu( separator(), aMenuId);
1277 createMenu( _makeGrid, subMenuId ); //Cartesian, Cylindrical, Spherical
1278 createMenu( _makeCylinder, subMenuId );
1279 createMenu( _makePipe, subMenuId );
1280 createMenu( _makeCylinders,subMenuId );
1281 createMenu( _makePipes, subMenuId );
1282 // createMenu( _makeRind, aMenuId );
1283 createMenu( _makeHemiSphere,subMenuId );
1284 //createMenu( separator(), aMenuId);
1286 // Pattern Data Edition
1287 subMenuId = createMenu( tr( "Operation" ), aMenuId, -1 );
1288 createMenu( _removeHexa, subMenuId );
1289 createMenu( _prismQuad, subMenuId );
1290 createMenu( _joinQuad, subMenuId );
1291 createMenu( _merge, subMenuId );// createMenu( _mergeVertices, aMenuId ); // createMenu( _mergeEdges, aMenuId );
1292 createMenu( _disconnect, subMenuId );
1293 createMenu( _cutEdge, subMenuId );
1294 createMenu( _makeTransformation, subMenuId ); // createMenu( _makeTranslation, aMenuId );
1295 createMenu( _makeSymmetry, subMenuId );
1296 createMenu( _performTransformation, subMenuId );
1297 createMenu( _performSymmetry, subMenuId );
1298 createMenu( _replaceHexa, subMenuId );
1299 createMenu( _quadRevolution, subMenuId );
1302 aMenuId = createMenu( tr("Association"), -1, -1, 30 );
1303 createMenu( _assocVertex, aMenuId );
1304 createMenu( _assocEdge, aMenuId );
1305 createMenu( _assocQuad, aMenuId );
1308 aMenuId = createMenu( tr("Groups"), -1, -1, 30 );
1309 createMenu( _addGroup, aMenuId );
1310 createMenu( _removeGroup, aMenuId ); //CS_TODO
1313 aMenuId = createMenu( tr("Mesh "), -1, -1, 30 );
1314 createMenu( _addLaw, aMenuId );
1315 createMenu( _removeLaw, aMenuId );
1316 createMenu( _setPropagation, aMenuId );
1317 createMenu( _computeMesh, aMenuId );
1321 void HEXABLOCKGUI::createTools()
1325 aToolId = createTool ( tr( "HexaBlock Toolbar" ) );
1326 createTool( _newAct, aToolId );
1327 createTool( _importAct, aToolId );
1328 createTool( _saveAct, aToolId );
1329 // createTool( _testAct, aToolId );
1330 //createTool( separator(), aToolId );
1333 aToolId = createTool ( tr( "Construction" ) );
1334 createTool( _addVertex, aToolId );
1335 createTool( _addEdge, aToolId );
1336 createTool( _addQuad, aToolId );
1337 createTool( _addHexa, aToolId );
1338 //createTool( separator(), aToolId );
1341 createTool( _addVector, aToolId );
1342 createTool( _addCylinder, aToolId );
1343 createTool( _addPipe, aToolId );
1344 //createTool( separator(), aToolId );
1346 createTool( _makeGrid, aToolId );
1347 createTool( _makeCylinder, aToolId );
1348 createTool( _makePipe, aToolId );
1349 createTool( _makeCylinders,aToolId );
1350 createTool( _makePipes, aToolId );
1351 // createTool( _makeRind, aToolId);
1352 createTool( _makeHemiSphere, aToolId );
1353 //createTool( separator(), aToolId );
1355 // Pattern Data Edition
1356 aToolId = createTool ( tr( "Operation" ) );
1357 createTool( _removeHexa, aToolId );
1358 createTool( _prismQuad, aToolId );
1359 createTool( _joinQuad, aToolId );
1360 createTool( _merge, aToolId );
1361 createTool( _disconnect, aToolId );
1362 createTool( _cutEdge, aToolId );
1363 createTool( _makeTransformation, aToolId );
1364 createTool( _makeSymmetry, aToolId );
1365 createTool( _performTransformation, aToolId );
1366 createTool( _performSymmetry, aToolId );
1367 createTool( _replaceHexa, aToolId );
1368 createTool( _quadRevolution, aToolId );
1369 //createTool( separator(), aToolId );
1372 aToolId = createTool ( tr( "Association" ) );
1373 createTool( _assocVertex, aToolId );
1374 createTool( _assocEdge, aToolId );
1375 createTool( _assocQuad, aToolId );
1376 //createTool( separator(), aToolId );
1379 aToolId = createTool ( tr( "Group" ) );
1380 createTool( _addGroup, aToolId );
1381 createTool( _removeGroup, aToolId ); //CS_TODO
1382 //createTool( separator(), aToolId );
1385 aToolId = createTool ( tr( "Mesh" ) );
1386 createTool( _addLaw, aToolId );
1387 createTool( _removeLaw, aToolId );
1388 createTool( _setPropagation, aToolId );
1389 createTool( _computeMesh, aToolId );
1393 void HEXABLOCKGUI::initialMenus()
1395 showDocumentMenus( true );
1396 showPatternMenus( false );
1397 showAssociationMenus( false );
1398 showGroupsMenus( false );
1399 showMeshMenus( false );
1402 void HEXABLOCKGUI::showAllMenus()
1404 showDocumentMenus( true );
1405 showPatternMenus( true );
1406 showAssociationMenus( true );
1407 showGroupsMenus( true );
1408 showMeshMenus( true );
1412 void HEXABLOCKGUI::showDocumentMenus(bool show)
1414 DEBTRACE("HEXABLOCKGUI::showDocumentMenus " << show);
1416 setMenuShown(_newAct, show);
1417 setToolShown(_newAct, show);
1418 setMenuShown(_importAct, show);
1419 setToolShown(_importAct, show);
1420 setMenuShown(_saveAct, show);
1421 setToolShown(_saveAct, show);
1422 // setMenuShown(_testAct, show);
1423 // setToolShown(_testAct, show);
1426 void HEXABLOCKGUI::showPatternMenus(bool show)
1428 DEBTRACE("HEXABLOCKGUI::showPatternMenus " << show);
1429 DEBTRACE("_currentModel " << _currentModel );
1430 if ( show && !_currentModel ) return;
1432 setMenuShown(_addVertex, show );//true);
1433 setToolShown(_addVertex, show);
1434 setMenuShown(_addEdge, show );//true);
1435 setToolShown(_addEdge, show);
1436 setMenuShown(_addQuad, show );//true);
1437 setToolShown(_addQuad, show);
1438 setMenuShown(_addHexa, show );//true);
1439 setToolShown(_addHexa, show);
1442 setMenuShown( _addVector, show );//true);
1443 setToolShown( _addVector, show);
1444 setMenuShown( _addCylinder, show );//true);
1445 setToolShown( _addCylinder, show);
1446 setMenuShown( _addPipe, show );//true);
1447 setToolShown( _addPipe, show);
1448 setMenuShown( _makeGrid, show );//true);
1449 setToolShown( _makeGrid, show);
1450 setMenuShown( _makeCylinder, show );//true);
1451 setToolShown( _makeCylinder, show);
1452 setMenuShown( _makePipe, show );//true);
1453 setToolShown( _makePipe, show);
1454 setMenuShown( _makeCylinders, show );//true);
1455 setToolShown( _makeCylinders, show);
1456 setMenuShown( _makePipes, show );//true);
1457 setToolShown( _makePipes, show);
1458 // setMenuShown( _makeRind, show );//true);
1459 // setToolShown( _makeRind, show);
1460 setMenuShown( _makeHemiSphere, show );//true);
1461 setToolShown( _makeHemiSphere, show);
1463 // Pattern Data Edition
1464 setMenuShown( _removeHexa, show );//true);
1465 setToolShown( _removeHexa, show);
1466 setMenuShown( _prismQuad, show );//true);
1467 setToolShown( _prismQuad, show);
1468 setMenuShown( _joinQuad, show );//true);
1469 setToolShown( _joinQuad, show);
1470 setMenuShown( _merge, show );//true);
1471 setToolShown( _merge, show);
1472 setMenuShown( _disconnect, show );//true);
1473 setToolShown( _disconnect, show);
1474 setMenuShown( _cutEdge, show );//true);
1475 setToolShown( _cutEdge, show);
1476 setMenuShown( _makeTransformation, show );//true);
1477 setToolShown( _makeTransformation, show);
1478 setMenuShown( _makeSymmetry, show );//true);
1479 setToolShown( _makeSymmetry, show);
1480 setMenuShown( _performTransformation, show );//true);
1481 setToolShown( _performTransformation, show);
1482 setMenuShown( _performSymmetry, show );//true);
1483 setToolShown( _performSymmetry, show);
1484 setMenuShown( _replaceHexa, show );//true);
1485 setToolShown( _replaceHexa, show);
1486 setMenuShown( _quadRevolution, show );//true);
1487 setToolShown( _quadRevolution, show);
1492 void HEXABLOCKGUI::showAssociationMenus(bool show)
1494 DEBTRACE("HEXABLOCKGUI::showAssociationMenus" << show);
1495 if ( show && !_currentModel ) return;
1497 // Association Edition
1498 setMenuShown( _assocVertex, show );
1499 setToolShown( _assocVertex, show);
1500 setMenuShown( _assocEdge, show );
1501 setToolShown( _assocEdge, show);
1502 setMenuShown( _assocQuad, show );
1503 setToolShown( _assocQuad, show);
1507 void HEXABLOCKGUI::showGroupsMenus(bool show)
1509 DEBTRACE("HEXABLOCKGUI::showGroupsMenus" << show);
1510 if ( show && !_currentModel ) return;
1511 setMenuShown( _addGroup, show );//true);
1512 setToolShown( _addGroup, show);
1513 setMenuShown( _removeGroup , show );//true);
1514 setToolShown( _removeGroup , show);
1517 void HEXABLOCKGUI::showMeshMenus(bool show)
1519 DEBTRACE("HEXABLOCKGUI::showMeshMenus" << show);
1520 if ( show && !_currentModel ) return;
1521 setMenuShown( _addLaw, show );//true);
1522 setToolShown( _addLaw, show);
1523 setMenuShown( _removeLaw, show );//true);
1524 setToolShown( _removeLaw, show);;
1525 setMenuShown( _setPropagation, show );//true);
1526 setToolShown( _setPropagation, show);
1527 setMenuShown( _computeMesh, show); //true);
1528 setToolShown( _computeMesh, show);
1533 void HEXABLOCKGUI::switchModel(SUIT_ViewWindow *view)
1535 DEBTRACE("HEXABLOCKGUI::switchModel " << view);
1537 if ( _documentModels.count(view) == 0 ){
1538 DEBTRACE("HEXABLOCKGUI::switchModel : no model found, cannot switch");
1543 if ( _currentModel != _documentModels[view] ){ // need to switch
1545 QWidget* w = _dwInputPanel->widget();
1550 _currentModel = _documentModels[view];
1551 _patternDataModel->setSourceModel(_currentModel);
1552 _patternBuilderModel->setSourceModel(_currentModel);
1553 // _associationsModel->setSourceModel(_currentModel);
1554 _groupsModel->setSourceModel(_currentModel);
1555 _meshModel->setSourceModel(_currentModel);
1557 // associate models and views
1558 _currentGraphicView = _documentView[view];
1559 // _currentGraphicView->setModel(_patternDataModel);
1560 // connect( _currentModel, SIGNAL(patternDataChanged() ), _currentGraphicView, SLOT ( onPatternDatachanged() ) );
1561 _currentGraphicView->setModel(_currentModel);
1563 _patternDataTreeView->setModel(_patternDataModel); //_currentModel
1564 _patternBuilderTreeView->setModel(_patternBuilderModel);//_currentModel
1565 // _associationTreeView->setModel(_associationsModel);;
1566 _groupsTreeView->setModel(_groupsModel);
1567 _meshTreeView->setModel(_meshModel);
1569 // set selections for each view
1570 // if ( _patternDataSelectionModel ) delete _patternDataSelectionModel;
1571 // if ( _patternBuilderSelectionModel ) delete _patternBuilderSelectionModel;
1572 // if ( _groupsSelectionModel ) delete _groupsSelectionModel;
1573 // if ( _meshSelectionModel ) delete _meshSelectionModel;
1575 _patternDataSelectionModel = new PatternDataSelectionModel( _patternDataModel );
1576 _patternBuilderSelectionModel = new PatternBuilderSelectionModel( _patternBuilderModel, _patternDataSelectionModel );
1577 _groupsSelectionModel = new GroupsSelectionModel( _groupsModel );
1578 _meshSelectionModel = new MeshSelectionModel( _meshModel );
1580 _patternDataSelectionModel->setSalomeSelectionMgr( selectionMgr() );
1581 // _meshSelectionModel->setSalomeSelectionMgr( selectionMgr() );
1582 // _patternDataSelectionModel->setGeomEngine( _geomEngine );
1584 _currentGraphicView->setSelectionModel(_patternDataSelectionModel);
1586 _patternDataTreeView->setSelectionModel(_patternDataSelectionModel);
1587 _patternDataTreeView->setEditTriggers(/*QAbstractItemView::EditKeyPressed*/QAbstractItemView::AllEditTriggers /*QAbstractItemView::NoEditTriggers*/);
1589 _patternBuilderTreeView->setSelectionModel(_patternBuilderSelectionModel);
1590 _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1592 _groupsTreeView->setSelectionModel(_groupsSelectionModel);
1593 _groupsTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1595 _meshTreeView->setSelectionModel( _meshSelectionModel );
1596 _meshTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1599 // delegate for edition
1600 _treeViewDelegate->setDocumentModel( _currentModel );
1601 _treeViewDelegate->setPatternDataSelectionModel( _patternDataSelectionModel );
1602 _treeViewDelegate->setPatternBuilderSelectionModel( _patternBuilderSelectionModel );
1603 _treeViewDelegate->setGroupsSelectionModel( _groupsSelectionModel /*_groupsTreeView->selectionModel()*/ );
1604 _treeViewDelegate->setMeshSelectionModel( _meshSelectionModel/*_meshTreeView->selectionModel()*/ );
1607 connect( _patternDataSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1608 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1609 connect( _patternBuilderSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1610 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1611 connect( _groupsSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1612 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1613 connect( _meshSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1614 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1618 showPatternMenus(true);
1624 void HEXABLOCKGUI::showDockWidgets(bool isVisible)
1626 DEBTRACE("HEXABLOCKGUI::showDockWidgets " << isVisible);
1628 if (_dwObjectBrowser) _dwObjectBrowser->setVisible(isVisible);
1629 if (_dwObjectBrowser) _dwObjectBrowser->toggleViewAction()->setVisible(isVisible);
1631 if (_dwPattern) _dwPattern->setVisible(isVisible);
1632 if (_dwPattern) _dwPattern->toggleViewAction()->setVisible(isVisible);
1634 // if (_dwAssociation) _dwAssociation->setVisible(isVisible);
1635 // if (_dwAssociation) _dwAssociation->toggleViewAction()->setVisible(isVisible);
1637 if (_dwMesh) _dwMesh->setVisible(isVisible);
1638 if (_dwMesh) _dwMesh->toggleViewAction()->setVisible(isVisible);
1640 if (_dwGroups) _dwGroups->setVisible(isVisible);
1641 if (_dwGroups) _dwGroups->toggleViewAction()->setVisible(isVisible);
1643 if (_dwInputPanel) _dwInputPanel->setVisible(isVisible);
1644 if (_dwInputPanel) _dwInputPanel->toggleViewAction()->setVisible(isVisible);
1646 QWidget* w = _dwInputPanel->widget();
1648 // if ( isVisible ) _dwObjectBrowser->raise();//_dwPattern->raise();
1652 // void HEXABLOCKGUI::raiseStacked()
1654 // // if (_dwStacked) _dwStacked->raise();
1660 DocumentGraphicView* HEXABLOCKGUI::newGraphicView()
1662 MESSAGE("HEXABLOCKGUI::newGraphicView");
1663 DocumentGraphicView *newGView = NULL;
1664 SUIT_ViewWindow *suitVW = NULL;
1666 //For the first time initialize occ view manager
1667 if (_documentView.size() == 0)
1669 occViewManager = getApp()->getViewManager( OCCViewer_Viewer::Type(), true );
1670 occViewManager->getActiveView()->setClosable(false);
1671 currentOccView = dynamic_cast<OCCViewer_ViewWindow*>(occViewManager->getActiveView());
1674 vtkViewManager = getApp()->getViewManager( SVTK_Viewer::Type(), true );
1675 if (_documentView.size() == 0)
1677 suitVW = vtkViewManager->getActiveView();
1678 suitVW->setClosable(false);
1681 suitVW = vtkViewManager->createViewWindow();
1683 currentVtkView = dynamic_cast<SVTK_ViewWindow*>(suitVW);
1684 currentVtkView->installEventFilter(this);
1685 newGView = new DocumentGraphicView(getApp(), suitVW, application()->desktop());
1686 _documentView[suitVW] = newGView;
1690 //DocumentGraphicView* HEXABLOCKGUI::newGraphicView()
1692 // MESSAGE("HEXABLOCKGUI::newGraphicView");
1693 // DocumentGraphicView *newGView = 0;
1694 // SUIT_ViewWindow *suitVW = NULL;
1696 // SUIT_ViewManager *vtkViewManager = getApp()->getViewManager(SVTK_Viewer::Type(), true);
1697 // MESSAGE("suitVM->getViewsCount() => " << suitVM->getViewsCount() );
1698 // suitVW = suitVM->getActiveView();
1699 // if ( _documentView.count(suitVW) > 0)
1700 // suitVW = suitVM->createViewWindow();
1703 //// suitVW->setClosable(false);
1704 // suitVW->setClosable(true);
1705 // newGView = new DocumentGraphicView(getApp(), suitVW, application()->desktop());
1706 // _documentView[suitVW] = newGView;
1713 void HEXABLOCKGUI::testDocument()
1717 // QStandardItem *parentItem = _currentModel->invisibleRootItem();
1718 // QStandardItem *myItem = new QStandardItem("MyItem");
1719 // parentItem->appendRow(myItem);
1721 // QModelIndex v0 = _currentModel->addVertex(0., 0., 0.);
1722 // QModelIndex v1 = _currentModel->addVertex(5., 0., 0.);
1723 // QModelIndex v2 = _currentModel->addVertex(5., 5., 0.);
1724 // QModelIndex v3 = _currentModel->addVertex(0., 5., 0.);
1725 // QModelIndex v4 = _currentModel->addVertex(0., 0., 5.);
1726 // QModelIndex v5 = _currentModel->addVertex(5., 0., 5.);
1727 // QModelIndex v6 = _currentModel->addVertex(5., 5., 5.);
1728 // QModelIndex v7 = _currentModel->addVertex(0., 5., 5.);
1731 // QModelIndex q0 = _currentModel->addQuadVertices( v0, v1, v2, v3 );
1732 // QModelIndex q1 = _currentModel->addQuadVertices( v4, v5, v6, v7 );
1733 // QModelIndex q2 = _currentModel->addQuadVertices( v0, v3, v7, v4 );
1734 // QModelIndex q3 = _currentModel->addQuadVertices( v1, v2, v6, v5 );
1735 // QModelIndex q4 = _currentModel->addQuadVertices( v0, v1, v5, v4 );
1736 // QModelIndex q5 = _currentModel->addQuadVertices( v3, v2, v6, v7 );
1738 // QModelIndex h0 = _currentModel->addHexaQuad( q0, q1, q2, q3, q4, q5 );
1739 // QModelIndex vx = _currentModel->addVector(1., 0., 0.);
1740 // QModelIndex vy = _currentModel->addVector(0., 1., 0.);
1741 // QModelIndex vz = _currentModel->addVector(0., 0., 1.);
1746 // // QModelIndex orig1 = _currentModel->addVertex (0, 0,0);
1747 // // QModelIndex orig2 = _currentModel->addVertex (50,0,0);
1748 // // QModelIndex vz = _currentModel->addVector (0,0,1);
1749 // // QModelIndex vx = _currentModel->addVector (1,0,0);
1757 // // QModelIndex cyl = _currentModel->addCylinder (orig1, vz, nr, nl);
1758 // // QModelIndex pipe = _currentModel->addPipe (orig2, vz, nri, nre, nl);
1760 // // _currentModel->makeCylinder (cyl, vx, nr, na, nl);
1761 // // _currentModel->makePipe(pipe, vx, nr, na, nl);
1765 // newMesh( "toto", 3, "FactoryServer");
1769 void HEXABLOCKGUI::test_make_cart_grid()
1771 QModelIndex orig1 = _currentModel->addVertex( 0, 0, 0);
1772 QModelIndex orig2 = _currentModel->addVertex( 10, 0, 0);
1773 QModelIndex orig3 = _currentModel->addVertex( 0, 10, 0);
1774 QModelIndex orig4 = _currentModel->addVertex( 10, 10, 0);
1775 QModelIndex orig5 = _currentModel->addVertex( 0, 20, 0);
1776 QModelIndex orig6 = _currentModel->addVertex( 10, 20, 0);
1778 QModelIndex vz = _currentModel->addVector(0, 0, 1);
1779 QModelIndex vx = _currentModel->addVector(1, 0, 0);
1786 // QModelIndex c1 = _currentModel->makeCylindrical(orig1, vx, vz, dr, 360, dl, nr, 4, nl, true);
1787 // QModelIndex c2 = _currentModel->makeCylindrical(orig2, vx, vz, dr, 360, dl, nr, 8, nl, true);
1788 // QModelIndex c3 = _currentModel->makeCylindrical(orig3, vx, vz, dr, 270, dl, nr, 8, nl, true);
1789 // QModelIndex c4 = _currentModel->makeCylindrical(orig4, vx, vz, dr, 270, dl, nr, 7, nl, true);
1790 // QModelIndex c5 = _currentModel->makeCylindrical(orig5, vx, vz, dr, 360, dl, nr, 5, nl, true);
1791 // QModelIndex c6 = _currentModel->makeCylindrical(orig6, vx, vz, dr, 360, dl, nr, 6, nl, true);
1796 void HEXABLOCKGUI::test_make_elmts_transform()
1803 QModelIndex orig = _currentModel->addVertex(0, 0, 0);
1804 QModelIndex dirVr = _currentModel->addVector(1, 1, 1);
1806 QModelIndex grid = _currentModel->makeCartesian(orig, dirVr, size_x, size_y, size_z);//, 0, 0, 0);
1807 // orig.setScalar(2);
1809 // file_name = os.path.join(os.environ['TMP'], 'transfo0.vtk')
1810 // _currentModel->saveVtk(file_name)
1812 QModelIndex devant = _currentModel->addVector(5, 0, 0);
1813 QModelIndex grid2 = _currentModel->makeTranslation(grid, devant);
1815 // file_name = os.path.join(os.environ['TMP'], 'transfo_translation.vtk')
1816 // _currentModel->saveVtk(file_name)
1818 QModelIndex grid4 = _currentModel->makeRotation(grid2, orig, dirVr, 45);
1821 // file_name = os.path.join(os.environ['TMP'], 'transfo_rotation.vtk');
1822 // _currentModel->saveVtk(file_name);
1825 // print "...test make elements by transforming elements OK"
1829 void HEXABLOCKGUI::test()
1831 DEBTRACE("HEXABLOCKGUI::test");
1832 _currentGraphicView->update();
1836 void HEXABLOCKGUI::test_association()
1838 DEBTRACE("HEXABLOCKGUI::test_association");
1841 QModelIndex v0, v1, v2, v3, e0, e1, q0;
1843 DocumentModel::GeomObj v0Assoc, v1Assoc, v2Assoc, v3Assoc;
1844 DocumentModel::GeomObj e0AssocA, e1AssocA, e1AssocB, e1AssocC;
1845 DocumentModel::GeomObj q0AssocA, q0AssocB;
1847 DocumentModel::GeomObj v0Assoc_test, v1Assoc_test, v2Assoc_test, v3Assoc_test;
1848 QList<DocumentModel::GeomObj> e1Assocs_test;
1849 DocumentModel::GeomObj q0Assoc_test;
1851 v0 = _currentModel->addVertex(0, 0, 0);
1852 v1 = _currentModel->addVertex(1, 0, 0);
1853 v2 = _currentModel->addVertex(1, 1, 0);
1854 v3 = _currentModel->addVertex(0, 1, 0);
1855 e0 = _currentModel->addEdgeVertices(v0, v1);
1856 e1 = _currentModel->addEdgeVertices(v1, v2);
1857 q0 = _currentModel->addQuadVertices( v0, v1, v2, v3 );
1860 // >>> face3.GetEntry()'0:1:4'
1861 // >>> e1.GetEntry()'0:1:8'
1862 // >>> e2.GetEntry()'0:1:9'
1863 // >>> e3.GetEntry()'0:1:10'
1864 // >>> e4.GetEntry()'0:1:11'
1865 // >>> v1.GetEntry()'0:1:12'
1866 // >>> v2.GetEntry()'0:1:13'
1867 // >>> v3.GetEntry()'0:1:14'
1868 // >>> v4.GetEntry()'0:1:15'
1871 // v0Assoc.name = "geomV0";
1872 // v0Assoc.entry = "0:1:1:1:3:6";//"0:1:12";
1873 // v0Assoc.brep = "brepV0";
1874 // v1Assoc.name = "geomV1";
1875 // v1Assoc.entry = "0:1:1:1:3:7";//"0:1:13";
1876 // v1Assoc.brep = "brepV1";
1877 // v2Assoc.name = "geomV2";
1878 // v2Assoc.entry = "0:1:1:1:3:8";//"0:1:14";
1879 // v2Assoc.brep = "brepV2";
1880 // v3Assoc.name = "geomV3";
1881 // v3Assoc.entry = "0:1:1:1:3:9";//"0:1:15";
1882 // v3Assoc.brep = "brepV3";
1886 // e0AssocA.name = "geomE0a";
1887 // e0AssocA.entry = "0:1:1:1:3:5";//"0:1:8";
1888 // e0AssocA.brep = "brepE0a";
1889 // e0AssocA.start = 0.10;
1890 // e0AssocA.end = 0.95;
1894 // e1AssocA.name = "geomE1a";
1895 // e1AssocA.entry = "0:1:1:1:3:2";//"0:1:8";
1896 // e1AssocA.brep = "brepE1a";
1897 // e1AssocA.start = 0.12;
1898 // e1AssocA.end = 0.89;
1899 // e1AssocB.name = "geomE1b";
1900 // e1AssocB.entry = "0:1:1:1:3:3";//"0:1:9";
1901 // e1AssocB.brep = "brepE1b";
1902 // e1AssocB.start = 0.20;
1903 // e1AssocB.end = 0.80;
1904 // e1AssocC.name = "geomE1c";
1905 // e1AssocC.entry = "0:1:1:1:3:4";//"0:1:10";
1906 // e1AssocC.brep = "brepE1c";
1907 // e1AssocC.start = 0.16;
1908 // e1AssocC.end = 0.96;
1910 // q0AssocA.name = "geomQuad";
1911 // q0AssocA.entry = "0:1:1:1:3";
1912 // q0AssocA.brep = "brepq0";
1914 // q0AssocB.name = "geomQuad";
1915 // q0AssocB.entry = "0:1:1:1:4";
1916 // q0AssocB.brep = "brepq0";
1918 // _currentModel->addAssociation( v0, v0Assoc );
1919 // _currentModel->addAssociation( v1, v1Assoc );
1920 // _currentModel->addAssociation( v2, v2Assoc );
1921 // _currentModel->addAssociation( v3, v3Assoc );
1924 // _currentModel->addAssociation( e0, e0AssocA );
1926 // _currentModel->addAssociation( e1, e1AssocA );
1927 // _currentModel->addAssociation( e1, e1AssocB );
1928 // _currentModel->addAssociation( e1, e1AssocC );
1930 // _currentModel->addAssociation( q0, q0AssocA );
1931 // _currentModel->addAssociation( q0, q0AssocB );
1937 // v0Assoc_test = _currentModel->getAssociations( v0 )[0];
1938 // v1Assoc_test = _currentModel->getAssociations( v1 )[0];
1939 // v2Assoc_test = _currentModel->getAssociations( v2 )[0];
1940 // v3Assoc_test = _currentModel->getAssociations( v3 )[0];
1941 // ASSERT( v0Assoc.name == v0Assoc_test.name );
1942 // ASSERT( v1Assoc.name == v1Assoc_test.name );
1943 // ASSERT( v2Assoc.name == v2Assoc_test.name );
1944 // ASSERT( v3Assoc.name == v3Assoc_test.name );
1945 // ASSERT( v0Assoc.entry == v0Assoc_test.entry );
1946 // ASSERT( v1Assoc.entry == v1Assoc_test.entry );
1947 // ASSERT( v2Assoc.entry == v2Assoc_test.entry );
1948 // ASSERT( v3Assoc.entry == v3Assoc_test.entry );
1951 // e1Assocs_test = _currentModel->getAssociations( e1 );
1952 // ASSERT( e1Assocs_test[0].name == e1AssocA.name );
1953 // ASSERT( e1Assocs_test[1].name == e1AssocB.name );
1954 // ASSERT( e1Assocs_test[2].name == e1AssocC.name );
1955 // ASSERT( e1Assocs_test[0].entry == e1AssocA.entry );
1956 // ASSERT( e1Assocs_test[1].entry == e1AssocB.entry );
1957 // ASSERT( e1Assocs_test[2].entry == e1AssocC.entry );
1958 // ASSERT( e1Assocs_test[0].start == e1AssocA.start );
1959 // ASSERT( e1Assocs_test[1].start == e1AssocB.start );
1960 // ASSERT( e1Assocs_test[2].start == e1AssocC.start );
1961 // ASSERT( e1Assocs_test[0].end == e1AssocA.end );
1962 // ASSERT( e1Assocs_test[1].end == e1AssocB.end );
1963 // ASSERT( e1Assocs_test[2].end == e1AssocC.end );
1965 // q0Assoc_test = _currentModel->getAssociations( q0 )[0];
1966 // ASSERT( q0Assoc_test.name == q0Assoc.name );
1967 // ASSERT( q0Assoc_test.entry == q0Assoc.entry );
1970 DEBTRACE("HEXABLOCKGUI::test_association fin");
1974 void HEXABLOCKGUI::newDocument()
1976 DEBTRACE("HEXABLOCKGUI::newDocument");
1978 SUIT_ViewWindow *suitVW = NULL;
1979 // std::stringstream name;
1980 // name << "newDoc_" << ++_documentCnt;
1981 // QString fileName = name.str().c_str();
1982 QMainWindow *aParent = application()->desktop();
1983 QWidget *central = aParent->centralWidget();
1985 central->setFocus();
1987 DEBTRACE("No Central Widget");
1989 // BasicGUI_PointDlg* aDlg = new BasicGUI_PointDlg( NULL, aParent );
1992 // Create Document from HEXABLOCK ENGINE
1993 // WARNING : IN HEXABLOCK component, GUI and ENGINE share the same process
1994 HEXABLOCK_ORB::Document_ptr docIn = _hexaEngine->addDocument("default");
1996 HEXA_NS::Document* doc = NULL;
1999 // looking doc impl ( c++ )
2000 Document_impl* dServant = DownCast<Document_impl*>( docIn );
2002 if ( dServant) doc = dServant->GetImpl();
2004 // doc->reorderFaces(); //CS_TEST
2006 // looking for docEntry
2007 if ( !CORBA::is_nil(docIn) ){
2008 CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( docIn );
2009 QString docIOR = anIOR.in();
2010 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
2011 if ( !docIOR.isEmpty() ) {
2012 _PTR(SObject) SO( study->studyDS()->FindObjectIOR( docIOR.toLatin1().constData() ) );
2014 docEntry = SO->GetID().c_str();
2018 DEBTRACE("HEXABLOCKGUI::newDocument docEntry "<<docEntry.toStdString());
2021 // Now create Document Model
2022 _currentModel = new DocumentModel( doc, docEntry, this ); //CS_TOCHECK this
2023 // _currentModel->setHeaderData(0, Qt::Horizontal, tr("HELLOH0"));
2024 // _currentModel->setHeaderData(1, Qt::Horizontal, tr("HELLOH1"));
2025 // _currentModel->setHeaderData(0, Qt::Vertical, tr("HELLOV0"));
2026 _patternDataModel = new PatternDataModel(this);
2027 _patternBuilderModel = new PatternBuilderModel(this);
2028 // _associationsModel = new AssociationsModel(this);
2029 _groupsModel = new GroupsModel(this);
2030 _meshModel = new MeshModel(this);
2032 _patternDataModel->setSourceModel(_currentModel);
2033 _patternBuilderModel->setSourceModel(_currentModel);
2034 // _associationsModel->setSourceModel(_currentModel);
2035 _groupsModel->setSourceModel(_currentModel);
2036 _meshModel->setSourceModel(_currentModel);
2038 // --- new Graphic view ( SVTK )
2039 _currentGraphicView = newGraphicView();
2040 suitVW = _currentGraphicView->get_SUIT_ViewWindow();
2042 // --- setting model
2043 _currentGraphicView->setModel(_currentModel);
2044 // _currentGraphicView->setModel(_patternDataModel);
2045 // connect( _currentModel, SIGNAL(patternDataChanged() ), _currentGraphicView, SLOT ( onPatternDatachanged() ) );
2046 _patternDataTreeView->setModel(_patternDataModel);//_currentModel;
2047 // _patternDataTreeView->setModel(_currentModel);//;
2048 _patternBuilderTreeView->setModel(_patternBuilderModel);//_currentModel;
2049 // _associationTreeView->setModel(_associationsModel);
2050 _groupsTreeView->setModel(_groupsModel);
2051 _meshTreeView->setModel(_meshModel);
2054 // if ( _patternDataSelectionModel ) delete _patternDataSelectionModel;
2055 // if ( _patternBuilderSelectionModel ) delete _patternBuilderSelectionModel;
2056 // if ( _groupsSelectionModel ) delete _groupsSelectionModel;
2057 // if ( _meshSelectionModel ) delete _meshSelectionModel;
2059 // --- setting selection model
2060 _patternDataSelectionModel = new PatternDataSelectionModel(_patternDataModel);
2061 _patternBuilderSelectionModel = new PatternBuilderSelectionModel( _patternBuilderModel, _patternDataSelectionModel );
2062 _groupsSelectionModel = new GroupsSelectionModel(_groupsModel);
2063 _meshSelectionModel = new MeshSelectionModel(_meshModel);
2065 _patternDataSelectionModel->setSalomeSelectionMgr( selectionMgr() );
2066 // _meshSelectionModel->setSalomeSelectionMgr( selectionMgr() );
2068 _currentGraphicView->setSelectionModel(_patternDataSelectionModel);
2069 _patternDataTreeView->setSelectionModel(_patternDataSelectionModel);
2070 _patternDataTreeView->setSelectionMode(QAbstractItemView::SingleSelection); //QAbstractItemView::MultiSelection //CS_TEST
2071 _patternBuilderTreeView->setSelectionModel(_patternBuilderSelectionModel);
2072 _groupsTreeView->setSelectionModel(_groupsSelectionModel);
2073 _meshTreeView->setSelectionModel(_meshSelectionModel);
2074 _meshTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
2076 _treeViewDelegate->setDocumentModel( _currentModel );
2077 _treeViewDelegate->setPatternDataSelectionModel( _patternDataSelectionModel );
2078 _treeViewDelegate->setPatternBuilderSelectionModel( _patternBuilderSelectionModel );
2079 _treeViewDelegate->setGroupsSelectionModel( _groupsSelectionModel/*_groupsTreeView->selectionModel()*/ );
2080 _treeViewDelegate->setMeshSelectionModel( _meshSelectionModel/*_meshTreeView->selectionModel()*/ );
2083 connect( _patternDataSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2084 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2085 connect( _patternBuilderSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2086 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2087 connect( _groupsSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2088 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2089 connect( _meshSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2090 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2093 // salome view/object browser/model management
2094 _documentModels[ suitVW ] = _currentModel;
2096 // _salomeViews[ _currentModel ] = suitVW;
2097 // std::map<const QAbstractItemModel*, SUIT_ViewWindow*> _salomeViews;
2099 _salomeViewWindows[docEntry] = suitVW;
2100 currentVtkView = dynamic_cast<SVTK_ViewWindow*>( _currentGraphicView->get_SUIT_ViewWindow() );
2101 currentVtkView->raise();
2103 // _currentGraphicView->setWindowTitle( _currentModel->getName() );
2104 // currentVtkView->setWindowTitle( _currentModel->getName() );
2105 // showDockWidgets(true);
2107 // _dwPattern->setVisible(true);
2108 // _dwPattern->toggleViewAction()->setVisible(true);
2109 _dwPattern->raise();
2111 // test_make_cart_grid();
2112 // test_make_elmts_transform();
2114 getApp()->updateObjectBrowser();
2116 graphicViewIsEmpty[suitVW] = true;
2120 void HEXABLOCKGUI::slot_modelChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
2122 //std::cout << "HHHHHHHHHHHHHHHHHH Model changed." << std::endl;
2123 //std::cout << "HHHHHHHHHHHHHHHHHH slot_modelChanged topLeft -> " << topLeft.data().toString().toStdString()<<std::endl;
2124 //std::cout << "HHHHHHHHHHHHHHHHHH slot_modelChanged bottomRight ->" << bottomRight.data().toString().toStdString()<<std::endl;
2126 _patternDataTreeView->openPersistentEditor( topLeft );
2128 // // Make the combo boxes always displayed.
2129 // for ( int i = 0; i < _currentModel->rowCount(); ++i )
2131 // QModelIndex ind = _currentModel->index(i);
2132 // _patternDataTreeView->openPersistentEditor( ind );
2133 // std::cout << "ind" << ind.data() << std::endl;
2137 void HEXABLOCKGUI::loadDocument( const QString &inFile )
2139 DEBTRACE("HEXABLOCKGUI::loadDocument");
2140 QMainWindow *aParent = application()->desktop();
2141 QString selectedFile;
2143 if ( inFile.isNull() ){
2144 QFileDialog dialog( aParent, tr("Open HexaBlock Document") ,
2145 QString::null, tr( "XML-Files (*.xml);;All Files (*)" ) );
2146 dialog.setHistory( getQuickDirList() );
2148 QStringList selectedFiles = dialog.selectedFiles();
2149 if (!selectedFiles.isEmpty())
2150 selectedFile = selectedFiles.first();
2153 selectedFile = inFile;
2155 if (! selectedFile.isEmpty()){
2156 if (vtkViewManager==NULL || vtkViewManager->getViewsCount()==0 || !graphicViewIsEmpty[vtkViewManager->getActiveView()])
2158 _currentModel->load(selectedFile);
2159 renameObject( _currentModel->documentEntry(), _currentModel->getName() );
2160 graphicViewIsEmpty[vtkViewManager->getActiveView()] = false;
2164 void HEXABLOCKGUI::saveDocument()
2166 QMainWindow *aParent = application()->desktop();
2167 QString anInitialPath = "";
2168 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
2169 anInitialPath = QDir::currentPath();
2170 // QString aMeshName = anIO->getName();
2172 QString aDocName = "document";
2174 filter.append( QObject::tr( "XML_FILES_FILTER" ) + " (*.xml)" );
2175 filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
2176 QString aFilename = anInitialPath + QString("/") + aDocName;
2177 aFilename = SUIT_FileDlg::getFileName( aParent,
2180 tr( "Save HexaBlock Document" ),
2182 if ( !aFilename.isEmpty() ) {
2183 _currentModel->save( aFilename );
2189 void HEXABLOCKGUI::_showDialogBox( HexaBaseDialog* diag )
2191 MESSAGE("HEXABLOCKGUI::_showDialogBox()");
2192 if (vtkViewManager == NULL || vtkViewManager->getViewsCount() == 0) return;
2194 MESSAGE("if (!diag) return;");
2195 if (!_dwInputPanel) return;
2196 MESSAGE("if (!_dwInputPanel) return;");
2198 currentDialog = diag;
2199 diag->setDocumentModel(_currentModel);
2200 diag->setPatternDataSelectionModel(_patternDataSelectionModel);
2201 diag->setPatternBuilderSelectionModel(_patternBuilderSelectionModel);
2202 diag->setGroupsSelectionModel(_groupsSelectionModel);
2203 diag->setMeshSelectionModel(_meshSelectionModel);
2205 //close the current widget
2206 if (_treeViewDelegate != NULL)
2207 _treeViewDelegate->closeDialog();
2209 if (_dwInputPanel->widget())
2210 _dwInputPanel->widget()->close();
2212 //Temporary for debugging EdgeAssoc Faked InfoDialog
2213 if (diag == _edgeAssocDiag)
2214 diag->debugEdgeAssoc = true;
2216 diag->debugEdgeAssoc = false;
2218 if (diag == _quadAssocDiag || diag == _edgeAssocDiag)
2219 assocInProgress = true;
2221 assocInProgress = false;
2223 //show the dialog box in the dockwidget
2224 diag->resetSizeAndShow(_dwInputPanel);
2228 void HEXABLOCKGUI::addVertex()
2230 if ( !_vertexDiag ){
2231 _vertexDiag = new VertexDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2233 _showDialogBox( _vertexDiag );
2236 void HEXABLOCKGUI::addEdge()
2239 _edgeDiag = new EdgeDialog( _dwInputPanel, HexaBaseDialog::NEW_MODE);
2241 _showDialogBox( _edgeDiag );
2244 void HEXABLOCKGUI::addQuad()
2247 _quadDiag = new QuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2249 _showDialogBox( _quadDiag );
2252 void HEXABLOCKGUI::addHexa()
2255 _hexaDiag = new HexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2257 _showDialogBox( _hexaDiag );
2260 void HEXABLOCKGUI::addVector()
2262 if ( !_vectorDiag ){
2263 _vectorDiag = new VectorDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2265 _showDialogBox( _vectorDiag );
2268 void HEXABLOCKGUI::addCylinder()
2270 if ( !_cylinderDiag ){
2271 _cylinderDiag = new CylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2273 _showDialogBox( _cylinderDiag );
2277 void HEXABLOCKGUI::addPipe()
2280 _pipeDiag = new PipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2282 _showDialogBox( _pipeDiag );
2286 void HEXABLOCKGUI::makeGrid()
2288 if ( !_makeGridDiag ){
2289 _makeGridDiag = new MakeGridDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2291 _showDialogBox( _makeGridDiag );
2295 void HEXABLOCKGUI::makeCylinder()
2297 if ( !_makeCylinderDiag ){
2298 _makeCylinderDiag = new MakeCylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2300 _showDialogBox( _makeCylinderDiag );
2303 void HEXABLOCKGUI::makePipe()
2305 if ( !_makePipeDiag ){
2306 _makePipeDiag = new MakePipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2308 _showDialogBox( _makePipeDiag );
2311 void HEXABLOCKGUI::makeCylinders()
2313 if ( !_makeCylindersDiag ){
2314 _makeCylindersDiag = new MakeCylindersDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2316 _showDialogBox( _makeCylindersDiag );
2319 void HEXABLOCKGUI::makePipes()
2321 if ( !_makePipesDiag ){
2322 _makePipesDiag = new MakePipesDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2324 _showDialogBox( _makePipesDiag );
2328 void HEXABLOCKGUI::makeHemiSphere() // NEW HEXA3
2330 if ( !_makeHemiSphereDiag ){
2331 _makeHemiSphereDiag = new MakeHemiSphereDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2333 _showDialogBox( _makeHemiSphereDiag );
2337 void HEXABLOCKGUI::removeHexa()
2339 if ( !_removeHexaDiag ){
2340 _removeHexaDiag = new RemoveHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2342 _showDialogBox( _removeHexaDiag );
2346 void HEXABLOCKGUI::prismQuad()
2348 if ( !_prismQuadDiag ){
2349 _prismQuadDiag = new PrismQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2351 _showDialogBox( _prismQuadDiag );
2355 void HEXABLOCKGUI::joinQuad()
2357 if ( !_joinQuadDiag ){
2358 _joinQuadDiag = new JoinQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2360 _showDialogBox( _joinQuadDiag );
2363 void HEXABLOCKGUI::merge()
2366 _mergeDiag = new MergeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2368 _showDialogBox( _mergeDiag );
2371 void HEXABLOCKGUI::disconnectElts()
2373 if ( !_disconnectDiag ){
2374 _disconnectDiag = new DisconnectDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2376 _showDialogBox( _disconnectDiag );
2379 void HEXABLOCKGUI::cutEdge()
2381 if ( !_cutEdgeDiag ){
2382 _cutEdgeDiag = new CutEdgeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2384 _showDialogBox( _cutEdgeDiag );
2387 void HEXABLOCKGUI::makeTransformation()
2389 if ( !_makeTransformationDiag ){
2390 _makeTransformationDiag = new MakeTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2392 _showDialogBox( _makeTransformationDiag );
2396 void HEXABLOCKGUI::makeSymmetry()
2398 if ( !_makeSymmetryDiag ){
2399 _makeSymmetryDiag = new MakeSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2401 _showDialogBox( _makeSymmetryDiag );
2405 void HEXABLOCKGUI::performTransformation()
2407 if ( !_performTransformationDiag ){
2408 _performTransformationDiag = new PerformTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2410 _showDialogBox( _performTransformationDiag );
2414 void HEXABLOCKGUI::performSymmetry()
2416 if ( !_performSymmetryDiag ){
2417 _performSymmetryDiag = new PerformSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2419 _showDialogBox( _performSymmetryDiag );
2423 void HEXABLOCKGUI::replaceHexa() // NEW HEXA3
2425 if ( !_replaceHexaDiag ){
2426 _replaceHexaDiag = new ReplaceHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2428 _showDialogBox( _replaceHexaDiag );
2432 void HEXABLOCKGUI::quadRevolution() // NEW HEXA3
2434 if ( !_quadRevolutionDiag ){
2435 _quadRevolutionDiag = new QuadRevolutionDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2437 _showDialogBox( _quadRevolutionDiag );
2441 // void HEXABLOCKGUI::assocVertex()
2443 // if ( !_vertexAssocDiag ){
2444 // _vertexAssocDiag = new VertexAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2446 // _showDialogBox( vertexAssocDiag );
2450 void HEXABLOCKGUI::assocVertex()
2452 MESSAGE("HEXABLOCKGUI::assocVertex()");
2453 if (!_dwInputPanel) return;
2454 QWidget* d = dynamic_cast<SUIT_Desktop*>(_dwInputPanel->parent());
2456 if ( !_vertexAssocDiag ){
2457 _vertexAssocDiag = new VertexAssocDialog( NULL, d );
2458 if (!_vertexAssocDiag) return;
2460 _vertexAssocDiag->setDocumentModel(_currentModel);
2461 _vertexAssocDiag->setPatternDataSelectionModel(_patternDataSelectionModel);
2463 //close current widget
2464 if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
2465 if (_dwInputPanel->widget()) _dwInputPanel->widget()->close();
2467 //add the vertex assoc dialog in the dockwidget
2468 if ( !_dwInputPanel->isVisible() ) _dwInputPanel->setVisible(true);
2469 _dwInputPanel->setWidget(_vertexAssocDiag);
2470 _dwInputPanel->setWindowTitle(_vertexAssocDiag->windowTitle());
2471 _vertexAssocDiag->adjustSize();
2472 assocInProgress = true;
2473 _vertexAssocDiag->show();
2478 void HEXABLOCKGUI::assocEdge()
2480 if ( !_edgeAssocDiag ){
2481 _edgeAssocDiag = new EdgeAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2482 _edgeAssocDiag->setGeomEngine( _geomEngine );
2484 _showDialogBox( _edgeAssocDiag );
2487 void HEXABLOCKGUI::assocQuad()
2489 if ( !_quadAssocDiag ){
2490 _quadAssocDiag = new QuadAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2492 _showDialogBox( _quadAssocDiag );
2496 void HEXABLOCKGUI::addGroup()
2499 _groupDiag = new GroupDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2501 _showDialogBox( _groupDiag );
2506 void HEXABLOCKGUI::removeGroup()
2508 QItemSelectionModel *groupsSelectionModel = _groupsTreeView->selectionModel();
2509 QModelIndex selected = groupsSelectionModel->currentIndex();
2510 selected = _groupsModel->mapToSource( selected );
2513 if ( !selected.isValid() ){
2514 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ), tr( "No group selected!" ) );
2518 //Demande de confirmation de la suppression des groupes
2519 if (SUIT_MessageBox::question(
2522 tr("Remove group : %1 ?").arg(selected.data().toString()),
2523 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2524 SUIT_MessageBox::Cancel
2525 ) == SUIT_MessageBox::Cancel) return;
2527 groupsSelectionModel->clearSelection();
2529 std::cout << "////////////////////////// " << selected.data().toString().toStdString() << std::endl;
2530 bool removed = _currentModel->removeGroup( selected );
2531 //std::cout << " " << selected.data().toString().toStdString() << std::endl;
2533 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2534 groupsSelectionModel->clearSelection();
2541 void HEXABLOCKGUI::removeGroup()
2543 QItemSelectionModel *groupsSelectionModel = _groupsTreeView->selectionModel();
2544 QModelIndexList l = groupsSelectionModel->selectedIndexes();
2545 int nbGroupsRemoved = 0;
2548 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
2549 tr( "No group selected!" ) );
2553 foreach( QModelIndex selected, l ){
2554 if ( selected.data(HEXA_TREE_ROLE) == GROUP_TREE ){
2555 selected = _groupsModel->mapToSource( selected );
2556 Q_ASSERT(selected.isValid());
2558 //Confirm the deletion of the group
2559 if (SUIT_MessageBox::question(
2562 tr("Remove group : %1 ?").arg(selected.data().toString()),
2563 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2564 SUIT_MessageBox::Cancel
2565 ) == SUIT_MessageBox::Cancel) return;
2567 bool removed = _currentModel->removeGroup( selected );
2569 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
2570 tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2576 if (!nbGroupsRemoved)
2577 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
2578 tr( "No group selected!" ) );
2582 void HEXABLOCKGUI::addLaw()
2585 _lawDiag = new LawDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2587 _showDialogBox( _lawDiag );
2590 void HEXABLOCKGUI::removeLaw()
2593 QModelIndexList l = _meshSelectionModel->selectedIndexes();
2594 int nbLawsRemoved = 0;
2597 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
2598 tr( "No law selected!" ) );
2602 foreach( QModelIndex selected, l ){
2603 if ( selected.data(HEXA_TREE_ROLE) == LAW_TREE ){
2604 selected = _meshModel->mapToSource( selected );
2605 Q_ASSERT(selected.isValid());
2607 //Confirm the deletion of the law
2608 if (SUIT_MessageBox::question(
2611 tr("Remove law : %1 ?\nAll propagations having this law will \
2612 have the default law.").arg(selected.data().toString()),
2613 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2614 SUIT_MessageBox::Cancel
2615 ) == SUIT_MessageBox::Cancel) return;
2617 bool removed = _currentModel->removeLaw(selected);
2619 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
2620 tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2627 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
2628 tr( "No law selected!" ) );
2633 void HEXABLOCKGUI::setPropagation()
2635 if ( !_propagationDiag ){
2636 _propagationDiag = new PropagationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2638 _showDialogBox( _propagationDiag );
2642 // Dialog box to compute a mesh from a document
2643 // --------------------------------------------
2645 void HEXABLOCKGUI::computeMesh()
2647 if ( !_computeMeshDiag ){
2648 _computeMeshDiag = new ComputeMeshDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2650 _computeMeshDiag->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
2651 _showDialogBox( _computeMeshDiag );
2654 void HEXABLOCKGUI::clearAssociations()
2656 // QMessageBox::warning( 0, "windowTitle()", "clearAssociations" );
2657 QModelIndex iDataModel = _patternDataTreeView->currentIndex();
2658 QModelIndex iModel = _patternDataModel->mapToSource(iDataModel);
2660 _currentModel->clearEltAssociations(iModel);
2662 // SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
2665 void HEXABLOCKGUI::clearAllAssociations()
2667 //Confirm the deletion of the associations
2668 if (SUIT_MessageBox::question(
2670 tr("Clear Associations"),
2671 tr("Clear all associations ?"),
2672 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2673 SUIT_MessageBox::Cancel
2674 ) == SUIT_MessageBox::Cancel) return;
2676 int currentChildIndex = 0;
2677 QModelIndex currentIndex = _patternDataModel->mapToSource(_patternDataTreeView->currentIndex());
2678 QVariant currentAssocVariant;
2679 QString currentAssocEntry;
2681 QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
2682 while( currentChild.isValid() ) {
2684 currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
2685 currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
2686 if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
2687 _currentModel->clearEltAssociations(currentChild);
2689 currentChild = currentChild.sibling(currentChildIndex++, 0);
2692 //SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
2695 void HEXABLOCKGUI::showAssociations()
2697 QModelIndexList elts;
2698 int currentChildIndex = 0;
2699 QVariant currentAssocVariant;
2700 QString currentAssocEntry;
2701 QModelIndex currentIndex = _patternDataTreeView->currentIndex();
2702 QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
2704 while( currentChild.isValid() ) {
2706 currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
2707 currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
2708 if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
2709 elts << currentChild;
2711 currentChild = currentChild.sibling(currentChildIndex++, 0);
2713 _patternDataSelectionModel-> highlightVTKElts( elts );
2718 LightApp_SelectionMgr* HEXABLOCKGUI::selectionMgr()
2720 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2722 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2727 QStringList HEXABLOCKGUI::getQuickDirList()
2729 QStringList dirList;
2730 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2732 dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
2738 // --- Export the module
2742 HEXABLOCKGUI_EXPORT CAM_Module* createModule()
2744 return new HEXABLOCKGUI();
2747 HEXABLOCKGUI_EXPORT char* getModuleVersion()
2749 return (char*)HEXABLOCK_VERSION_STR;
2754 // void HEXABLOCKGUI::newMesh( const std::string& meshName,
2756 // const std::string& container )
2758 // SalomeApp_Application* app = getApp();
2759 // int activeStudyId = app->activeStudy()->id();
2761 // if ( CORBA::is_nil(_hexaEngine) ) _hexaEngine = InitHEXABLOCKGen( app );
2762 // if ( CORBA::is_nil(_smeshEngine)) _smeshEngine = InitSMESHGen( app, container );
2763 // if ( CORBA::is_nil(_geomEngine) ) _geomEngine = InitGEOMGen( app, container );
2765 // std::cout << "_hexaEngine =>" << _hexaEngine << std::endl;
2766 // std::cout << "_smeshEngine =>" << _smeshEngine << std::endl;
2767 // std::cout << "_geomEngine =>" << _geomEngine << std::endl;
2769 // HEXA_NS::Document* docImpl = _currentModel->documentImpl();
2770 // std::cout << "docImpl =>" << docImpl << std::endl;
2771 // std::cout << "docImpl->getFile() =>" << docImpl->getFile() << std::endl;
2772 // HEXABLOCK_ORB::Document_var anDocObj= _hexaEngine->loadDocument( docImpl->getFile() );
2773 // std::cout << "anDocObj =>" << anDocObj << std::endl;
2776 // GEOM::GEOM_I3DPrimOperations_var anGeomOper = _geomEngine->GetI3DPrimOperations( activeStudyId );
2777 // if ( CORBA::is_nil(anGeomOper) ) return; //!anGeomOper->_is_nil() ) {
2778 // std::cout << "anGeomOper =>" << anGeomOper << std::endl;
2779 // GEOM::GEOM_Object_var anGeomObj = anGeomOper->MakeBoxDXDYDZ( 5., 5., 5. );
2780 // std::cout << "anGeomObj =>" << anGeomObj << std::endl;
2783 // SALOMEDS::SObject _geomEngine->AddInStudy (in SALOMEDS::Study theStudy,
2784 // in GEOM_Object theObject,
2785 // in string theName,
2789 // // void GEOMBase::PublishSubObject( GEOM::GEOM_Object_ptr object )
2791 // SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
2792 // if ( study && !CORBA::is_nil( object ) ) {
2793 // _PTR(Study) studyDS = study->studyDS();
2794 // QString entry = GetEntry( object );
2795 // GEOM::GEOM_Object_var father = object->GetMainShape();
2796 // QString fatherEntry = GetEntry( father );
2797 // if ( entry.isEmpty() && !CORBA::is_nil( father ) && !fatherEntry.isEmpty() ) {
2798 // QString name = GetName( object );
2799 // GeometryGUI::GetGeomGen()->AddInStudy( GeometryGUI::ClientStudyToStudy( studyDS ),
2800 // object, name.toLatin1().data(), father.in() );
2806 // // geompy = smesh.geompy
2807 // // #fkl: shape = doc.getShape()
2808 // // shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
2809 // // geompy.addToStudy(shape, name)
2811 // // component = salome.lcc.FindOrLoadComponent(container, "SMESH")
2812 // // component.init_smesh(salome.myStudy, geompy.geom)
2813 // // mesh = component.Mesh(shape, name)
2815 // // so = "libHexaBlockEngine.so"
2817 // // algo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(component, "HEXABLOCK_3D", so)
2818 // SMESH::SMESH_Hypothesis_var algo = _smeshEngine->CreateHypothesis( "HEXABLOCK_3D", "libHexaBlockEngine.so");
2819 // // raises ( SALOME::SALOME_Exception );
2820 // // mesh.mesh.AddHypothesis(shape, algo)
2822 // // hypo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(component, "HEXABLOCK_Parameters", so)
2823 // //HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var
2824 // SMESH::SMESH_Hypothesis_var hypo = _smeshEngine->CreateHypothesis( "HEXABLOCK_Parameters", "libHexaBlockEngine.so");
2826 // HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var hexHypo = HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis::_narrow(hypo);
2827 // ASSERT(!CORBA::is_nil(hexHypo));
2829 // // mesh.mesh.AddHypothesis(shape, hypo)
2831 // // hexHypo->SetDocument(anDocObj);
2832 // // hexHypo->SetDimension(dim);
2834 // // mesh.Compute()
2842 // void newMesh( const std::string& meshName, int dim )// const std::string& container )
2845 // // _smeshEngine.init_smesh(salome.myStudy, geompy.geom)
2846 // SMESH::SMESH_var mesh = _smeshEngine->Mesh(shape, name);
2847 // SMESH::SMESH_Hypothesis_var algo = _smeshEngine->CreateHypothesis( "HEXABLOCK_3D", "libHexaBlockEngine.so");
2848 // SMESH::SMESH_Hypothesis_var hypo = _smeshEngine->CreateHypothesis( "HEXABLOCK_Parameters", "libHexaBlockEngine.so");
2849 // HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var hexHypo = HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis::_narrow(hypo);
2850 // hexHypo->SetDocument(anDocObj);
2851 // hexHypo->SetDimension(dim);
2855 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
2857 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
2858 if ( CORBA::is_nil( myComponentSMESH ) )
2860 SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
2862 aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2863 return aGUI.myComponentSMESH;
2866 myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2867 return myComponentSMESH;
2870 bool HEXABLOCKGUI::eventFilter(QObject *obj, QEvent *event)
2872 if ( event->type() == QEvent::Enter ){//QEvent::Show ){ //QEvent::KeyPress) {
2873 // showDocumentMenus( false );
2874 // showPatternMenus( false );
2875 // showAssociationMenus( false );
2876 // showGroupsMenus( false );
2877 // showMeshMenus( false );
2878 // if ( obj == _dwObjectBrowser ) {
2879 // showDocumentMenus( true );
2880 // } else if ( obj == _dwPattern ) {
2881 // showPatternMenus( true );
2882 // } else if ( obj == _dwAssociation ) {
2883 // showAssociationMenus( true );
2884 // } else if ( obj == _dwGroups ) {
2885 // showGroupsMenus( true );
2886 // } else if ( obj == _dwMesh ) {
2888 // showMeshMenus( true );
2890 OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>(obj);
2891 if ( occWindow != NULL )
2893 occWindow->setFocus();
2895 SVTK_ViewWindow* vtkWindow = dynamic_cast<SVTK_ViewWindow*>(obj);
2896 if (vtkWindow != NULL)
2898 // vtkWindow->setFocus();
2902 // standard event processing
2903 return QObject::eventFilter(obj, event);
2908 // // throw SALOME_Exception(LOCALIZED("assocVertex"));
2909 // } catch ( SALOME::SALOME_Exception& exc ){
2910 // INFOS("Following exception was cought:\n\t"<<exc.details.text);
2911 // } catch( const std::exception& exc){
2912 // INFOS("Following exception was cought:\n\t"<<exc.what());
2913 // } catch (Standard_Failure& exc) {
2914 // MESSAGE("OCCT Exception in SMESH_Pattern: " << exc.GetMessageString());
2916 // MESSAGE("Unknown exception was cought !!!");