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>
54 #include <SOCC_ViewModel.h>
55 #include <SOCC_ViewWindow.h>
56 #include <OCCViewer_ViewWindow.h>
60 // SALOME KERNEL includes
61 #include <SALOMEDS_Study.hxx>
62 #include <SALOMEDSClient_StudyBuilder.hxx>
63 #include <SALOMEDSClient_SComponent.hxx>
64 #include <SALOMEDSClient_ClientFactory.hxx>
65 #include <SALOMEDSClient_IParameters.hxx>
69 #include <SalomeApp_DataObject.h>
70 #include <SalomeApp_Study.h>
71 #include <SalomeApp_Module.h>
72 #include <SalomeApp_Application.h>
73 #include <SalomeApp_DataModel.h>
76 #include <SALOME_ListIO.hxx>
77 #include <SALOME_ListIteratorOfListIO.hxx>
80 #include <SALOME_LifeCycleCORBA.hxx>
82 #include <LightApp_VTKSelector.h>
84 #include <OCCViewer_ViewManager.h>
87 #include <QtxPopupMgr.h>
90 #include "Resource.hxx"
91 // #include "QtGuiContext.hxx"
93 #include "HEXABLOCKGUI.hxx"
94 #include "HEXABLOCKGUI_Export.hxx"
95 #include "HEXABLOCKGUI_Trace.hxx"
96 #include "HEXABLOCKGUI_Resource.hxx"
97 // #include "HEXABLOCKGUI_DataModel.hxx"
98 #include "HEXABLOCKGUI_DocumentGraphicView.hxx"
99 #include "HEXABLOCKGUI_DocumentModel.hxx"
100 #include "HEXABLOCKGUI_DocumentSelectionModel.hxx"
101 #include "HEXABLOCKGUI_DocumentDelegate.hxx"
102 #include "HEXABLOCKGUI_DocumentPanel.hxx"
104 #include <HEXABLOCK_version.h>
106 #include "MyBasicGUI_PointDlg.hxx"
108 // #include CORBA_CLIENT_HEADER(HEXABLOCKPlugin_Algorithm)
110 #include "HEXABLOCK.hxx"
111 #include "HexDocument_impl.hxx"
114 #define DW_MINIMUM_WIDTH 50
115 #define DWINPUT_MINIMUM_HEIGHT 50
118 using namespace HEXABLOCK::GUI;
120 int HEXABLOCKGUI::_oldStudyId = -1;
122 HEXABLOCK_ORB::HEXABLOCK_Gen_var HEXABLOCKGUI::_hexaEngine = HEXABLOCK_ORB::HEXABLOCK_Gen::_nil();
123 // SMESH::SMESH_Gen_var HEXABLOCKGUI::_smeshEngine = SMESH::SMESH_Gen::_nil();
124 GEOM::GEOM_Gen_var HEXABLOCKGUI::_geomEngine = GEOM::GEOM_Gen::_nil();
126 // std::map<HEXABLOCK::GUI::DocumentModel*, SVTK_ViewWindow*> HEXABLOCKGUI::svtkViews;
127 // std::map<const QAbstractItemModel*, SVTK_ViewWindow*> HEXABLOCKGUI::svtkViews;
128 // std::map<const QAbstractItemModel*, SUIT_ViewWindow*> HEXABLOCKGUI::salomeViews;
129 // HEXABLOCK::GUI::DocumentModel *HEXABLOCKGUI::_currentModel = NULL;
131 SVTK_ViewWindow* HEXABLOCKGUI::currentVtkView = NULL;
132 OCCViewer_ViewWindow* HEXABLOCKGUI::currentOccView = NULL;
134 HEXABLOCKGUI::HEXABLOCKGUI() :
135 SalomeApp_Module( "HEXABLOCK" ), // default name
136 LightApp_Module( "HEXABLOCK" ),
145 _patternDataModel(0),
146 _patternBuilderModel(0),
147 _patternDataTreeView(0),
148 _patternBuilderTreeView(0),
149 _associationTreeView(0),
152 _currentGraphicView(0),
153 _treeViewDelegate(0),
154 _patternDataSelectionModel(0),
155 _patternBuilderSelectionModel(0),
156 _meshSelectionModel(0),
157 _groupsSelectionModel(0),
161 // _selectFromTree( false )
170 _makeCylinderDiag(0),
172 _makeCylindersDiag(0),
180 _makeTransformationDiag(0),
181 _makeSymmetryDiag(0),
182 _performTransformationDiag(0),
183 _performSymmetryDiag(0),
192 _quadRevolutionDiag(0),
193 _makeHemiSphereDiag(0)
195 DEBTRACE("HEXABLOCKGUI::HEXABLOCKGUI");
196 // _studyContextMap.clear();
199 HEXABLOCKGUI::~HEXABLOCKGUI()
202 // disconnect( getApp(), SIGNAL(studyClosed()), _genericGui, SLOT (onCleanOnExit()));
206 SalomeApp_Study* HEXABLOCKGUI::activeStudy()
208 SUIT_Application* app = SUIT_Session::session()->activeApplication();
210 return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
216 // Gets an reference to the module's engine
217 HEXABLOCK_ORB::HEXABLOCK_Gen_ptr HEXABLOCKGUI::InitHEXABLOCKGen( SalomeApp_Application* app )
219 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer", "HEXABLOCK" );
220 HEXABLOCK_ORB::HEXABLOCK_Gen_ptr clr = HEXABLOCK_ORB::HEXABLOCK_Gen::_narrow(comp);
221 ASSERT(!CORBA::is_nil(clr));
225 // // Gets an reference to SMESH's engine CS_TO_DELETE
226 // SMESH::SMESH_Gen_ptr HEXABLOCKGUI::InitSMESHGen( SalomeApp_Application* app,
227 // const std::string& container )
229 // Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( container.c_str(), "SMESH" );
230 // SMESH::SMESH_Gen_ptr clr = SMESH::SMESH_Gen::_narrow(comp);
231 // ASSERT(!CORBA::is_nil(clr));
235 // // Gets an reference to GEOM's engine CS_TO_DELETE
236 GEOM::GEOM_Gen_ptr HEXABLOCKGUI::InitGEOMGen( SalomeApp_Application* app,
237 const std::string& container )
239 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( container.c_str(), "GEOM" );
240 GEOM::GEOM_Gen_ptr clr = GEOM::GEOM_Gen::_narrow(comp);
241 ASSERT(!CORBA::is_nil(clr));
246 void HEXABLOCKGUI::initialize( CAM_Application* app )
248 DEBTRACE("HEXABLOCKGUI::initialize");
249 SalomeApp_Module::initialize( app );
251 _hexaEngine = InitHEXABLOCKGen( dynamic_cast<SalomeApp_Application*>( app ) );
252 _geomEngine = InitGEOMGen( dynamic_cast<SalomeApp_Application*>( app ) );
254 QWidget* aParent = application()->desktop();
255 DEBTRACE(app << " " << application() << " " << application()->desktop() << " " << aParent);
257 SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
258 setResource(aResourceMgr);
260 // if ( app && app->desktop() ){
261 // connect( app->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
262 // this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
263 // connect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
264 // this, SLOT( onObjectBrowserClick(const QModelIndex&) ) );
265 // // connect( getApp(), SIGNAL(studyClosed()), _genericGui,SLOT (onCleanOnExit()));
269 // QGraphicsScene* scene = new QGraphicsScene;
270 // scene->addText("Hello, philou!");
271 // QGraphicsView* view = new QGraphicsView(scene);
273 // app->desktop()->setCentralWidget(view);
276 createAndFillDockWidget();
281 // add component to study
282 if (createSComponent()) updateObjBrowser();
286 void HEXABLOCKGUI::viewManagers( QStringList& list ) const
288 DEBTRACE("HEXABLOCKGUI::viewManagers");
289 MESSAGE("HEXABLOCKGUI::viewManagers");
290 // foreach (const QString &str, list)
291 // MESSAGE("HEXABLOCKGUI::viewManagers"<<str.toStdString() );
292 // list.append( QxScene_Viewer::Type() );
293 // list.append( OCCViewer_Viewer::Type() );
294 // list.append( SVTK_Viewer::Type() );
297 bool HEXABLOCKGUI::activateModule( SUIT_Study* theStudy )
299 DEBTRACE("HEXABLOCKGUI::activateModule");
300 bool bOk = SalomeApp_Module::activateModule( theStudy );
301 if ( !bOk ) return false;
303 // setMenuShown( true );
304 // setToolShown( true );
305 if ( _currentModel == 0 )
311 // showDockWidgets(false);
312 showDockWidgets(true);
314 // // import Python module that manages HEXABLOCK plugins (need to be here because SalomePyQt API uses active module)
315 // PyGILState_STATE gstate = PyGILState_Ensure();
316 // PyObject* pluginsmanager=PyImport_ImportModule((char*)"salome_pluginsmanager");
317 // if(pluginsmanager==NULL)
321 // PyObject* result=PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"hexablock","HEXABLOCK","Plugins");
324 // Py_XDECREF(result);
326 // PyGILState_Release(gstate);
327 // // end of HEXABLOCK plugins loading
329 connect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
330 this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
331 connect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
332 this, SLOT( onObjectBrowserClick(const QModelIndex&) ) );
333 // connect( getApp(), SIGNAL(studyClosed()), _genericGui,SLOT (onCleanOnExit()));
336 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
338 SUIT_ViewManager* vm;
339 ViewManagerList OCCViewManagers, VTKViewManagers;
341 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
342 QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
343 while ( itOCC.hasNext() && (vm = itOCC.next()) )
344 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
346 application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
347 QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
348 while ( itVTK.hasNext() && (vm = itVTK.next()) )
349 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
352 SALOME_ListIO selected;
353 sm->selectedObjects( selected );
356 // disable OCC selectors
357 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
358 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
359 while ( itOCCSel.hasNext() )
360 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
361 sr->setEnabled(true);
363 // disable VTK selectors
364 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
365 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
366 while ( itVTKSel.hasNext() )
367 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
368 sr->setEnabled(true);
370 sm->setSelectedObjects( selected, true ); //NPAL 19674
373 _hexaEngine->SetCurrentStudy(SALOMEDS::Study::_nil());
374 if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( theStudy ))
375 if ( _PTR(Study) aStudy = s->studyDS()) {
376 //define _CAST(Class, shared_ptr_Obj) dynamic_cast<SALOMEDS_##Class*>(shared_ptr_Obj.get())
377 _hexaEngine->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
378 updateObjBrowser(); // objects can be removed
387 bool HEXABLOCKGUI::deactivateModule( SUIT_Study* theStudy )
389 DEBTRACE("HEXABLOCKGUI::deactivateModule");
391 setMenuShown( false );
392 setToolShown( false );
393 showDockWidgets( false );
394 // QtGuiContext *context = QtGuiContext::getQtCurrent();
395 // _studyContextMap[theStudy->id()] = context;
396 // DEBTRACE("_studyContextMap[theStudy] " << theStudy << " " << context);
398 disconnect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
399 this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
400 disconnect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
401 this, SLOT( onObjectBrowserClick(const QModelIndex&) ) );
402 // connect( getApp(), SIGNAL(studyClosed()), _genericGui,SLOT (onCleanOnExit()));
405 if ( HEXABLOCKGUI::currentVtkView ){
406 HEXABLOCKGUI::currentVtkView->SetSelectionMode( ActorSelection ); //default selectionMode in VTKView
409 // if (HEXABLOCKGUI::currentOccView)
411 // //getDisplayer()->globalSelection();//???? //defaut selectionMode in OccView
415 // if ( _patternDataSelectionModel ){
416 // delete _patternDataSelectionModel;
417 // _patternDataSelectionModel = NULL;
419 // if ( _patternBuilderSelectionModel ){
420 // delete _patternBuilderSelectionModel;
421 // _patternBuilderSelectionModel = NULL;
424 qDeleteAll(myOCCSelectors);
425 myOCCSelectors.clear();
426 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
428 qDeleteAll(myVTKSelectors);
429 myVTKSelectors.clear();
430 getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
432 return SalomeApp_Module::deactivateModule( theStudy );
436 bool HEXABLOCKGUI::renameAllowed( const QString& entry) const
438 // MESSAGE("HEXABLOCKGUI::renameAllowed");
439 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
440 SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
441 SalomeApp_DataObject* obj = appStudy ? dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry)) : 0;
443 bool res = app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference();
444 return (app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference());
448 bool HEXABLOCKGUI::renameObject( const QString& entry, const QString& name)
450 MESSAGE("HEXABLOCKGUI::renameObject");
451 // bool appRes = SalomeApp_Module::renameObject(entry,name);
452 // MESSAGE("appRes"<<appRes);
457 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
458 SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
463 _PTR(Study) aStudy = appStudy->studyDS();
468 _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
469 _PTR(GenericAttribute) anAttr;
471 if ( obj->FindAttribute(anAttr, "AttributeName") ){
472 _PTR(AttributeName) aName (anAttr);
473 // GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
475 // HEXABLOCK_Gen_i::Document_var aDoc = HEXABLOCK_Gen_i::Document::_narrow( theIOR );
476 // if (!CORBA::is_nil(aDoc)) {
477 aName->SetValue( name.toLatin1().data() ); // rename the SObject
478 // aDoc->setName( name.toLatin1().data() ); // Rename the corresponding GEOM_Object
479 _currentModel->setName( name/*.toLatin1().data()*/ );
480 // _currentGraphicView->setWindowTitle( _currentModel->getName() );
488 // --- Default windows
489 void HEXABLOCKGUI::windows( QMap<int, int>& theMap ) const
491 DEBTRACE("HEXABLOCKGUI::windows");
493 theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
494 theMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
497 // LightApp_Displayer* HEXABLOCKGUI::displayer()
499 // DEBTRACE("HEXABLOCKGUI::displayer");
500 // return _currentGraphicView;
504 // QString HEXABLOCKGUI::engineIOR() const
506 // DEBTRACE("HEXABLOCKGUI::engineIOR");
507 // // return getApp()->defaultEngineIOR();
513 QString HEXABLOCKGUI::engineIOR() const
515 DEBTRACE("HEXABLOCKGUI::engineIOR");
516 CORBA::ORB_var anORB = getApp()->orb();
517 CORBA::String_var anIOR = anORB->object_to_string(_hexaEngine);
518 return QString( anIOR.in() );
523 void HEXABLOCKGUI::onObjectBrowserClick(const QModelIndex& index)
525 DEBTRACE("HEXABLOCKGUI::onObjectBrowserClick");
526 // we want to switch automatically to the right view windows
527 QWidget *viewWindow = NULL;
529 //first, find entry of item selected
531 DataObjectList dol = getApp()->objectBrowser()->getSelected();
532 if (dol.isEmpty()) return;
533 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
535 itemEntry = item->entry();
537 // DEBTRACE("HEXABLOCKGUI::onClick index.data() => "<<index.data().toString().toStdString());
538 // DEBTRACE("HEXABLOCKGUI::onClick index.model() => "<<index.model());
539 // DEBTRACE("HEXABLOCKGUI::onClick item->name(). => "<<item->name().toStdString());
540 // DEBTRACE("HEXABLOCKGUI::onClick itemEntry =>"<<itemEntry.toStdString());
542 if ( !_salomeViewWindows.count( itemEntry ) ) return;
543 viewWindow = _salomeViewWindows[ itemEntry ];
544 if ( !viewWindow ) return;
545 // _selectFromTree = true;
546 viewWindow->setFocus();
547 _currentGraphicView->update(); //CS_TEST
548 // _selectFromTree = false;
550 // if (getApp()->activeModule()->moduleName().compare("HEXABLOCK") != 0)
551 // getApp()->activateModule("HEXABLOCK");
558 void HEXABLOCKGUI::onWindowActivated( SUIT_ViewWindow* svw)
560 DEBTRACE("HEXABLOCKGUI::onWindowActivated");
561 OCCViewer_ViewWindow* anOccVw = dynamic_cast<OCCViewer_ViewWindow*>(svw);
563 if ( anOccVw != NULL )
564 currentOccView = dynamic_cast<OCCViewer_ViewWindow*>(svw);
565 // OCCViewer_Viewer* aModel = dynamic_cast<OCCViewer_Viewer*>(svw);
567 // we want to switch automatically to the right model
569 SVTK_ViewWindow* viewWindow = dynamic_cast<SVTK_ViewWindow*>(svw);
570 if (!viewWindow) return;
571 if (getApp()->activeModule() && getApp()->activeModule()->moduleName().compare("HEXABLOCK") != 0) //CS_TODO?
572 getApp()->activateModule("HEXABLOCK");
574 switchModel( viewWindow );
578 void HEXABLOCKGUI::onWindowClosed( SUIT_ViewWindow* svw)
580 DEBTRACE("HEXABLOCKGUI::onWindowClosed");
586 void HEXABLOCKGUI::onViewManagerAdded( SUIT_ViewManager* vm)
588 DEBTRACE("HEXABLOCKGUI::onViewManagerAdded");
589 if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
591 // qDebug( "connect" );
592 // // connect( vm, SIGNAL( keyPress ( SUIT_ViewWindow*, QKeyEvent* ) ),
593 // // this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
594 // // connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
595 // // this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
596 // // connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
597 // // this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
598 // LightApp_SelectionMgr* sm = getApp()->selectionMgr();
599 // myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
601 // // disable OCC selectors
602 // getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
603 // QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
604 // while ( itOCCSel.hasNext() )
605 // if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() ){
606 // sr->setEnabled(true);
607 // std::cout<<"HEXABLOCKGUI::onViewManagerAdded sr"<<sr;
610 DEBTRACE("HEXABLOCKGUI::onViewManagerAdded");
613 void HEXABLOCKGUI::onViewManagerRemoved( SUIT_ViewManager* vm)
615 DEBTRACE("HEXABLOCKGUI::::onViewManagerRemoved");
618 void HEXABLOCKGUI::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
620 QModelIndexList l = selected.indexes();
621 if ( l.count() == 0 ) return;
622 if ( !l[0].isValid() ) return;
624 QTreeView* theTree = NULL;
625 if ( sender() == _patternDataSelectionModel ){
626 theTree = _patternDataTreeView;
627 } else if ( sender() == _patternBuilderSelectionModel ){
628 theTree = _patternBuilderTreeView;
629 } else if ( sender() == _groupsSelectionModel ){
630 theTree = _groupsTreeView;
631 } else if ( sender() == _meshSelectionModel ){
632 theTree = _meshTreeView;
635 theTree->scrollTo ( l[0] );
639 // void HEXABLOCKGUI::onTryClose(bool &isClosed, QxScene_ViewWindow* window) //CS_TODO
641 // DEBTRACE("HEXABLOCKGUI::onTryClose");
642 // isClosed = _genericGui->closeContext(window);
645 // CAM_DataModel* HEXABLOCKGUI::createDataModel()
647 // DEBTRACE("HEXABLOCKGUI::createDataModel");
648 // return new HEXABLOCKGUI_DataModel(this);
652 bool HEXABLOCKGUI::createSComponent() //addComponent
654 DEBTRACE("HEXABLOCKGUI::createSComponent");
655 // --- Find or create "HEXABLOCK" SComponent in the study
657 _PTR(Study) aStudy = (( SalomeApp_Study* )(getApp()->activeStudy()))->studyDS();
658 _PTR(StudyBuilder) aBuilder (aStudy->NewBuilder());
659 _PTR(GenericAttribute) anAttr;
660 _PTR(AttributeName) aName;
662 _PTR(SComponent) aComponent = aStudy->FindComponent("HEXABLOCK");
664 aComponent = aBuilder->NewComponent("HEXABLOCK");
665 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
666 aName = _PTR(AttributeName) (anAttr);
667 aName->SetValue(getApp()->moduleTitle("HEXABLOCK").toStdString());
669 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
670 _PTR(AttributePixMap) aPixmap(anAttr);
671 aPixmap->SetPixMap("share/salome/resources/hexablock/ModuleHexablock.png");
673 aBuilder->DefineComponentInstance(aComponent, engineIOR().toStdString());
674 DEBTRACE("HEXABLOCKGUI::createSComponent engineIOR=>"<<engineIOR().toStdString());
675 // aBuilder->DefineComponentInstance(aComponent, getApp()->defaultEngineIOR().toStdString());
676 // DEBTRACE("HEXABLOCKGUI::createSComponent defaultEngineIOR=>"<<getApp()->defaultEngineIOR().toStdString());
678 // SalomeApp_DataModel::synchronize( aComponent, HEXABLOCKGUI::activeStudy() );
686 // bool HEXABLOCKGUI::isSelectionCompatible()
688 // DEBTRACE("HEXABLOCKGUI::isSelectionCompatible");
690 // bool isCompatible = true;
691 // SALOME_ListIO selected;
692 // if ( LightApp_SelectionMgr *Sel = selectionMgr() )
693 // Sel->selectedObjects( selected );
695 // SALOME_ListIteratorOfListIO It( selected );
696 // for ( ; isCompatible && It.More(); It.Next())
698 // ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
699 // ( strcmp("HEXABLOCK", It.Value()->getComponentDataType()) == 0 );
701 // return isCompatible;
704 void HEXABLOCKGUI::setResource(SUIT_ResourceMgr* r)
706 DEBTRACE("HEXABLOCKGUI::setResource");
707 _myresource = new HEXABLOCKGUI_Resource(r);
708 _myresource->preferencesChanged();
711 void HEXABLOCKGUI::createPreferences()
713 DEBTRACE("HEXABLOCKGUI::createPreferences");
714 _myresource->createPreferences(this);
717 void HEXABLOCKGUI::preferencesChanged( const QString& sect, const QString& name )
719 DEBTRACE("HEXABLOCKGUI::preferencesChanged");
720 _myresource->preferencesChanged(sect, name);
721 if(name=="userCatalog")
723 // _genericGui->getCatalogWidget()->addCatalogFromFile(Resource::userCatalog.toStdString());
727 void HEXABLOCKGUI::studyActivated() //CS_TODO
729 int newStudyId = getApp()->activeStudy()->id();
730 DEBTRACE("HEXABLOCKGUI::studyActivated " << _oldStudyId << " " << newStudyId);
732 if (_oldStudyId != -1)
734 // _studyContextMap[_oldStudyId] = QtGuiContext::getQtCurrent();
735 // if (_studyContextMap.count(newStudyId))
737 // DEBTRACE("switch to valid context " << QtGuiContext::getQtCurrent() << " " << _studyContextMap[newStudyId]);
738 // QtGuiContext::setQtCurrent(_studyContextMap[newStudyId]);
742 // DEBTRACE("no switch to null context");
745 _oldStudyId = newStudyId;
750 void HEXABLOCKGUI::treeContextMenu(const QPoint& aPosition)
752 QModelIndex currentIndex = _patternDataTreeView->currentIndex();
753 QVariant currentAssocVariant;
754 QString currentAssocEntry;
756 currentAssocVariant = currentIndex.data( HEXA_ASSOC_ENTRY_ROLE );
757 currentAssocEntry = currentIndex.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
758 if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() ){
759 // _currentModel->allowEdition();
760 QMenu menu( _patternDataTreeView );
762 QAction *clearAct = menu.addAction( "Remove association(s)" );
763 connect( clearAct, SIGNAL(triggered()), this, SLOT(clearAssociations()) );
764 menu.exec( _patternDataTreeView->mapToGlobal( aPosition) );
768 QStandardItem *item = _patternDataModel->itemFromIndex ( currentIndex );
770 //We don't do anything for single items having no association
771 if ( item->type() == VERTEXITEM || item->type() == EDGEITEM ||
772 item->type() == QUADITEM || item->type() == HEXAITEM) return;
774 QMenu menu( _patternDataTreeView );
776 //Show association(s)
777 QAction *showAssocAct = menu.addAction( "Show associations" );
778 connect( showAssocAct, SIGNAL(triggered()), this, SLOT(showAssociations()) );
780 //Clear all associations
781 QAction *clearAllAssocAct = menu.addAction( "Remove all associations" );
782 connect( clearAllAssocAct, SIGNAL(triggered()), this, SLOT(clearAllAssociations()) );
784 menu.exec( _patternDataTreeView->mapToGlobal( aPosition) );
789 void HEXABLOCKGUI::createAndFillDockWidget()
791 QMainWindow *aParent = application()->desktop();
793 // Create dock widget (3 dock)
795 //1) *********** user input panel ( contain user's edit dialog box )
796 _dwInputPanel = new QDockWidget(aParent);
797 // _dwInputPanel->setWindowFlags(Qt::FramelessWindowHint);
798 // _dwInputPanel->setWindowFlags(Qt::WindowTitleHint);
799 _dwInputPanel->setVisible(false);
800 _dwInputPanel->setWindowTitle("Input Panel");
801 // _dwInputPanel->setMinimumHeight(DWINPUT_MINIMUM_HEIGHT);
802 _dwInputPanel->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
803 _dwInputPanel->raise();
805 // _stacked = new QStackedWidget(_dwInputPanel);
806 // _dwInputPanel->setWidget(_stacked);
808 _treeViewDelegate = new DocumentDelegate(_dwInputPanel);
810 //2) ************* document data ( Pattern, Association, Mesh ) in treeview representation
812 _dwPattern = new QDockWidget(aParent);
813 // _dwPattern->installEventFilter(this);
814 _dwPattern->setVisible(false);
815 _dwPattern->setWindowTitle("Model");
816 _dwPattern->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
818 QFrame* patternFrame = new QFrame(_dwPattern);
819 patternFrame->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
820 QVBoxLayout* patternLayout = new QVBoxLayout(patternFrame);
821 patternLayout->setSizeConstraint(QLayout::SetMaximumSize);
822 QSplitter *splitter = new QSplitter(Qt::Vertical,patternFrame);
823 _patternDataTreeView = new QTreeView(patternFrame);//_dwPattern);
824 _patternBuilderTreeView = new QTreeView(patternFrame);
825 splitter->addWidget(_patternDataTreeView);
826 splitter->addWidget(_patternBuilderTreeView);
827 patternLayout->addWidget(splitter);
828 // _patternDataTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
830 _patternDataTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers/*QAbstractItemView::DoubleClicked*/);
831 _patternDataTreeView->setSelectionMode(QAbstractItemView::SingleSelection/*QAbstractItemView::MultiSelection*/);//);//QAbstractItemView::DoubleClicked, QAbstractItemView::SelectedClicked)
832 _patternDataTreeView->setItemDelegate(_treeViewDelegate);
835 _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
836 _patternBuilderTreeView->setItemDelegate(_treeViewDelegate);
837 _dwPattern->setWidget(patternFrame);
838 patternFrame->show();
839 //_dwPattern->raise();
842 _dwGroups = new QDockWidget(aParent);
843 // _dwGroups->installEventFilter(this);
845 _dwGroups->setVisible(false);
846 _dwGroups->setWindowTitle("Groups");
847 _dwGroups->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
848 _groupsTreeView = new QTreeView(_dwGroups);
849 // _associationTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
850 _groupsTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
851 _groupsTreeView->setItemDelegate(_treeViewDelegate);
852 _dwGroups->setWidget(_groupsTreeView);
853 _groupsTreeView->show();
856 _dwMesh = new QDockWidget(aParent);
857 // _dwMesh->installEventFilter(this);
858 _dwMesh->setVisible(false);
859 _dwMesh->setWindowTitle("Mesh");
860 _dwMesh->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
861 _meshTreeView = new QTreeView(_dwMesh);
862 // _meshTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
863 _meshTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
864 _meshTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
865 _meshTreeView->setItemDelegate(_treeViewDelegate);
866 _dwMesh->setWidget(_meshTreeView);
867 _meshTreeView->show();
872 //3) ************* documents ( salome objectbrowser )
873 QDockWidget *_dwObjectBrowser = 0;
874 QWidget* wid = getApp()->objectBrowser()->treeView();
875 // QWidget *wid = application()->objectBrowser()->treeView();
876 QWidget *w = wid->parentWidget();
877 while ( w && !_dwObjectBrowser ) {
878 _dwObjectBrowser = ::qobject_cast<QDockWidget*>( w );
879 w = w->parentWidget();
881 // _dwObjectBrowser->installEventFilter(this);
882 // _dwObjectBrowser->setVisible(false);
883 _dwObjectBrowser->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
884 _dwObjectBrowser->setWindowTitle("Study");
887 // dock widget position
888 // aParent->addDockWidget(Qt::LeftDockWidgetArea, _dwPattern);
889 // aParent->addDockWidget(Qt::RightDockWidgetArea, _dwInputPanel);
890 // aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwPattern );
891 aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwObjectBrowser );
892 aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwInputPanel );
894 aParent->tabifyDockWidget( _dwObjectBrowser, _dwPattern );
895 aParent->tabifyDockWidget( _dwPattern, /*_dwAssociation );
896 aParent->tabifyDockWidget( _dwAssociation, */_dwGroups );
897 aParent->tabifyDockWidget( _dwGroups, _dwMesh );
900 #if QT_VERSION >= 0x040500
901 aParent->setTabPosition(Qt::AllDockWidgetAreas, Resource::tabPanelsUp? QTabWidget::North: QTabWidget::South);
905 // connect( _dwPattern, SIGNAL( visibilityChanged(bool) ), this, SLOT( showPatternMenus(bool) ) );
906 // // connect( _dwAssociation, SIGNAL( visibilityChanged(bool) ), this, SLOT( showAssociationMenus(bool) ) );
907 // connect( _dwGroups, SIGNAL( visibilityChanged(bool) ), this, SLOT( showGroupsMenus(bool) ) );
908 // connect( _dwMesh, SIGNAL( visibilityChanged(bool) ), this, SLOT( showMeshMenus(bool) ) );
912 // popup menu on data tree view
913 _patternDataTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
914 connect(_patternDataTreeView,
915 SIGNAL(customContextMenuRequested(const QPoint &)),
917 SLOT(treeContextMenu(const QPoint &)));
920 void HEXABLOCKGUI::createActions()
922 QMainWindow *aParent = application()->desktop();
923 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
926 _newAct = createAction(_menuId++,
927 tr("Create a new document"),
928 resMgr->loadPixmap("HEXABLOCK", tr("ICON_NEW_DOCUMENT")),
930 tr("Create a new document"),
931 0, aParent, false, this, SLOT(newDocument()));
932 _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
934 _importAct = createAction(_menuId++,
935 tr("Load a document"),
936 resMgr->loadPixmap("HEXABLOCK", tr("ICON_LOAD_DOCUMENT")),
938 tr("Load a document"),
939 0, aParent, false, this, SLOT(loadDocument()));
940 _importAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_O); // --- QKeySequence::Open ambiguous in SALOME
942 _saveAct = createAction(_menuId++,
943 tr("Save the document"),
944 resMgr->loadPixmap("HEXABLOCK", tr("ICON_SAVE_DOCUMENT")),
946 tr("Save the document"),
947 0, aParent, false, this, SLOT(saveDocument()));
949 // _testAct = createAction(_menuId++, tr("Test"), resMgr->loadPixmap("HEXABLOCK", tr("ICON_TEST")),
950 // tr("Test"), tr("New test"),
951 // 0, aParent, false, this, SLOT(test_association()));
953 // Pattern Data creation
954 _addVertex = createAction(_menuId++,
955 tr("Create a vertex"),
956 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_VERTEX")),
958 tr("Create a new vertex"),
959 0, aParent, false, this, SLOT(addVertex()));
961 _addEdge = createAction(_menuId++,
962 tr("Create an edge"),
963 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_EDGE")),
965 tr("Create a new edge"),
966 0, aParent, false, this, SLOT(addEdge()));
968 _addQuad = createAction(_menuId++,
969 tr("Create a quadrangle"),
970 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_QUAD")),
971 tr("Add Quadrangle"),
972 tr("Create a new quadrangle"),
973 0, aParent, false, this, SLOT(addQuad()));
975 _addHexa = createAction(_menuId++,
976 tr("Create an hexahedron"),
977 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_HEXA")),
978 tr("Add Hexahedron"),
979 tr("Create a new hexahedron"),
980 0, aParent, false, this, SLOT(addHexa()));
982 // Builder Data creation
983 _addVector = createAction(_menuId++,
984 tr("Create a vector"),
985 resMgr->loadPixmap( "HEXABLOCK", tr("ICON_ADD_VECTOR")),
987 tr("Create a new vector"),
988 0, aParent, false, this, SLOT(addVector()));
990 _addCylinder = createAction(_menuId++,
991 tr("Create a cylinder"),
992 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_CYLINDER")),
994 tr("Create a new cylinder"),
995 0, aParent, false, this, SLOT(addCylinder()));
997 _addPipe = createAction(_menuId++,
999 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_PIPE")),
1001 tr("Create a new pipe"),
1002 0, aParent, false, this, SLOT(addPipe()));
1004 _makeGrid = createAction(_menuId++,
1006 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_GRID")),
1009 0, aParent, false, this, SLOT(makeGrid()));
1011 _makeCylinder = createAction(_menuId++,
1012 tr("Make a cylinder"),
1013 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDER")),
1014 tr("Make Cylinder"),
1015 tr("Make a cylinder"),
1016 0, aParent, false, this, SLOT(makeCylinder()));
1018 _makePipe = createAction(_menuId++,
1020 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPE")),
1023 0, aParent, false, this, SLOT(makePipe()));
1025 _makeCylinders = createAction(_menuId++,
1026 tr("Make cylinders"),
1027 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDERS")),
1028 tr("Make Cylinders"),
1029 tr("Make cylinders"),
1030 0, aParent, false, this, SLOT(makeCylinders()));
1032 _makePipes = createAction(_menuId++,
1034 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPES")),
1037 0, aParent, false, this, SLOT(makePipes()));
1039 // // _makeRind = createAction( _menuId++, tr("Make rind"), resMgr->loadPixmap( "HEXABLOCK", tr("ICON_MAKE_RIND")),
1040 // // tr("Make rind"), tr("Make rind"),
1041 // // 0, aParent, false, this, SLOT(makeRind()));
1043 _makeHemiSphere = createAction(_menuId++,
1044 tr("Make an hemisphere"),
1045 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_HEMISPHERE")),
1046 tr("Make Hemisphere"),
1047 tr("Make an hemisphere"),
1048 0, aParent, false, this, SLOT(makeHemiSphere()));
1050 // Pattern Data edition
1051 _removeHexa = createAction(_menuId++,
1052 tr("Remove hexahedra"),
1053 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_HEXA")),
1054 tr("Remove Hexahedra"),
1055 tr("Remove hexahedra"),
1056 0, aParent, false, this, SLOT(removeHexa()));
1058 _prismQuad = createAction(_menuId++,
1059 tr("Prism quadrangles"),
1060 resMgr->loadPixmap( "HEXABLOCK", tr("ICON_PRISM_QUAD")),
1061 tr("Prism Quadrangles"),
1062 tr("Prism quadrangles"),
1063 0, aParent, false, this, SLOT(prismQuad()));
1065 _joinQuad = createAction(_menuId++,
1066 tr("Join quadrangles"),
1067 resMgr->loadPixmap("HEXABLOCK", tr("ICON_JOIN_QUAD")),
1068 tr("Join Quadrangles"),
1069 tr("Join quadrangles with hexahedra"),
1070 0, aParent, false, this, SLOT(joinQuad()));
1072 _merge = createAction(_menuId++,
1074 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MERGE")),
1077 0, aParent, false, this, SLOT(merge()));
1079 _disconnect = createAction(_menuId++,
1081 resMgr->loadPixmap("HEXABLOCK", tr("ICON_DISCONNECT")),
1083 tr("Disconnect edges, vertexes or quadrangles"),
1084 0, aParent, false, this, SLOT(disconnectElts()));
1086 _cutEdge = createAction(_menuId++,
1088 resMgr->loadPixmap("HEXABLOCK", tr("ICON_CUT_EDGE")),
1091 0, aParent, false, this, SLOT(cutEdge()));
1093 _makeTransformation = createAction(_menuId++,
1094 tr("Make transformation"),
1095 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_TRANSFORMATION")),
1096 tr("Make Transformation"),
1097 tr("Make transformation"),
1098 0, aParent, false, this, SLOT(makeTransformation()));
1100 _makeSymmetry = createAction(_menuId++,
1101 tr("Make symmetry"),
1102 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_SYMMETRY")),
1103 tr("Make Symmetry"),
1104 tr("Make symmetry"),
1105 0, aParent, false, this, SLOT(makeSymmetry()));
1107 _performTransformation = createAction(_menuId++,
1108 tr("Perform transformation"),
1109 resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_TRANSFORMATION")),
1110 tr("Perform Transformation"),
1111 tr("Perform transformation"),
1112 0, aParent, false, this, SLOT(performTransformation()));
1114 _performSymmetry = createAction(_menuId++,
1115 tr("Perform symmetry"),
1116 resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_SYMMETRY")),
1117 tr("Perform Symmetry"),
1118 tr("Perform symmetry"),
1119 0, aParent, false, this, SLOT(performSymmetry()));
1121 _replaceHexa = createAction(_menuId++,
1122 tr("Replace hexahedron"),
1123 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REPLACE_HEXA")),
1124 tr("Replace Hexahedron"),
1125 tr("Replace hexahedron"),
1126 0, aParent, false, this, SLOT(replaceHexa()));
1128 _quadRevolution = createAction(_menuId++,
1129 tr("Quad revolution"),
1130 resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_REVOLUTION")),
1131 tr("Quad Revolution"),
1132 tr("Quad revolution"),
1133 0, aParent, false, this, SLOT(quadRevolution()));
1136 _assocVertex = createAction(_menuId++,
1137 tr("Make vertex association"),
1138 resMgr->loadPixmap("HEXABLOCK", tr("ICON_VERTEX_ASSOCIATION")),
1139 tr("Make Vertex association"),
1140 tr("Make vertex association"),
1141 0, aParent, false, this, SLOT(assocVertex()));
1143 _assocEdge = createAction(_menuId++,
1144 tr("Make edge association"),
1145 resMgr->loadPixmap("HEXABLOCK", tr("ICON_EDGE_ASSOCIATION")),
1146 tr("Make Edge Association"),
1147 tr("Make edge association"),
1148 0, aParent, false, this, SLOT(assocEdge()));
1150 _assocQuad = createAction(_menuId++,
1151 tr("Make quadrangle association"),
1152 resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_ASSOCIATION")),
1153 tr("Make Quadrangle Association"),
1154 tr("Make quadrangle association"),
1155 0, aParent, false, this, SLOT(assocQuad()));
1158 _addGroup = createAction(_menuId++,
1160 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_GROUP")),
1163 0, aParent, false, this, SLOT(addGroup()));
1165 _removeGroup = createAction(_menuId++,
1166 tr("Remove a group"),
1167 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_GROUP")),
1169 tr("Remove a group"),
1170 0, aParent, false, this, SLOT(removeGroup()));
1173 _addLaw = createAction(_menuId++,
1175 resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_LAW")),
1178 0, aParent, false, this, SLOT(addLaw()));
1180 _removeLaw = createAction(_menuId++,
1182 resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_LAW")),
1185 0, aParent, false, this, SLOT(removeLaw()));
1187 _setPropagation = createAction(_menuId++,
1188 tr("Set propagation"),
1189 resMgr->loadPixmap("HEXABLOCK", tr("ICON_SET_PROPAGATION")),
1190 tr("Set Propagation"),
1191 tr("Set propagation"),
1192 0, aParent, false, this, SLOT(setPropagation()));
1194 _computeMesh = createAction(_menuId++,
1196 resMgr->loadPixmap("HEXABLOCK", tr("ICON_COMPUTE_MESH")),
1199 0, aParent, false, this, SLOT(computeMesh()));
1202 // _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1203 // QAction* createAction(const int id,
1204 // const QString& toolTip,
1205 // const QIcon& icon,
1206 // const QString& menu,
1207 // const QString& status,
1208 // const int shortCut,
1209 // QObject* parent =0,
1210 // bool checkable = false,
1211 // QObject* receiver =0,
1212 // const char* member =0);
1216 void HEXABLOCKGUI::createMenus()
1218 int aMenuId, subMenuId;
1219 aMenuId = createMenu( tr("MEN_FILE"), -1, -1 );
1220 createMenu( separator(), aMenuId, -1, 10 );
1221 aMenuId = createMenu( tr("HEXABLOCK"), aMenuId, -1, 10 );
1222 createMenu( _newAct, aMenuId );
1223 createMenu( _importAct, aMenuId );
1224 createMenu( _saveAct, aMenuId );
1225 // createMenu( _testAct, aMenuId );
1227 // aMenuId = createMenu( tr( "HEXABLOCK" ), -1, -1, 30 );
1228 aMenuId = createMenu( tr( "Document" ), -1, -1, 30 );
1229 createMenu( _newAct, aMenuId );//, 10
1230 createMenu( _importAct, aMenuId );
1231 createMenu( _saveAct, aMenuId );
1232 // createMenu( _testAct, aMenuId );
1234 aMenuId = createMenu( tr("Model"), -1, -1, 30 );
1235 subMenuId = createMenu( tr( "Construction" ), aMenuId, -1 );
1236 createMenu( _addVertex, subMenuId );
1237 createMenu( _addEdge, subMenuId );
1238 createMenu( _addQuad, subMenuId );
1239 createMenu( _addHexa, subMenuId );
1240 //createMenu( separator(), aMenuId);
1243 createMenu( _addVector, subMenuId );
1244 createMenu( _addCylinder, subMenuId );
1245 createMenu( _addPipe, subMenuId );
1246 //createMenu( separator(), aMenuId);
1247 createMenu( _makeGrid, subMenuId ); //Cartesian, Cylindrical, Spherical
1248 createMenu( _makeCylinder, subMenuId );
1249 createMenu( _makePipe, subMenuId );
1250 createMenu( _makeCylinders,subMenuId );
1251 createMenu( _makePipes, subMenuId );
1252 // createMenu( _makeRind, aMenuId );
1253 createMenu( _makeHemiSphere,subMenuId );
1254 //createMenu( separator(), aMenuId);
1256 // Pattern Data Edition
1257 subMenuId = createMenu( tr( "Operation" ), aMenuId, -1 );
1258 createMenu( _removeHexa, subMenuId );
1259 createMenu( _prismQuad, subMenuId );
1260 createMenu( _joinQuad, subMenuId );
1261 createMenu( _merge, subMenuId );// createMenu( _mergeVertices, aMenuId ); // createMenu( _mergeEdges, aMenuId );
1262 createMenu( _disconnect, subMenuId );
1263 createMenu( _cutEdge, subMenuId );
1264 createMenu( _makeTransformation, subMenuId ); // createMenu( _makeTranslation, aMenuId );
1265 createMenu( _makeSymmetry, subMenuId );
1266 createMenu( _performTransformation, subMenuId );
1267 createMenu( _performSymmetry, subMenuId );
1268 createMenu( _replaceHexa, subMenuId );
1269 createMenu( _quadRevolution, subMenuId );
1272 aMenuId = createMenu( tr("Association"), -1, -1, 30 );
1273 createMenu( _assocVertex, aMenuId );
1274 createMenu( _assocEdge, aMenuId );
1275 createMenu( _assocQuad, aMenuId );
1278 aMenuId = createMenu( tr("Groups"), -1, -1, 30 );
1279 createMenu( _addGroup, aMenuId );
1280 createMenu( _removeGroup, aMenuId ); //CS_TODO
1283 aMenuId = createMenu( tr("Mesh "), -1, -1, 30 );
1284 createMenu( _addLaw, aMenuId );
1285 createMenu( _removeLaw, aMenuId );
1286 createMenu( _setPropagation, aMenuId );
1287 createMenu( _computeMesh, aMenuId );
1291 void HEXABLOCKGUI::createTools()
1295 aToolId = createTool ( tr( "HexaBlock Toolbar" ) );
1296 createTool( _newAct, aToolId );
1297 createTool( _importAct, aToolId );
1298 createTool( _saveAct, aToolId );
1299 // createTool( _testAct, aToolId );
1300 //createTool( separator(), aToolId );
1303 aToolId = createTool ( tr( "Construction" ) );
1304 createTool( _addVertex, aToolId );
1305 createTool( _addEdge, aToolId );
1306 createTool( _addQuad, aToolId );
1307 createTool( _addHexa, aToolId );
1308 //createTool( separator(), aToolId );
1311 createTool( _addVector, aToolId );
1312 createTool( _addCylinder, aToolId );
1313 createTool( _addPipe, aToolId );
1314 //createTool( separator(), aToolId );
1316 createTool( _makeGrid, aToolId );
1317 createTool( _makeCylinder, aToolId );
1318 createTool( _makePipe, aToolId );
1319 createTool( _makeCylinders,aToolId );
1320 createTool( _makePipes, aToolId );
1321 // createTool( _makeRind, aToolId);
1322 createTool( _makeHemiSphere, aToolId );
1323 //createTool( separator(), aToolId );
1325 // Pattern Data Edition
1326 aToolId = createTool ( tr( "Operation" ) );
1327 createTool( _removeHexa, aToolId );
1328 createTool( _prismQuad, aToolId );
1329 createTool( _joinQuad, aToolId );
1330 createTool( _merge, aToolId );
1331 createTool( _disconnect, aToolId );
1332 createTool( _cutEdge, aToolId );
1333 createTool( _makeTransformation, aToolId );
1334 createTool( _makeSymmetry, aToolId );
1335 createTool( _performTransformation, aToolId );
1336 createTool( _performSymmetry, aToolId );
1337 createTool( _replaceHexa, aToolId );
1338 createTool( _quadRevolution, aToolId );
1339 //createTool( separator(), aToolId );
1342 aToolId = createTool ( tr( "Association" ) );
1343 createTool( _assocVertex, aToolId );
1344 createTool( _assocEdge, aToolId );
1345 createTool( _assocQuad, aToolId );
1346 //createTool( separator(), aToolId );
1349 aToolId = createTool ( tr( "Group" ) );
1350 createTool( _addGroup, aToolId );
1351 createTool( _removeGroup, aToolId ); //CS_TODO
1352 //createTool( separator(), aToolId );
1355 aToolId = createTool ( tr( "Mesh" ) );
1356 createTool( _addLaw, aToolId );
1357 createTool( _removeLaw, aToolId );
1358 createTool( _setPropagation, aToolId );
1359 createTool( _computeMesh, aToolId );
1363 void HEXABLOCKGUI::initialMenus()
1365 showDocumentMenus( true );
1366 showPatternMenus( false );
1367 showAssociationMenus( false );
1368 showGroupsMenus( false );
1369 showMeshMenus( false );
1372 void HEXABLOCKGUI::showAllMenus()
1374 showDocumentMenus( true );
1375 showPatternMenus( true );
1376 showAssociationMenus( true );
1377 showGroupsMenus( true );
1378 showMeshMenus( true );
1382 void HEXABLOCKGUI::showDocumentMenus(bool show)
1384 DEBTRACE("HEXABLOCKGUI::showDocumentMenus " << show);
1386 setMenuShown(_newAct, show);
1387 setToolShown(_newAct, show);
1388 setMenuShown(_importAct, show);
1389 setToolShown(_importAct, show);
1390 setMenuShown(_saveAct, show);
1391 setToolShown(_saveAct, show);
1392 // setMenuShown(_testAct, show);
1393 // setToolShown(_testAct, show);
1396 void HEXABLOCKGUI::showPatternMenus(bool show)
1398 DEBTRACE("HEXABLOCKGUI::showPatternMenus " << show);
1399 DEBTRACE("_currentModel " << _currentModel );
1400 if ( show && !_currentModel ) return;
1402 setMenuShown(_addVertex, show );//true);
1403 setToolShown(_addVertex, show);
1404 setMenuShown(_addEdge, show );//true);
1405 setToolShown(_addEdge, show);
1406 setMenuShown(_addQuad, show );//true);
1407 setToolShown(_addQuad, show);
1408 setMenuShown(_addHexa, show );//true);
1409 setToolShown(_addHexa, show);
1412 setMenuShown( _addVector, show );//true);
1413 setToolShown( _addVector, show);
1414 setMenuShown( _addCylinder, show );//true);
1415 setToolShown( _addCylinder, show);
1416 setMenuShown( _addPipe, show );//true);
1417 setToolShown( _addPipe, show);
1418 setMenuShown( _makeGrid, show );//true);
1419 setToolShown( _makeGrid, show);
1420 setMenuShown( _makeCylinder, show );//true);
1421 setToolShown( _makeCylinder, show);
1422 setMenuShown( _makePipe, show );//true);
1423 setToolShown( _makePipe, show);
1424 setMenuShown( _makeCylinders, show );//true);
1425 setToolShown( _makeCylinders, show);
1426 setMenuShown( _makePipes, show );//true);
1427 setToolShown( _makePipes, show);
1428 // setMenuShown( _makeRind, show );//true);
1429 // setToolShown( _makeRind, show);
1430 setMenuShown( _makeHemiSphere, show );//true);
1431 setToolShown( _makeHemiSphere, show);
1433 // Pattern Data Edition
1434 setMenuShown( _removeHexa, show );//true);
1435 setToolShown( _removeHexa, show);
1436 setMenuShown( _prismQuad, show );//true);
1437 setToolShown( _prismQuad, show);
1438 setMenuShown( _joinQuad, show );//true);
1439 setToolShown( _joinQuad, show);
1440 setMenuShown( _merge, show );//true);
1441 setToolShown( _merge, show);
1442 setMenuShown( _disconnect, show );//true);
1443 setToolShown( _disconnect, show);
1444 setMenuShown( _cutEdge, show );//true);
1445 setToolShown( _cutEdge, show);
1446 setMenuShown( _makeTransformation, show );//true);
1447 setToolShown( _makeTransformation, show);
1448 setMenuShown( _makeSymmetry, show );//true);
1449 setToolShown( _makeSymmetry, show);
1450 setMenuShown( _performTransformation, show );//true);
1451 setToolShown( _performTransformation, show);
1452 setMenuShown( _performSymmetry, show );//true);
1453 setToolShown( _performSymmetry, show);
1454 setMenuShown( _replaceHexa, show );//true);
1455 setToolShown( _replaceHexa, show);
1456 setMenuShown( _quadRevolution, show );//true);
1457 setToolShown( _quadRevolution, show);
1462 void HEXABLOCKGUI::showAssociationMenus(bool show)
1464 DEBTRACE("HEXABLOCKGUI::showAssociationMenus" << show);
1465 if ( show && !_currentModel ) return;
1467 // Association Edition
1468 setMenuShown( _assocVertex, show );
1469 setToolShown( _assocVertex, show);
1470 setMenuShown( _assocEdge, show );
1471 setToolShown( _assocEdge, show);
1472 setMenuShown( _assocQuad, show );
1473 setToolShown( _assocQuad, show);
1477 void HEXABLOCKGUI::showGroupsMenus(bool show)
1479 DEBTRACE("HEXABLOCKGUI::showGroupsMenus" << show);
1480 if ( show && !_currentModel ) return;
1481 setMenuShown( _addGroup, show );//true);
1482 setToolShown( _addGroup, show);
1483 setMenuShown( _removeGroup , show );//true);
1484 setToolShown( _removeGroup , show);
1487 void HEXABLOCKGUI::showMeshMenus(bool show)
1489 DEBTRACE("HEXABLOCKGUI::showMeshMenus" << show);
1490 if ( show && !_currentModel ) return;
1491 setMenuShown( _addLaw, show );//true);
1492 setToolShown( _addLaw, show);
1493 setMenuShown( _removeLaw, show );//true);
1494 setToolShown( _removeLaw, show);;
1495 setMenuShown( _setPropagation, show );//true);
1496 setToolShown( _setPropagation, show);
1497 setMenuShown( _computeMesh, show); //true);
1498 setToolShown( _computeMesh, show);
1503 void HEXABLOCKGUI::switchModel(SUIT_ViewWindow *view)
1505 DEBTRACE("HEXABLOCKGUI::switchModel " << view);
1507 if ( _documentModels.count(view) == 0 ){
1508 DEBTRACE("HEXABLOCKGUI::switchModel : no model found, cannot switch");
1513 if ( _currentModel != _documentModels[view] ){ // need to switch
1515 QWidget* w = _dwInputPanel->widget();
1520 _currentModel = _documentModels[view];
1521 _patternDataModel->setSourceModel(_currentModel);
1522 _patternBuilderModel->setSourceModel(_currentModel);
1523 // _associationsModel->setSourceModel(_currentModel);
1524 _groupsModel->setSourceModel(_currentModel);
1525 _meshModel->setSourceModel(_currentModel);
1527 // associate models and views
1528 _currentGraphicView = _documentView[view];
1529 // _currentGraphicView->setModel(_patternDataModel);
1530 // connect( _currentModel, SIGNAL(patternDataChanged() ), _currentGraphicView, SLOT ( onPatternDatachanged() ) );
1531 _currentGraphicView->setModel(_currentModel);
1533 _patternDataTreeView->setModel(_patternDataModel); //_currentModel
1534 _patternBuilderTreeView->setModel(_patternBuilderModel);//_currentModel
1535 // _associationTreeView->setModel(_associationsModel);;
1536 _groupsTreeView->setModel(_groupsModel);
1537 _meshTreeView->setModel(_meshModel);
1539 // set selections for each view
1540 if ( _patternDataSelectionModel ) delete _patternDataSelectionModel;
1541 if ( _patternBuilderSelectionModel ) delete _patternBuilderSelectionModel;
1542 if ( _groupsSelectionModel ) delete _groupsSelectionModel;
1543 if ( _meshSelectionModel ) delete _meshSelectionModel;
1545 _patternDataSelectionModel = new PatternDataSelectionModel( _patternDataModel );
1546 _patternBuilderSelectionModel = new PatternBuilderSelectionModel( _patternBuilderModel, _patternDataSelectionModel );
1547 _groupsSelectionModel = new GroupsSelectionModel( _groupsModel );
1548 _meshSelectionModel = new MeshSelectionModel( _meshModel );
1550 _patternDataSelectionModel->setSalomeSelectionMgr( selectionMgr() );
1551 // _meshSelectionModel->setSalomeSelectionMgr( selectionMgr() );
1552 // _patternDataSelectionModel->setGeomEngine( _geomEngine );
1554 _currentGraphicView->setSelectionModel(_patternDataSelectionModel);
1556 _patternDataTreeView->setSelectionModel(_patternDataSelectionModel);
1557 _patternDataTreeView->setEditTriggers(/*QAbstractItemView::EditKeyPressed*/QAbstractItemView::AllEditTriggers /*QAbstractItemView::NoEditTriggers*/);
1559 _patternBuilderTreeView->setSelectionModel(_patternBuilderSelectionModel);
1560 _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1562 _groupsTreeView->setSelectionModel(_groupsSelectionModel);
1563 _groupsTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1565 _meshTreeView->setSelectionModel( _meshSelectionModel );
1566 _meshTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1569 // delegate for edition
1570 _treeViewDelegate->setDocumentModel( _currentModel );
1571 _treeViewDelegate->setPatternDataSelectionModel( _patternDataSelectionModel );
1572 _treeViewDelegate->setPatternBuilderSelectionModel( _patternBuilderSelectionModel );
1573 _treeViewDelegate->setGroupsSelectionModel( _groupsSelectionModel /*_groupsTreeView->selectionModel()*/ );
1574 _treeViewDelegate->setMeshSelectionModel( _meshSelectionModel/*_meshTreeView->selectionModel()*/ );
1577 connect( _patternDataSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1578 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1579 connect( _patternBuilderSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1580 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1581 connect( _groupsSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1582 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1583 connect( _meshSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1584 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1587 currentVtkView = dynamic_cast<SVTK_ViewWindow*>( _currentGraphicView->get_SUIT_ViewWindow() );
1590 showPatternMenus(true);
1596 void HEXABLOCKGUI::showDockWidgets(bool isVisible)
1598 DEBTRACE("HEXABLOCKGUI::showDockWidgets " << isVisible);
1600 if (_dwObjectBrowser) _dwObjectBrowser->setVisible(isVisible);
1601 if (_dwObjectBrowser) _dwObjectBrowser->toggleViewAction()->setVisible(isVisible);
1603 if (_dwPattern) _dwPattern->setVisible(isVisible);
1604 if (_dwPattern) _dwPattern->toggleViewAction()->setVisible(isVisible);
1606 // if (_dwAssociation) _dwAssociation->setVisible(isVisible);
1607 // if (_dwAssociation) _dwAssociation->toggleViewAction()->setVisible(isVisible);
1609 if (_dwMesh) _dwMesh->setVisible(isVisible);
1610 if (_dwMesh) _dwMesh->toggleViewAction()->setVisible(isVisible);
1612 if (_dwGroups) _dwGroups->setVisible(isVisible);
1613 if (_dwGroups) _dwGroups->toggleViewAction()->setVisible(isVisible);
1615 if (_dwInputPanel) _dwInputPanel->setVisible(isVisible);
1616 if (_dwInputPanel) _dwInputPanel->toggleViewAction()->setVisible(isVisible);
1618 QWidget* w = _dwInputPanel->widget();
1620 // if ( isVisible ) _dwObjectBrowser->raise();//_dwPattern->raise();
1624 // void HEXABLOCKGUI::raiseStacked()
1626 // // if (_dwStacked) _dwStacked->raise();
1632 DocumentGraphicView* HEXABLOCKGUI::newGraphicView()
1634 MESSAGE("HEXABLOCKGUI::newGraphicView");
1635 DocumentGraphicView *newGView = 0;
1636 SUIT_ViewWindow *suitVW = NULL;
1638 SUIT_ViewManager *suitVM = getApp()->getViewManager(SVTK_Viewer::Type(), true);
1639 MESSAGE("suitVM->getViewsCount() => " << suitVM->getViewsCount() );
1640 suitVW = suitVM->getActiveView();
1641 if ( _documentView.count(suitVW) > 0)
1642 suitVW = suitVM->createViewWindow();
1645 suitVW->setClosable(false);
1646 newGView = new DocumentGraphicView(getApp(), suitVW, application()->desktop());
1647 _documentView[suitVW] = newGView;
1660 void HEXABLOCKGUI::testDocument()
1664 // QStandardItem *parentItem = _currentModel->invisibleRootItem();
1665 // QStandardItem *myItem = new QStandardItem("MyItem");
1666 // parentItem->appendRow(myItem);
1668 // QModelIndex v0 = _currentModel->addVertex(0., 0., 0.);
1669 // QModelIndex v1 = _currentModel->addVertex(5., 0., 0.);
1670 // QModelIndex v2 = _currentModel->addVertex(5., 5., 0.);
1671 // QModelIndex v3 = _currentModel->addVertex(0., 5., 0.);
1672 // QModelIndex v4 = _currentModel->addVertex(0., 0., 5.);
1673 // QModelIndex v5 = _currentModel->addVertex(5., 0., 5.);
1674 // QModelIndex v6 = _currentModel->addVertex(5., 5., 5.);
1675 // QModelIndex v7 = _currentModel->addVertex(0., 5., 5.);
1678 // QModelIndex q0 = _currentModel->addQuadVertices( v0, v1, v2, v3 );
1679 // QModelIndex q1 = _currentModel->addQuadVertices( v4, v5, v6, v7 );
1680 // QModelIndex q2 = _currentModel->addQuadVertices( v0, v3, v7, v4 );
1681 // QModelIndex q3 = _currentModel->addQuadVertices( v1, v2, v6, v5 );
1682 // QModelIndex q4 = _currentModel->addQuadVertices( v0, v1, v5, v4 );
1683 // QModelIndex q5 = _currentModel->addQuadVertices( v3, v2, v6, v7 );
1685 // QModelIndex h0 = _currentModel->addHexaQuad( q0, q1, q2, q3, q4, q5 );
1686 // QModelIndex vx = _currentModel->addVector(1., 0., 0.);
1687 // QModelIndex vy = _currentModel->addVector(0., 1., 0.);
1688 // QModelIndex vz = _currentModel->addVector(0., 0., 1.);
1693 // // QModelIndex orig1 = _currentModel->addVertex (0, 0,0);
1694 // // QModelIndex orig2 = _currentModel->addVertex (50,0,0);
1695 // // QModelIndex vz = _currentModel->addVector (0,0,1);
1696 // // QModelIndex vx = _currentModel->addVector (1,0,0);
1704 // // QModelIndex cyl = _currentModel->addCylinder (orig1, vz, nr, nl);
1705 // // QModelIndex pipe = _currentModel->addPipe (orig2, vz, nri, nre, nl);
1707 // // _currentModel->makeCylinder (cyl, vx, nr, na, nl);
1708 // // _currentModel->makePipe(pipe, vx, nr, na, nl);
1712 // newMesh( "toto", 3, "FactoryServer");
1716 void HEXABLOCKGUI::test_make_cart_grid()
1718 QModelIndex orig1 = _currentModel->addVertex( 0, 0, 0);
1719 QModelIndex orig2 = _currentModel->addVertex( 10, 0, 0);
1720 QModelIndex orig3 = _currentModel->addVertex( 0, 10, 0);
1721 QModelIndex orig4 = _currentModel->addVertex( 10, 10, 0);
1722 QModelIndex orig5 = _currentModel->addVertex( 0, 20, 0);
1723 QModelIndex orig6 = _currentModel->addVertex( 10, 20, 0);
1725 QModelIndex vz = _currentModel->addVector(0, 0, 1);
1726 QModelIndex vx = _currentModel->addVector(1, 0, 0);
1733 // QModelIndex c1 = _currentModel->makeCylindrical(orig1, vx, vz, dr, 360, dl, nr, 4, nl, true);
1734 // QModelIndex c2 = _currentModel->makeCylindrical(orig2, vx, vz, dr, 360, dl, nr, 8, nl, true);
1735 // QModelIndex c3 = _currentModel->makeCylindrical(orig3, vx, vz, dr, 270, dl, nr, 8, nl, true);
1736 // QModelIndex c4 = _currentModel->makeCylindrical(orig4, vx, vz, dr, 270, dl, nr, 7, nl, true);
1737 // QModelIndex c5 = _currentModel->makeCylindrical(orig5, vx, vz, dr, 360, dl, nr, 5, nl, true);
1738 // QModelIndex c6 = _currentModel->makeCylindrical(orig6, vx, vz, dr, 360, dl, nr, 6, nl, true);
1743 void HEXABLOCKGUI::test_make_elmts_transform()
1750 QModelIndex orig = _currentModel->addVertex(0, 0, 0);
1751 QModelIndex dirVr = _currentModel->addVector(1, 1, 1);
1753 QModelIndex grid = _currentModel->makeCartesian(orig, dirVr, size_x, size_y, size_z);//, 0, 0, 0);
1754 // orig.setScalar(2);
1756 // file_name = os.path.join(os.environ['TMP'], 'transfo0.vtk')
1757 // _currentModel->saveVtk(file_name)
1759 QModelIndex devant = _currentModel->addVector(5, 0, 0);
1760 QModelIndex grid2 = _currentModel->makeTranslation(grid, devant);
1762 // file_name = os.path.join(os.environ['TMP'], 'transfo_translation.vtk')
1763 // _currentModel->saveVtk(file_name)
1765 QModelIndex grid4 = _currentModel->makeRotation(grid2, orig, dirVr, 45);
1768 // file_name = os.path.join(os.environ['TMP'], 'transfo_rotation.vtk');
1769 // _currentModel->saveVtk(file_name);
1772 // print "...test make elements by transforming elements OK"
1776 void HEXABLOCKGUI::test()
1778 DEBTRACE("HEXABLOCKGUI::test");
1779 _currentGraphicView->update();
1783 void HEXABLOCKGUI::test_association()
1785 DEBTRACE("HEXABLOCKGUI::test_association");
1788 QModelIndex v0, v1, v2, v3, e0, e1, q0;
1790 DocumentModel::GeomObj v0Assoc, v1Assoc, v2Assoc, v3Assoc;
1791 DocumentModel::GeomObj e0AssocA, e1AssocA, e1AssocB, e1AssocC;
1792 DocumentModel::GeomObj q0AssocA, q0AssocB;
1794 DocumentModel::GeomObj v0Assoc_test, v1Assoc_test, v2Assoc_test, v3Assoc_test;
1795 QList<DocumentModel::GeomObj> e1Assocs_test;
1796 DocumentModel::GeomObj q0Assoc_test;
1798 v0 = _currentModel->addVertex(0, 0, 0);
1799 v1 = _currentModel->addVertex(1, 0, 0);
1800 v2 = _currentModel->addVertex(1, 1, 0);
1801 v3 = _currentModel->addVertex(0, 1, 0);
1802 e0 = _currentModel->addEdgeVertices(v0, v1);
1803 e1 = _currentModel->addEdgeVertices(v1, v2);
1804 q0 = _currentModel->addQuadVertices( v0, v1, v2, v3 );
1807 // >>> face3.GetEntry()'0:1:4'
1808 // >>> e1.GetEntry()'0:1:8'
1809 // >>> e2.GetEntry()'0:1:9'
1810 // >>> e3.GetEntry()'0:1:10'
1811 // >>> e4.GetEntry()'0:1:11'
1812 // >>> v1.GetEntry()'0:1:12'
1813 // >>> v2.GetEntry()'0:1:13'
1814 // >>> v3.GetEntry()'0:1:14'
1815 // >>> v4.GetEntry()'0:1:15'
1818 // v0Assoc.name = "geomV0";
1819 // v0Assoc.entry = "0:1:1:1:3:6";//"0:1:12";
1820 // v0Assoc.brep = "brepV0";
1821 // v1Assoc.name = "geomV1";
1822 // v1Assoc.entry = "0:1:1:1:3:7";//"0:1:13";
1823 // v1Assoc.brep = "brepV1";
1824 // v2Assoc.name = "geomV2";
1825 // v2Assoc.entry = "0:1:1:1:3:8";//"0:1:14";
1826 // v2Assoc.brep = "brepV2";
1827 // v3Assoc.name = "geomV3";
1828 // v3Assoc.entry = "0:1:1:1:3:9";//"0:1:15";
1829 // v3Assoc.brep = "brepV3";
1833 // e0AssocA.name = "geomE0a";
1834 // e0AssocA.entry = "0:1:1:1:3:5";//"0:1:8";
1835 // e0AssocA.brep = "brepE0a";
1836 // e0AssocA.start = 0.10;
1837 // e0AssocA.end = 0.95;
1841 // e1AssocA.name = "geomE1a";
1842 // e1AssocA.entry = "0:1:1:1:3:2";//"0:1:8";
1843 // e1AssocA.brep = "brepE1a";
1844 // e1AssocA.start = 0.12;
1845 // e1AssocA.end = 0.89;
1846 // e1AssocB.name = "geomE1b";
1847 // e1AssocB.entry = "0:1:1:1:3:3";//"0:1:9";
1848 // e1AssocB.brep = "brepE1b";
1849 // e1AssocB.start = 0.20;
1850 // e1AssocB.end = 0.80;
1851 // e1AssocC.name = "geomE1c";
1852 // e1AssocC.entry = "0:1:1:1:3:4";//"0:1:10";
1853 // e1AssocC.brep = "brepE1c";
1854 // e1AssocC.start = 0.16;
1855 // e1AssocC.end = 0.96;
1857 // q0AssocA.name = "geomQuad";
1858 // q0AssocA.entry = "0:1:1:1:3";
1859 // q0AssocA.brep = "brepq0";
1861 // q0AssocB.name = "geomQuad";
1862 // q0AssocB.entry = "0:1:1:1:4";
1863 // q0AssocB.brep = "brepq0";
1865 // _currentModel->addAssociation( v0, v0Assoc );
1866 // _currentModel->addAssociation( v1, v1Assoc );
1867 // _currentModel->addAssociation( v2, v2Assoc );
1868 // _currentModel->addAssociation( v3, v3Assoc );
1871 // _currentModel->addAssociation( e0, e0AssocA );
1873 // _currentModel->addAssociation( e1, e1AssocA );
1874 // _currentModel->addAssociation( e1, e1AssocB );
1875 // _currentModel->addAssociation( e1, e1AssocC );
1877 // _currentModel->addAssociation( q0, q0AssocA );
1878 // _currentModel->addAssociation( q0, q0AssocB );
1884 // v0Assoc_test = _currentModel->getAssociations( v0 )[0];
1885 // v1Assoc_test = _currentModel->getAssociations( v1 )[0];
1886 // v2Assoc_test = _currentModel->getAssociations( v2 )[0];
1887 // v3Assoc_test = _currentModel->getAssociations( v3 )[0];
1888 // ASSERT( v0Assoc.name == v0Assoc_test.name );
1889 // ASSERT( v1Assoc.name == v1Assoc_test.name );
1890 // ASSERT( v2Assoc.name == v2Assoc_test.name );
1891 // ASSERT( v3Assoc.name == v3Assoc_test.name );
1892 // ASSERT( v0Assoc.entry == v0Assoc_test.entry );
1893 // ASSERT( v1Assoc.entry == v1Assoc_test.entry );
1894 // ASSERT( v2Assoc.entry == v2Assoc_test.entry );
1895 // ASSERT( v3Assoc.entry == v3Assoc_test.entry );
1898 // e1Assocs_test = _currentModel->getAssociations( e1 );
1899 // ASSERT( e1Assocs_test[0].name == e1AssocA.name );
1900 // ASSERT( e1Assocs_test[1].name == e1AssocB.name );
1901 // ASSERT( e1Assocs_test[2].name == e1AssocC.name );
1902 // ASSERT( e1Assocs_test[0].entry == e1AssocA.entry );
1903 // ASSERT( e1Assocs_test[1].entry == e1AssocB.entry );
1904 // ASSERT( e1Assocs_test[2].entry == e1AssocC.entry );
1905 // ASSERT( e1Assocs_test[0].start == e1AssocA.start );
1906 // ASSERT( e1Assocs_test[1].start == e1AssocB.start );
1907 // ASSERT( e1Assocs_test[2].start == e1AssocC.start );
1908 // ASSERT( e1Assocs_test[0].end == e1AssocA.end );
1909 // ASSERT( e1Assocs_test[1].end == e1AssocB.end );
1910 // ASSERT( e1Assocs_test[2].end == e1AssocC.end );
1912 // q0Assoc_test = _currentModel->getAssociations( q0 )[0];
1913 // ASSERT( q0Assoc_test.name == q0Assoc.name );
1914 // ASSERT( q0Assoc_test.entry == q0Assoc.entry );
1917 DEBTRACE("HEXABLOCKGUI::test_association fin");
1921 void HEXABLOCKGUI::newDocument()
1923 DEBTRACE("HEXABLOCKGUI::newDocument");
1925 SUIT_ViewWindow *suitVW = NULL;
1926 // std::stringstream name;
1927 // name << "newDoc_" << ++_documentCnt;
1928 // QString fileName = name.str().c_str();
1929 QMainWindow *aParent = application()->desktop();
1930 QWidget *central = aParent->centralWidget();
1932 central->setFocus();
1934 DEBTRACE("No Central Widget");
1936 // BasicGUI_PointDlg* aDlg = new BasicGUI_PointDlg( NULL, aParent );
1939 // Create Document from HEXABLOCK ENGINE
1940 // WARNING : IN HEXABLOCK component, GUI and ENGINE share the same process
1941 HEXABLOCK_ORB::Document_ptr docIn = _hexaEngine->addDocument("default");
1943 HEXA_NS::Document* doc = NULL;
1946 // looking doc impl ( c++ )
1947 Document_impl* dServant = DownCast<Document_impl*>( docIn );
1949 if ( dServant) doc = dServant->GetImpl();
1951 // doc->reorderFaces(); //CS_TEST
1953 // looking for docEntry
1954 if ( !CORBA::is_nil(docIn) ){
1955 CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( docIn );
1956 QString docIOR = anIOR.in();
1957 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1958 if ( !docIOR.isEmpty() ) {
1959 _PTR(SObject) SO( study->studyDS()->FindObjectIOR( docIOR.toLatin1().constData() ) );
1961 docEntry = SO->GetID().c_str();
1965 DEBTRACE("HEXABLOCKGUI::newDocument docEntry "<<docEntry.toStdString());
1968 // Now create Document Model
1969 _currentModel = new DocumentModel( doc, docEntry, this ); //CS_TOCHECK this
1970 // _currentModel->setHeaderData(0, Qt::Horizontal, tr("HELLOH0"));
1971 // _currentModel->setHeaderData(1, Qt::Horizontal, tr("HELLOH1"));
1972 // _currentModel->setHeaderData(0, Qt::Vertical, tr("HELLOV0"));
1973 _patternDataModel = new PatternDataModel(this);
1974 _patternBuilderModel = new PatternBuilderModel(this);
1975 // _associationsModel = new AssociationsModel(this);
1976 _groupsModel = new GroupsModel(this);
1977 _meshModel = new MeshModel(this);
1979 _patternDataModel->setSourceModel(_currentModel);
1980 _patternBuilderModel->setSourceModel(_currentModel);
1981 // _associationsModel->setSourceModel(_currentModel);
1982 _groupsModel->setSourceModel(_currentModel);
1983 _meshModel->setSourceModel(_currentModel);
1985 // --- new Graphic view ( SVTK )
1986 _currentGraphicView = newGraphicView();
1987 suitVW = _currentGraphicView->get_SUIT_ViewWindow();
1989 // --- setting model
1990 _currentGraphicView->setModel(_currentModel);
1991 // _currentGraphicView->setModel(_patternDataModel);
1992 // connect( _currentModel, SIGNAL(patternDataChanged() ), _currentGraphicView, SLOT ( onPatternDatachanged() ) );
1993 _patternDataTreeView->setModel(_patternDataModel);//_currentModel;
1994 // _patternDataTreeView->setModel(_currentModel);//;
1995 _patternBuilderTreeView->setModel(_patternBuilderModel);//_currentModel;
1996 // _associationTreeView->setModel(_associationsModel);
1997 _groupsTreeView->setModel(_groupsModel);
1998 _meshTreeView->setModel(_meshModel);
2001 // --- setting selection model
2002 if ( _patternDataSelectionModel ) delete _patternDataSelectionModel;
2003 if ( _patternBuilderSelectionModel ) delete _patternBuilderSelectionModel;
2004 if ( _groupsSelectionModel ) delete _groupsSelectionModel;
2005 if ( _meshSelectionModel ) delete _meshSelectionModel;
2007 _patternDataSelectionModel = new PatternDataSelectionModel(_patternDataModel);
2008 _patternBuilderSelectionModel = new PatternBuilderSelectionModel( _patternBuilderModel, _patternDataSelectionModel );
2009 _groupsSelectionModel = new GroupsSelectionModel(_groupsModel);
2010 _meshSelectionModel = new MeshSelectionModel(_meshModel);
2012 _patternDataSelectionModel->setSalomeSelectionMgr( selectionMgr() );
2013 // _meshSelectionModel->setSalomeSelectionMgr( selectionMgr() );
2015 _currentGraphicView->setSelectionModel(_patternDataSelectionModel);
2016 _patternDataTreeView->setSelectionModel(_patternDataSelectionModel);
2017 _patternDataTreeView->setSelectionMode(QAbstractItemView::SingleSelection); //QAbstractItemView::MultiSelection //CS_TEST
2018 _patternBuilderTreeView->setSelectionModel(_patternBuilderSelectionModel);
2019 _groupsTreeView->setSelectionModel(_groupsSelectionModel);
2020 _meshTreeView->setSelectionModel(_meshSelectionModel);
2021 _meshTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
2023 _treeViewDelegate->setDocumentModel( _currentModel );
2024 _treeViewDelegate->setPatternDataSelectionModel( _patternDataSelectionModel );
2025 _treeViewDelegate->setPatternBuilderSelectionModel( _patternBuilderSelectionModel );
2026 _treeViewDelegate->setGroupsSelectionModel( _groupsSelectionModel/*_groupsTreeView->selectionModel()*/ );
2027 _treeViewDelegate->setMeshSelectionModel( _meshSelectionModel/*_meshTreeView->selectionModel()*/ );
2030 connect( _patternDataSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2031 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2032 connect( _patternBuilderSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2033 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2034 connect( _groupsSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2035 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2036 connect( _meshSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2037 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2040 // salome view/object browser/model management
2041 _documentModels[ suitVW ] = _currentModel;
2043 // _salomeViews[ _currentModel ] = suitVW;
2044 // std::map<const QAbstractItemModel*, SUIT_ViewWindow*> _salomeViews;
2046 _salomeViewWindows[docEntry] = suitVW;
2047 currentVtkView = dynamic_cast<SVTK_ViewWindow*>( _currentGraphicView->get_SUIT_ViewWindow() );
2048 currentVtkView->raise();
2050 // _currentGraphicView->setWindowTitle( _currentModel->getName() );
2051 // currentVtkView->setWindowTitle( _currentModel->getName() );
2052 // showDockWidgets(true);
2054 // _dwPattern->setVisible(true);
2055 // _dwPattern->toggleViewAction()->setVisible(true);
2056 _dwPattern->raise();
2058 // test_make_cart_grid();
2059 // test_make_elmts_transform();
2061 getApp()->updateObjectBrowser();
2065 void HEXABLOCKGUI::slot_modelChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
2067 //std::cout << "HHHHHHHHHHHHHHHHHH Model changed." << std::endl;
2068 //std::cout << "HHHHHHHHHHHHHHHHHH slot_modelChanged topLeft -> " << topLeft.data().toString().toStdString()<<std::endl;
2069 //std::cout << "HHHHHHHHHHHHHHHHHH slot_modelChanged bottomRight ->" << bottomRight.data().toString().toStdString()<<std::endl;
2071 _patternDataTreeView->openPersistentEditor( topLeft );
2073 // // Make the combo boxes always displayed.
2074 // for ( int i = 0; i < _currentModel->rowCount(); ++i )
2076 // QModelIndex ind = _currentModel->index(i);
2077 // _patternDataTreeView->openPersistentEditor( ind );
2078 // std::cout << "ind" << ind.data() << std::endl;
2082 void HEXABLOCKGUI::loadDocument( const QString &inFile )
2084 DEBTRACE("HEXABLOCKGUI::loadDocument");
2085 QMainWindow *aParent = application()->desktop();
2086 QString selectedFile;
2088 if ( inFile.isNull() ){
2089 QFileDialog dialog( aParent, tr("Open HexaBlock Document") ,
2090 QString::null, tr( "XML-Files (*.xml);;All Files (*)" ) );
2091 dialog.setHistory( getQuickDirList() );
2093 QStringList selectedFiles = dialog.selectedFiles();
2094 if (!selectedFiles.isEmpty())
2095 selectedFile = selectedFiles.first();
2098 selectedFile = inFile;
2101 if (! selectedFile.isEmpty()){
2103 _currentModel->load(selectedFile);
2104 renameObject( _currentModel->documentEntry(), _currentModel->getName() );
2108 void HEXABLOCKGUI::saveDocument()
2110 QMainWindow *aParent = application()->desktop();
2111 QString anInitialPath = "";
2112 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
2113 anInitialPath = QDir::currentPath();
2114 // QString aMeshName = anIO->getName();
2116 QString aDocName = "document";
2118 filter.append( QObject::tr( "XML_FILES_FILTER" ) + " (*.xml)" );
2119 filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
2120 QString aFilename = anInitialPath + QString("/") + aDocName;
2121 aFilename = SUIT_FileDlg::getFileName( aParent,
2124 tr( "Save HexaBlock Document" ),
2126 //std::cout<<"HEXABLOCKGUI::saveDocument()"<<std::endl;
2127 if ( !aFilename.isEmpty() ) {
2128 //std::cout<<"!aFilename.isEmpty()"<<std::endl;
2129 _currentModel->save( aFilename );
2134 void HEXABLOCKGUI::_showDialogBox( HexaBaseDialog* diag )
2136 MESSAGE("HEXABLOCKGUI::_showDialogBox()");
2138 MESSAGE("if (!diag) return;");
2139 if (!_dwInputPanel) return;
2140 MESSAGE("if (!_dwInputPanel) return;");
2142 diag->setDocumentModel(_currentModel);
2143 diag->setPatternDataSelectionModel(_patternDataSelectionModel);
2144 diag->setPatternBuilderSelectionModel(_patternBuilderSelectionModel);
2145 diag->setGroupsSelectionModel(_groupsSelectionModel);
2146 diag->setMeshSelectionModel(_meshSelectionModel/*_meshTreeView->selectionModel()*/);
2148 QWidget* w = _dwInputPanel->widget();
2151 if ( !_dwInputPanel->isVisible() ) _dwInputPanel->setVisible(true);
2152 _dwInputPanel->setWidget(diag);
2153 _dwInputPanel->setWindowTitle(diag->windowTitle());
2158 void HEXABLOCKGUI::addVertex()
2160 if ( !_vertexDiag ){
2161 _vertexDiag = new VertexDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2163 _showDialogBox( _vertexDiag );
2166 void HEXABLOCKGUI::addEdge()
2169 _edgeDiag = new EdgeDialog( _dwInputPanel, HexaBaseDialog::NEW_MODE);
2171 _showDialogBox( _edgeDiag );
2177 void HEXABLOCKGUI::addQuad()
2180 _quadDiag = new QuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2182 _showDialogBox( _quadDiag );
2185 void HEXABLOCKGUI::addHexa()
2188 _hexaDiag = new HexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2190 _showDialogBox( _hexaDiag );
2193 void HEXABLOCKGUI::addVector()
2195 if ( !_vectorDiag ){
2196 _vectorDiag = new VectorDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2198 _showDialogBox( _vectorDiag );
2201 void HEXABLOCKGUI::addCylinder()
2203 if ( !_cylinderDiag ){
2204 _cylinderDiag = new CylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2206 _showDialogBox( _cylinderDiag );
2210 void HEXABLOCKGUI::addPipe()
2213 _pipeDiag = new PipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2215 _showDialogBox( _pipeDiag );
2219 void HEXABLOCKGUI::makeGrid()
2221 if ( !_makeGridDiag ){
2222 _makeGridDiag = new MakeGridDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2224 _showDialogBox( _makeGridDiag );
2228 void HEXABLOCKGUI::makeCylinder()
2230 if ( !_makeCylinderDiag ){
2231 _makeCylinderDiag = new MakeCylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2233 _showDialogBox( _makeCylinderDiag );
2236 void HEXABLOCKGUI::makePipe()
2238 if ( !_makePipeDiag ){
2239 _makePipeDiag = new MakePipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2241 _showDialogBox( _makePipeDiag );
2244 void HEXABLOCKGUI::makeCylinders()
2246 if ( !_makeCylindersDiag ){
2247 _makeCylindersDiag = new MakeCylindersDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2249 _showDialogBox( _makeCylindersDiag );
2252 void HEXABLOCKGUI::makePipes()
2254 if ( !_makePipesDiag ){
2255 _makePipesDiag = new MakePipesDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2257 _showDialogBox( _makePipesDiag );
2261 void HEXABLOCKGUI::makeHemiSphere() // NEW HEXA3
2263 if ( !_makeHemiSphereDiag ){
2264 _makeHemiSphereDiag = new MakeHemiSphereDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2266 _showDialogBox( _makeHemiSphereDiag );
2270 void HEXABLOCKGUI::removeHexa()
2272 if ( !_removeHexaDiag ){
2273 _removeHexaDiag = new RemoveHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2275 _showDialogBox( _removeHexaDiag );
2279 void HEXABLOCKGUI::prismQuad()
2281 if ( !_prismQuadDiag ){
2282 _prismQuadDiag = new PrismQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2284 _showDialogBox( _prismQuadDiag );
2288 void HEXABLOCKGUI::joinQuad()
2290 if ( !_joinQuadDiag ){
2291 _joinQuadDiag = new JoinQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2293 _showDialogBox( _joinQuadDiag );
2296 void HEXABLOCKGUI::merge()
2299 _mergeDiag = new MergeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2301 _showDialogBox( _mergeDiag );
2304 void HEXABLOCKGUI::disconnectElts()
2306 if ( !_disconnectDiag ){
2307 _disconnectDiag = new DisconnectDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2309 _showDialogBox( _disconnectDiag );
2312 void HEXABLOCKGUI::cutEdge()
2314 if ( !_cutEdgeDiag ){
2315 _cutEdgeDiag = new CutEdgeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2317 _showDialogBox( _cutEdgeDiag );
2320 void HEXABLOCKGUI::makeTransformation()
2322 if ( !_makeTransformationDiag ){
2323 _makeTransformationDiag = new MakeTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2325 _showDialogBox( _makeTransformationDiag );
2329 void HEXABLOCKGUI::makeSymmetry()
2331 if ( !_makeSymmetryDiag ){
2332 _makeSymmetryDiag = new MakeSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2334 _showDialogBox( _makeSymmetryDiag );
2338 void HEXABLOCKGUI::performTransformation()
2340 if ( !_performTransformationDiag ){
2341 _performTransformationDiag = new PerformTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2343 _showDialogBox( _performTransformationDiag );
2347 void HEXABLOCKGUI::performSymmetry()
2349 if ( !_performSymmetryDiag ){
2350 _performSymmetryDiag = new PerformSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2352 _showDialogBox( _performSymmetryDiag );
2356 void HEXABLOCKGUI::replaceHexa() // NEW HEXA3
2358 if ( !_replaceHexaDiag ){
2359 _replaceHexaDiag = new ReplaceHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2361 _showDialogBox( _replaceHexaDiag );
2365 void HEXABLOCKGUI::quadRevolution() // NEW HEXA3
2367 if ( !_quadRevolutionDiag ){
2368 _quadRevolutionDiag = new QuadRevolutionDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2370 _showDialogBox( _quadRevolutionDiag );
2374 // void HEXABLOCKGUI::assocVertex()
2376 // if ( !_vertexAssocDiag ){
2377 // _vertexAssocDiag = new VertexAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2379 // _showDialogBox( vertexAssocDiag );
2383 void HEXABLOCKGUI::assocVertex()
2385 MESSAGE("HEXABLOCKGUI::assocVertex()");
2386 QWidget* d = dynamic_cast<SUIT_Desktop*>(_dwInputPanel->parent());
2387 if ( !_vertexAssocDiag ){
2388 _vertexAssocDiag = new VertexAssocDialog( NULL, d );
2390 _vertexAssocDiag->setDocumentModel(_currentModel);
2391 _vertexAssocDiag->setPatternDataSelectionModel(_patternDataSelectionModel);
2392 _dwInputPanel->setWidget(_vertexAssocDiag);
2393 _dwInputPanel->setWindowTitle(_vertexAssocDiag->windowTitle());
2394 //_vertexAssocDiag->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
2395 _vertexAssocDiag->show();
2400 void HEXABLOCKGUI::assocEdge()
2402 if ( !_edgeAssocDiag ){
2403 _edgeAssocDiag = new EdgeAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2404 _edgeAssocDiag->setGeomEngine( _geomEngine );
2406 _showDialogBox( _edgeAssocDiag );
2409 void HEXABLOCKGUI::assocQuad()
2411 if ( !_quadAssocDiag ){
2412 _quadAssocDiag = new QuadAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2414 _showDialogBox( _quadAssocDiag );
2418 void HEXABLOCKGUI::addGroup()
2421 _groupDiag = new GroupDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2423 _showDialogBox( _groupDiag );
2428 void HEXABLOCKGUI::removeGroup()
2430 QItemSelectionModel *groupsSelectionModel = _groupsTreeView->selectionModel();
2431 QModelIndex selected = groupsSelectionModel->currentIndex();
2432 selected = _groupsModel->mapToSource( selected );
2435 if ( !selected.isValid() ){
2436 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ), tr( "No group selected!" ) );
2440 //Demande de confirmation de la suppression des groupes
2441 if (SUIT_MessageBox::question(
2444 tr("Remove group : %1 ?").arg(selected.data().toString()),
2445 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2446 SUIT_MessageBox::Cancel
2447 ) == SUIT_MessageBox::Cancel) return;
2449 groupsSelectionModel->clearSelection();
2451 std::cout << "////////////////////////// " << selected.data().toString().toStdString() << std::endl;
2452 bool removed = _currentModel->removeGroup( selected );
2453 //std::cout << " " << selected.data().toString().toStdString() << std::endl;
2455 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2456 groupsSelectionModel->clearSelection();
2463 void HEXABLOCKGUI::removeGroup()
2465 QItemSelectionModel *groupsSelectionModel = _groupsTreeView->selectionModel();
2466 QModelIndexList l = groupsSelectionModel->selectedIndexes();
2467 int nbGroupsRemoved = 0;
2470 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
2471 tr( "No group selected!" ) );
2475 foreach( QModelIndex selected, l ){
2476 if ( selected.data(HEXA_TREE_ROLE) == GROUP_TREE ){
2477 selected = _groupsModel->mapToSource( selected );
2478 Q_ASSERT(selected.isValid());
2480 //Confirm the deletion of the group
2481 if (SUIT_MessageBox::question(
2484 tr("Remove group : %1 ?").arg(selected.data().toString()),
2485 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2486 SUIT_MessageBox::Cancel
2487 ) == SUIT_MessageBox::Cancel) return;
2489 bool removed = _currentModel->removeGroup( selected );
2491 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
2492 tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2498 if (!nbGroupsRemoved)
2499 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
2500 tr( "No group selected!" ) );
2504 void HEXABLOCKGUI::addLaw()
2507 _lawDiag = new LawDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2509 _showDialogBox( _lawDiag );
2512 void HEXABLOCKGUI::removeLaw()
2515 QModelIndexList l = _meshSelectionModel->selectedIndexes();
2516 int nbLawsRemoved = 0;
2519 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
2520 tr( "No law selected!" ) );
2524 foreach( QModelIndex selected, l ){
2525 if ( selected.data(HEXA_TREE_ROLE) == LAW_TREE ){
2526 selected = _meshModel->mapToSource( selected );
2527 Q_ASSERT(selected.isValid());
2529 //Confirm the deletion of the law
2530 if (SUIT_MessageBox::question(
2533 tr("Remove law : %1 ?\nAll propagations having this law will \
2534 have the default law.").arg(selected.data().toString()),
2535 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2536 SUIT_MessageBox::Cancel
2537 ) == SUIT_MessageBox::Cancel) return;
2539 bool removed = _currentModel->removeLaw(selected);
2541 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
2542 tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2549 SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
2550 tr( "No law selected!" ) );
2555 void HEXABLOCKGUI::setPropagation()
2557 if (!_dwInputPanel) return;
2558 PropagationDialog* diag = new PropagationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2559 diag->setDocumentModel(_currentModel);
2560 diag->setMeshSelectionModel(_meshSelectionModel);
2561 //diag->setValue(p);
2563 _dwInputPanel->setWidget(diag);
2564 _dwInputPanel->setWindowTitle( diag->windowTitle() );
2569 // Dialog box to compute a mesh from a document
2570 // --------------------------------------------
2572 void HEXABLOCKGUI::computeMesh()
2574 if ( !_computeMeshDiag ){
2575 _computeMeshDiag = new ComputeMeshDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2577 _computeMeshDiag->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
2578 _showDialogBox( _computeMeshDiag );
2581 void HEXABLOCKGUI::clearAssociations()
2583 // QMessageBox::warning( 0, "windowTitle()", "clearAssociations" );
2584 QModelIndex iDataModel = _patternDataTreeView->currentIndex();
2585 QModelIndex iModel = _patternDataModel->mapToSource(iDataModel);
2587 _currentModel->clearEltAssociations(iModel);
2589 SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
2592 void HEXABLOCKGUI::clearAllAssociations()
2594 //Confirm the deletion of the associations
2595 if (SUIT_MessageBox::question(
2597 tr("Clear Associations"),
2598 tr("Clear all associations ?"),
2599 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2600 SUIT_MessageBox::Cancel
2601 ) == SUIT_MessageBox::Cancel) return;
2603 int currentChildIndex = 0;
2604 QModelIndex currentIndex = _patternDataModel->mapToSource(_patternDataTreeView->currentIndex());
2605 QVariant currentAssocVariant;
2606 QString currentAssocEntry;
2608 QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
2609 while( currentChild.isValid() ) {
2611 currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
2612 currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
2613 if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
2614 _currentModel->clearEltAssociations(currentChild);
2616 currentChild = currentChild.sibling(currentChildIndex++, 0);
2619 //SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
2622 void HEXABLOCKGUI::showAssociations()
2624 QModelIndexList elts;
2625 int currentChildIndex = 0;
2626 QVariant currentAssocVariant;
2627 QString currentAssocEntry;
2628 QModelIndex currentIndex = _patternDataTreeView->currentIndex();
2629 QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
2631 while( currentChild.isValid() ) {
2633 currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
2634 currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
2635 if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
2636 elts << currentChild;
2638 currentChild = currentChild.sibling(currentChildIndex++, 0);
2640 _patternDataSelectionModel-> highlightVTKElts( elts );
2645 LightApp_SelectionMgr* HEXABLOCKGUI::selectionMgr()
2647 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2649 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2654 QStringList HEXABLOCKGUI::getQuickDirList()
2656 QStringList dirList;
2657 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2659 dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
2665 // --- Export the module
2669 HEXABLOCKGUI_EXPORT CAM_Module* createModule()
2671 return new HEXABLOCKGUI();
2674 HEXABLOCKGUI_EXPORT char* getModuleVersion()
2676 return (char*)HEXABLOCK_VERSION_STR;
2689 // void HEXABLOCKGUI::newMesh( const std::string& meshName,
2691 // const std::string& container )
2693 // SalomeApp_Application* app = getApp();
2694 // int activeStudyId = app->activeStudy()->id();
2696 // if ( CORBA::is_nil(_hexaEngine) ) _hexaEngine = InitHEXABLOCKGen( app );
2697 // if ( CORBA::is_nil(_smeshEngine)) _smeshEngine = InitSMESHGen( app, container );
2698 // if ( CORBA::is_nil(_geomEngine) ) _geomEngine = InitGEOMGen( app, container );
2700 // std::cout << "_hexaEngine =>" << _hexaEngine << std::endl;
2701 // std::cout << "_smeshEngine =>" << _smeshEngine << std::endl;
2702 // std::cout << "_geomEngine =>" << _geomEngine << std::endl;
2704 // HEXA_NS::Document* docImpl = _currentModel->documentImpl();
2705 // std::cout << "docImpl =>" << docImpl << std::endl;
2706 // std::cout << "docImpl->getFile() =>" << docImpl->getFile() << std::endl;
2707 // HEXABLOCK_ORB::Document_var anDocObj= _hexaEngine->loadDocument( docImpl->getFile() );
2708 // std::cout << "anDocObj =>" << anDocObj << std::endl;
2711 // GEOM::GEOM_I3DPrimOperations_var anGeomOper = _geomEngine->GetI3DPrimOperations( activeStudyId );
2712 // if ( CORBA::is_nil(anGeomOper) ) return; //!anGeomOper->_is_nil() ) {
2713 // std::cout << "anGeomOper =>" << anGeomOper << std::endl;
2714 // GEOM::GEOM_Object_var anGeomObj = anGeomOper->MakeBoxDXDYDZ( 5., 5., 5. );
2715 // std::cout << "anGeomObj =>" << anGeomObj << std::endl;
2718 // SALOMEDS::SObject _geomEngine->AddInStudy (in SALOMEDS::Study theStudy,
2719 // in GEOM_Object theObject,
2720 // in string theName,
2724 // // void GEOMBase::PublishSubObject( GEOM::GEOM_Object_ptr object )
2726 // SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
2727 // if ( study && !CORBA::is_nil( object ) ) {
2728 // _PTR(Study) studyDS = study->studyDS();
2729 // QString entry = GetEntry( object );
2730 // GEOM::GEOM_Object_var father = object->GetMainShape();
2731 // QString fatherEntry = GetEntry( father );
2732 // if ( entry.isEmpty() && !CORBA::is_nil( father ) && !fatherEntry.isEmpty() ) {
2733 // QString name = GetName( object );
2734 // GeometryGUI::GetGeomGen()->AddInStudy( GeometryGUI::ClientStudyToStudy( studyDS ),
2735 // object, name.toLatin1().data(), father.in() );
2741 // // geompy = smesh.geompy
2742 // // #fkl: shape = doc.getShape()
2743 // // shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
2744 // // geompy.addToStudy(shape, name)
2746 // // component = salome.lcc.FindOrLoadComponent(container, "SMESH")
2747 // // component.init_smesh(salome.myStudy, geompy.geom)
2748 // // mesh = component.Mesh(shape, name)
2750 // // so = "libHexaBlockEngine.so"
2752 // // algo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(component, "HEXABLOCK_3D", so)
2753 // SMESH::SMESH_Hypothesis_var algo = _smeshEngine->CreateHypothesis( "HEXABLOCK_3D", "libHexaBlockEngine.so");
2754 // // raises ( SALOME::SALOME_Exception );
2755 // // mesh.mesh.AddHypothesis(shape, algo)
2757 // // hypo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(component, "HEXABLOCK_Parameters", so)
2758 // //HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var
2759 // SMESH::SMESH_Hypothesis_var hypo = _smeshEngine->CreateHypothesis( "HEXABLOCK_Parameters", "libHexaBlockEngine.so");
2761 // HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var hexHypo = HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis::_narrow(hypo);
2762 // ASSERT(!CORBA::is_nil(hexHypo));
2764 // // mesh.mesh.AddHypothesis(shape, hypo)
2766 // // hexHypo->SetDocument(anDocObj);
2767 // // hexHypo->SetDimension(dim);
2769 // // mesh.Compute()
2777 // void newMesh( const std::string& meshName, int dim )// const std::string& container )
2780 // // _smeshEngine.init_smesh(salome.myStudy, geompy.geom)
2781 // SMESH::SMESH_var mesh = _smeshEngine->Mesh(shape, name);
2782 // SMESH::SMESH_Hypothesis_var algo = _smeshEngine->CreateHypothesis( "HEXABLOCK_3D", "libHexaBlockEngine.so");
2783 // SMESH::SMESH_Hypothesis_var hypo = _smeshEngine->CreateHypothesis( "HEXABLOCK_Parameters", "libHexaBlockEngine.so");
2784 // HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var hexHypo = HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis::_narrow(hypo);
2785 // hexHypo->SetDocument(anDocObj);
2786 // hexHypo->SetDimension(dim);
2790 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
2792 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
2793 if ( CORBA::is_nil( myComponentSMESH ) )
2795 SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
2797 aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2798 return aGUI.myComponentSMESH;
2801 myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2802 return myComponentSMESH;
2805 // bool HEXABLOCKGUI::eventFilter(QObject *obj, QEvent *event)
2807 // if ( event->type() == QEvent::Enter ){//QEvent::Show ){ //QEvent::KeyPress) {
2808 // showDocumentMenus( false );
2809 // showPatternMenus( false );
2810 // showAssociationMenus( false );
2811 // showGroupsMenus( false );
2812 // showMeshMenus( false );
2813 // if ( obj == _dwObjectBrowser ) {
2814 // showDocumentMenus( true );
2815 // } else if ( obj == _dwPattern ) {
2816 // showPatternMenus( true );
2817 // } else if ( obj == _dwAssociation ) {
2818 // showAssociationMenus( true );
2819 // } else if ( obj == _dwGroups ) {
2820 // showGroupsMenus( true );
2821 // } else if ( obj == _dwMesh ) {
2823 // showMeshMenus( true );
2827 // // standard event processing
2828 // return QObject::eventFilter(obj, event);
2833 // // throw SALOME_Exception(LOCALIZED("assocVertex"));
2834 // } catch ( SALOME::SALOME_Exception& exc ){
2835 // INFOS("Following exception was cought:\n\t"<<exc.details.text);
2836 // } catch( const std::exception& exc){
2837 // INFOS("Following exception was cought:\n\t"<<exc.what());
2838 // } catch (Standard_Failure& exc) {
2839 // MESSAGE("OCCT Exception in SMESH_Pattern: " << exc.GetMessageString());
2841 // MESSAGE("Unknown exception was cought !!!");