1 // Copyright (C) 2009-2013 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
20 #include <OCCViewer_ViewWindow.h>
21 #include "HEXABLOCKGUI_DocumentPanel.hxx"
22 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
23 #include "HEXABLOCKGUI_OccGraphicView.hxx"
24 #include "HEXABLOCKGUI_SalomeTools.hxx"
31 #include <SalomeApp_Application.h>
32 #include <SalomeApp_Study.h>
33 #include <PyConsole_Console.h>
34 #include <SalomeApp_Tools.h>
36 #include <Standard_GUID.hxx>
37 #include <TDF_Label.hxx>
39 #include <OCCViewer_ViewManager.h>
42 #include <TopExp_Explorer.hxx>
43 #include <TopoDS_Iterator.hxx>
44 #include <TopTools_MapOfShape.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <TColStd_IndexedMapOfInteger.hxx>
48 #include <SUIT_Session.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_OverrideCursor.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_Session.h>
53 #include "SVTK_Selection.h"
54 #include <SVTK_ViewModel.h>
55 #include <VTKViewer_ViewModel.h>
56 #include <SVTK_View.h>
58 #include <SUIT_ResourceMgr.h>
62 #define BUTTON_BOX_MIN_WIDTH 5
63 #define VERTEX_COORD_MIN -1000000
64 #define VERTEX_COORD_MAX 1000000
65 #define SPINBOX_ANGLE_MAX 360
66 #define SPINBOX_DOUBLE_MAX 1000000000
67 #define SPINBOX_POSITIVE_DOUBLE_MIN 0
72 using namespace HEXABLOCK::GUI;
75 Q_DECLARE_METATYPE(HEXABLOCK::GUI::HexaTreeRole);
76 Q_DECLARE_METATYPE(DocumentModel::GeomObj);
77 Q_DECLARE_METATYPE(TopAbs_ShapeEnum);
78 Q_DECLARE_METATYPE(TopoDS_Shape);
80 //General SpinBox Delegate
81 class HexaDoubleSpinBoxDelegate : public QStyledItemDelegate {
83 HexaDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
85 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
86 const QModelIndex &index) const{
87 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
88 sb->setDecimals(NB_DECIMALS);
93 //Angle SpinBox Delegate
94 class HexaAngleDoubleSpinBoxDelegate : public QStyledItemDelegate {
96 HexaAngleDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
98 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
99 const QModelIndex &index) const{
100 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
101 sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
102 sb->setMaximum(SPINBOX_ANGLE_MAX);
103 sb->setDecimals(NB_DECIMALS);
109 //Positive DoubleSpinBox Delegate (for heigth, radius, ...)
110 class HexaPositiveDoubleSpinBoxDelegate : public QStyledItemDelegate {
112 HexaPositiveDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
114 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
115 const QModelIndex &index) const{
116 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
117 sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
118 /////// sb->setMaximum(1000000000000000); //10e15 Abu : Pb en 32 bits
119 sb->setMaximum(SPINBOX_DOUBLE_MAX); //10e9
120 sb->setDecimals(NB_DECIMALS);
125 // ======================================================== Constructeur
126 HexaBaseDialog::HexaBaseDialog( QWidget * parent, Mode editmode, Qt::WindowFlags f ):
128 _editMode( editmode ),
131 debugEdgeAssoc(false),
132 autoFocusSwitch(true)
134 _strHexaWidgetType[VERTEX_TREE] = tr( "VERTEX" );
135 _strHexaWidgetType[EDGE_TREE] = tr( "EDGE" );
136 _strHexaWidgetType[QUAD_TREE] = tr( "QUAD" );
137 _strHexaWidgetType[HEXA_TREE] = tr( "HEXA" );
139 _strHexaWidgetType[VECTOR_TREE] = tr( "VECTOR" );
140 _strHexaWidgetType[CYLINDER_TREE] = tr( "CYLINDER" );
141 _strHexaWidgetType[PIPE_TREE] = tr( "PIPE" );
142 _strHexaWidgetType[ELEMENTS_TREE] = tr( "ELEMENTS" );
143 _strHexaWidgetType[CROSSELEMENTS_TREE]= tr( "CROSSELEMENTS" );
146 _strHexaWidgetType[GEOMSHAPE_TREE] = tr( "GEOMSHAPE" );
147 _strHexaWidgetType[GEOMPOINT_TREE] = tr( "GEOMPOINT" );
148 _strHexaWidgetType[GEOMEDGE_TREE] = tr( "GEOMEDGE" );
149 _strHexaWidgetType[GEOMFACE_TREE] = tr( "GEOMFACE" );
152 _strHexaWidgetType[GROUP_TREE] = tr( "GROUP" );
153 _strHexaWidgetType[LAW_TREE] = tr( "LAW" );
154 _strHexaWidgetType[PROPAGATION_TREE]= tr( "PROPAGATION" );
157 // ============================================================= getIndexList
158 QModelIndexList HexaBaseDialog::getIndexList(QListWidget* itemsList, bool mapToSource)
160 QModelIndexList iItems;
162 QListWidgetItem* item = NULL;
164 const PatternDataModel* patternDataModel = getPatternDataModel();
165 if (patternDataModel == NULL || itemsList == NULL) return iItems;
167 unsigned int nbItems = itemsList->count();
168 for ( int r = 0; r < nbItems; ++r){
169 item = itemsList->item(r);
171 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
173 iItem = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
179 // ============================================================= lockSizeToSizeHint
180 void HexaBaseDialog::lockSizeToSizeHint()
182 setMaximumHeight(sizeHint().height());
183 // setMaximumWidth(sizeHint().width());
184 // setMinimumHeight(sizeHint().height());
185 // setMinimumWidth(sizeHint().width());
188 // ============================================================= unlockSizeModification
189 void HexaBaseDialog::unlockSizeModification()
191 setMaximumHeight(MAX_HEIGHT);
192 // setMaximumWidth(MAX_WIDTH);
193 // setMinimumHeight(MIN_HEIGHT);
194 // setMinimumWidth(MIN_WIDTH);
197 // ============================================================= resetSizeAndShow
198 void HexaBaseDialog::resetSizeAndShow(QDockWidget* parent)
200 //force the dialog to fit its contain
201 lockSizeToSizeHint();
203 //set the dialog in the dockwidget
204 parent->setWidget(this);
205 parent->setWindowTitle(windowTitle());
206 parent->setVisible(true);
209 unlockSizeModification();
212 QString HexaBaseDialog::getErrorMsg()
214 DocumentModel* docModel = getDocumentModel();
215 Hex::Hex* hex = docModel->getHexaRoot();
216 int nbErrorMsg = hex->sizeofMessage();
217 QString msg, newLine = "\n";
218 for (int i = 1; i < nbErrorMsg; ++i)
219 msg += newLine + hex->getMessageLine(i);
224 //unlink the widget from the model
225 void HexaBaseDialog::modelUnregister(QWidget* widget)
227 if (widget == NULL) return;
229 if (widget->property("GeomWidgetType").isValid())
231 widget->setProperty("GeomObj", QVariant());
232 widget->setProperty("TopoDS_Shape", QVariant());
235 widget->setProperty("HexaData", QVariant());
236 widget->setProperty("QModelIndex", QVariant());
237 _index[widget] = QModelIndex();
239 HexaBaseDialog* diag = dynamic_cast<HexaBaseDialog*>(widget);
241 diag->clearWidgetsIndexes();
244 // ============================================================= connectDocumentGraphicView
245 void HexaBaseDialog::connectDocumentGraphicView(VtkDocumentGraphicView* docGView)
247 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
248 if (docGView == NULL) return;
250 disconnectDocumentGraphicView(docGView); //to avoid double connect
252 //Connect the graphic view and its model to the dialog box
253 connect( docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
254 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
255 connect( docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
256 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
257 connect( docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
258 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
259 connect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
260 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
261 connect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
262 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
265 // ============================================================= disconnectDocumentGraphicView
266 void HexaBaseDialog::disconnectDocumentGraphicView(VtkDocumentGraphicView* docGView)
268 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
269 if (docGView == NULL) return;
272 //Disconnect graphic view signals form the dialog box
273 disconnect(docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
274 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
276 disconnect(docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
277 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
279 disconnect(docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
280 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
282 disconnect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
283 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
285 disconnect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
286 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
289 // ============================================================= onCurrentSelectionChanged
290 void HexaBaseDialog::onCurrentSelectionChanged()
292 highlightSelectedAssocs();
295 void HexaBaseDialog::clearCurrentObjectFocus()
297 QWidget* currentWidget = dynamic_cast<QWidget*>(_currentObj);
298 if (currentWidget != NULL)
300 currentWidget->clearFocus();
305 // ============================================================= setFocusToNextField
306 //Sets focus to the next field of the current object
307 void HexaBaseDialog::setFocusToNextField()
311 if (!HEXABLOCKGUI::assocInProgress && autoFocusSwitch)
313 _highlightWidget(_currentObj, Qt::white);
318 // ============================================================== _initButtonBox
319 QGroupBox* HexaBaseDialog::_initButtonBox( Mode editmode )
321 if ( editmode == INFO_MODE )
324 QGroupBox* buttonBox = new QGroupBox();
325 buttonBox->setMinimumWidth(BUTTON_BOX_MIN_WIDTH);
326 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
327 QHBoxLayout* buttonsHLayout = new QHBoxLayout();
328 _applyButton = new QPushButton(tr("Apply"));
329 QPushButton* closeButton = new QPushButton(tr("Close"));
330 QPushButton* helpButton = new QPushButton(tr("Help"));
332 connect( _applyButton, SIGNAL(clicked()), this, SLOT(apply()), Qt::UniqueConnection );
333 connect( closeButton, SIGNAL(clicked()), this, SLOT(close()), Qt::UniqueConnection );
334 connect( helpButton, SIGNAL(clicked()), this, SLOT(onHelpRequested()), Qt::UniqueConnection );
336 buttonsHLayout->addWidget( _applyButton );
337 buttonsHLayout->addWidget( closeButton );
338 buttonsHLayout->addStretch(1);
339 buttonsHLayout->addWidget( helpButton );
340 buttonBox->setLayout(buttonsHLayout);
341 layout()->addWidget(buttonBox);
342 buttonBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
346 // ============================================================== _initWidget
347 void HexaBaseDialog::_initWidget( Mode editmode )
349 _initInputWidget( editmode );
350 _initButtonBox( editmode );
353 // ============================================================== apply
354 bool HexaBaseDialog::apply()
357 bool applied = apply(iNew);
360 _selectAndHighlight( iNew );
361 if (!HEXABLOCKGUI::assocInProgress)
362 getDocumentModel()->updateGeomTree();
367 void HexaBaseDialog::clearVTKSelection()
369 HEXABLOCKGUI::currentDocGView->clearSelection();
370 _highlightWidget(_currentObj, Qt::white);
373 void HexaBaseDialog::clearOCCSelection()
375 HEXABLOCKGUI::currentOccGView->clearSelection();
378 // ============================================================== close
379 void HexaBaseDialog::close()
381 //reset the data selection pattern (forget all selections of the current context)
382 getPatternDataSelectionModel()->reset();
383 getPatternBuilderSelectionModel()->reset();
384 getPatternGeomSelectionModel()->reset();
386 //Clear vtk selection
389 //Clear occ selection
392 //Close the dialog box
394 parentWidget()->close();
397 // ============================================================== onHelpRequested
398 void HexaBaseDialog::onHelpRequested()
400 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
402 app->onHelpContextModule( "HEXABLOCK", _helpFileName );
406 platform = "winapplication";
408 platform = "application";
411 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
412 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
413 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( _helpFileName ),
414 QObject::tr( "BUT_OK" ) );
418 // ============================================================== highlightSelectedAssocs
419 void HexaBaseDialog::highlightSelectedAssocs()
421 QMultiMap<QString, int> geomAssocs = getAssocsGEOM();
422 QModelIndexList vtkAssocs = getAssocsVTK();
424 // HEXABLOCKGUI::selectionMgr()->clearSelected();
425 //highlight geom selected elts
426 if (geomAssocs.size() > 0)
427 HEXABLOCKGUI::currentOccGView->highlight(geomAssocs, false);
429 //highlight vtk selected elts
430 if (!vtkAssocs.isEmpty())
431 HEXABLOCKGUI::currentDocGView->highlight(vtkAssocs);
434 // ============================================================== refreshHighlight
435 void HexaBaseDialog::refreshHighlight()
437 HEXABLOCKGUI::selectionMgr()->clearSelected();
438 highlightSelectedAssocs();
441 // ============================================================== getObjectViewType
442 HEXABLOCKGUI::ViewType HexaBaseDialog::getObjectViewType(QObject* obj)
445 return HEXABLOCKGUI::UNKNOWN;
447 QVariant v = obj->property("GeomWidgetType");
449 return HEXABLOCKGUI::OCC;
451 v = obj->property("HexaWidgetType");
453 return HEXABLOCKGUI::VTK;
455 return HEXABLOCKGUI::UNKNOWN;
458 // ============================================================== _selectAndHighlight
459 void HexaBaseDialog::_selectAndHighlight( const QModelIndex& i )
461 if ( !i.isValid() ) return;
462 setProperty("QModelIndex", QVariant::fromValue(i));
466 // ============================================================== _allowSelection
467 void HexaBaseDialog::_allowSelection()
469 if ( getDocumentModel() )
470 getDocumentModel()->disallowEdition();
473 // ============================================================== _disallowSelection
474 void HexaBaseDialog::_disallowSelection()
476 if ( getDocumentModel() ){
477 getDocumentModel()->allowEdition();
479 HEXABLOCKGUI::currentDocGView->setAllSelection();
482 // ============================================================== _allowVTKSelection
483 bool HexaBaseDialog::_allowVTKSelection( QObject* obj )
488 QVariant v = obj->property("HexaWidgetType");
489 HexaWidgetType wType = v.value<HexaWidgetType>();
493 HEXABLOCKGUI::currentDocGView->setVertexSelection(); isOk = true;
496 HEXABLOCKGUI::currentDocGView->setEdgeSelection(); isOk = true;
499 HEXABLOCKGUI::currentDocGView->setQuadSelection(); isOk = true;
502 HEXABLOCKGUI::currentDocGView->setHexaSelection(); isOk = true;
504 default: HEXABLOCKGUI::currentDocGView->setAllSelection();
509 // ============================================================== _allowOCCSelection
510 bool HexaBaseDialog::_allowOCCSelection( QObject* obj )
512 QVariant v = obj->property("GeomWidgetType");
513 GeomWidgetType wType = v.value<GeomWidgetType>();
514 HEXABLOCKGUI::currentOccGView->setSelectionMode(wType);
519 // ============================================================== _getSelector
520 QItemSelectionModel* HexaBaseDialog::_getSelector( QObject* obj )
522 QItemSelectionModel* selector = NULL;
524 HexaWidgetType wtype;
525 QVariant v = obj->property("HexaWidgetType");
526 if ( !v.isValid() ) {
530 wtype = v.value<HexaWidgetType>();
536 case HEXA_TREE: selector = getPatternDataSelectionModel(); break;
541 case CROSSELEMENTS_TREE: selector = getPatternBuilderSelectionModel(); break;
544 case GEOMFACE_TREE: selector = getPatternGeomSelectionModel(); break;
545 case GROUP_TREE: selector = getGroupsSelectionModel(); break;
547 case PROPAGATION_TREE: selector = getMeshSelectionModel(); break;
554 DocumentModel::GeomObj* HexaBaseDialog::getGeomObj(const QModelIndex& index)
556 HEXA_NS::NewShape* aSh = getDocumentModel()->getHexaPtr<HEXA_NS::NewShape*>(index);
557 DocumentModel::GeomObj* geomObj = NULL;
560 geomObj = new DocumentModel::GeomObj;
561 geomObj->shapeName = aSh->getName();
562 geomObj->subId = QString::number(-1);
566 HEXA_NS::EltBase* aSShElt = getDocumentModel()->getHexaPtr(index);
567 HEXA_NS::SubShape* aSSh = dynamic_cast<HEXA_NS::SubShape*>(aSShElt);
570 geomObj = new DocumentModel::GeomObj;
572 if (aSSh->getParentShape() != NULL)
573 shapeName = aSSh->getParentShape()->getName();
574 geomObj->shapeName = shapeName;
575 geomObj->subId = QString::number(aSSh->getIdent());
581 // ============================================================== _onSelectionChanged
583 * Puts elements selected in the model (treeview) in the corresponding
584 * line edit widget (the one that has the focus) of the current dialog box.
586 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QLineEdit* le )
588 QModelIndexList l = sel.indexes();
589 if ( l.count() == 0 ) return false;
591 // mono selection mode: we just get the first selected element
592 QModelIndex selected = l[0];
594 // we just return if the selection is not valid or the selection and the
595 // line content are the same
596 if ( !selected.isValid() || le->property("HexaData") == selected.data(HEXA_DATA_ROLE) )
600 int selType = selected.data(HEXA_TREE_ROLE).toInt();
603 QVariant v = le->property("HexaWidgetType");
604 if ( !v.isValid() ) return false;
605 HexaWidgetType wType = v.value<HexaWidgetType>();
607 // check selection compatibility between selection and widget
608 if ( selType != wType ){
609 SUIT_MessageBox::information( 0, tr("HEXA_INFO"),
610 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg(_strHexaWidgetType[wType]));
613 if (le->property("GeomWidgetType").isValid())
615 DocumentModel::GeomObj* geomObj = getGeomObj(selected);
618 le->setProperty("GeomObj", QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
620 DocumentModel* docModel = getDocumentModel();
621 QString objId = geomObj->shapeName + "," + geomObj->subId;
622 HEXA_NS::SubShape* ssh = docModel->getGeomPtr(objId);
625 TopoDS_Shape shape = ssh->getShape();
627 le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(shape));
629 setCurrentGeomObj(geomObj);
633 //fill the lineEdit if selection is OK
634 le->setText( selected.data().toString() );// name
635 le->setProperty("QModelIndex", QVariant::fromValue(selected));
636 le->setProperty("HexaData", selected.data(HEXA_DATA_ROLE));
637 _index[le] = selected;
639 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(_currentObj);
640 if (selected.isValid() && lineEdit != NULL)
641 setFocusToNextField();
646 // ============================================================== _onSelectionChanged
648 * Puts elements selected in the model (treeview) in the corresponding list widget
649 * of the current dialog box.
651 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QListWidget* lw )
653 QModelIndexList l = sel.indexes();
655 if ( l.count() == 0 ) return false;
658 QVariant v = lw->property("HexaWidgetType");
659 if ( !v.isValid() ) return false;
660 HexaWidgetType wType = v.value<HexaWidgetType>();
662 //fill the listWidget
663 QListWidgetItem* item = NULL;
667 foreach( const QModelIndex& isel, l ){
668 // if ( lw->count() == maxSize) break;
669 selType = isel.data(HEXA_TREE_ROLE).toInt();
670 if ( selType != wType ){ // check selection compatibility between selection and widget
671 SUIT_MessageBox::information( 0,
673 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg( _strHexaWidgetType[wType]) );
676 // add selection to listWidget if selection is OK
677 selName = isel.data().toString();
678 QList<QListWidgetItem *> twice = lw->findItems( selName, Qt::MatchExactly);
679 if ( twice.count() == 0 ){
680 item = new QListWidgetItem( selName );
681 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(isel) );
682 item->setData(LW_DATA_ROLE, isel.data(HEXA_DATA_ROLE));
683 if (lw->property("GeomWidgetType").isValid())
685 DocumentModel::GeomObj* geomObj = getGeomObj(isel);
687 item->setData(LW_ASSOC_ROLE, QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
696 // ============================================================== onSelectionChanged
698 * Puts elements selected in the model in the corresponding widget (list widget or line edit)
699 * of the current dialog box.
701 void HexaBaseDialog::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
703 // * no edition for Info Dialogs
704 if ( _editMode == INFO_MODE )
707 QLineEdit* aLineEdit = NULL;
708 QListWidget* aListWidget = NULL;
710 // * fill the lineedit with selection
711 aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
714 _onSelectionChanged( sel, aLineEdit );
718 // * fill the listWidget with selection
719 aListWidget = dynamic_cast<QListWidget*>(_currentObj);
721 _onSelectionChanged( sel, aListWidget );
724 // ============================================================== showEvent
725 void HexaBaseDialog::showEvent( QShowEvent * event )
727 if ( _editMode == INFO_MODE )
728 getDocumentModel()->allowEdition();
730 getDocumentModel()->disallowEdition();
732 //Connect to salome selection signals
733 if (HEXABLOCKGUI::selectionMgr() != NULL)
735 connect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
736 this, SLOT(onCurrentSelectionChanged()), Qt::UniqueConnection );
739 //connect model selection signals
740 connectDocumentGraphicView();
742 QDialog::showEvent ( event );
746 // ============================================================== hideEvent
747 void HexaBaseDialog::hideEvent ( QHideEvent * event )
749 //Disconnection salome selection signals
750 if (HEXABLOCKGUI::selectionMgr() != NULL)
752 disconnect( HEXABLOCKGUI::selectionMgr() , SIGNAL(currentSelectionChanged()),
753 this, SLOT(onCurrentSelectionChanged()) );
756 //Disconnect vtk window activation signals
757 // if (HEXABLOCKGUI::currentDocGView->getViewWindow() != NULL)
758 // disconnect( HEXABLOCKGUI::currentDocGView->getViewWindow()->getViewManager(),
759 // SIGNAL( activated(SUIT_ViewManager*) ),
760 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
762 //Disconnect occ window activation signals
763 // if (HEXABLOCKGUI::currentOccGView->getViewWindow() != NULL)
764 // disconnect( HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager(),
765 // SIGNAL( activated(SUIT_ViewManager*) ),
766 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
768 //Disconnect model selection signals
769 disconnectDocumentGraphicView();
771 getDocumentModel()->allowEdition();
773 QDialog::hideEvent( event );
776 // ============================================================== updateButtonBox
777 void HexaBaseDialog::updateButtonBox()
781 // ============================================================== updateName
782 void HexaBaseDialog::updateName()
784 const PatternDataModel* patternDataModel = getPatternDataModel();
786 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(sender());
787 if (!lineEdit) return;
788 QString newName = lineEdit->text();
789 if ( newName.isEmpty() ) return;
791 QVariant v = lineEdit->property("QModelIndex");
792 if ( !v.isValid() ) return;
794 QModelIndex index = v.value<QModelIndex>();
795 if ( index.isValid() )
796 getDocumentModel()->setName( patternDataModel->mapToSource(index), newName );
799 // ============================================================== updateDefaultName
800 void HexaBaseDialog::updateDefaultName(QLineEdit* name_field, HEXA_NS::EnumElt type)
802 if (name_field == NULL) return;
804 HEXA_NS::Document* doc = getDocumentModel()->getHexaDocument();
805 if (doc == NULL) return;
807 name_field->setText(doc->getNextName(type).c_str());
810 // ============================================================== selectElementOfModel
811 /*Selects in the model (treeview) elements selected in a listwidget,
812 * or an element in a line edit.*/
813 void HexaBaseDialog::selectElementOfModel()
815 if (getPatternDataSelectionModel() == NULL) return;
817 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
818 if ( !currentListWidget ) return;
820 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
822 getPatternDataSelectionModel()->clearSelection();
823 foreach ( QListWidgetItem *item, sel ){
824 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
825 index = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
826 if ( index.isValid() )
827 getPatternDataSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
831 // ============================================================== _isLineOrListWidget
833 * Return true is the widget is a line or a list
836 bool HexaBaseDialog::_isLineOrListWidget(QObject *widget)
838 if (widget == NULL) return false;
840 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(widget);
841 QListWidget *listWidget = dynamic_cast<QListWidget*>(widget);
842 return (lineEdit != NULL) || (listWidget != NULL);
844 }//_isLineOrListWidget
847 // ============================================================== _highlightWidget
849 * Highlight the given widget with the given color.
851 void HexaBaseDialog::_highlightWidget(QObject *obj, Qt::GlobalColor clr)
853 if (!_isLineOrListWidget(obj)) return;
855 QWidget *widget = dynamic_cast<QWidget*>(obj); //sure it's not NULL (_isLineOrListWidget(obj))
856 QPalette palette1 = widget->palette();
857 palette1.setColor(widget->backgroundRole(), clr);
858 widget->setPalette(palette1);
863 // ============================================================== _updateCurrentObject
864 void HexaBaseDialog::_updateCurrentObject(QObject* obj)
866 _highlightWidget(_currentObj, Qt::white);
868 _highlightWidget(obj, Qt::yellow);
871 // ============================================================== eventFilter
873 * Handles events from the treeview and the dialog boxes.
875 bool HexaBaseDialog::eventFilter(QObject *obj, QEvent *event)
877 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(obj);
878 QListWidget *listWidget = dynamic_cast<QListWidget*>(obj);
880 // * Enter key press ------
881 if ( event->type() == QEvent::KeyPress &&
882 ((QKeyEvent*)event)->key() == Qt::Key_Return)
884 setFocusToNextField();
888 // * Focus out from a list widget ------
889 if ( event->type() == QEvent::FocusOut && listWidget != NULL)
891 QItemSelectionModel * selectionModel = listWidget->selectionModel();
892 selectionModel->clearSelection();
895 if ( event->type() != QEvent::FocusIn )
900 // allow vtk selection
901 if (getObjectViewType(obj) == HEXABLOCKGUI::VTK)
902 _allowVTKSelection( obj );
904 //allow occ selection
905 if (getObjectViewType(obj) == HEXABLOCKGUI::OCC)
906 _allowOCCSelection( obj );
908 //Depending on the focused widget type, get the right selector for it
911 QItemSelectionModel* selector = _getSelector( obj );
912 if ( selector == NULL )
914 _updateCurrentObject(obj);
918 if ( _currentObj != obj && (lineEdit == NULL || listWidget == NULL) )
919 selector->clearSelection();
921 _updateCurrentObject(obj);
923 //If the widget contains an element, select it in model/view
924 if ( lineEdit != NULL ){ //element can be from lineEdit
925 v = lineEdit->property("HexaData");
927 return QObject::eventFilter(obj, event);
928 index = ((SelectionModel*)selector)->indexBy( HEXA_DATA_ROLE, v);
930 selector->select( index, QItemSelectionModel::SelectCurrent );
933 return QObject::eventFilter(obj, event);
936 // ------------------------- VERTEX ----------------------------------
937 // ============================================================== Constructeur
938 VertexDialog::VertexDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
939 HexaBaseDialog(parent, editmode, f),
942 _helpFileName = "gui_vertex.html";
944 _initWidget(editmode);
945 // setFocusProxy( name_le );
947 if ( editmode == NEW_MODE ){
948 setWindowTitle( tr("Vertex Construction") );
949 } else if ( editmode == UPDATE_MODE ){
950 setWindowTitle( tr("Vertex Modification") );
952 else if ( editmode == INFO_MODE){
953 setWindowTitle( tr("Vertex Information") );
957 // ============================================================== Destructeur
958 VertexDialog::~VertexDialog()
962 // ============================================================== _initInputWidget
963 void VertexDialog::_initInputWidget( Mode editmode )
965 // x_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
966 // y_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
967 // z_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
968 QDoubleValidator *doubleValidator = new QDoubleValidator(widget_2);
969 x_spb->setValidator(doubleValidator);
970 y_spb->setValidator(doubleValidator);
971 z_spb->setValidator(doubleValidator);
973 // setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
974 installEventFilter(this);
975 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
976 name_le->installEventFilter(this);
978 if (editmode == INFO_MODE)
980 name_le->setReadOnly(true);
981 x_spb->setReadOnly(true);
982 y_spb->setReadOnly(true);
983 z_spb->setReadOnly(true);
986 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
989 // ============================================================== clear
990 void VertexDialog::clear()
994 modelUnregister(this);
997 // ============================================================== setValue
998 void VertexDialog::setValue(HEXA_NS::Vertex* v)
1001 name_le->setText( v->getName() );
1004 // x_spb->setValue( v->getX() );
1005 // y_spb->setValue( v->getY() );
1006 // z_spb->setValue( v->getZ() );
1007 x_spb->setText( QString::number(v->getX()) );
1008 y_spb->setText( QString::number(v->getY()) );
1009 z_spb->setText( QString::number(v->getZ()) );
1011 if ( getPatternDataSelectionModel() != NULL ){
1012 QModelIndex iv = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1014 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1015 name_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1020 // ============================================================== getValue
1021 HEXA_NS::Vertex* VertexDialog::getValue()
1027 // ============================================================== apply
1028 bool VertexDialog::apply(QModelIndex& result)
1030 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1033 if ( !getDocumentModel() ) return false;
1034 if ( !getPatternDataSelectionModel() ) return false;
1035 const PatternDataModel* patternDataModel = getPatternDataModel();
1036 if ( !patternDataModel ) return false;
1038 QModelIndex iVertex;
1040 QString xStr = x_spb->text();
1041 QString yStr = y_spb->text();
1042 QString zStr = z_spb->text();
1043 bool isOk = false, validArgs = !xStr.isEmpty() && !yStr.isEmpty() && !zStr.isEmpty();
1045 double newX, newY, newZ;
1048 newX = xStr.toDouble();
1049 newY = yStr.toDouble();
1050 newZ = zStr.toDouble();
1053 if ( _editMode == UPDATE_MODE && validArgs){
1054 QVariant v = property("QModelIndex");
1056 iVertex = patternDataModel->mapToSource( v.value<QModelIndex>() );
1057 if ( iVertex.isValid() )
1058 isOk = getDocumentModel()->updateVertex( iVertex, newX, newY, newZ );
1060 } else if ( _editMode == NEW_MODE && validArgs){
1061 iVertex = getDocumentModel()->addVertex( newX, newY, newZ );
1062 if ( iVertex.isValid() )
1066 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "VERTEX UPDATE/CONSTRUCTION" ) + "\n" + getErrorMsg() );
1070 QString newName = name_le->text();
1071 if ( !newName.isEmpty() )/*{*/
1072 getDocumentModel()->setName( iVertex, newName );
1074 //the default name in the dialog box
1075 HEXA_NS::Vertex* v = getDocumentModel()->getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1077 updateDefaultName(name_le, v->getType());
1079 // to select/highlight result
1080 result = patternDataModel->mapFromSource(iVertex);
1082 // updateDialogBoxName(name_le, result);
1083 // const char *defaultName = getDocumentModel()->getHexaPtr(last)->getName();
1087 // ------------------------- EDGE ----------------------------------
1089 // ============================================================== Constructeur
1090 EdgeDialog::EdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1091 HexaBaseDialog(parent, editmode, f),
1094 _helpFileName = "gui_edge.html";
1096 _initWidget(editmode);
1098 // rb0->setFocusProxy( v0_le_rb0 );
1099 // rb1->setFocusProxy( vex_le_rb1 );
1101 if ( editmode == INFO_MODE ){
1102 setWindowTitle( tr("Edge Information") );
1105 else if ( editmode == UPDATE_MODE ){
1106 setWindowTitle( tr("Edge Modification") );
1112 // ============================================================== Destructeur
1113 EdgeDialog::~EdgeDialog()
1118 // ============================================================== _initInputWidget
1119 void EdgeDialog::_initInputWidget( Mode editmode )
1122 QValidator *validator = new QRegExpValidator(rx, this);
1124 // setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1125 installEventFilter(this);
1127 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1128 name_le->installEventFilter(this);
1130 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1131 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1132 v0_le_rb0->setValidator( validator );
1133 v1_le_rb0->setValidator( validator );
1134 v0_le_rb0->installEventFilter(this);
1135 v1_le_rb0->installEventFilter(this);
1137 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1138 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1139 vex_le_rb1->setValidator( validator );
1140 vec_le_rb1->setValidator( validator );
1141 vex_le_rb1->installEventFilter(this);
1142 vec_le_rb1->installEventFilter(this);
1144 v0_le_rb0->setReadOnly(true);
1145 v1_le_rb0->setReadOnly(true);
1146 vex_le_rb1->setReadOnly(true);
1147 vec_le_rb1->setReadOnly(true);
1149 if (editmode == INFO_MODE)
1150 name_le->setReadOnly(true);
1152 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()) );
1156 // ============================================================== Clear
1157 void EdgeDialog::clear()
1162 modelUnregister(v0_le_rb0);
1165 modelUnregister(v1_le_rb0);
1167 vex_le_rb1->clear();
1168 modelUnregister(vex_le_rb1);
1170 vec_le_rb1->clear();
1171 modelUnregister(vec_le_rb1);
1173 modelUnregister(this);
1176 // ============================================================== setValue
1177 void EdgeDialog::setValue(HEXA_NS::Edge* e)
1179 HEXA_NS::Vertex* v0 = e->getVertex(0);
1180 HEXA_NS::Vertex* v1 = e->getVertex(1);
1182 name_le->setText( e->getName() );
1183 v0_le_rb0->setText( v0->getName() );
1184 v1_le_rb0->setText( v1->getName() );
1186 if ( getPatternDataSelectionModel() ){
1187 QModelIndex ie = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e) );
1188 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1189 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1191 name_le->setProperty( "QModelIndex", QVariant::fromValue(ie) );
1192 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1193 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1198 // ============================================================== getValue
1199 HEXA_NS::Edge* EdgeDialog::getValue()
1204 // ============================================================== apply
1205 bool EdgeDialog::apply(QModelIndex& result)
1207 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1210 if ( !getDocumentModel() ) return false;
1211 const PatternDataModel* patternDataModel = getPatternDataModel();
1212 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1213 if ( !patternDataModel || !patternBuilderModel ) return false;
1217 if ( rb0->isChecked() ){
1218 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1219 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1220 if ( iv0.isValid()&& iv1.isValid() ){
1221 iEdge = getDocumentModel()->addEdgeVertices( iv0, iv1 );
1223 } else if ( rb1->isChecked() ){
1224 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
1225 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
1226 if ( ivex.isValid() && ivec.isValid() ){
1227 iEdge = getDocumentModel()->addEdgeVector( ivex, ivec );
1231 if ( !iEdge.isValid() ){
1232 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD EDGE" ) + "\n" + getErrorMsg() );
1235 _value = iEdge.model()->data(iEdge, HEXA_DATA_ROLE).value<HEXA_NS::Edge*>();
1237 QString newName = name_le->text();
1238 if ( !newName.isEmpty() )/*{*/
1239 getDocumentModel()->setName( iEdge, newName );
1241 //update the default name in the dialog box
1243 updateDefaultName(name_le, _value->getType());
1245 result = patternDataModel->mapFromSource(iEdge);
1250 // ------------------------- QUAD ----------------------------------
1252 // ============================================================== Constructeur
1253 QuadDialog::QuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1254 HexaBaseDialog(parent, editmode, f),
1257 _helpFileName = "gui_quadrangle.html";
1259 _initWidget(editmode);
1262 if ( editmode == INFO_MODE ){
1263 setWindowTitle( tr("Quad Information") );
1267 // ============================================================== Destructeur
1268 QuadDialog::~QuadDialog()
1272 // ============================================================== _initInputWidget
1273 void QuadDialog::_initInputWidget( Mode editmode )
1276 QValidator *validator = new QRegExpValidator(rx, this);
1278 installEventFilter(this);
1279 name_le->installEventFilter(this);
1281 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1282 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1283 v2_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1284 v3_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1286 v0_le_rb0->setValidator( validator );
1287 v1_le_rb0->setValidator( validator );
1288 v2_le_rb0->setValidator( validator );
1289 v3_le_rb0->setValidator( validator );
1290 v0_le_rb0->installEventFilter(this);
1291 v1_le_rb0->installEventFilter(this);
1292 v2_le_rb0->installEventFilter(this);
1293 v3_le_rb0->installEventFilter(this);
1295 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1296 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1297 e2_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1298 e3_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1300 e0_le_rb1->setValidator( validator );
1301 e1_le_rb1->setValidator( validator );
1302 e2_le_rb1->setValidator( validator );
1303 e3_le_rb1->setValidator( validator );
1305 e0_le_rb1->installEventFilter(this);
1306 e1_le_rb1->installEventFilter(this);
1307 e2_le_rb1->installEventFilter(this);
1308 e3_le_rb1->installEventFilter(this);
1310 v0_le_rb0->setReadOnly(true);
1311 v1_le_rb0->setReadOnly(true);
1312 v2_le_rb0->setReadOnly(true);
1313 v3_le_rb0->setReadOnly(true);
1315 e0_le_rb1->setReadOnly(true);
1316 e1_le_rb1->setReadOnly(true);
1317 e2_le_rb1->setReadOnly(true);
1318 e3_le_rb1->setReadOnly(true);
1320 if (editmode == INFO_MODE)
1321 name_le->setReadOnly(true);
1324 // ============================================================== clear
1325 void QuadDialog::clear()
1327 //Clear the dialog and unregister it from the model
1328 QModelIndex invalidIndex;
1333 modelUnregister(v0_le_rb0);
1336 modelUnregister(v1_le_rb0);
1339 modelUnregister(v2_le_rb0);
1342 modelUnregister(v3_le_rb0);
1345 modelUnregister(e0_le_rb1);
1348 modelUnregister(e1_le_rb1);
1351 modelUnregister(e2_le_rb1);
1354 modelUnregister(e3_le_rb1);
1356 modelUnregister(this);
1360 // ============================================================== setValue
1361 void QuadDialog::setValue(HEXA_NS::Quad* q)
1363 Q_ASSERT( q->countEdge() == 4 );
1364 Q_ASSERT( q->countVertex() == 4 );
1367 name_le->setText( q->getName() );
1370 HEXA_NS::Vertex* v0 = q->getVertex(0);
1371 HEXA_NS::Vertex* v1 = q->getVertex(1);
1372 HEXA_NS::Vertex* v2 = q->getVertex(2);
1373 HEXA_NS::Vertex* v3 = q->getVertex(3);
1375 v0_le_rb0->setText( v0->getName() );
1376 v1_le_rb0->setText( v1->getName() );
1377 v2_le_rb0->setText( v2->getName() );
1378 v3_le_rb0->setText( v3->getName() );
1382 HEXA_NS::Edge* e0 = q->getEdge(0);
1383 HEXA_NS::Edge* e1 = q->getEdge(1);
1384 HEXA_NS::Edge* e2 = q->getEdge(2);
1385 HEXA_NS::Edge* e3 = q->getEdge(3);
1387 e0_le_rb1->setText( e0->getName() );
1388 e1_le_rb1->setText( e1->getName() );
1389 e2_le_rb1->setText( e2->getName() );
1390 e3_le_rb1->setText( e3->getName() );
1392 if ( getPatternDataSelectionModel() ){
1393 QModelIndex iq = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(q) );
1395 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1396 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1397 QModelIndex iv2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v2) );
1398 QModelIndex iv3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v3) );
1400 QModelIndex ie0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e0) );
1401 QModelIndex ie1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e1) );
1402 QModelIndex ie2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e2) );
1403 QModelIndex ie3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e3) );
1405 name_le->setProperty( "QModelIndex", QVariant::fromValue(iq) );
1407 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1408 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1409 v2_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv2) );
1410 v3_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv3) );
1412 e0_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie0) );
1413 e1_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie1) );
1414 e2_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie2) );
1415 e3_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie3) );
1421 // ============================================================== getValue
1422 HEXA_NS::Quad* QuadDialog::getValue()
1428 // ============================================================== apply
1429 bool QuadDialog::apply(QModelIndex& result)
1431 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1434 if ( !getDocumentModel() ) return false;
1435 const PatternDataModel* patternDataModel = getPatternDataModel();
1436 if ( !patternDataModel ) return false;
1440 if ( rb0->isChecked() ){ //vertices
1441 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1442 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1443 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb0] );
1444 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb0] );
1450 iQuad = getDocumentModel()->addQuadVertices( iv0, iv1, iv2, iv3 );
1452 } else if ( rb1->isChecked() ){ //edges
1453 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
1454 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
1455 QModelIndex ie2 = patternDataModel->mapToSource( _index[e2_le_rb1] );
1456 QModelIndex ie3 = patternDataModel->mapToSource( _index[e3_le_rb1] );
1462 iQuad = getDocumentModel()->addQuadEdges( ie0, ie1, ie2, ie3 );
1466 if ( !iQuad.isValid() ){
1467 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD QUAD" ) + "\n" + getErrorMsg());
1470 _value = iQuad.model()->data(iQuad, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1472 QString newName = name_le->text();
1473 if ( !newName.isEmpty() )/*{*/
1474 getDocumentModel()->setName( iQuad, newName );
1476 //the default name in the dialog box
1478 updateDefaultName(name_le, _value->getType());
1480 // to select/highlight result
1481 result = patternDataModel->mapFromSource(iQuad);
1487 // ------------------------- HEXA ----------------------------------
1489 // ============================================================== HexaDialog
1491 HexaDialog::HexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1492 HexaBaseDialog(parent, editmode, f),
1495 _helpFileName = "gui_hexahedron.html";
1497 _initWidget(editmode);
1500 if ( editmode == INFO_MODE ){
1501 setWindowTitle( tr("Hexahedron Information") );
1505 // ============================================================== Destructeur
1506 HexaDialog::~HexaDialog()
1510 // ============================================================== _initInputWidget
1511 void HexaDialog::_initInputWidget( Mode editmode )
1515 installEventFilter(this);
1516 name_le->installEventFilter(this);
1518 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
1519 quads_lw->installEventFilter(this);
1521 vertices_lw->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1522 vertices_lw->installEventFilter(this);
1525 if ( editmode != INFO_MODE ) {
1526 // delete item from listwidget
1527 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
1528 QShortcut* delVertexShortcut = new QShortcut( QKeySequence(Qt::Key_X), vertices_lw );
1529 delQuadShortcut->setContext( Qt::WidgetShortcut );
1530 delVertexShortcut->setContext( Qt::WidgetShortcut );
1531 connect(delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()));
1532 connect(delVertexShortcut, SIGNAL(activated()), this, SLOT(deleteVertexItem()));
1534 // highlight item on model view (VTK) from listwidget
1535 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1536 connect( vertices_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1538 if ( editmode != INFO_MODE)
1540 connect( vertices_rb, SIGNAL(clicked()), vertices_lw, SLOT(setFocus()));
1541 connect( quads_rb, SIGNAL(clicked()), quads_lw, SLOT(setFocus()));
1544 connect( vertices_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1545 connect( quads_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1547 if (editmode == INFO_MODE)
1548 name_le->setReadOnly(true);
1552 // ============================================================== clear
1553 void HexaDialog::clear()
1558 modelUnregister(quads_lw);
1560 vertices_lw->clear();
1561 modelUnregister(vertices_lw);
1563 modelUnregister(this);
1566 // ============================================================== getAssocsVTK
1568 * Returns elements currently associated to vtk
1570 QModelIndexList HexaDialog::getAssocsVTK()
1572 QModelIndexList assocs;
1573 QModelIndex iQuad, iVertex;
1574 QListWidgetItem* item = NULL;
1576 const PatternDataModel* patternDataModel = getPatternDataModel();
1577 if (patternDataModel == NULL) return assocs;
1578 if (quads_rb->isChecked())
1580 //ListWidget content
1581 int nbQuads = quads_lw->count();
1582 for ( int r = 0; r < nbQuads; ++r ){
1583 item = quads_lw->item(r);
1584 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1585 if ( iQuad.isValid() )
1590 else if (vertices_rb->isChecked())
1592 //ListWidget content
1593 int nbVertices = vertices_lw->count();
1594 for ( int r = 0; r < nbVertices; ++r ){
1595 item = vertices_lw->item(r);
1596 iVertex = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1597 if ( iVertex.isValid() )
1606 // ============================================================== updateButtonBox
1607 void HexaDialog::updateButtonBox()
1609 if ( _editMode == INFO_MODE )
1612 if ( quads_rb->isChecked() ){ // build from quads count() must be between [2,6]
1613 int nbQuads = quads_lw->count();
1614 if ( nbQuads >= 2 && nbQuads <= 6 ){
1615 _applyButton->setEnabled(true);
1617 _applyButton->setEnabled(false);
1619 } else if ( vertices_rb->isChecked() ){ // build from vertices count() must be equals to 8
1620 int nbVertices = vertices_lw->count();
1621 if ( nbVertices == 8 ){
1622 _applyButton->setEnabled(true);
1624 _applyButton->setEnabled(false);
1629 // ============================================================== deleteQuadItem
1630 void HexaDialog::deleteQuadItem()
1632 delete quads_lw->currentItem();
1636 // ============================================================== deleteVertexItem
1637 void HexaDialog::deleteVertexItem()
1639 delete vertices_lw->currentItem();
1643 // ============================================================== _setValueQuads
1644 void HexaDialog::_setValueQuads( HEXA_NS::Hexa* h )
1646 QListWidgetItem *qItem = NULL;
1647 HEXA_NS::Quad *q = NULL;
1649 if (getPatternDataSelectionModel() == NULL) return;
1651 for( int i = 0; i <= 5; ++i ){
1653 qIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(q)) );
1654 qItem = new QListWidgetItem( q->getName() );
1655 qItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(qIndex) );
1656 qItem->setData(LW_DATA_ROLE, qIndex.data(HEXA_DATA_ROLE));
1657 quads_lw->addItem( qItem );
1661 // ============================================================== _setValueVertices
1662 void HexaDialog::_setValueVertices( HEXA_NS::Hexa* h )
1664 QListWidgetItem *vItem = NULL;
1665 HEXA_NS::Vertex* v = NULL;
1667 if (getPatternDataSelectionModel() == NULL) return;
1668 vertices_lw->clear();
1669 for( int i = 0; i <= 7; ++i ){
1670 v = h->getVertex(i);
1671 vIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(v)) );
1672 vItem = new QListWidgetItem( v->getName() );
1673 vItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(vIndex) );
1674 vItem->setData(LW_DATA_ROLE, vIndex.data(HEXA_DATA_ROLE));
1675 vertices_lw->addItem( vItem );
1679 // ============================================================== setValue
1680 void HexaDialog::setValue(HEXA_NS::Hexa* h)
1683 name_le->setText( h->getName() );
1685 if ( getPatternDataSelectionModel()){
1686 QModelIndex hIndex = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(h) );
1687 _setValueVertices(h);
1689 name_le->setProperty( "QModelIndex", QVariant::fromValue(hIndex) );
1694 // ============================================================== getValue
1695 HEXA_NS::Hexa* HexaDialog::getValue()
1700 // ============================================================== apply
1701 bool HexaDialog::apply(QModelIndex& result)
1703 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1706 if ( !getDocumentModel() ) return false;
1707 const PatternDataModel* patternDataModel = getPatternDataModel();
1708 if ( !patternDataModel ) return false;
1712 QListWidget* currentLw = NULL;
1713 QListWidgetItem* item = NULL;
1715 if ( quads_rb->isChecked() )
1716 currentLw = dynamic_cast<QListWidget*>( quads_lw );
1717 else if ( vertices_rb->isChecked() )
1718 currentLw = dynamic_cast<QListWidget*>( vertices_lw );
1721 QModelIndexList iElts;
1722 int nbItems = currentLw->count();
1723 for ( int r = 0; r < nbItems; ++r){
1724 item = currentLw->item(r);
1725 iElt = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1726 if ( iElt.isValid() )
1730 nbItems = iElts.count();
1731 if ( quads_rb->isChecked() and (nbItems>=2 and nbItems<=6) ){ // build from quads iElts.count() should be between [2,6]
1732 iHexa = getDocumentModel()->addHexaQuads( iElts );
1733 } else if ( vertices_rb->isChecked() and nbItems== 8 ){ // build from vertices
1734 iHexa = getDocumentModel()->addHexaVertices( iElts[0], iElts[1], iElts[2], iElts[3],
1735 iElts[4], iElts[5], iElts[6], iElts[7] );
1738 if ( !iHexa.isValid() ){
1739 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD HEXA" ) + "\n" + getErrorMsg() );
1742 _value = iHexa.model()->data(iHexa, HEXA_DATA_ROLE).value<HEXA_NS::Hexa*>();
1744 QString newName = name_le->text();
1745 if ( !newName.isEmpty() )/*{*/
1746 getDocumentModel()->setName( iHexa, newName );
1748 //update the default name in the dialog box
1750 updateDefaultName(name_le, _value->getType());
1752 // to select/highlight result
1753 result = patternDataModel->mapFromSource(iHexa);
1759 // ------------------------- VECTOR ----------------------------------
1761 // ============================================================== Constructeur
1763 VectorDialog::VectorDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1764 HexaBaseDialog(parent, editmode, f),
1767 _helpFileName = "gui_vector.html";
1769 _initWidget(editmode);
1773 if ( editmode == INFO_MODE ){
1774 setWindowTitle( tr("Vector Information") );
1779 // ============================================================== Destructeur
1780 VectorDialog::~VectorDialog()
1784 // ============================================================== _initInputWidget
1785 void VectorDialog::_initInputWidget( Mode editmode )
1788 QValidator *validator = new QRegExpValidator(rx, this);
1790 installEventFilter(this);
1791 name_le->installEventFilter(this);
1793 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1794 v0_le_rb1->setValidator( validator );
1795 v0_le_rb1->installEventFilter(this);
1797 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1798 v1_le_rb1->setValidator( validator );
1799 v1_le_rb1->installEventFilter(this);
1801 if ( editmode == INFO_MODE ){
1802 name_le->setReadOnly(true);
1803 dx_spb_rb0->setReadOnly(true);
1804 dy_spb_rb0->setReadOnly(true);
1805 dz_spb_rb0->setReadOnly(true);
1808 v0_le_rb1->setReadOnly(true);
1809 v1_le_rb1->setReadOnly(true);
1812 // ============================================================== clear
1813 void VectorDialog::clear()
1817 modelUnregister(v0_le_rb1);
1820 modelUnregister(v1_le_rb1);
1822 modelUnregister(this);
1825 // ============================================================== setValue
1826 void VectorDialog::setValue(HEXA_NS::Vector* v)
1828 name_le->setText( v->getName() );
1829 dx_spb_rb0->setValue( v->getDx() );
1830 dy_spb_rb0->setValue( v->getDy() );
1831 dz_spb_rb0->setValue( v->getDz() );
1833 if ( getPatternDataSelectionModel() ){
1834 QModelIndex ivec = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1835 name_le->setProperty( "QModelIndex", QVariant::fromValue(ivec) );
1840 // ============================================================== getValue
1841 HEXA_NS::Vector* VectorDialog::getValue()
1846 // ============================================================== apply
1847 bool VectorDialog::apply(QModelIndex& result)
1849 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1852 if ( !getDocumentModel() ) return false;
1853 const PatternDataModel* patternDataModel = getPatternDataModel();
1854 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1855 if ( !patternDataModel || !patternBuilderModel) return false;
1857 QModelIndex iVector;
1859 if ( rb0->isChecked() ){ //scalar
1860 double dx = dx_spb_rb0->value();
1861 double dy = dy_spb_rb0->value();
1862 double dz = dz_spb_rb0->value();
1864 iVector = getDocumentModel()->addVector( dx, dy, dz );
1865 } else if ( rb1->isChecked() ){ //vertices
1866 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
1867 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
1871 iVector = getDocumentModel()->addVectorVertices( iv0, iv1 );
1875 if ( !iVector.isValid() ){
1876 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD VECTOR" ) + "\n" + getErrorMsg());
1880 _value = iVector.model()->data(iVector, HEXA_DATA_ROLE).value<HEXA_NS::Vector *>();
1882 QString newName = name_le->text();
1883 if ( !newName.isEmpty() )/*{*/
1884 getDocumentModel()->setName( iVector, newName );
1886 //update the default name in the dialog box
1888 updateDefaultName(name_le, _value->getType());
1890 // to select/highlight result
1891 result = patternBuilderModel->mapFromSource(iVector);
1896 // ------------------------- MakeGridDialog ----------------------------------
1897 // ============================================================== Constructeur
1899 MakeGridDialog::MakeGridDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
1900 : HexaBaseDialog(parent, editmode, f)
1903 _initWidget(editmode);
1906 _helpFileName = "creategrids.html#guicartgrid";
1907 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1908 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1909 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1911 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1912 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1913 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1915 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1916 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1917 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1920 // ============================================================== Destructeur
1921 MakeGridDialog::~MakeGridDialog()
1925 // ============================================================== _initInputWidget
1926 void MakeGridDialog::_initInputWidget( Mode editmode )
1928 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1929 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1930 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1931 vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1933 center_le->setReadOnly(true);
1934 axis_le->setReadOnly(true);
1935 base_le->setReadOnly(true);
1936 vec_le->setReadOnly(true);
1938 installEventFilter(this);
1939 center_le->installEventFilter(this);
1940 axis_le->installEventFilter(this);
1941 base_le->installEventFilter(this);
1942 vec_le->installEventFilter(this);
1944 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
1945 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
1947 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
1948 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
1950 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
1951 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
1953 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
1954 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
1956 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
1957 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
1959 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
1960 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
1963 // ============================================================== clear
1964 void MakeGridDialog::clear()
1967 modelUnregister(center_le);
1970 modelUnregister(axis_le);
1973 modelUnregister(base_le);
1976 modelUnregister(vec_le);
1978 modelUnregister(this);
1981 // ============================================================== updateHelpFileName
1982 void MakeGridDialog::updateHelpFileName()
1984 if ( sender() == rb0 ){
1985 _helpFileName = "creategrids.html#guicartgrid";
1986 } else if ( sender() == rb1 ){
1987 _helpFileName = "creategrids.html#guicylgrid";
1988 } else if ( sender() == rb2 ){
1989 _helpFileName = "creategrids.html#guisphergrid";
1993 // ============================================================== addRadiusItem
1994 void MakeGridDialog::addRadiusItem()
1996 QListWidgetItem* previousItem = radius_lw->currentItem();
1997 QListWidgetItem* newItem = new QListWidgetItem();
1999 double defaultValue = 1.;
2001 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2003 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2004 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2005 radius_lw->addItem(newItem);
2008 // ============================================================== delRadiusItem
2009 void MakeGridDialog::delRadiusItem()
2011 delete radius_lw->currentItem();
2014 // ============================================================== addAngleItem
2015 void MakeGridDialog::addAngleItem()
2017 QListWidgetItem* previousItem = angle_lw->currentItem();
2018 QListWidgetItem* newItem = new QListWidgetItem();
2020 double defaultValue = 180.;
2022 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2024 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2025 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2026 angle_lw->addItem(newItem);
2029 // ============================================================== delAngleItem
2030 void MakeGridDialog::delAngleItem()
2032 delete angle_lw->currentItem();
2035 // ============================================================== addHeightItem
2036 void MakeGridDialog::addHeightItem()
2038 QListWidgetItem* previousItem = height_lw->currentItem();
2039 QListWidgetItem* newItem = new QListWidgetItem();
2041 double defaultValue = 1.;
2043 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2045 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2046 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2047 height_lw->addItem(newItem);
2050 // ============================================================== delHeightItem
2051 void MakeGridDialog::delHeightItem()
2053 delete height_lw->currentItem();
2056 // ============================================================== apply
2057 bool MakeGridDialog::apply(QModelIndex& result)
2059 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2062 DocumentModel* docModel = getDocumentModel();
2063 PatternDataModel* patternDataModel = getPatternDataModel();
2064 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2066 QModelIndex iNewElts;
2067 if ( rb0->isChecked() )
2069 long nx = nx_spb->value();
2070 long ny = ny_spb->value();
2071 long nz = nz_spb->value();
2072 iNewElts = docModel->makeCartesianTop(nx, ny, nz);
2074 else if ( rb1->isChecked() )
2076 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2077 QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2078 QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2079 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2081 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2083 double nx = nx_spb->value();
2084 double ny = ny_spb->value();
2085 double nz = nz_spb->value();
2086 double lx = lx_spb->value();
2087 double ly = ly_spb->value();
2088 double lz = lz_spb->value();
2090 iNewElts = docModel->makeCartesianUni( icenter, ibase, ivec, iaxis,
2091 nx, ny, nz, lx, ly, lz);
2094 } else if ( rb2->isChecked() )
2096 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2097 QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2098 QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2099 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2101 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2103 QListWidgetItem* item = NULL;
2105 vector<double> radius;
2106 vector<double> angles;
2107 vector<double> heights;
2110 int nbAngles = angle_lw->count();
2111 for ( int r = 0; r < nbAngles; ++r){
2112 item = angle_lw->item(r);
2113 double itemValue = item->data(Qt::EditRole).toDouble();
2114 angles.push_back(itemValue);
2119 SUIT_MessageBox::information( 0,
2121 tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2125 int nbRadius = radius_lw->count();
2126 for ( int r = 0; r < nbRadius; ++r){
2127 item = radius_lw->item(r);
2128 radius.push_back(item->data(Qt::EditRole).toDouble());
2131 int nbHeight = height_lw->count();
2132 for ( int r = 0; r < nbHeight; ++r){
2133 item = height_lw->item(r);
2134 heights.push_back(item->data(Qt::EditRole).toDouble());
2137 iNewElts = docModel->makeCartesian( icenter, ibase, ivec, iaxis,
2138 radius, angles, heights);
2143 if ( !iNewElts.isValid() )
2145 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE GRID" ) + "\n" + getErrorMsg() );
2149 result = patternBuilderModel->mapFromSource( iNewElts );
2154 // ============================================================== Constructeur
2156 MakeCylinderDialog::MakeCylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2157 : HexaBaseDialog(parent, editmode, f)
2159 _helpFileName = "gui_blocks_for_cyl_pipe.html#make-cylinder";
2161 _initWidget(editmode);
2166 // ============================================================== Destructeur
2167 MakeCylinderDialog::~MakeCylinderDialog()
2171 void MakeCylinderDialog::_initInputWidget( Mode editmode )
2173 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
2174 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2175 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE));
2177 installEventFilter(this);
2178 origin_le->installEventFilter(this);
2179 axis_le->installEventFilter(this);
2180 base_le->installEventFilter(this);
2182 origin_le->setReadOnly(true);
2183 axis_le->setReadOnly(true);
2184 base_le->setReadOnly(true);
2186 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2187 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2189 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2190 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2192 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2193 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2195 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2196 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2198 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2199 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2201 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2202 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2205 // ============================================================== addRadiusItem
2206 void MakeCylinderDialog::addRadiusItem()
2208 QListWidgetItem* previousItem = radius_lw->currentItem();
2209 QListWidgetItem* newItem = new QListWidgetItem();
2211 double defaultValue = 1.;
2213 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2215 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2216 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2217 radius_lw->addItem(newItem);
2220 // ============================================================== delRadiusItem
2221 void MakeCylinderDialog::delRadiusItem()
2223 delete radius_lw->currentItem();
2226 // ============================================================== addAngleItem
2227 void MakeCylinderDialog::addAngleItem()
2229 QListWidgetItem* previousItem = angle_lw->currentItem();
2230 QListWidgetItem* newItem = new QListWidgetItem();
2232 double defaultValue = 180.;
2234 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2236 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2237 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2238 angle_lw->addItem(newItem);
2241 // ============================================================== delAngleItem
2242 void MakeCylinderDialog::delAngleItem()
2244 delete angle_lw->currentItem();
2247 // ============================================================== addHeightItem
2248 void MakeCylinderDialog::addHeightItem()
2250 QListWidgetItem* previousItem = height_lw->currentItem();
2251 QListWidgetItem* newItem = new QListWidgetItem();
2253 double defaultValue = 1.;
2255 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2257 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2258 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2259 height_lw->addItem(newItem);
2262 // ============================================================== delHeightItem
2263 void MakeCylinderDialog::delHeightItem()
2265 delete height_lw->currentItem();
2268 // ============================================================== clear
2269 void MakeCylinderDialog::clear()
2272 modelUnregister(origin_le);
2275 modelUnregister(axis_le);
2278 modelUnregister(base_le);
2280 modelUnregister(this);
2283 // ============================================================== apply
2284 bool MakeCylinderDialog::apply(QModelIndex& result)
2286 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2289 DocumentModel* docModel = getDocumentModel();
2290 PatternDataModel* patternDataModel = getPatternDataModel();
2291 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2293 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2294 QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2295 QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2296 double rext = ext_radius_spb->value();
2297 double rint = int_radius_spb->value();
2298 double angle = angle_spb->value();
2299 double height = height_spb->value();
2300 double nr = nr_spb->value();
2301 double na = na_spb->value();
2302 double nh = nh_spb->value();
2305 if (rb0->isChecked())
2306 iElts = docModel->makeCylinderTop(nr, na, nh);
2307 else if (rb1->isChecked())
2309 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2310 iElts = docModel->makeCylinderUni(iorigin, ibase, iaxis, rint,
2311 rext, angle, height, nr, na, nh);
2313 else if (rb2->isChecked())
2315 QListWidgetItem* item = NULL;
2317 vector<double> radius;
2318 vector<double> angles;
2319 vector<double> heights;
2322 int nbAngles = angle_lw->count();
2323 for ( int r = 0; r < nbAngles; ++r){
2324 item = angle_lw->item(r);
2325 double itemValue = item->data(Qt::EditRole).toDouble();
2326 angles.push_back(itemValue);
2331 SUIT_MessageBox::information( 0,
2333 tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2337 int nbRadius = radius_lw->count();
2338 for ( int r = 0; r < nbRadius; ++r){
2339 item = radius_lw->item(r);
2340 radius.push_back(item->data(Qt::EditRole).toDouble());
2343 int nbHeight = height_lw->count();
2344 for ( int r = 0; r < nbHeight; ++r){
2345 item = height_lw->item(r);
2346 heights.push_back(item->data(Qt::EditRole).toDouble());
2349 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2350 iElts = docModel->makeCylinder( iorigin, ibase, iaxis, radius, angles, heights);
2354 if ( !iElts.isValid() ){
2355 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDER" ) + "\n" + getErrorMsg() );
2359 result = patternBuilderModel->mapFromSource(iElts);
2364 //---------------------------------- MakePipeDialog -----------------------------
2365 // ============================================================== Constructeur
2367 MakePipeDialog::MakePipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2368 : HexaBaseDialog(parent, editmode, f)
2370 _helpFileName = "gui_blocks_for_cyl_pipe.html#make-pipe";
2372 _initWidget(editmode);
2376 // ============================================================== Destructeur
2377 MakePipeDialog::~MakePipeDialog()
2381 // ============================================================== _initInputWidget
2382 void MakePipeDialog::_initInputWidget( Mode editmode )
2384 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2385 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2386 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2388 installEventFilter(this);
2389 origin_le->installEventFilter(this);
2390 axis_le->installEventFilter(this);
2391 base_le->installEventFilter(this);
2393 origin_le->setReadOnly(true);
2394 axis_le->setReadOnly(true);
2395 base_le->setReadOnly(true);
2397 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2398 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2400 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2401 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2403 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2404 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2406 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2407 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2409 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2410 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2412 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2413 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2416 // ============================================================== addRadiusItem
2417 void MakePipeDialog::addRadiusItem()
2419 QListWidgetItem* previousItem = radius_lw->currentItem();
2420 QListWidgetItem* newItem = new QListWidgetItem();
2422 double defaultValue = 1.;
2424 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2426 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2427 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2428 radius_lw->addItem(newItem);
2431 // ============================================================== delRadiusItem
2432 void MakePipeDialog::delRadiusItem()
2434 delete radius_lw->currentItem();
2437 // ============================================================== addAngleItem
2438 void MakePipeDialog::addAngleItem()
2440 QListWidgetItem* previousItem = angle_lw->currentItem();
2441 QListWidgetItem* newItem = new QListWidgetItem();
2443 double defaultValue = 180.;
2445 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2447 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2448 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2449 angle_lw->addItem(newItem);
2452 // ============================================================== delAngleItem
2453 void MakePipeDialog::delAngleItem()
2455 delete angle_lw->currentItem();
2458 // ============================================================== addHeightItem
2459 void MakePipeDialog::addHeightItem()
2461 QListWidgetItem* previousItem = height_lw->currentItem();
2462 QListWidgetItem* newItem = new QListWidgetItem();
2464 double defaultValue = 1.;
2466 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2468 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2469 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2470 height_lw->addItem(newItem);
2473 // ============================================================== delHeightItem
2474 void MakePipeDialog::delHeightItem()
2476 delete height_lw->currentItem();
2479 // ============================================================== clear
2480 void MakePipeDialog::clear()
2483 modelUnregister(origin_le);
2486 modelUnregister(axis_le);
2489 modelUnregister(base_le);
2491 modelUnregister(this);
2494 // ============================================================== apply
2495 bool MakePipeDialog::apply(QModelIndex& result)
2497 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2500 DocumentModel* docModel = getDocumentModel();
2501 PatternDataModel* patternDataModel = getPatternDataModel();
2502 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2504 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2505 QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2506 QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2507 double rext = ext_radius_spb->value();
2508 double rint = int_radius_spb->value();
2509 double angle = angle_spb->value();
2510 double height = height_spb->value();
2511 int nr = nr_spb->value();
2512 int na = na_spb->value();
2513 int nh = nh_spb->value();
2517 if (rb0->isChecked())
2518 iElts = docModel->makePipeTop(nr, na, nh);
2519 else if (rb1->isChecked())
2521 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2522 iElts = docModel->makePipeUni(iorigin, ibase, iaxis, rint, rext, angle, height,
2525 else if (rb2->isChecked())
2527 QListWidgetItem* item = NULL;
2529 vector<double> radius;
2530 vector<double> angles;
2531 vector<double> heights;
2534 int nbAngles = angle_lw->count();
2535 for ( int r = 0; r < nbAngles; ++r){
2536 item = angle_lw->item(r);
2537 double itemValue = item->data(Qt::EditRole).toDouble();
2538 angles.push_back(itemValue);
2543 SUIT_MessageBox::information( 0,
2545 tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2549 int nbRadius = radius_lw->count();
2550 for ( int r = 0; r < nbRadius; ++r){
2551 item = radius_lw->item(r);
2552 radius.push_back(item->data(Qt::EditRole).toDouble());
2555 int nbHeight = height_lw->count();
2556 for ( int r = 0; r < nbHeight; ++r){
2557 item = height_lw->item(r);
2558 heights.push_back(item->data(Qt::EditRole).toDouble());
2560 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2561 iElts = docModel->makePipe( iorigin, ibase, iaxis, radius, angles, heights );
2564 if ( !iElts.isValid() ){
2565 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPE" ) + "\n" + getErrorMsg() );
2569 // to select/highlight result
2570 result = patternBuilderModel->mapFromSource(iElts);
2575 //---------------------------------- MakeCylindersDialog -----------------------------
2576 // ============================================================== Constructeur
2578 MakeCylindersDialog::MakeCylindersDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2579 : HexaBaseDialog(parent, editmode, f)
2581 _helpFileName = "gui_blocks_for_cyl_pipe.html#make-cylinders";
2583 _initWidget(editmode);
2586 // ============================================================== Destructeur
2587 MakeCylindersDialog::~MakeCylindersDialog()
2591 void MakeCylindersDialog::_initInputWidget( Mode editmode )
2593 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2594 center2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2595 direction_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2596 direction2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2598 installEventFilter(this);
2599 center_le->installEventFilter(this);
2600 center2_le->installEventFilter(this);
2601 direction_le->installEventFilter(this);
2602 direction2_le->installEventFilter(this);
2604 center_le->setReadOnly(true);
2605 center2_le->setReadOnly(true);
2606 direction_le->setReadOnly(true);
2607 direction2_le->setReadOnly(true);
2610 // ============================================================== clear
2611 void MakeCylindersDialog::clear()
2614 modelUnregister(center_le);
2616 center2_le->clear();
2617 modelUnregister(center2_le);
2619 direction_le->clear();
2620 modelUnregister(direction_le);
2622 direction2_le->clear();
2623 modelUnregister(direction2_le);
2625 modelUnregister(this);
2628 // ============================================================== apply
2629 bool MakeCylindersDialog::apply(QModelIndex& result)
2631 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2634 DocumentModel* docModel = getDocumentModel();
2635 PatternDataModel* patternDataModel = getPatternDataModel();
2636 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2639 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2640 QModelIndex icenter2 = patternDataModel->mapToSource( _index[center2_le] );
2641 QModelIndex idir = patternBuilderModel->mapToSource( _index[direction_le] );
2642 QModelIndex idir2 = patternBuilderModel->mapToSource( _index[direction2_le] );
2644 if ( icenter.isValid() && icenter2.isValid() && idir.isValid() && idir2.isValid()){
2645 double r1 = radius_spb->value();
2646 double h1 = height_spb->value();
2647 double r2 = radius2_spb->value();
2648 double h2 = height2_spb->value();
2649 iElts = docModel->makeCylinders( icenter, idir, r1, h1, icenter2, idir2, r2, h2 );
2652 if ( !iElts.isValid() ){
2653 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDERS" ) + "\n" + getErrorMsg() );
2657 result = patternBuilderModel->mapFromSource(iElts);
2662 //---------------------------------- MakePipesDialog -----------------------------
2663 // ============================================================== Constructeur
2665 MakePipesDialog::MakePipesDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2666 : HexaBaseDialog(parent, editmode, f)
2668 _helpFileName = "gui_blocks_for_cyl_pipe.html#make-pipes";
2670 _initWidget(editmode);
2673 // ============================================================== Destructeur
2674 MakePipesDialog::~MakePipesDialog()
2678 // ============================================================== _initInputWidget
2679 void MakePipesDialog::_initInputWidget( Mode editmode )
2681 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2682 origin2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2683 dir_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2684 dir2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2686 installEventFilter(this);
2687 origin_le->installEventFilter(this);
2688 origin2_le->installEventFilter(this);
2689 dir_le->installEventFilter(this);
2690 dir2_le->installEventFilter(this);
2692 origin_le->setReadOnly(true);
2693 origin2_le->setReadOnly(true);
2694 dir_le->setReadOnly(true);
2695 dir2_le->setReadOnly(true);
2698 // ============================================================== clear
2699 void MakePipesDialog::clear()
2702 modelUnregister(origin_le);
2704 origin2_le->clear();
2705 modelUnregister(origin2_le);
2708 modelUnregister(dir_le);
2711 modelUnregister(dir2_le);
2713 modelUnregister(this);
2716 // ============================================================== apply
2717 bool MakePipesDialog::apply(QModelIndex& result)
2719 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2722 DocumentModel* docModel = getDocumentModel();
2723 PatternDataModel* patternDataModel = getPatternDataModel();
2724 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2726 QModelIndex iorigin1 = patternDataModel->mapToSource( _index[origin_le] );
2727 QModelIndex iorigin2 = patternDataModel->mapToSource( _index[origin2_le] );
2728 QModelIndex idir1 = patternBuilderModel->mapToSource( _index[dir_le] );
2729 QModelIndex idir2 = patternBuilderModel->mapToSource( _index[dir2_le] );
2730 double rint1 = int_radius_spb->value();
2731 double rext1 = ext_radius_spb->value();
2732 double height1 = height_spb->value();
2733 double rint2 = int_radius2_spb->value();
2734 double rext2 = ext_radius2_spb->value();
2735 double height2 = height_spb->value();
2739 if ( iorigin1.isValid() && iorigin2.isValid() && idir1.isValid() && idir2.isValid())
2740 iElts = docModel->makePipes( iorigin1, idir1, rint1, rext1, height1,
2741 iorigin2, idir2, rint2, rext2, height2);
2743 if ( !iElts.isValid() ){
2744 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPES" ) + "\n" + getErrorMsg() );
2748 result = patternBuilderModel->mapFromSource(iElts);
2753 //---------------------------------- RemoveHexaDialog -----------------------------
2754 // ============================================================== Constructeur
2756 RemoveHexaDialog::RemoveHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2757 : HexaBaseDialog(parent, editmode, f)
2759 _helpFileName = "gui_remove.html";
2761 _initWidget(editmode);
2764 // ============================================================== Destructeur
2765 RemoveHexaDialog::~RemoveHexaDialog()
2769 // ============================================================== _initInputWidget
2770 void RemoveHexaDialog::_initInputWidget( Mode editmode )
2773 QValidator *validator = new QRegExpValidator(rx, this);
2775 hexa_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
2776 hexa_le->setValidator( validator );
2777 hexa_le->installEventFilter(this);
2778 hexa_le->setReadOnly(true);
2779 autoFocusSwitch = false;
2782 // ============================================================== clear
2783 void RemoveHexaDialog::clear()
2786 modelUnregister(hexa_le);
2788 modelUnregister(this);
2791 // ============================================================== apply
2792 bool RemoveHexaDialog::apply(QModelIndex& result)
2794 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2797 if ( !getDocumentModel() ) return false;
2798 const PatternDataModel* patternDataModel = getPatternDataModel();
2799 if ( !patternDataModel ) return false;
2801 QModelIndex ihexa = patternDataModel->mapToSource( _index[hexa_le] );
2803 bool removed = false;
2804 if ( ihexa.isValid() ){
2805 if ( connected_cb->isChecked() ){
2806 removed = getDocumentModel()->removeConnectedHexa( ihexa );
2808 removed = getDocumentModel()->removeHexa( ihexa );
2812 if ( removed == false ){
2813 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE HEXA" ) + "\n" + getErrorMsg() );
2822 //---------------------------------- PrismQuadDialog -----------------------------
2823 // ============================================================== Constructeur
2825 PrismQuadDialog::PrismQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2826 : HexaBaseDialog(parent, editmode, f)
2828 _helpFileName = "gui_prism_join_quad.html#prism-quadrangles";
2830 _initWidget(editmode);
2831 extrudeTop_rb->click();
2834 // ============================================================== Destructeur
2835 PrismQuadDialog::~PrismQuadDialog()
2839 // ============================================================== getAssocsVTK
2841 * Returns elements currently associated to vtk
2843 QModelIndexList PrismQuadDialog::getAssocsVTK()
2845 QModelIndexList assocs;
2847 QListWidgetItem* item = NULL;
2849 //ListWidget content
2850 const PatternDataModel* patternDataModel = getPatternDataModel();
2851 if ( !patternDataModel ) return assocs;
2852 int nbQuads = quads_lw->count();
2853 for ( int r = 0; r < nbQuads; ++r ){
2854 item = quads_lw->item(r);
2855 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
2856 if ( iQuad.isValid() )
2862 // ============================================================== _initInputWidget
2863 void PrismQuadDialog::_initInputWidget( Mode editmode )
2865 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
2866 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2868 installEventFilter(this);
2869 quads_lw->installEventFilter(this);
2870 axis_le->installEventFilter(this);
2872 axis_le->setReadOnly(true);
2874 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
2875 delQuadShortcut->setContext( Qt::WidgetShortcut );
2876 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2877 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2879 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
2880 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
2881 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2882 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2885 // ============================================================== clear
2886 void PrismQuadDialog::clear()
2889 modelUnregister(quads_lw);
2892 modelUnregister(axis_le);
2894 modelUnregister(this);
2897 // ============================================================== removeQuad
2898 void PrismQuadDialog::removeQuad()
2900 QListWidgetItem *item = quads_lw->currentItem();
2903 int r = quads_lw->row(item);
2904 quads_lw->takeItem(r);
2909 // ============================================================== addHeightItem
2910 void PrismQuadDialog::addHeightItem()
2912 QListWidgetItem* previousItem = height_lw->currentItem();
2913 QListWidgetItem* newItem = new QListWidgetItem();
2915 double defaultValue = 1.;
2917 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2919 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2920 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2921 height_lw->addItem(newItem);
2924 // ============================================================== delHeightItem
2925 void PrismQuadDialog::delHeightItem()
2927 delete height_lw->currentItem();
2930 // ============================================================== apply
2931 bool PrismQuadDialog::apply(QModelIndex& result)
2933 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2936 DocumentModel* docModel = getDocumentModel();
2937 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2939 QModelIndexList iquads = getIndexList(quads_lw);
2940 QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2941 double length = length_spb->value();
2942 int nb = nb_spb->value();
2944 vector<double> heights;
2945 QListWidgetItem* item = NULL;
2946 int nbItems = height_lw->count();
2948 for ( int r = 0; r < nbItems; ++r){
2949 item = height_lw->item(r);
2950 heights.push_back( item->data(Qt::EditRole).toDouble() );
2954 int nbQuads = iquads.count();
2956 if (nbQuads == 1 && iquads[0].isValid())
2958 if (extrudeTop_rb->isChecked())
2959 iElts = docModel->extrudeQuadTop(iquads[0], nb);
2960 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
2961 iElts = docModel->extrudeQuadUni(iquads[0], iaxis, length, nb);
2962 else if (extrude_rb->isChecked() && iaxis.isValid())
2963 iElts = docModel->extrudeQuad(iquads[0], iaxis, heights);
2965 else if (nbQuads > 1)
2967 if (extrudeTop_rb->isChecked())
2968 iElts = docModel->extrudeQuadsTop(iquads, nb);
2969 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
2970 iElts = docModel->extrudeQuadsUni(iquads, iaxis, length, nb);
2971 else if (extrude_rb->isChecked() && iaxis.isValid())
2972 iElts = docModel->extrudeQuads(iquads, iaxis, heights);
2975 if ( !iElts.isValid() ){
2976 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PRISM QUAD(S)" ) + "\n" + getErrorMsg() );
2980 result = patternBuilderModel->mapFromSource(iElts);
2985 //---------------------------------- JoinQuadDialog -----------------------------
2986 // ============================================================== Constructeur
2988 JoinQuadDialog::JoinQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2989 : HexaBaseDialog(parent, editmode, f)
2991 _helpFileName = "gui_prism_join_quad.html#join-quadrangles";
2993 _initWidget(editmode);
2994 joinUni_rb->click();
2997 // ============================================================== Destructeur
2998 JoinQuadDialog::~JoinQuadDialog()
3002 // ============================================================== getAssocsVTK
3004 * Returns elements currently associated to vtk
3006 QModelIndexList JoinQuadDialog::getAssocsVTK()
3008 QModelIndexList assocs;
3010 QListWidgetItem* item = NULL;
3012 if (getPatternDataSelectionModel() == NULL) return assocs;
3014 //ListWidget content
3015 const PatternDataModel* patternDataModel = getPatternDataModel();
3016 if ( !patternDataModel ) return assocs;
3017 int nbQuads = quads_lw->count();
3018 for ( int r = 0; r < nbQuads; ++r ){
3019 item = quads_lw->item(r);
3020 // iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
3021 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
3022 if ( iQuad.isValid() ) assocs << iQuad;
3027 // ============================================================== _initInputWidget
3028 void JoinQuadDialog::_initInputWidget( Mode editmode )
3030 quad_dest_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3031 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3032 vex0_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3033 vex1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3034 vex2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3035 vex3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3037 installEventFilter(this);
3038 quad_dest_le->installEventFilter(this);
3039 quads_lw->installEventFilter(this);
3040 vex0_le->installEventFilter(this);
3041 vex1_le->installEventFilter(this);
3042 vex2_le->installEventFilter(this);
3043 vex3_le->installEventFilter(this);
3045 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3046 delQuadShortcut->setContext( Qt::WidgetShortcut );
3047 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3049 quad_dest_le->setReadOnly(true);
3050 vex0_le->setReadOnly(true);
3051 vex1_le->setReadOnly(true);
3052 vex2_le->setReadOnly(true);
3053 vex3_le->setReadOnly(true);
3055 _currentObj = quads_lw;
3056 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3057 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3059 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3061 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3062 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3065 // ============================================================== addHeightItem
3066 void JoinQuadDialog::addHeightItem()
3068 QListWidgetItem* previousItem = height_lw->currentItem();
3069 QListWidgetItem* newItem = new QListWidgetItem();
3071 double defaultValue = 1.;
3073 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3075 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3076 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3077 height_lw->addItem(newItem);
3080 // ============================================================== delHeightItem
3081 void JoinQuadDialog::delHeightItem()
3083 delete height_lw->currentItem();
3086 // ============================================================== clear
3087 void JoinQuadDialog::clear()
3089 quad_dest_le->clear();
3090 modelUnregister(quad_dest_le);
3093 modelUnregister(quads_lw);
3096 modelUnregister(vex0_le);
3099 modelUnregister(vex1_le);
3102 modelUnregister(vex2_le);
3105 modelUnregister(vex3_le);
3107 modelUnregister(this);
3110 // ============================================================== removeQuad
3111 void JoinQuadDialog::removeQuad()
3113 QListWidgetItem *item = quads_lw->currentItem();
3116 int r = quads_lw->row(item);
3117 quads_lw->takeItem(r);
3122 // ============================================================== apply
3123 bool JoinQuadDialog::apply(QModelIndex& result)
3125 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3128 DocumentModel* docModel = getDocumentModel();
3129 PatternDataModel* patternDataModel = getPatternDataModel();
3130 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3132 QModelIndexList iquads;
3134 QListWidgetItem* item = NULL;
3135 int nbQuads = quads_lw->count();
3136 for ( int r = 0; r < nbQuads; ++r){
3137 item = quads_lw->item(r);
3138 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3139 if ( iquad.isValid() )
3142 QModelIndex iquaddest = patternDataModel->mapToSource( _index[quad_dest_le] );
3143 QModelIndex ivex0 = patternDataModel->mapToSource( _index[vex0_le] );
3144 QModelIndex ivex1 = patternDataModel->mapToSource( _index[vex1_le] );
3145 QModelIndex ivex2 = patternDataModel->mapToSource( _index[vex2_le] );
3146 QModelIndex ivex3 = patternDataModel->mapToSource( _index[vex3_le] );
3147 double nb = nb_spb->value();
3149 vector<double> heights;
3150 int nbHeight = height_lw->count();
3151 for ( int r = 0; r < nbHeight; ++r){
3152 item = height_lw->item(r);
3153 heights.push_back(item->data(Qt::EditRole).toDouble());
3157 if (nbQuads == 1 && iquads[0].isValid() && iquaddest.isValid() && ivex0.isValid() &&
3158 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3160 if (joinUni_rb->isChecked())
3161 iElts = docModel->joinQuadUni(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3162 else if (join_rb->isChecked())
3163 iElts = docModel->joinQuad(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3165 else if (nbQuads > 1 && iquaddest.isValid() && ivex0.isValid() &&
3166 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3168 if (joinUni_rb->isChecked())
3169 iElts = docModel->joinQuadsUni(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3170 else if (join_rb->isChecked())
3171 iElts = docModel->joinQuads(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3174 if ( !iElts.isValid() ){
3175 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT JOIN QUAD(S)" ) + "\n" + getErrorMsg() );
3178 result = patternBuilderModel->mapFromSource(iElts);
3183 // ------------------------- MergeDialog ----------------------------------
3184 // ============================================================== Constructeur
3186 MergeDialog::MergeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3187 : HexaBaseDialog(parent, editmode, f)
3190 _initWidget(editmode);
3193 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3194 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3195 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3196 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3198 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3199 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3200 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3202 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3203 connect( rb2, SIGNAL(cliked()), this, SLOT(clearVTKSelection()) );
3204 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3207 // ============================================================== Destructeur
3208 MergeDialog::~MergeDialog()
3212 // ============================================================== _initInputWidget
3213 void MergeDialog::_initInputWidget( Mode editmode )
3216 QValidator *validator = new QRegExpValidator(rx, this);
3218 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3219 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3220 v0_le_rb0->setValidator( validator );
3221 v1_le_rb0->setValidator( validator );
3222 v0_le_rb0->installEventFilter(this);
3223 v1_le_rb0->installEventFilter(this);
3225 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3226 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3227 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3228 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3230 v0_le_rb1->setValidator( validator );
3231 v1_le_rb1->setValidator( validator );
3232 e0_le_rb1->setValidator( validator );
3233 e1_le_rb1->setValidator( validator );
3235 v0_le_rb1->installEventFilter(this);
3236 v1_le_rb1->installEventFilter(this);
3237 e0_le_rb1->installEventFilter(this);
3238 e1_le_rb1->installEventFilter(this);
3240 v0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3241 v1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3242 v2_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3243 v3_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3244 q0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3245 q1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3247 v0_le_rb2->setValidator( validator );
3248 v1_le_rb2->setValidator( validator );
3249 v2_le_rb2->setValidator( validator );
3250 v3_le_rb2->setValidator( validator );
3251 q0_le_rb2->setValidator( validator );
3252 q1_le_rb2->setValidator( validator );
3254 v0_le_rb2->installEventFilter(this);
3255 v1_le_rb2->installEventFilter(this);
3256 v2_le_rb2->installEventFilter(this);
3257 v3_le_rb2->installEventFilter(this);
3258 q0_le_rb2->installEventFilter(this);
3259 q1_le_rb2->installEventFilter(this);
3261 v0_le_rb0->setReadOnly(true);
3262 v1_le_rb0->setReadOnly(true);
3264 v0_le_rb1->setReadOnly(true);
3265 v1_le_rb1->setReadOnly(true);
3266 e0_le_rb1->setReadOnly(true);
3267 e1_le_rb1->setReadOnly(true);
3269 v0_le_rb2->setReadOnly(true);
3270 v1_le_rb2->setReadOnly(true);
3271 v2_le_rb2->setReadOnly(true);
3272 v3_le_rb2->setReadOnly(true);
3273 q0_le_rb2->setReadOnly(true);
3274 q1_le_rb2->setReadOnly(true);
3277 // ============================================================== clear
3278 void MergeDialog::clear()
3281 modelUnregister(v0_le_rb0);
3284 modelUnregister(v1_le_rb0);
3287 modelUnregister(e0_le_rb1);
3290 modelUnregister(e1_le_rb1);
3293 modelUnregister(v0_le_rb1);
3296 modelUnregister(v1_le_rb1);
3299 modelUnregister(q0_le_rb2);
3302 modelUnregister(q1_le_rb2);
3305 modelUnregister(v0_le_rb2);
3308 modelUnregister(v1_le_rb2);
3311 modelUnregister(v2_le_rb2);
3314 modelUnregister(v3_le_rb2);
3316 modelUnregister(this);
3319 // ============================================================== updateHelpFileName
3320 void MergeDialog::updateHelpFileName()
3322 if ( sender() == rb0 ){
3323 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3324 } else if ( sender() == rb1 ){
3325 _helpFileName = "gui_merge_elmts.html#merge-two-edges";
3326 } else if ( sender() == rb2 ){
3327 _helpFileName = "gui_merge_elmts.html#merge-two-quadrangles";
3331 // ============================================================== apply
3332 bool MergeDialog::apply(QModelIndex& result)
3334 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3337 if (getDocumentModel() == NULL) return false;
3338 const PatternDataModel* patternDataModel = getPatternDataModel();
3339 if ( !patternDataModel ) return false;
3341 bool merged = false;
3343 if ( rb0->isChecked() ){
3344 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
3345 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
3349 merged = getDocumentModel()->mergeVertices( iv0, iv1 );
3351 } else if ( rb1->isChecked() ){
3352 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
3353 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
3354 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
3355 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
3361 merged = getDocumentModel()->mergeEdges( ie0, ie1, iv0, iv1);
3363 } else if ( rb2->isChecked() ){
3365 QModelIndex iq0 = patternDataModel->mapToSource( _index[q0_le_rb2] );
3366 QModelIndex iq1 = patternDataModel->mapToSource( _index[q1_le_rb2] );
3367 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb2] );
3368 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb2] );
3369 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb2] );
3370 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb2] );
3378 merged = getDocumentModel()->mergeQuads( iq0, iq1,
3379 iv0, iv1, iv2, iv3 );
3383 if ( merged == false ){
3384 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MERGE" ) + "\n" + getErrorMsg() );
3391 // ------------------------- DisconnectDialog ----------------------------------
3392 // ============================================================== Constructeur
3394 DisconnectDialog::DisconnectDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3395 : HexaBaseDialog(parent, editmode, f)
3398 _initWidget(editmode);
3401 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3403 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3404 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3405 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3407 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3408 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3409 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3411 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3412 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3413 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3415 connect( rb3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3416 connect( rb3, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3417 connect( rb3, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3421 // ============================================================== Destructeur
3422 DisconnectDialog::~DisconnectDialog()
3426 // ============================================================== _initInputWidget
3427 void DisconnectDialog::_initInputWidget( Mode editmode )
3430 QValidator *validator = new QRegExpValidator(rx, this);
3432 installEventFilter(this);
3435 v_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3436 h_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3437 v_le_rb0->setValidator( validator );
3438 h_le_rb0->setValidator( validator );
3439 v_le_rb0->installEventFilter(this);
3440 h_le_rb0->installEventFilter(this);
3443 e_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3444 h_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3445 e_le_rb1->setValidator( validator );
3446 h_le_rb1->setValidator( validator );
3447 e_le_rb1->installEventFilter(this);
3448 h_le_rb1->installEventFilter(this);
3451 q_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3452 h_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3453 q_le_rb2->setValidator( validator );
3454 h_le_rb2->setValidator( validator );
3455 q_le_rb2->installEventFilter(this);
3456 h_le_rb2->installEventFilter(this);
3459 d_edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3460 hexas_lw->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3461 d_edges_lw->installEventFilter(this);
3462 hexas_lw->installEventFilter(this);
3464 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), d_edges_lw);
3465 QShortcut* delHexaShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), hexas_lw);
3466 delEdgeShortcut->setContext( Qt::WidgetShortcut );
3467 delHexaShortcut->setContext( Qt::WidgetShortcut );
3469 v_le_rb0->setReadOnly(true);
3470 h_le_rb0->setReadOnly(true);
3472 e_le_rb1->setReadOnly(true);
3473 h_le_rb1->setReadOnly(true);
3475 q_le_rb2->setReadOnly(true);
3476 h_le_rb2->setReadOnly(true);
3478 connect( d_edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3479 connect( hexas_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3480 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
3481 connect( delHexaShortcut, SIGNAL(activated()), this, SLOT(deleteHexaItem()) );
3482 autoFocusSwitch = false;
3486 // =============================================== getAssocsVTK
3488 * Returns elements in the list
3490 QModelIndexList DisconnectDialog::getAssocsVTK()
3492 QModelIndexList iElts;
3494 QListWidgetItem* item = NULL;
3496 const PatternDataModel* patternDataModel = getPatternDataModel();
3497 if (patternDataModel == NULL || !rb3->isChecked())
3499 //ListWidget content
3500 if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == EDGE_TREE)
3502 int nbEdges = d_edges_lw->count();
3503 for ( int r = 0; r < nbEdges; ++r )
3505 item = d_edges_lw->item(r);
3506 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3507 if ( index.isValid() )
3511 else if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == HEXA_TREE)
3513 int nbHexas = hexas_lw->count();
3514 for ( int r = 0; r < nbHexas; ++r )
3516 item = hexas_lw->item(r);
3517 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3518 if ( index.isValid() )
3525 // ============================================================== clear
3526 void DisconnectDialog::clear()
3529 modelUnregister(v_le_rb0);
3532 modelUnregister(h_le_rb0);
3535 modelUnregister(e_le_rb1);
3538 modelUnregister(h_le_rb1);
3540 d_edges_lw->clear();
3541 modelUnregister(d_edges_lw);
3544 modelUnregister(hexas_lw);
3547 modelUnregister(q_le_rb2);
3550 modelUnregister(h_le_rb2);
3552 modelUnregister(this);
3555 // ============================================================== deleteEdgeItem
3556 void DisconnectDialog::deleteEdgeItem()
3558 delete d_edges_lw->currentItem();
3561 // ============================================================== deleteHexaItem
3562 void DisconnectDialog::deleteHexaItem()
3564 delete hexas_lw->currentItem();
3567 // ============================================================== updateHelpFileName
3568 void DisconnectDialog::updateHelpFileName()
3570 if ( sender() == rb0 ){
3571 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3572 } else if ( sender() == rb1 ){
3573 _helpFileName = "gui_disc_elmts.html#disconnect-an-edge";
3574 } else if ( sender() == rb2 ){
3575 _helpFileName = "gui_disc_elmts.html#disconnect-a-quadrangle";
3576 } else if (sender() == rb3 ){
3577 _helpFileName = "gui_disc_elmts.html#disconnect-edges";
3581 // ============================================================== apply
3582 bool DisconnectDialog::apply(QModelIndex& result)
3584 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3586 if (getDocumentModel() == NULL) return false;
3587 const PatternDataModel* patternDataModel = getPatternDataModel();
3588 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3589 if ( !patternDataModel || !patternBuilderModel) return false;
3593 if ( rb0->isChecked() ){
3594 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb0] );
3595 QModelIndex ivex = patternDataModel->mapToSource( _index[v_le_rb0] );
3597 if ( ihexa.isValid()
3598 && ivex.isValid() ){
3599 iElts = getDocumentModel()->disconnectVertex( ihexa, ivex );
3601 } else if ( rb1->isChecked() ){
3602 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb1] );
3603 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le_rb1] );
3605 if ( ihexa.isValid()
3606 && iedge.isValid() ){
3607 iElts = getDocumentModel()->disconnectEdge( ihexa, iedge );
3609 } else if ( rb2->isChecked() ){
3610 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb2] );
3611 QModelIndex iquad = patternDataModel->mapToSource( _index[q_le_rb2] );
3613 if ( ihexa.isValid()
3614 && iquad.isValid() ){
3615 iElts = getDocumentModel()->disconnectQuad( ihexa, iquad );
3617 } else if ( rb3->isChecked() ){ //
3619 QModelIndex iedge, ihexa;
3620 QModelIndexList iedges, ihexas;
3621 QListWidgetItem* item = NULL;
3624 int nbEdges = d_edges_lw->count();
3625 for (int r = 0; r < nbEdges; ++r){
3626 item = d_edges_lw->item(r);
3627 iedge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3628 if ( iedge.isValid() )
3633 int nbHexas = hexas_lw->count();
3634 for (int r = 0; r < nbHexas; ++r){
3635 item = hexas_lw->item(r);
3636 ihexa = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3637 if ( ihexa.isValid() )
3641 iElts = getDocumentModel()->disconnectEdges( ihexas, iedges );
3644 if ( !iElts.isValid() ){
3645 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT DISCONNECT" ) + "\n" + getErrorMsg() );
3649 result = patternBuilderModel->mapFromSource(iElts);
3655 // ------------------------- CutEdgeDialog ----------------------------------
3656 // ============================================================== Constructeur
3658 CutEdgeDialog::CutEdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3659 HexaBaseDialog(parent, editmode, f)
3661 _helpFileName = "gui_cut_hexa.html";
3663 _initWidget(editmode);
3668 // ============================================================== Destructeur
3669 CutEdgeDialog::~CutEdgeDialog()
3673 // ============================================================== _initInputWidget
3674 void CutEdgeDialog::_initInputWidget( Mode editmode )
3676 installEventFilter(this);
3678 e_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3679 e_le->installEventFilter(this);
3681 e_le->setReadOnly(true);
3683 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3684 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3686 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3687 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3690 // ============================================================== clear
3691 void CutEdgeDialog::clear()
3694 modelUnregister(e_le);
3696 modelUnregister(this);
3699 // ============================================================== addHeightItem
3700 void CutEdgeDialog::addHeightItem()
3702 QListWidgetItem* previousItem = height_lw->currentItem();
3703 QListWidgetItem* newItem = new QListWidgetItem();
3705 double defaultValue = 1.;
3707 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3709 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3710 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3711 height_lw->addItem(newItem);
3714 // ============================================================== delHeightItem
3715 void CutEdgeDialog::delHeightItem()
3717 delete height_lw->currentItem();
3720 // ============================================================== apply
3721 bool CutEdgeDialog::apply(QModelIndex& result)
3723 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3726 DocumentModel* docModel = getDocumentModel();
3727 PatternDataModel* patternDataModel = getPatternDataModel();
3728 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3731 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le] );
3733 if (cutUni_rb->isChecked() && iedge.isValid())
3735 int nbCut = nb_cut_spb->value();
3736 iElts = docModel->cutUni(iedge, nbCut);
3738 else if (cut_rb->isChecked() && iedge.isValid())
3740 vector<double> heights;
3741 QListWidgetItem* item = NULL;
3742 int nbItems = height_lw->count();
3744 for ( int r = 0; r < nbItems; ++r){
3745 item = height_lw->item(r);
3746 heights.push_back( item->data(Qt::EditRole).toDouble() );
3749 iElts = docModel->cut(iedge, heights);
3752 if ( !iElts.isValid() ){
3753 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT CUT EDGE" ) + "\n" + getErrorMsg() );
3757 result = patternBuilderModel->mapFromSource(iElts);
3759 //Update the line edit
3761 e_le->setProperty("QModelIndex", invalid );
3763 QModelIndex invalidIndex;
3764 _index[e_le] = invalidIndex;
3771 // // ------------------------- MakeTransformationDialog ----------------------------------
3772 // ============================================================== Constructeur
3774 MakeTransformationDialog::MakeTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3775 : HexaBaseDialog(parent, editmode, f)
3778 _initWidget(editmode);
3781 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
3782 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3783 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3784 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3787 // ============================================================== Destructeur
3788 MakeTransformationDialog::~MakeTransformationDialog()
3792 // ============================================================== _initInputWidget
3793 void MakeTransformationDialog::_initInputWidget( Mode editmode )
3796 QValidator *validator = new QRegExpValidator(rx, this);
3798 installEventFilter(this);
3800 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3801 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3803 vec_le_rb0->setValidator( validator );
3804 elts_le_rb0->setValidator( validator );
3805 vec_le_rb0->installEventFilter(this);
3806 elts_le_rb0->installEventFilter(this);
3808 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3809 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3810 vex_le_rb1->setValidator( validator );
3811 elts_le_rb1->setValidator( validator );
3812 vex_le_rb1->installEventFilter(this);
3813 elts_le_rb1->installEventFilter(this);
3815 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3816 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3817 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3818 vex_le_rb2->setValidator( validator );
3819 vec_le_rb2->setValidator( validator );
3820 elts_le_rb2->setValidator( validator );
3821 vex_le_rb2->installEventFilter(this);
3822 vec_le_rb2->installEventFilter(this);
3823 elts_le_rb2->installEventFilter(this);
3825 vec_le_rb0->setReadOnly(true);
3826 elts_le_rb0->setReadOnly(true);
3828 vex_le_rb1->setReadOnly(true);
3829 elts_le_rb1->setReadOnly(true);
3831 vex_le_rb2->setReadOnly(true);
3832 vec_le_rb2->setReadOnly(true);
3833 elts_le_rb2->setReadOnly(true);
3837 // ============================================================== clear
3838 void MakeTransformationDialog::clear()
3840 elts_le_rb0->clear();
3841 modelUnregister(elts_le_rb0);
3843 vec_le_rb0->clear();
3844 modelUnregister(vec_le_rb0);
3846 elts_le_rb1->clear();
3847 modelUnregister(elts_le_rb1);
3849 vex_le_rb1->clear();
3850 modelUnregister(vex_le_rb1);
3852 elts_le_rb2->clear();
3853 modelUnregister(elts_le_rb2);
3855 vex_le_rb2->clear();
3856 modelUnregister(vex_le_rb2);
3858 vec_le_rb2->clear();
3859 modelUnregister(vec_le_rb2);
3861 modelUnregister(this);
3864 // ============================================================== updateHelpFileName
3865 void MakeTransformationDialog::updateHelpFileName()
3867 if ( sender() == rb0 ){
3868 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
3869 } else if ( sender() == rb1 ){
3870 _helpFileName = "gui_make_elmts.html#make-elements-by-scaling";
3871 } else if ( sender() == rb2 ){
3872 _helpFileName = "gui_make_elmts.html#make-elements-by-rotation";
3876 // ============================================================== apply
3877 bool MakeTransformationDialog::apply(QModelIndex& result)
3879 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3882 if (getDocumentModel() == NULL) return false;
3883 const PatternDataModel* patternDataModel = getPatternDataModel();
3884 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3885 if ( !patternDataModel || !patternBuilderModel) return false;
3887 QModelIndex iNewElts;
3889 if ( rb0->isChecked() ){
3890 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
3891 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
3893 if ( ielts.isValid()
3895 iNewElts = getDocumentModel()->makeTranslation( ielts, ivec );
3897 } else if ( rb1->isChecked() ){
3898 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
3899 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
3900 double k = k_spb->value();
3902 if ( ielts.isValid()
3904 iNewElts = getDocumentModel()->makeScale( ielts, ivex, k );
3906 } else if ( rb2->isChecked() ){
3907 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
3908 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
3909 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
3910 double angle = angle_spb->value();
3912 if ( ielts.isValid()
3915 iNewElts = getDocumentModel()->makeRotation( ielts, ivex, ivec, angle );
3918 if ( !iNewElts.isValid() ){
3919 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
3923 result = patternBuilderModel->mapFromSource(iNewElts);
3928 // // ------------------------- MakeSymmetryDialog ----------------------------------
3929 // ============================================================== Constructeur
3931 MakeSymmetryDialog::MakeSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3932 HexaBaseDialog(parent, editmode, f)
3935 _initWidget(editmode);
3938 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
3939 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3940 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3941 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3944 // ============================================================== Destructeur
3945 MakeSymmetryDialog::~MakeSymmetryDialog()
3949 // ============================================================== _initInputWidget
3950 void MakeSymmetryDialog::_initInputWidget( Mode editmode )
3953 QValidator *validator = new QRegExpValidator(rx, this);
3955 installEventFilter(this);
3957 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3958 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3959 vex_le_rb0->setValidator( validator );
3960 elts_le_rb0->setValidator( validator );
3961 vex_le_rb0->installEventFilter(this);
3962 elts_le_rb0->installEventFilter(this);
3964 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3965 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3966 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3967 vex_le_rb1->setValidator( validator );
3968 vec_le_rb1->setValidator( validator );
3969 elts_le_rb1->setValidator( validator );
3970 vex_le_rb1->installEventFilter(this);
3971 vec_le_rb1->installEventFilter(this);
3972 elts_le_rb1->installEventFilter(this);
3974 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3975 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3976 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3977 vex_le_rb2->setValidator( validator );
3978 vec_le_rb2->setValidator( validator );
3979 elts_le_rb2->setValidator( validator );
3980 vex_le_rb2->installEventFilter(this);
3981 vec_le_rb2->installEventFilter(this);
3982 elts_le_rb2->installEventFilter(this);
3984 vex_le_rb0->setReadOnly(true);
3985 elts_le_rb0->setReadOnly(true);
3986 vex_le_rb1->setReadOnly(true);
3987 vec_le_rb1->setReadOnly(true);
3988 elts_le_rb1->setReadOnly(true);
3989 vex_le_rb2->setReadOnly(true);
3990 vec_le_rb2->setReadOnly(true);
3991 elts_le_rb2->setReadOnly(true);
3994 // ============================================================== clear
3995 void MakeSymmetryDialog::clear()
3997 elts_le_rb0->clear();
3998 modelUnregister(elts_le_rb0);
4000 vex_le_rb0->clear();
4001 modelUnregister(vex_le_rb0);
4003 elts_le_rb1->clear();
4004 modelUnregister(elts_le_rb1);
4006 vex_le_rb1->clear();
4007 modelUnregister(vex_le_rb1);
4009 vec_le_rb1->clear();
4010 modelUnregister(vec_le_rb1);
4012 elts_le_rb2->clear();
4013 modelUnregister(elts_le_rb2);
4015 vex_le_rb2->clear();
4016 modelUnregister(vex_le_rb2);
4018 vec_le_rb2->clear();
4019 modelUnregister(vec_le_rb2);
4021 modelUnregister(this);
4024 // ============================================================== updateHelpFileName
4025 void MakeSymmetryDialog::updateHelpFileName()
4027 if ( sender() == rb0 ){
4028 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4029 } else if ( sender() == rb1 ){
4030 _helpFileName = "gui_make_symmetry.html#make-elements-by-line-symmetry";
4031 } else if ( sender() == rb2 ){
4032 _helpFileName = "gui_make_symmetry.html#make-elements-by-plane-symmetry";
4036 // ============================================================== apply
4037 bool MakeSymmetryDialog::apply(QModelIndex& result)
4039 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4041 if (getDocumentModel() == NULL) return false;
4042 const PatternDataModel* patternDataModel = getPatternDataModel();
4043 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4044 if ( !patternDataModel || !patternBuilderModel) return false;
4046 QModelIndex iNewElts;
4048 if ( rb0->isChecked() ){
4049 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4050 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4052 if ( ielts.isValid()
4054 iNewElts = getDocumentModel()->makeSymmetryPoint( ielts, ivex );
4057 } else if ( rb1->isChecked() ){
4058 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4059 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4060 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4062 if ( ielts.isValid()
4065 iNewElts = getDocumentModel()->makeSymmetryLine( ielts, ivex, ivec );
4067 } else if ( rb2->isChecked() ){
4068 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4069 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4070 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4072 if ( ielts.isValid()
4075 iNewElts = getDocumentModel()->makeSymmetryPlane( ielts, ivex, ivec );
4078 if ( !iNewElts.isValid() ){
4079 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4083 result = patternBuilderModel->mapFromSource(iNewElts);
4088 // // ------------------------- PerformTransformationDialog ----------------------------------
4089 // ============================================================== Constructeur
4090 PerformTransformationDialog::PerformTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4091 HexaBaseDialog(parent, editmode, f)
4094 _initWidget(editmode);
4097 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4098 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4099 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4100 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4103 // ============================================================== Destructeur
4104 PerformTransformationDialog::~PerformTransformationDialog()
4108 // ============================================================== _initInputWidget
4109 void PerformTransformationDialog::_initInputWidget( Mode editmode )
4112 QValidator *validator = new QRegExpValidator(rx, this);
4114 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4115 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4116 vec_le_rb0->setValidator( validator );
4117 elts_le_rb0->setValidator( validator );
4118 vec_le_rb0->installEventFilter(this);
4119 elts_le_rb0->installEventFilter(this);
4121 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4122 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4123 vex_le_rb1->setValidator( validator );
4124 elts_le_rb1->setValidator( validator );
4125 vex_le_rb1->installEventFilter(this);
4126 elts_le_rb1->installEventFilter(this);
4129 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4130 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4131 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4132 vex_le_rb2->setValidator( validator );
4133 vec_le_rb2->setValidator( validator );
4134 elts_le_rb2->setValidator( validator );
4135 vex_le_rb2->installEventFilter(this);
4136 vec_le_rb2->installEventFilter(this);
4137 elts_le_rb2->installEventFilter(this);
4139 vec_le_rb0->setReadOnly(true);
4140 elts_le_rb0->setReadOnly(true);
4141 vex_le_rb1->setReadOnly(true);
4142 elts_le_rb1->setReadOnly(true);
4143 vex_le_rb2->setReadOnly(true);
4144 vec_le_rb2->setReadOnly(true);
4145 elts_le_rb2->setReadOnly(true);
4149 // ============================================================== clear
4150 void PerformTransformationDialog::clear()
4152 vec_le_rb0->clear();
4153 modelUnregister(vec_le_rb0);
4155 elts_le_rb0->clear();
4156 modelUnregister(elts_le_rb0);
4158 vex_le_rb1->clear();
4159 modelUnregister(vex_le_rb1);
4161 elts_le_rb1->clear();
4162 modelUnregister(elts_le_rb1);
4164 vex_le_rb2->clear();
4165 modelUnregister(vex_le_rb2);
4167 vec_le_rb2->clear();
4168 modelUnregister(vec_le_rb2);
4170 elts_le_rb2->clear();
4171 modelUnregister(elts_le_rb2);
4173 modelUnregister(this);
4176 // ============================================================== updateHelpFileName
4177 void PerformTransformationDialog::updateHelpFileName()
4179 if ( sender() == rb0 ){
4180 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4181 } else if ( sender() == rb1 ){
4182 _helpFileName = "gui_modify_elmts.html#modify-elements-by-scaling";
4183 } else if ( sender() == rb2 ){
4184 _helpFileName = "gui_modify_elmts.html#modify-elements-by-rotation";
4188 // ============================================================== apply
4189 bool PerformTransformationDialog::apply(QModelIndex& result)
4191 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4194 if (getDocumentModel() == NULL) return false;
4195 const PatternDataModel* patternDataModel = getPatternDataModel();
4196 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4197 if ( !patternDataModel || !patternBuilderModel) return false;
4199 bool performed = false;
4201 if ( rb0->isChecked() ){
4202 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4203 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4205 if ( ielts.isValid()
4207 performed = getDocumentModel()->performTranslation( ielts, ivec );
4209 } else if ( rb1->isChecked() ){
4210 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4211 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4212 double k = k_spb->value();
4214 if ( ielts.isValid()
4216 performed = getDocumentModel()->performScale( ielts, ivex, k );
4218 } else if ( rb2->isChecked() ){
4219 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4220 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4221 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4222 double angle = angle_spb->value();
4224 if ( ielts.isValid()
4227 performed = getDocumentModel()->performRotation( ielts, ivex, ivec, angle );
4230 if ( performed == false){
4231 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM TRANSFORMATION" ) + "\n" + getErrorMsg() );
4238 // // ------------------------- PerformSymmetryDialog ----------------------------------
4239 // ============================================================== Constructeur
4240 PerformSymmetryDialog::PerformSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4241 : HexaBaseDialog(parent, editmode, f)
4244 _initWidget( editmode );
4247 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4248 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4249 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4250 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4253 // ============================================================== Destructeur
4254 PerformSymmetryDialog::~PerformSymmetryDialog()
4258 // ============================================================== _initInputWidget
4259 void PerformSymmetryDialog::_initInputWidget( Mode editmode )
4262 QValidator *validator = new QRegExpValidator(rx, this);
4264 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4265 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4266 vex_le_rb0->setValidator( validator );
4267 elts_le_rb0->setValidator( validator );
4268 vex_le_rb0->installEventFilter(this);
4269 elts_le_rb0->installEventFilter(this);
4271 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4272 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4273 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4274 vex_le_rb1->setValidator( validator );
4275 vec_le_rb1->setValidator( validator );
4276 elts_le_rb1->setValidator( validator );
4277 vex_le_rb1->installEventFilter(this);
4278 vec_le_rb1->installEventFilter(this);
4279 elts_le_rb1->installEventFilter(this);
4281 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4282 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4283 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4284 vex_le_rb2->setValidator( validator );
4285 vec_le_rb2->setValidator( validator );
4286 elts_le_rb2->setValidator( validator );
4287 vex_le_rb2->installEventFilter(this);
4288 vec_le_rb2->installEventFilter(this);
4289 elts_le_rb2->installEventFilter(this);
4291 vex_le_rb0->setReadOnly(true);
4292 elts_le_rb0->setReadOnly(true);
4293 vex_le_rb1->setReadOnly(true);
4294 vec_le_rb1->setReadOnly(true);
4295 elts_le_rb1->setReadOnly(true);
4296 vex_le_rb2->setReadOnly(true);
4297 vec_le_rb2->setReadOnly(true);
4298 elts_le_rb2->setReadOnly(true);
4302 // ============================================================== clear
4303 void PerformSymmetryDialog::clear()
4305 vex_le_rb0->clear();
4306 modelUnregister(vex_le_rb0);
4308 elts_le_rb0->clear();
4309 modelUnregister(elts_le_rb0);
4311 elts_le_rb1->clear();
4312 modelUnregister(elts_le_rb1);
4314 vex_le_rb1->clear();
4315 modelUnregister(vex_le_rb1);
4317 vec_le_rb1->clear();
4318 modelUnregister(vec_le_rb1);
4320 elts_le_rb2->clear();
4321 modelUnregister(elts_le_rb2);
4323 vex_le_rb2->clear();
4324 modelUnregister(vex_le_rb2);
4326 vec_le_rb2->clear();
4327 modelUnregister(vec_le_rb2);
4329 modelUnregister(this);
4332 // ============================================================== updateHelpFileName
4333 void PerformSymmetryDialog::updateHelpFileName()
4335 if ( sender() == rb0 ){
4336 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4337 } else if ( sender() == rb1 ){
4338 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-line-symmetry";
4339 } else if ( sender() == rb2 ){
4340 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-plane-symmetry";
4344 // ============================================================== apply
4345 bool PerformSymmetryDialog::apply(QModelIndex& result)
4347 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4350 if (getDocumentModel() == NULL) return false;
4351 const PatternDataModel* patternDataModel = getPatternDataModel();
4352 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4353 if ( !patternDataModel || !patternBuilderModel) return false;
4355 bool performed = false;
4357 if ( rb0->isChecked() ){
4358 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4359 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4361 if ( ielts.isValid()
4363 performed = getDocumentModel()->performSymmetryPoint( ielts, ivex );
4365 } else if ( rb1->isChecked() ){
4366 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4367 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4368 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4370 if ( ielts.isValid()
4373 performed = getDocumentModel()->performSymmetryLine( ielts, ivex, ivec );
4375 } else if ( rb2->isChecked() ){
4376 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4377 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4378 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4380 if ( ielts.isValid()
4383 performed = getDocumentModel()->performSymmetryPlane( ielts, ivex, ivec );
4386 if ( performed == false ){
4387 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM SYMMETRY" ) + "\n" + getErrorMsg() );
4394 // // ------------------------- EdgeAssocDialog ----------------------------------
4395 // ============================================================== Constructeur
4396 EdgeAssocDialog::EdgeAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4397 HexaBaseDialog( parent, editmode, f )
4399 _helpFileName ="gui_asso_quad_to_geom.html#one-edge";
4401 _initWidget(editmode);
4406 // ============================================================== Destructeur
4407 EdgeAssocDialog::~EdgeAssocDialog()
4411 // ============================================================== close
4412 void EdgeAssocDialog::close()
4414 HEXABLOCKGUI::assocInProgress = false;
4415 HexaBaseDialog::close();
4418 // ============================================================== _initInputWidget
4419 void EdgeAssocDialog::_initInputWidget( Mode editmode )
4422 QValidator *validator = new QRegExpValidator(rx, this);
4425 first_vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4426 first_vex_le->installEventFilter(this);
4427 first_vex_le->setValidator( validator );
4429 single_edge_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4430 single_edge_le->installEventFilter(this);
4432 edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4433 edges_lw->installEventFilter(this);
4437 lines_lw->setProperty("HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4438 lines_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4439 lines_lw->installEventFilter(this);
4441 single_line_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4442 single_line_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4443 single_line_le->installEventFilter(this);
4446 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), edges_lw);
4447 QShortcut* delLineShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), lines_lw);
4448 delLineShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4449 delEdgeShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4451 pend_spb->setValue(1.);
4453 first_vex_le->setReadOnly(true);
4454 single_edge_le->setReadOnly(true);
4455 single_line_le->setReadOnly(true);
4457 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
4458 connect( delLineShortcut, SIGNAL(activated()), this, SLOT(deleteLineItem()) );
4459 connect( edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
4460 connect( lines_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4461 connect( single_rb, SIGNAL(clicked()), this, SLOT( refreshHighlight()), Qt::UniqueConnection );
4462 connect( multiple_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection );
4463 connect( single_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4464 connect( multiple_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4467 // ============================================================== updateHelpFileName
4468 void EdgeAssocDialog::updateHelpFileName()
4470 if ( sender() == single_rb ){
4471 _helpFileName = "gui_asso_quad_to_geom.html#one-edge";
4472 } else if ( sender() == multiple_rb ){
4473 _helpFileName = "gui_asso_quad_to_geom.html#line";
4477 // ============================================================== getAssocsVTK
4479 * Returns elements currently being associated in vtk side
4481 QModelIndexList EdgeAssocDialog::getAssocsVTK()
4483 QModelIndexList assocs;
4485 QListWidgetItem* item = NULL;
4487 if (getPatternDataSelectionModel() == NULL) return assocs;
4488 if (single_rb->isChecked())
4491 QVariant v = single_edge_le->property("QModelIndex");
4492 if ( !v.isValid() ) return assocs;
4493 assocs << v.value<QModelIndex>();
4496 else if (multiple_rb->isChecked())
4498 //ListWidget content
4499 const PatternDataModel* patternDataModel = getPatternDataModel();
4500 if ( !patternDataModel ) return assocs;
4501 int nbEdges = edges_lw->count();
4502 for ( int r = 0; r < nbEdges; ++r){
4503 item = edges_lw->item(r);
4504 iEdge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4505 if ( iEdge.isValid() ) assocs << iEdge;
4512 // ============================================================== getAssocsGEOM
4514 * Returns elements currently being associated in geom side
4516 QMultiMap<QString, int> EdgeAssocDialog::getAssocsGEOM()
4518 QMultiMap<QString, int> assocs;
4519 QListWidgetItem* item = NULL;
4520 DocumentModel::GeomObj geomObj;
4522 if (single_rb->isChecked())
4525 QVariant v = single_line_le->property("GeomObj");
4526 if ( !v.isValid() ) return assocs;
4527 geomObj = v.value<DocumentModel::GeomObj>();
4528 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4531 else if (multiple_rb->isChecked())
4533 //ListWidget content
4534 unsigned int nbEdges = lines_lw->count();
4535 for ( int r = 0; r < nbEdges; ++r){
4536 item = lines_lw->item(r);
4537 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4538 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4545 // ============================================================== selectElementOfGeom
4546 /*Highlight in the OCC view selected elements in a listwidget,
4547 * or an element in a line edit.*/
4548 void EdgeAssocDialog::selectElementOfGeom()
4550 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4551 if ( !currentListWidget )
4555 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4556 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4557 pgsm->clearSelection();
4558 if (sel.count() == 0)
4561 QListWidgetItem *item = sel[0];
4562 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
4563 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4564 if ( index.isValid() )
4565 pgsm->select( index, QItemSelectionModel::SelectCurrent );
4568 // ============================================================== clear
4569 void EdgeAssocDialog::clear()
4571 first_vex_le->clear();
4572 modelUnregister(first_vex_le);
4575 modelUnregister(edges_lw);
4579 single_edge_le->clear();
4580 modelUnregister(single_edge_le);
4582 single_line_le->clear();
4583 modelUnregister(single_line_le);
4585 modelUnregister(this);
4588 // ============================================================== onWindowActivated
4589 void EdgeAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4591 QString vmType = vm->getType();
4592 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4594 if (single_rb->isChecked())
4595 single_edge_le->setFocus();
4596 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le )
4597 edges_lw->setFocus();
4599 else if ( vmType == OCCViewer_Viewer::Type() ){
4600 if (single_rb->isChecked())
4601 single_line_le->setFocus();
4602 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le)
4603 lines_lw->setFocus();
4607 // ============================================================== apply
4608 bool EdgeAssocDialog::apply(QModelIndex& result)
4610 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4613 bool assocOk = false;
4615 PatternDataModel* patternDataModel = getPatternDataModel();
4616 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4617 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4619 QModelIndex iEdge, iGeomEdge;
4620 QModelIndexList iEdges;
4621 QListWidgetItem* item = NULL;
4622 QList<DocumentModel::GeomObj> assocs;
4623 DocumentModel::GeomObj aLine;
4624 HEXA_NS::SubShape* ssh;
4625 HEXA_NS::EdgeShape* sh;
4626 HEXA_NS::NewShapes shapes;
4627 HEXA_NS::IntVector subIds;
4629 QModelIndexList edges, lines;
4631 if (single_rb->isChecked()){ //Single edge and/or line association
4633 iEdge = patternDataModel->mapToSource( _index[single_edge_le] );
4634 if ( !iEdge.isValid() || myLine == NULL)
4636 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4639 id = myLine->shapeName+","+myLine->subId;
4640 ssh = getDocumentModel()->getGeomPtr(id);
4641 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
4642 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
4643 if (!iGeomEdge.isValid())
4645 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4648 assocOk = getDocumentModel()->addEdgeAssociation(iEdge, iGeomEdge, pstart_spb->value(), pend_spb->value());
4649 edges << _index[single_edge_le];
4652 else { //Multiple edge and/or line association
4655 iEdges = getIndexList(edges_lw, true);
4656 int nbLines = lines_lw->count();
4657 if (iEdges.count() == 0 || nbLines == 0)
4659 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4662 edges = getIndexList(edges_lw, false);
4664 for (int r = 0; r < nbLines; ++r){
4665 item = lines_lw->item(r);
4666 aLine = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4667 id = aLine.shapeName+","+aLine.subId;
4668 ssh = getDocumentModel()->getGeomPtr(id);
4669 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
4672 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4675 shapes.push_back(sh->getParentShape());
4676 subIds.push_back(sh->getIdent());
4677 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
4678 if (iGeomEdge.isValid())
4682 if ( close_cb->isChecked() ){ //closed line
4683 QModelIndex iFirstVertex = patternDataModel->mapToSource( _index[first_vex_le] );
4684 if ( !iFirstVertex.isValid() )
4686 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4689 bool inv = inverse_cb->isChecked();
4690 assocOk = getDocumentModel()->associateClosedLine( iFirstVertex, iEdges, shapes, subIds, pstart_spb->value(), inv );
4694 assocOk = getDocumentModel()->associateOpenedLine( iEdges, shapes, subIds, pstart_spb->value(), pend_spb->value() );
4698 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) + "\n" + getErrorMsg() );
4702 // highlight associated items in the trees
4703 pdsm->unhighlightTreeItems();
4704 pgsm->unhighlightTreeItems();
4705 pdsm->highlightTreeItems(edges);
4706 pgsm->highlightTreeItems(lines);
4708 // highlight associated items in the views
4709 highlightSelectedAssocs();
4714 // ------------------------- QuadAssocDialog ----------------------------------
4715 // ============================================================== Constructeur
4716 QuadAssocDialog::QuadAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4717 HexaBaseDialog(parent, editmode, f)
4719 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-face-or-a-shell-of-the-geometry";
4721 _initWidget(editmode);
4724 // ============================================================== Destructeur
4725 QuadAssocDialog::~QuadAssocDialog()
4727 disconnect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
4728 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(addFace()) );
4729 delete _delFaceShortcut;
4732 // ============================================================== close
4733 void QuadAssocDialog::close()
4735 HEXABLOCKGUI::assocInProgress = false;
4736 HexaBaseDialog::close();
4739 // ============================================================== _initInputWidget
4740 void QuadAssocDialog::_initInputWidget( Mode editmode )
4743 QValidator *validator = new QRegExpValidator(rx, this);
4745 quad_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
4746 quad_le->installEventFilter(this);
4747 quad_le->setValidator( validator );
4750 faces_lw->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
4751 faces_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
4752 faces_lw->installEventFilter(this);
4753 _delFaceShortcut = new QShortcut( QKeySequence(Qt::Key_X/*Qt::Key_Delete*/), faces_lw );
4754 _delFaceShortcut->setContext( Qt::WidgetShortcut );
4756 quad_le->setReadOnly(true);
4758 connect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
4759 connect( faces_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4762 // ============================================================== getAssocsVTK
4764 * Returns elements currently being associated in vtk side
4766 QModelIndexList QuadAssocDialog::getAssocsVTK()
4768 QModelIndexList assocs;
4772 QVariant v = quad_le->property("QModelIndex");
4775 assocs << v.value<QModelIndex>();
4779 // ============================================================== getAssocsGEOM
4781 * Returns elements currently being associated in geom side
4783 QMultiMap<QString, int> QuadAssocDialog::getAssocsGEOM()
4785 QMultiMap<QString, int> assocs;
4786 QListWidgetItem* item = NULL;
4787 DocumentModel::GeomObj geomObj;
4789 //ListWidget content
4790 unsigned int nbFaces = faces_lw->count();
4791 for ( int r = 0; r < nbFaces; ++r){
4792 item = faces_lw->item(r);
4793 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4794 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4799 // ============================================================== selectElementOfGeom
4800 /*Highlight in the OCC view selected elements in a listwidget,
4801 * or an element in a line edit.*/
4803 void QuadAssocDialog::selectElementOfGeom()
4805 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4806 if ( !currentListWidget )
4810 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4811 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4812 pgsm->clearSelection();
4813 if (sel.count() == 0)
4815 QListWidgetItem *item = sel[0];
4816 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
4817 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4818 if ( index.isValid() )
4819 pgsm->select( index, QItemSelectionModel::SelectCurrent );
4822 void QuadAssocDialog::clear()
4825 modelUnregister(quad_le);
4829 modelUnregister(this);
4832 // ============================================================== onWindowActivated
4833 void QuadAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4835 QString vmType = vm->getType();
4836 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4837 quad_le->setFocus();
4838 else if ( vmType == OCCViewer_Viewer::Type() ){
4839 faces_lw->setFocus();
4843 // ============================================================== deleteFaceItem
4844 void QuadAssocDialog::deleteFaceItem()
4846 delete faces_lw->currentItem();
4849 // ============================================================== apply
4850 bool QuadAssocDialog::apply(QModelIndex& result)
4852 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4855 PatternDataModel* patternDataModel = getPatternDataModel();
4856 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4857 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4860 QModelIndex iQuad, iGeomFace;
4861 HEXA_NS::SubShape* ssh;
4862 HEXA_NS::FaceShape* sh;
4866 iQuad = patternDataModel->mapToSource( _index[quad_le] );
4869 QListWidgetItem* item = NULL;
4870 DocumentModel::GeomObj aFace;
4871 QModelIndexList quads, faces;
4872 int nbFaces = faces_lw->count();
4873 for ( int r = 0; r < nbFaces; ++r ){
4874 item = faces_lw->item(r);
4875 aFace = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4876 id = aFace.shapeName+","+aFace.subId;
4877 ssh = getDocumentModel()->getGeomPtr(id);
4878 sh = dynamic_cast<HEXA_NS::FaceShape*>(ssh);
4881 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) );
4884 iGeomFace = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
4885 if (!getDocumentModel()->addQuadAssociation(iQuad, iGeomFace))
4887 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) + "\n" + getErrorMsg() );
4890 else if (iGeomFace.isValid())
4895 if (iQuad.isValid())
4896 quads << _index[quad_le];
4898 // highlight associated items in the trees
4899 pdsm->highlightTreeItems(quads);
4900 pgsm->highlightTreeItems(faces);
4902 // highlight associated items in the views
4903 highlightSelectedAssocs();
4908 // ------------------------- GroupDialog ----------------------------------
4909 // ============================================================== Constructeur
4910 GroupDialog::GroupDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4911 HexaBaseDialog(parent, editmode, f),
4914 _helpFileName = "gui_groups.html#add-group";
4916 _initWidget(editmode);
4917 // setFocusProxy( name_le/*eltBase_lw */);
4919 if ( editmode == NEW_MODE ){
4920 setWindowTitle( tr("Group Construction") );
4921 } else if ( editmode == UPDATE_MODE ){
4922 setWindowTitle( tr("Group Modification") );
4923 } else if ( editmode == INFO_MODE ){
4924 setWindowTitle( tr("Group Information") );
4928 // ============================================================== Destructeur
4929 GroupDialog::~GroupDialog()
4933 // ============================================================== getAssocsVTK
4935 * Returns elements currently being associated in vtk side
4937 QModelIndexList GroupDialog::getAssocsVTK()
4939 QModelIndexList assocs;
4941 QListWidgetItem* item = NULL;
4942 if (getPatternDataSelectionModel() == NULL) return assocs;
4943 //ListWidget content
4944 const PatternDataModel* patternDataModel = getPatternDataModel();
4945 if ( !patternDataModel ) return assocs;
4946 int nbElts = eltBase_lw->count();
4947 for ( int r = 0; r < nbElts; ++r){
4948 item = eltBase_lw->item(r);
4949 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4950 if ( iItem.isValid() ) assocs << iItem;
4955 // ============================================================== _initInputWidget
4956 void GroupDialog::_initInputWidget( Mode editmode )
4958 installEventFilter(this);
4959 name_le->installEventFilter(this);
4962 strKind[ HEXA_NS::HexaCell ] = "HexaCell";
4963 strKind[ HEXA_NS::QuadCell ] = "QuadCell";
4964 strKind[ HEXA_NS::EdgeCell ] = "EdgeCell";
4965 strKind[ HEXA_NS::HexaNode ] = "HexaNode";
4966 strKind[ HEXA_NS::QuadNode ] = "QuadNode";
4967 strKind[ HEXA_NS::EdgeNode ] = "EdgeNode";
4968 strKind[ HEXA_NS::VertexNode ] = "VertexNode";
4970 QMap<HEXA_NS::EnumGroup, QString>::ConstIterator iKind;
4971 for( iKind = strKind.constBegin(); iKind != strKind.constEnd(); ++iKind )
4972 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
4974 onKindChanged( kind_cb->currentIndex() );
4975 eltBase_lw->installEventFilter(this);
4977 if ( editmode != INFO_MODE ){
4978 QShortcut* delEltShortcut = new QShortcut( QKeySequence(Qt::Key_X), eltBase_lw );
4979 delEltShortcut->setContext( Qt::WidgetShortcut );
4980 connect(delEltShortcut, SIGNAL(activated()), this, SLOT(removeEltBase()));
4981 connect(kind_cb, SIGNAL(activated(int)), this, SLOT(onKindChanged(int)) );
4984 if ( editmode == INFO_MODE)
4986 name_le->setReadOnly(true);
4987 kind_cb->setEnabled(false);
4990 connect(eltBase_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
4993 // ============================================================== clear
4994 void GroupDialog::clear()
4998 eltBase_lw->clear();
4999 modelUnregister(eltBase_lw);
5001 modelUnregister(this);
5004 // ============================================================== onKindChanged
5005 void GroupDialog::onKindChanged(int index)
5008 switch ( kind_cb->itemData(index).toInt() ){
5009 case HEXA_NS::HexaCell:
5010 case HEXA_NS::HexaNode:
5011 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(HEXA_TREE));
5014 case HEXA_NS::QuadCell:
5015 case HEXA_NS::QuadNode:
5016 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5019 case HEXA_NS::EdgeCell:
5020 case HEXA_NS::EdgeNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
5023 case HEXA_NS::VertexNode:
5024 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
5027 default:Q_ASSERT(false);
5029 eltBase_lw->clear();
5030 eltBase_lw->setFocus();
5033 // ============================================================== setValue
5034 void GroupDialog::setValue(HEXA_NS::Group* g)
5037 name_le->setText( g->getName() );
5041 kind_cb->addItem ( strKind[g->getKind()], QVariant( g->getKind() ) );
5044 HEXA_NS::EltBase* eltBase = NULL;
5045 QListWidgetItem* item = NULL;
5046 QModelIndex iEltBase;
5047 QList<QStandardItem *> eltBaseItems;
5050 if ( !getPatternDataSelectionModel() ) return;
5051 if ( !getGroupsSelectionModel() ) return;
5053 QModelIndex iGroup = getGroupsSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(g) );
5054 name_le->setProperty( "QModelIndex", QVariant::fromValue(iGroup) );
5057 int nbElts = g->countElement();
5058 for ( int nr = 0; nr < nbElts; ++nr ){
5059 eltBase = g->getElement( nr );
5060 switch ( g->getKind() ){
5061 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: v = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
5062 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: v = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
5063 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: v = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
5064 case HEXA_NS::VertexNode: v = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
5066 iEltBase = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, v);
5067 if ( iEltBase.isValid() ){
5068 item = new QListWidgetItem( eltBase->getName() );
5069 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iEltBase) );
5070 item->setData(LW_DATA_ROLE, iEltBase.data(HEXA_DATA_ROLE));
5071 eltBase_lw->addItem( item );
5077 // ============================================================== getValue
5078 HEXA_NS::Group* GroupDialog::getValue()
5083 // ============================================================== removeEltBase
5084 void GroupDialog::removeEltBase()
5086 QListWidgetItem *item = eltBase_lw->currentItem();
5089 int r = eltBase_lw->row(item);
5090 eltBase_lw->takeItem(r);
5096 // ============================================================== apply
5097 bool GroupDialog::apply(QModelIndex& result)
5099 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5102 if ( !getDocumentModel() ) return false;
5103 const PatternDataModel* patternDataModel = getPatternDataModel();
5104 const GroupsModel* groupsModel = getGroupsModel();
5105 if (patternDataModel == NULL || groupsModel == NULL) return false;
5107 QString grpName = name_le->text();
5108 DocumentModel::Group grpKind = static_cast<DocumentModel::Group>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5110 if ( _value == NULL ){ // create group
5111 iGrp = getDocumentModel()->addGroup( grpName, grpKind );
5113 QModelIndexList iGrps = getDocumentModel()->match(
5114 getDocumentModel()->index(0, 0),
5116 QVariant::fromValue( _value ),
5118 Qt::MatchRecursive );
5119 if ( !iGrps.isEmpty() )
5124 if ( !iGrp.isValid() ){
5125 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD GROUP" ) + "\n" + getErrorMsg() );
5129 //fill it and select it
5130 QModelIndex iEltBase;
5131 QListWidgetItem* item = NULL;
5132 bool eltAdded = false;
5133 getDocumentModel()->clearGroupElement(iGrp);
5134 int nbElts = eltBase_lw->count();
5135 for ( int r = 0; r < nbElts; ++r){
5136 item = eltBase_lw->item(r);
5137 iEltBase = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5138 if ( iEltBase.isValid() )
5139 eltAdded = getDocumentModel()->addGroupElement( iGrp, iEltBase );
5142 QString newName = name_le->text();
5143 if ( !newName.isEmpty() )
5144 getDocumentModel()->setName( iGrp, newName );
5146 HEXA_NS::Group* hGroup = getDocumentModel()->data(iGrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
5149 QString groupName = QString::fromStdString(hGroup->getNextName());
5150 name_le->setText(groupName);
5153 result = groupsModel->mapFromSource(iGrp);
5158 // ------------------------- LawDialog ----------------------------------
5159 // ============================================================== Constructeur
5161 LawDialog::LawDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5162 : HexaBaseDialog(parent, editmode, f),
5165 _helpFileName = "gui_discret_law.html#add-law";
5167 _initWidget(editmode);
5168 if ( editmode == NEW_MODE ){
5169 setWindowTitle( tr("Law Construction") );
5170 } else if ( editmode == UPDATE_MODE ){
5171 setWindowTitle( tr("Law Modification") );
5173 else if ( editmode == INFO_MODE){
5174 setWindowTitle( tr("Law Information") );
5178 // ============================================================== Destructeur
5179 LawDialog::~LawDialog()
5183 // ============================================================== _initInputWidget
5184 void LawDialog::_initInputWidget( Mode editmode )
5188 // setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5189 installEventFilter(this);
5191 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5192 name_le->installEventFilter(this);
5195 strKind[ HEXA_NS::Uniform ] = "Uniform";
5196 strKind[ HEXA_NS::Arithmetic ] = "Arithmetic";
5197 strKind[ HEXA_NS::Geometric ] = "Geometric";
5200 QMap<HEXA_NS::KindLaw, QString>::ConstIterator iKind, iEnd;
5201 for( iKind = strKind.constBegin(), iEnd = strKind.constEnd(); iKind != iEnd; ++iKind )
5202 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5204 if (editmode == INFO_MODE)
5206 name_le->setReadOnly(true);
5207 nb_nodes_spb->setReadOnly(true);
5208 coeff_spb->setReadOnly(true);
5209 kind_cb->setEnabled(false);
5213 // ============================================================== clear
5214 void LawDialog::clear()
5218 modelUnregister(this);
5221 // ============================================================== setValue
5222 void LawDialog::setValue(HEXA_NS::Law* l)
5225 name_le->setText( l->getName() );
5227 nb_nodes_spb->setValue( l->getNodes() );
5228 coeff_spb->setValue( l->getCoefficient() );
5230 HEXA_NS::KindLaw k = l->getKind();
5231 kind_cb->setCurrentIndex( kind_cb->findData(k) );
5236 // ============================================================== getValue
5237 HEXA_NS::Law* LawDialog::getValue()
5242 // ============================================================== apply
5243 bool LawDialog::apply(QModelIndex& result)
5245 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5248 if ( !getDocumentModel() ) return false;
5250 const MeshModel* meshModel = getMeshModel();
5251 if (meshModel == NULL) return false;
5253 QString lawName = name_le->text();
5254 int nbnodes = nb_nodes_spb->value();
5255 double coeff = coeff_spb->value();
5256 DocumentModel::KindLaw lawKind = static_cast<DocumentModel::KindLaw>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5259 if ( _value == NULL ){ // create Law
5260 iLaw = getDocumentModel()->addLaw( lawName, nbnodes );
5262 QModelIndexList iLaws = getDocumentModel()->match(
5263 getDocumentModel()->index(0, 0),
5265 QVariant::fromValue( _value ),
5267 Qt::MatchRecursive );
5268 if ( !iLaws.isEmpty() )
5272 if ( !iLaw.isValid() ){
5273 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5276 //fill it and select it
5277 bool setOk = getDocumentModel()->setLaw( iLaw, nbnodes, coeff, lawKind );
5279 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5283 QString newName = name_le->text();
5284 if ( !newName.isEmpty() )/*{*/
5285 getDocumentModel()->setName( iLaw, newName );
5287 HEXA_NS::Law* hLaw = getDocumentModel()->data(iLaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
5291 name_le->setText(hLaw->getNextName(buffer));
5295 result = meshModel->mapFromSource(iLaw);
5300 // ------------------------- PropagationDialog ----------------------------------
5301 // ============================================================== Constructeur
5302 PropagationDialog::PropagationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5303 : HexaBaseDialog(parent, editmode, f),
5306 _helpFileName = "gui_propag.html";
5308 _initWidget(editmode);
5310 if ( editmode == INFO_MODE ){
5311 setWindowTitle( tr("Propagation Information") );
5314 } else if ( editmode == UPDATE_MODE ){
5315 setWindowTitle( tr("Propagation Modification") );
5318 } else if ( editmode == NEW_MODE ){
5319 setWindowTitle( tr("Propagation(s) Setting") );
5323 // ============================================================== Destructeur
5324 PropagationDialog::~PropagationDialog()
5328 // ============================================================== _initInputWidget
5329 void PropagationDialog::_initInputWidget( Mode editmode )
5332 QValidator *validator = new QRegExpValidator(rx, this);
5334 installEventFilter(this);
5337 law_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5338 law_le->installEventFilter(this);
5339 law_le->setValidator( validator );
5341 propagations_lw->setProperty( "HexaWidgetType", QVariant::fromValue(PROPAGATION_TREE) );
5342 propagations_lw->installEventFilter(this);
5344 QShortcut* delPropagationShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), propagations_lw);
5345 delPropagationShortcut->setContext( Qt::WidgetShortcut );
5347 law_le->setReadOnly(true);
5349 if ( editmode == INFO_MODE)
5350 way_cb->setEnabled(false);
5352 connect( delPropagationShortcut, SIGNAL(activated()), this, SLOT(deletePropagationItem()) );
5353 connect( propagations_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
5356 // ============================================================== clear
5357 void PropagationDialog::clear()
5359 propagations_lw->clear();
5360 modelUnregister(propagations_lw);
5363 modelUnregister(law_le);
5365 modelUnregister(this);
5368 // ============================================================== deletePropagationItem
5369 void PropagationDialog::deletePropagationItem()
5371 delete propagations_lw->currentItem();
5374 // ============================================================== setValue
5375 void PropagationDialog::setValue(HEXA_NS::Propagation* p)
5377 if (getMeshSelectionModel() == NULL) return;
5378 HEXA_NS::Law* l = p->getLaw();
5379 bool way = p->getWay();
5382 QModelIndex ip = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
5383 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(ip) );
5385 // law on propagation
5387 law_le->setText( l->getName() );
5388 QModelIndex il = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(l) );
5389 law_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(il) );
5392 // way of propagation
5393 way_cb->setChecked(way);
5398 // ============================================================== selectElementOfModel
5400 /*Selects in the model (treeview) elements selected in a listwidget,
5401 * or an element in a line edit.*/
5403 void PropagationDialog::selectElementOfModel()
5405 if (!getMeshSelectionModel()) return;
5407 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5408 if ( !currentListWidget ) return;
5410 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5412 getMeshSelectionModel()->clearSelection();
5413 foreach ( QListWidgetItem *item, sel ){
5414 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
5415 index = getMeshSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5416 if ( index.isValid() )
5417 getMeshSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
5421 // ============================================================== getValue
5422 HEXA_NS::Propagation* PropagationDialog::getValue()
5427 // ============================================================== apply
5428 bool PropagationDialog::apply(QModelIndex& result)
5430 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5434 if ( !getDocumentModel() ) return false;
5435 const MeshModel* meshModel = getMeshModel();
5436 if (meshModel == NULL) return false;
5438 bool way = way_cb->isChecked();
5439 QListWidgetItem* item = NULL;
5441 QModelIndex iPropagation;
5442 QModelIndex iLaw = meshModel->mapToSource( law_le->property("QModelIndex").value<QModelIndex>() );
5443 if (!iLaw.isValid() ){
5444 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5448 int nbPropagations = propagations_lw->count();
5449 for (int r = 0; r < nbPropagations; ++r){
5450 item = propagations_lw->item(r);
5451 iPropagation = meshModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5452 if ( !iPropagation.isValid() ){
5453 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5457 //fill it and select it
5458 isOk = getDocumentModel()->setPropagation( iPropagation, iLaw, way );
5460 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) + "\n" + getErrorMsg() );
5464 result = meshModel->mapFromSource(iPropagation);
5470 // ------------------------- ComputeMeshDialog ----------------------------------
5471 // ============================================================== Constructeur
5472 ComputeMeshDialog::ComputeMeshDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5473 HexaBaseDialog(parent, editmode, f)
5475 _helpFileName = "gui_mesh.html";
5476 setWindowTitle( tr("Compute mesh") );
5477 QVBoxLayout* layout = new QVBoxLayout;
5480 QHBoxLayout* up = new QHBoxLayout;
5481 QHBoxLayout* down = new QHBoxLayout;
5483 layout->addLayout(up);
5484 layout->addLayout(down);
5486 QVBoxLayout* vlg = new QVBoxLayout;
5487 QVBoxLayout* vld = new QVBoxLayout;
5492 vlg->addWidget(new QLabel("Name"));
5493 vlg->addWidget(new QLabel("Dimension"));
5494 vlg->addWidget(new QLabel("Container"));
5496 _name = new QLineEdit("Mesh");
5497 _dim = new QSpinBox();
5498 _fact = new QLineEdit("FactoryServer");
5500 vld->addWidget(_name);
5501 vld->addWidget(_dim);
5502 vld->addWidget(_fact);
5504 _dim->setRange(1, 3);
5507 _initWidget(editmode);
5510 // ============================================================== Destructeur
5511 ComputeMeshDialog::~ComputeMeshDialog()
5515 // ============================================================== _initInputWidget
5516 void ComputeMeshDialog::_initInputWidget( Mode editmode )
5520 // ============================================================== setDocumentModel
5521 void ComputeMeshDialog::setDocumentModel(DocumentModel* m)
5523 if (m == NULL) return;
5524 _name->setText(m->getName());
5527 // ============================================================== clear
5528 void ComputeMeshDialog::clear()
5530 modelUnregister(this);
5533 // ============================================================== apply
5534 bool ComputeMeshDialog::apply(QModelIndex& result)
5536 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5539 if (getDocumentModel() == NULL) return false;
5540 QString command = QString("import hexablock ; %1 = hexablock.mesh(\"%2\", \"%1\", %3, \"%4\")")
5541 .arg( _name->text() )
5542 .arg( getDocumentModel()->getName() )
5543 .arg( _dim->value() )
5544 .arg( _fact->text() );
5546 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
5547 PyConsole_Console* pyConsole = app->pythonConsole();
5550 pyConsole->exec( command );
5557 // ------------------------- ReplaceHexaDialog ----------------------------------
5558 // ============================================================== Constructeur
5559 ReplaceHexaDialog::ReplaceHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5560 HexaBaseDialog(parent, editmode, f)
5562 _helpFileName = "gui_replace_hexa.html";
5564 _initWidget(editmode);
5567 // ============================================================== Destructeur
5568 ReplaceHexaDialog::~ReplaceHexaDialog()
5572 // ============================================================== getAssocsVTK
5574 * Returns elements currently associated to vtk
5576 QModelIndexList ReplaceHexaDialog::getAssocsVTK()
5578 QModelIndexList assocs;
5580 QListWidgetItem* item = NULL;
5582 //ListWidget content
5583 const PatternDataModel* patternDataModel = getPatternDataModel();
5584 if ( !patternDataModel ) return assocs;
5585 int nbQuads = quads_lw->count();
5586 for ( int r = 0; r < nbQuads; ++r ){
5587 item = quads_lw->item(r);
5588 // iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
5589 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5590 if ( iQuad.isValid() ) assocs << iQuad;
5595 // ============================================================== _initInputWidget
5596 void ReplaceHexaDialog::_initInputWidget( Mode editmode )
5600 installEventFilter(this);
5602 c1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5603 c2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5604 c3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5606 p1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5607 p2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5608 p3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5610 c1_le->installEventFilter(this);
5611 c2_le->installEventFilter(this);
5612 c3_le->installEventFilter(this);
5614 p1_le->installEventFilter(this);
5615 p2_le->installEventFilter(this);
5616 p3_le->installEventFilter(this);
5618 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5619 quads_lw->installEventFilter(this);
5621 if ( editmode == NEW_MODE ){
5622 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5623 delQuadShortcut->setContext( Qt::WidgetShortcut );
5625 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()) );
5626 connect( quads_lw, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5629 c1_le->setReadOnly(true);
5630 c2_le->setReadOnly(true);
5631 c3_le->setReadOnly(true);
5633 p1_le->setReadOnly(true);
5634 p2_le->setReadOnly(true);
5635 p3_le->setReadOnly(true);
5637 connect(quads_lw, SIGNAL(itemSelectionChanged()),
5638 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5641 // ============================================================== clear
5642 void ReplaceHexaDialog::clear()
5645 modelUnregister(quads_lw);
5648 modelUnregister(p1_le);
5651 modelUnregister(p2_le);
5654 modelUnregister(p3_le);
5657 modelUnregister(c1_le);
5660 modelUnregister(c2_le);
5663 modelUnregister(c3_le);
5665 modelUnregister(this);
5668 // ============================================================== updateButtonBox
5669 void ReplaceHexaDialog::updateButtonBox()
5671 int nbQuad = quads_lw->count();
5674 _applyButton->setEnabled(true);
5676 _applyButton->setEnabled(false);
5680 // ============================================================== deleteQuadItem
5681 void ReplaceHexaDialog::deleteQuadItem()
5683 delete quads_lw->currentItem();
5687 // ============================================================== apply
5688 bool ReplaceHexaDialog::apply(QModelIndex& result)
5690 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5693 if ( !getDocumentModel() ) return false;
5694 const PatternDataModel* patternDataModel = getPatternDataModel();
5695 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
5696 if ( !patternDataModel || !patternBuilderModel) return false;
5698 QModelIndex ielts; //result
5700 QListWidgetItem* item = NULL;
5701 QModelIndexList iquads;
5703 int nbQuads = quads_lw->count();
5704 for ( int r = 0; r < nbQuads; ++r){
5705 item = quads_lw->item(r);
5706 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5707 if ( iquad.isValid() )
5711 QModelIndex ic1 = patternDataModel->mapToSource( _index[c1_le] );
5712 QModelIndex ic2 = patternDataModel->mapToSource( _index[c2_le] );
5713 QModelIndex ic3 = patternDataModel->mapToSource( _index[c3_le] );
5715 QModelIndex ip1 = patternDataModel->mapToSource( _index[p1_le] );
5716 QModelIndex ip2 = patternDataModel->mapToSource( _index[p2_le] );
5717 QModelIndex ip3 = patternDataModel->mapToSource( _index[p3_le] );
5719 if ( ic1.isValid() && ic2.isValid() && ic3.isValid()
5720 && ip1.isValid() && ip2.isValid() && ip3.isValid() ){
5721 ielts = getDocumentModel()->replace( iquads,
5727 if ( !ielts.isValid() ){
5728 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REPLACE HEXA" ) + "\n" + getErrorMsg() );
5731 _value = ielts.model()->data(ielts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
5732 result = patternBuilderModel->mapFromSource(ielts);
5734 //update the list (indexes)
5735 for ( int r = 0; r < nbQuads; ++r ){
5736 item = quads_lw->item(r);
5737 iquad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5738 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iquad) );
5739 item->setData(LW_DATA_ROLE, iquad.data(HEXA_DATA_ROLE));
5745 // ------------------------- QuadRevolutionDialog ----------------------------------
5746 // ============================================================== Constructeur
5748 QuadRevolutionDialog::QuadRevolutionDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5749 HexaBaseDialog(parent, editmode, f)
5751 _helpFileName = "gui_quad_revolution.html";
5753 _initWidget(editmode);
5754 revolutionUni_rb->click();
5757 // ============================================================== getAssocsVTK
5759 * Returns elements currently associated to vtk
5761 QModelIndexList QuadRevolutionDialog::getAssocsVTK()
5763 QModelIndexList assocs;
5765 QListWidgetItem* item = NULL;
5766 if (getPatternDataSelectionModel() == NULL) return assocs;
5768 //ListWidget content
5769 const PatternDataModel* patternDataModel = getPatternDataModel();
5770 if ( !patternDataModel ) return assocs;
5771 int nbQuads = quads_lw->count();
5772 for ( int r = 0; r < nbQuads; ++r ){
5773 item = quads_lw->item(r);
5774 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5775 if ( iQuad.isValid() )
5781 // ============================================================== Destructeur
5782 QuadRevolutionDialog::~QuadRevolutionDialog()
5786 // ============================================================== _initInputWidget
5787 void QuadRevolutionDialog::_initInputWidget( Mode editmode )
5789 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5790 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5791 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
5793 installEventFilter(this);
5794 quads_lw->installEventFilter(this);
5795 center_le->installEventFilter(this);
5796 axis_le->installEventFilter(this);
5798 center_le->setReadOnly(true);
5799 axis_le->setReadOnly(true);
5801 angles_lw->setItemDelegate( new HexaAngleDoubleSpinBoxDelegate(angles_lw) );
5802 angles_lw->setEditTriggers( QAbstractItemView::DoubleClicked );
5804 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5805 delQuadShortcut->setContext( Qt::WidgetShortcut );
5806 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(delQuadItem()) );
5807 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()));
5808 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()));
5810 connect(quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5813 // ============================================================== clear
5814 void QuadRevolutionDialog::clear()
5817 modelUnregister(quads_lw);
5820 modelUnregister(center_le);
5823 modelUnregister(axis_le);
5825 modelUnregister(this);
5828 // ============================================================== addAngleItem
5829 void QuadRevolutionDialog::addAngleItem() //CS_TODO
5831 QListWidgetItem* previousItem = angles_lw->currentItem();
5832 QListWidgetItem* newItem = new QListWidgetItem();
5834 double defaultValue = 180.;
5836 defaultValue = previousItem->data(Qt::EditRole).toDouble();
5838 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
5839 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
5840 angles_lw->addItem(newItem);
5845 // ============================================================== delAngleItem
5846 void QuadRevolutionDialog::delAngleItem()
5848 delete angles_lw->currentItem();
5852 // ============================================================== delQuadItem
5853 void QuadRevolutionDialog::delQuadItem()
5855 delete quads_lw->currentItem();
5859 // ============================================================== apply
5860 bool QuadRevolutionDialog::apply(QModelIndex& result)
5862 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5865 DocumentModel* docModel = getDocumentModel();
5866 PatternDataModel* patternDataModel = getPatternDataModel();
5867 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
5869 QListWidgetItem* item = NULL;
5871 QModelIndexList istartquads;
5873 int nbQuads = quads_lw->count();
5874 for ( int r = 0; r < nbQuads; ++r){
5875 item = quads_lw->item(r);
5876 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5877 if ( iquad.isValid() )
5878 istartquads << iquad;
5881 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
5882 QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
5883 int angle = angle_spb->value();
5884 int nbre = nbre_spb->value();
5886 vector<double> angles;
5887 int nbAngles = angles_lw->count();
5888 for ( int r = 0; r < nbAngles; ++r){
5889 item = angles_lw->item(r);
5890 angles.push_back(item->data(Qt::EditRole).toDouble());
5893 QModelIndex iElts; //result
5894 if (nbQuads == 1 && istartquads[0].isValid() && icenter.isValid() && iaxis.isValid())
5896 if (revolutionUni_rb->isChecked())
5897 iElts = docModel->revolutionQuadUni(istartquads[0], icenter, iaxis, angle, nbre);
5898 else if (revolution_rb->isChecked())
5899 iElts = docModel->revolutionQuad(istartquads[0], icenter, iaxis, angles);
5901 else if (nbQuads > 1 && icenter.isValid() && iaxis.isValid())
5903 if (revolutionUni_rb->isChecked())
5904 iElts = docModel->revolutionQuadsUni(istartquads, icenter, iaxis, angle, nbre);
5905 else if (revolution_rb->isChecked())
5906 iElts = docModel->revolutionQuads(istartquads, icenter, iaxis, angles);
5909 if ( !iElts.isValid() ){
5910 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD REVOLUTION" ) + "\n" + getErrorMsg() );
5913 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
5914 result = patternBuilderModel->mapFromSource(iElts);
5919 // ------------------------- MakeHemiSphereDialog ----------------------------------
5920 // ============================================================== Constructeur
5921 MakeHemiSphereDialog::MakeHemiSphereDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5922 HexaBaseDialog(parent, editmode, f)
5924 _helpFileName = "gui_hemisphere.html";
5926 _initWidget(editmode);
5929 connect( sphereTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5930 connect( sphereUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5931 connect( sphere2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5932 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
5933 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
5935 connect( sphericalTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5936 connect( sphericalUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5937 connect( spherical2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5938 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
5939 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
5941 connect( rindTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5942 connect( rindUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5943 connect( rind2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5944 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
5945 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
5948 // ============================================================== Destructeur
5949 MakeHemiSphereDialog::~MakeHemiSphereDialog()
5953 // ============================================================== _initInputWidget
5954 void MakeHemiSphereDialog::_initInputWidget( Mode editmode )
5956 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5957 hole_axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
5958 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
5959 vplan_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5961 installEventFilter(this);
5962 center_le->installEventFilter(this);
5963 hole_axis_le->installEventFilter(this);
5964 base_le->installEventFilter(this);
5965 vplan_le->installEventFilter(this);
5967 center_le->setReadOnly(true);
5968 hole_axis_le->setReadOnly(true);
5969 base_le->setReadOnly(true);
5970 vplan_le->setReadOnly(true);
5972 radius_lw_1->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_1));
5973 radius_lw_1->setEditTriggers(QAbstractItemView::DoubleClicked);
5975 radius_lw_2->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_2));
5976 radius_lw_2->setEditTriggers(QAbstractItemView::DoubleClicked);
5978 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
5979 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
5981 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
5982 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
5984 connect( add_radius_pb_1, SIGNAL(clicked()), this, SLOT(addRadiusItem1()) );
5985 connect( del_radius_pb_1, SIGNAL(clicked()), this, SLOT(delRadiusItem1()) );
5987 connect( add_radius_pb_2, SIGNAL(clicked()), this, SLOT(addRadiusItem2()) );
5988 connect( del_radius_pb_2, SIGNAL(clicked()), this, SLOT(delRadiusItem2()) );
5990 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
5991 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
5993 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
5994 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
5997 // ============================================================== addRadiusItem
5998 void MakeHemiSphereDialog::addRadiusItem1()
6000 QListWidgetItem* previousItem = radius_lw_1->currentItem();
6001 QListWidgetItem* newItem = new QListWidgetItem();
6003 double defaultValue = 1.;
6005 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6007 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6008 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6009 radius_lw_1->addItem(newItem);
6012 // ============================================================== delRadiusItem
6013 void MakeHemiSphereDialog::delRadiusItem1()
6015 delete radius_lw_1->currentItem();
6018 // ============================================================== addRadiusItem
6019 void MakeHemiSphereDialog::addRadiusItem2()
6021 QListWidgetItem* previousItem = radius_lw_2->currentItem();
6022 QListWidgetItem* newItem = new QListWidgetItem();
6024 double defaultValue = 1.;
6026 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6028 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6029 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6030 radius_lw_2->addItem(newItem);
6033 // ============================================================== delRadiusItem
6034 void MakeHemiSphereDialog::delRadiusItem2()
6036 delete radius_lw_2->currentItem();
6039 // ============================================================== addAngleItem
6040 void MakeHemiSphereDialog::addAngleItem()
6042 QListWidgetItem* previousItem = angle_lw->currentItem();
6043 QListWidgetItem* newItem = new QListWidgetItem();
6045 double defaultValue = 180.;
6047 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6049 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6050 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6051 angle_lw->addItem(newItem);
6054 // ============================================================== delAngleItem
6055 void MakeHemiSphereDialog::delAngleItem()
6057 delete angle_lw->currentItem();
6060 // ============================================================== addHeightItem
6061 void MakeHemiSphereDialog::addHeightItem()
6063 QListWidgetItem* previousItem = height_lw->currentItem();
6064 QListWidgetItem* newItem = new QListWidgetItem();
6066 double defaultValue = 1.;
6068 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6070 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6071 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6072 height_lw->addItem(newItem);
6075 // ============================================================== delHeightItem
6076 void MakeHemiSphereDialog::delHeightItem()
6078 delete height_lw->currentItem();
6081 // ============================================================== updateHelpFileName
6082 void MakeHemiSphereDialog::updateHelpFileName()
6086 // ============================================================== clear
6087 void MakeHemiSphereDialog::clear()
6090 modelUnregister(center_le);
6092 hole_axis_le->clear();
6093 modelUnregister(hole_axis_le);
6096 modelUnregister(base_le);
6099 modelUnregister(vplan_le);
6101 modelUnregister(this);
6104 // ============================================================== apply
6105 bool MakeHemiSphereDialog::apply(QModelIndex& result)
6107 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6110 DocumentModel* docModel = getDocumentModel();
6111 PatternDataModel* patternDataModel = getPatternDataModel();
6112 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6115 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6116 QModelIndex ivplan = patternDataModel->mapToSource( _index[vplan_le] );
6117 QModelIndex ivecx = patternBuilderModel->mapToSource( _index[base_le] );
6118 QModelIndex ivecz = patternBuilderModel->mapToSource( _index[hole_axis_le] );
6120 double radhole = hole_rad_spb->value();
6121 double radext = sphere_radext_spb->value();
6122 double radint = sphere_radint_spb->value();
6123 double radang = radial_angle_spb->value();
6125 int crit = crit_spb->value();
6126 int nb = nbre_spb->value();
6127 int nrad = ngrid_rad_spb->value();
6128 int nang = ngrid_ang_spb->value();
6129 int nhaut = ngrid_height_spb->value();
6131 //radius, angles and heights collection
6132 QListWidgetItem* item = NULL;
6134 vector<double> radius1;
6135 vector<double> radius2;
6136 vector<double> angles;
6137 vector<double> heights;
6141 int nbAngles = angle_lw->count();
6142 for ( int r = 0; r < nbAngles; ++r){
6143 item = angle_lw->item(r);
6144 double itemValue = item->data(Qt::EditRole).toDouble();
6145 angles.push_back(itemValue);
6149 //radius1 collection
6150 int nbRadius = radius_lw_1->count();
6151 for ( int r = 0; r < nbRadius; ++r){
6152 item = radius_lw_1->item(r);
6153 radius1.push_back(item->data(Qt::EditRole).toDouble());
6156 //radius2 collection
6157 nbRadius = radius_lw_2->count();
6158 for ( int r = 0; r < nbRadius; ++r){
6159 item = radius_lw_2->item(r);
6160 radius2.push_back(item->data(Qt::EditRole).toDouble());
6163 //heights collection
6164 int nbHeight = height_lw->count();
6165 for ( int r = 0; r < nbHeight; ++r){
6166 item = height_lw->item(r);
6167 heights.push_back(item->data(Qt::EditRole).toDouble());
6170 if (sphere_rb->isChecked())
6172 if (sphereTop_rb->isChecked())
6173 iElts = docModel->makeSphereTop( nrad, nang, nhaut );
6174 else if (sphereUni_rb->isChecked())
6176 if (icenter.isValid() && ivplan.isValid() && ivecx.isValid() && ivecz.isValid())
6177 iElts = docModel->makeSphereUni(icenter, ivecx, ivecz, radhole, radext, radang,
6178 ivplan, nrad, nang, nhaut);
6180 else if (sphere2_rb->isChecked())
6184 SUIT_MessageBox::information( 0,
6186 tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6189 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6190 iElts = docModel->makeSphere(icenter, ivecx, ivecz, radius2, angles, heights);
6193 else if (spherical_rb->isChecked())
6195 if (sphericalTop_rb->isChecked())
6196 iElts = docModel->makeSphericalTop(nb, crit);
6197 else if (sphericalUni_rb->isChecked())
6199 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6200 iElts = docModel->makeSphericalUni(icenter, ivecx, ivecz, radhole, nb, crit);
6202 else if (spherical2_rb->isChecked())
6204 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6205 iElts = docModel->makeSpherical(icenter, ivecx, ivecz, radius1, crit);
6208 else if (rind_rb->isChecked())
6210 if (rindTop_rb->isChecked())
6211 iElts = docModel->makeRindTop(nrad, nang, nhaut);
6212 else if (rindUni_rb->isChecked())
6214 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid() && ivplan.isValid())
6215 iElts = docModel->makeRindUni(icenter, ivecx, ivecz,
6216 radhole, radint, radext, radang,
6217 ivplan, nrad, nang, nhaut);
6219 else if (rind2_rb->isChecked())
6223 SUIT_MessageBox::information( 0,
6225 tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6228 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6229 iElts = docModel->makeRind(icenter, ivecx, ivecz, radius2, angles, heights);
6233 if ( !iElts.isValid() ){
6234 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) + "\n" + getErrorMsg() );
6237 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6238 result = patternBuilderModel->mapFromSource(iElts);
6243 // ------------------------- ModelInfoDialog ----------------------------------
6244 ModelInfoDialog::ModelInfoDialog(QWidget* parent, Qt::WindowFlags wf):
6245 HexaBaseDialog(parent, INFO_MODE, wf)
6248 setWindowTitle(HEXABLOCKGUI::tr("MODEL_INFO"));
6251 void ModelInfoDialog::updateInfo()
6253 DocumentModel* docModel = getDocumentModel();
6254 if (docModel == NULL) return;
6257 model_name_le->setText(docModel->getName());
6259 //Nb of elements in the model
6260 total_vertices_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_VERTEX)));
6261 total_edges_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_EDGE)));
6262 total_quads_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_QUAD)));
6263 total_hexas_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_HEXA)));
6265 ///Nb of used elements in the model
6266 used_vertices_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_VERTEX)));
6267 used_edges_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_EDGE)));
6268 used_quads_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_QUAD)));
6269 used_hexas_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_HEXA)));
6271 //Nb of unused elements in the model
6272 unused_vertices_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_VERTEX)));
6273 unused_edges_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_EDGE)));
6274 unused_quads_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_QUAD)));
6275 unused_hexas_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_HEXA)));
6278 void ModelInfoDialog::showEvent( QShowEvent * event )
6281 QDialog::showEvent ( event );
6284 // ============================================================== hideEvent
6285 void ModelInfoDialog::hideEvent ( QHideEvent * event )
6287 QDialog::hideEvent( event );
6290 // ------------------------- AddShapeDialog ----------------------------------
6291 AddShapeDialog::AddShapeDialog(QWidget* parent, Mode editmode, Qt::WindowFlags wf):
6292 HexaBaseDialog(parent, editmode, wf)
6296 _initWidget(editmode);
6297 setWindowTitle(HEXABLOCKGUI::tr("ADD_SHAPE"));
6300 // ============================================================== Destructeur
6301 AddShapeDialog::~AddShapeDialog()
6303 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
6304 this, SLOT(onCurrentSelectionChanged()) );
6307 // ============================================================== close
6308 void AddShapeDialog::close()
6310 HEXABLOCKGUI::assocInProgress = false;
6311 HexaBaseDialog::close();
6314 // ============================================================== _initInputWidget
6315 void AddShapeDialog::_initInputWidget( Mode editmode )
6317 shape_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMSHAPE_TREE) );
6318 shape_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_SHAPE) );
6319 shape_le->installEventFilter(this);
6320 shape_le->setReadOnly(true);
6323 void AddShapeDialog::clear()
6326 shape_le->setProperty("GeomObj", QVariant());
6328 modelUnregister(this);
6331 // ============================================================== onCurrentSelectionChanged
6332 void AddShapeDialog::onCurrentSelectionChanged()
6334 SALOME_ListIO selectedObjects;
6335 HEXABLOCKGUI::currentDocGView->getSelected(selectedObjects);
6336 if (selectedObjects.IsEmpty())
6339 // * extract the TopoDS_Shape of the selected object
6340 TopoDS_Shape selectedTopoShape = GEOMBase::GetTopoFromSelection( selectedObjects );
6341 if (selectedTopoShape.IsNull())
6343 shape_le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(selectedTopoShape));
6345 // * extract the name of the selected shape
6347 GEOMBase::GetNameOfSelectedIObjects( selectedObjects, name, true );
6348 shape_le->setText(name);
6351 // ============================================================== onWindowActivated
6352 void AddShapeDialog::onWindowActivated(SUIT_ViewManager* vm)
6354 QString vmType = vm->getType();
6355 if ( vmType == OCCViewer_Viewer::Type() )
6356 shape_le->setFocus();
6359 // ============================================================== apply
6360 bool AddShapeDialog::apply(QModelIndex& result)
6363 QString shapeName = shape_le->text();
6364 QVariant v = shape_le->property("TopoDS_Shape");
6365 if ( !v.isValid() || shapeName.isEmpty())
6369 TopoDS_Shape shape = v.value<TopoDS_Shape>();
6373 assocOk = getDocumentModel()->addShape(shape, shapeName);
6377 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), HEXABLOCKGUI::tr("ADD_SHAPE_FAILED") + "\n" + getErrorMsg() );
6389 //***************************** OBSOLETE: A SUPPRIMER !!!! ************************************//
6391 // ============================================================== Constructeur
6392 CylinderDialog::CylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
6393 : HexaBaseDialog(parent, editmode, f),
6396 _helpFileName = "gui_cyl.html";
6398 _initWidget(editmode);
6400 if ( editmode == INFO_MODE ){
6401 setWindowTitle( tr("Cylinder Information") );
6405 // ============================================================== Destructeur
6406 CylinderDialog::~CylinderDialog()
6410 // ============================================================== _initInputWidget
6411 void CylinderDialog::_initInputWidget( Mode editmode )
6414 QValidator *validator = new QRegExpValidator(rx, this);
6416 installEventFilter(this);
6417 name_le->installEventFilter(this);
6419 vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6420 vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6422 vex_le->setValidator( validator );
6423 vec_le->setValidator( validator );
6425 vex_le->installEventFilter(this);
6426 vec_le->installEventFilter(this);
6428 vex_le->setReadOnly(true);
6429 vec_le->setReadOnly(true);
6431 if (editmode == INFO_MODE)
6433 name_le->setReadOnly(true);
6434 r_spb->setReadOnly(true);
6435 h_spb->setReadOnly(true);
6440 // ============================================================== clear
6441 void CylinderDialog::clear()
6446 modelUnregister(vex_le);
6449 modelUnregister(vec_le);
6454 modelUnregister(this);
6458 // ============================================================== setValue
6459 void CylinderDialog::setValue(HEXA_NS::Cylinder* c)
6461 HEXA_NS::Vertex* base = c->getBase();
6462 HEXA_NS::Vector* direction = c->getDirection();
6463 double r = c->getRadius();
6464 double h = c->getHeight();
6466 name_le->setText( c->getName() );
6467 vex_le->setText( base->getName() );
6468 vec_le->setText( direction->getName() );
6472 if ( getPatternDataSelectionModel() ){
6473 QModelIndex iCyl = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(c) );
6474 QModelIndex iBase = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(base) );
6475 QModelIndex iDirection = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(direction) );
6477 name_le->setProperty( "QModelIndex", QVariant::fromValue(iCyl) );
6478 vex_le->setProperty( "QModelIndex", QVariant::fromValue(iBase) );
6479 vec_le->setProperty( "QModelIndex", QVariant::fromValue(iDirection) );
6484 // ============================================================== getValue
6485 HEXA_NS::Cylinder* CylinderDialog::getValue()
6490 // ============================================================== apply
6491 bool CylinderDialog::apply(QModelIndex& result)
6493 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6496 if ( !getDocumentModel() ) return false;
6497 const PatternDataModel* patternDataModel = getPatternDataModel();
6498 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6499 if ( !patternDataModel || !patternBuilderModel) return false;
6502 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le] );
6503 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
6504 double r = r_spb->value();
6505 double h = h_spb->value();
6508 && ivec.isValid() ){
6509 iCyl = getDocumentModel()->addCylinder( ivex, ivec, r, h );
6512 if ( !iCyl.isValid() ){
6513 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD CYLINDER" ) );
6517 _value = iCyl.model()->data(iCyl, HEXA_DATA_ROLE).value<HEXA_NS::Cylinder *>();
6519 QString newName = name_le->text();
6520 if (!newName.isEmpty()) /*{*/
6521 getDocumentModel()->setName( iCyl, newName );
6523 //update the default name in the dialog box
6525 updateDefaultName(name_le, _value->getType());
6527 // to select/highlight result
6528 result = patternBuilderModel->mapFromSource(iCyl);
6533 //------------------------------- PipeDialog -----------------------------------
6535 // ============================================================== Constructeur
6537 PipeDialog::PipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
6538 : HexaBaseDialog(parent, editmode, f),
6541 _helpFileName = "gui_pipe.html";
6543 _initWidget(editmode);
6544 // setFocusProxy( vex_le );
6546 if ( editmode == INFO_MODE ){
6547 setWindowTitle( tr("Pipe Information") );
6552 // ============================================================== Destructeur
6553 PipeDialog::~PipeDialog()
6557 // ============================================================== _initInputWidget
6558 void PipeDialog::_initInputWidget( Mode editmode )
6561 QValidator *validator = new QRegExpValidator(rx, this);
6563 installEventFilter(this);
6564 name_le->installEventFilter(this);
6566 //Vertex Field config
6567 vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6568 vex_le->installEventFilter(this);
6569 vex_le->setValidator( validator );
6571 //Vector Field config
6572 vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6573 vec_le->installEventFilter(this);
6574 vec_le->setValidator( validator );
6577 if ( editmode == INFO_MODE ){
6578 name_le->setReadOnly(true);
6579 ir_spb->setReadOnly(true);
6580 er_spb->setReadOnly(true);
6581 h_spb->setReadOnly(true);
6584 vex_le->setReadOnly(true);
6585 vec_le->setReadOnly(true);
6587 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
6590 // ============================================================== clear
6591 void PipeDialog::clear()
6596 modelUnregister(vex_le);
6599 modelUnregister(vec_le);
6601 modelUnregister(this);
6604 // ============================================================== setValue
6605 void PipeDialog::setValue(HEXA_NS::Pipe* p)
6607 HEXA_NS::Vertex* base = p->getBase();
6608 HEXA_NS::Vector* direction = p->getDirection();
6609 double ir = p->getInternalRadius();
6610 double er = p->getRadius();
6611 double h = p->getHeight();
6613 name_le->setText( p->getName() );
6614 vex_le->setText( base->getName() );
6615 vec_le->setText( direction->getName() );
6616 ir_spb->setValue(ir);
6617 er_spb->setValue(er);
6620 if ( getPatternDataSelectionModel() ){
6621 QModelIndex iPipe = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
6622 QModelIndex iBase = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(base) );
6623 QModelIndex iDirection = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(direction) );
6625 name_le->setProperty( "QModelIndex", QVariant::fromValue(iPipe) );
6626 vex_le->setProperty( "QModelIndex", QVariant::fromValue(iBase) );
6627 vec_le->setProperty( "QModelIndex", QVariant::fromValue(iDirection) );
6632 // ============================================================== getValue
6633 HEXA_NS::Pipe* PipeDialog::getValue()
6638 // ============================================================== apply
6639 bool PipeDialog::apply(QModelIndex& result)
6641 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6644 if ( !getDocumentModel() ) return false;
6645 const PatternDataModel* patternDataModel = getPatternDataModel();
6646 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6647 if ( !patternDataModel || !patternBuilderModel) return false;
6650 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le] );
6651 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
6652 double ir = ir_spb->value();
6653 double er = er_spb->value();
6654 double h = h_spb->value();
6657 SUIT_MessageBox::information( this, tr( "CANNOT ADD PIPE" ), tr( "External radius must be greather than Internal radius!" ) );
6663 && ivec.isValid() ){
6664 iPipe = getDocumentModel()->addPipe( ivex, ivec, ir, er, h );
6667 if ( !iPipe.isValid() ){
6668 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD PIPE" ) );
6671 _value = iPipe.model()->data(iPipe, HEXA_DATA_ROLE).value<HEXA_NS::Pipe *>();
6673 QString newName = name_le->text();
6674 if ( !newName.isEmpty() )/*{*/
6675 getDocumentModel()->setName( iPipe, newName );
6677 //update the default name in the dialog box
6679 updateDefaultName(name_le, _value->getType());
6681 // to select/highlight result
6682 result = patternBuilderModel->mapFromSource(iPipe);
6686 // ************************************** FIN A SUPPRIMER ******************************************//