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 // ============================================================= resetSizeAndShow
180 void HexaBaseDialog::resetSizeAndShow(QDockWidget* parent)
185 //force the dialog to fit its contain
186 // setMinimumWidth(sizeHint().width());
188 //set the dialog in the dockwidget
189 if (parent->widget())
190 parent->widget()->close();
191 parent->setWidget(this);
192 parent->setWindowTitle(windowTitle());
195 // setMinimumWidth(MIN_WIDTH);
198 QString HexaBaseDialog::getErrorMsg()
200 DocumentModel* docModel = getDocumentModel();
201 Hex::Hex* hex = docModel->getHexaRoot();
202 int nbErrorMsg = hex->sizeofMessage();
203 QString msg, newLine = "\n";
204 for (int i = 1; i < nbErrorMsg; ++i)
205 msg += newLine + hex->getMessageLine(i);
210 //unlink the widget from the model
211 void HexaBaseDialog::modelUnregister(QWidget* widget)
213 if (widget == NULL) return;
215 if (widget->property("GeomWidgetType").isValid())
217 widget->setProperty("GeomObj", QVariant());
218 widget->setProperty("TopoDS_Shape", QVariant());
221 widget->setProperty("HexaData", QVariant());
222 widget->setProperty("QModelIndex", QVariant());
223 _index[widget] = QModelIndex();
225 HexaBaseDialog* diag = dynamic_cast<HexaBaseDialog*>(widget);
227 diag->clearWidgetsIndexes();
230 // ============================================================= connectDocumentGraphicView
231 void HexaBaseDialog::connectDocumentGraphicView(VtkDocumentGraphicView* docGView)
233 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
234 if (docGView == NULL) return;
236 disconnectDocumentGraphicView(docGView); //to avoid double connect
238 //Connect the graphic view and its model to the dialog box
239 connect( docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
240 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
241 // connect( docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
242 // this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
243 connect( docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
244 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
245 connect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
246 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
247 connect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
248 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
251 // ============================================================= disconnectDocumentGraphicView
252 void HexaBaseDialog::disconnectDocumentGraphicView(VtkDocumentGraphicView* docGView)
254 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
255 if (docGView == NULL) return;
258 //Disconnect graphic view signals form the dialog box
259 disconnect(docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
260 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
262 // disconnect(docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
263 // this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
265 disconnect(docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
266 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
268 disconnect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
269 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
271 disconnect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
272 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
275 // ============================================================= onCurrentSelectionChanged
276 void HexaBaseDialog::onCurrentSelectionChanged()
278 highlightSelectedAssocs();
281 void HexaBaseDialog::clearCurrentObjectFocus()
283 QWidget* currentWidget = dynamic_cast<QWidget*>(_currentObj);
284 if (currentWidget != NULL)
286 currentWidget->clearFocus();
291 // ============================================================= setFocusToNextField
292 //Sets focus to the next field of the current object
293 void HexaBaseDialog::setFocusToNextField()
297 if (!HEXABLOCKGUI::assocInProgress && autoFocusSwitch)
299 _highlightWidget(_currentObj, Qt::white);
304 // ============================================================== _initButtonBox
305 QGroupBox* HexaBaseDialog::_initButtonBox( Mode editmode )
307 if ( editmode == INFO_MODE )
310 QGroupBox* buttonBox = new QGroupBox();
311 buttonBox->setMinimumWidth(BUTTON_BOX_MIN_WIDTH);
312 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
313 QHBoxLayout* buttonsHLayout = new QHBoxLayout();
314 _applyButton = new QPushButton(tr("Apply"));
315 QPushButton* closeButton = new QPushButton(tr("Close"));
316 QPushButton* helpButton = new QPushButton(tr("Help"));
318 connect( _applyButton, SIGNAL(clicked()), this, SLOT(apply()), Qt::UniqueConnection );
319 connect( closeButton, SIGNAL(clicked()), this, SLOT(close()), Qt::UniqueConnection );
320 connect( helpButton, SIGNAL(clicked()), this, SLOT(onHelpRequested()), Qt::UniqueConnection );
322 buttonsHLayout->addWidget( _applyButton );
323 buttonsHLayout->addWidget( closeButton );
324 buttonsHLayout->addStretch(1);
325 buttonsHLayout->addWidget( helpButton );
326 buttonBox->setLayout(buttonsHLayout);
327 layout()->addWidget(buttonBox);
328 buttonBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
332 // ============================================================== _initWidget
333 void HexaBaseDialog::_initWidget( Mode editmode )
335 _initInputWidget( editmode );
336 _initButtonBox( editmode );
339 // ============================================================== apply
340 bool HexaBaseDialog::apply()
343 bool applied = apply(iNew);
346 _selectAndHighlight( iNew );
347 if (!HEXABLOCKGUI::assocInProgress)
348 getDocumentModel()->updateGeomTree();
353 void HexaBaseDialog::clearVTKSelection()
355 HEXABLOCKGUI::currentDocGView->clearSelection();
356 _highlightWidget(_currentObj, Qt::white);
359 void HexaBaseDialog::clearOCCSelection()
361 HEXABLOCKGUI::currentOccGView->clearSelection();
364 // ============================================================== close
365 void HexaBaseDialog::close()
367 //reset the data selection pattern (forget all selections of the current context)
368 getPatternDataSelectionModel()->reset();
369 // getPatternBuilderSelectionModel()->reset();
370 getPatternGeomSelectionModel()->reset();
372 //Clear vtk selection
375 //Clear occ selection
378 //Close the dialog box
380 parentWidget()->close();
382 getPatternDataSelectionModel()->setInfoMode(true);
385 // ============================================================== onHelpRequested
386 void HexaBaseDialog::onHelpRequested()
388 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
390 app->onHelpContextModule( "HEXABLOCK", _helpFileName );
394 platform = "winapplication";
396 platform = "application";
399 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
400 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
401 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( _helpFileName ),
402 QObject::tr( "BUT_OK" ) );
406 // ============================================================== highlightSelectedAssocs
407 void HexaBaseDialog::highlightSelectedAssocs()
409 QMultiMap<QString, int> geomAssocs = getAssocsGEOM();
410 QModelIndexList vtkAssocs = getAssocsVTK();
412 // HEXABLOCKGUI::selectionMgr()->clearSelected();
413 //highlight geom selected elts
414 if (geomAssocs.size() > 0)
415 HEXABLOCKGUI::currentOccGView->highlight(geomAssocs, false);
417 //highlight vtk selected elts
418 if (!vtkAssocs.isEmpty())
419 HEXABLOCKGUI::currentDocGView->highlight(vtkAssocs);
422 // ============================================================== refreshHighlight
423 void HexaBaseDialog::refreshHighlight()
425 HEXABLOCKGUI::selectionMgr()->clearSelected();
426 highlightSelectedAssocs();
429 // ============================================================== getObjectViewType
430 HEXABLOCKGUI::ViewType HexaBaseDialog::getObjectViewType(QObject* obj)
433 return HEXABLOCKGUI::UNKNOWN;
435 QVariant v = obj->property("GeomWidgetType");
437 return HEXABLOCKGUI::OCC;
439 v = obj->property("HexaWidgetType");
441 return HEXABLOCKGUI::VTK;
443 return HEXABLOCKGUI::UNKNOWN;
446 // ============================================================== _selectAndHighlight
447 void HexaBaseDialog::_selectAndHighlight( const QModelIndex& i )
449 if ( !i.isValid() ) return;
450 setProperty("QModelIndex", QVariant::fromValue(i));
454 // ============================================================== _allowSelection
455 void HexaBaseDialog::_allowSelection()
457 if ( getDocumentModel() )
458 getDocumentModel()->disallowEdition();
461 // ============================================================== _disallowSelection
462 void HexaBaseDialog::_disallowSelection()
464 if ( getDocumentModel() ){
465 getDocumentModel()->allowEdition();
467 HEXABLOCKGUI::currentDocGView->setAllSelection();
470 // ============================================================== _allowVTKSelection
471 bool HexaBaseDialog::_allowVTKSelection( QObject* obj )
476 QVariant v = obj->property("HexaWidgetType");
477 HexaWidgetType wType = v.value<HexaWidgetType>();
481 HEXABLOCKGUI::currentDocGView->setVertexSelection(); isOk = true;
484 HEXABLOCKGUI::currentDocGView->setEdgeSelection(); isOk = true;
487 HEXABLOCKGUI::currentDocGView->setQuadSelection(); isOk = true;
490 HEXABLOCKGUI::currentDocGView->setHexaSelection(); isOk = true;
492 default: HEXABLOCKGUI::currentDocGView->setAllSelection();
497 // ============================================================== _allowOCCSelection
498 bool HexaBaseDialog::_allowOCCSelection( QObject* obj )
500 QVariant v = obj->property("GeomWidgetType");
501 GeomWidgetType wType = v.value<GeomWidgetType>();
502 HEXABLOCKGUI::currentOccGView->setSelectionMode(wType);
507 // ============================================================== _getSelector
508 QItemSelectionModel* HexaBaseDialog::_getSelector( QObject* obj )
510 QItemSelectionModel* selector = NULL;
512 HexaWidgetType wtype;
513 QVariant v = obj->property("HexaWidgetType");
514 if ( !v.isValid() ) {
518 wtype = v.value<HexaWidgetType>();
525 case VECTOR_TREE: selector = getPatternDataSelectionModel(); break;
526 // case CYLINDER_TREE:
528 // case ELEMENTS_TREE:
529 // case CROSSELEMENTS_TREE: selector = getPatternBuilderSelectionModel(); break;
532 case GEOMFACE_TREE: selector = getPatternGeomSelectionModel(); break;
533 case GROUP_TREE: selector = getGroupsSelectionModel(); break;
535 case PROPAGATION_TREE: selector = getMeshSelectionModel(); break;
542 DocumentModel::GeomObj* HexaBaseDialog::getGeomObj(const QModelIndex& index)
544 HEXA_NS::NewShape* aSh = getDocumentModel()->getHexaPtr<HEXA_NS::NewShape*>(index);
545 DocumentModel::GeomObj* geomObj = NULL;
548 geomObj = new DocumentModel::GeomObj;
549 geomObj->shapeName = aSh->getName();
550 geomObj->subId = QString::number(-1);
554 HEXA_NS::EltBase* aSShElt = getDocumentModel()->getHexaPtr(index);
555 HEXA_NS::SubShape* aSSh = dynamic_cast<HEXA_NS::SubShape*>(aSShElt);
558 geomObj = new DocumentModel::GeomObj;
560 if (aSSh->getParentShape() != NULL)
561 shapeName = aSSh->getParentShape()->getName();
562 geomObj->shapeName = shapeName;
563 geomObj->subId = QString::number(aSSh->getIdent());
569 // ============================================================== _onSelectionChanged
571 * Puts elements selected in the model (treeview) in the corresponding
572 * line edit widget (the one that has the focus) of the current dialog box.
574 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QLineEdit* le )
576 QModelIndexList l = sel.indexes();
577 if ( l.count() == 0 ) return false;
579 // mono selection mode: we just get the first selected element
580 QModelIndex selected = l[0];
582 // we just return if the selection is not valid or the selection and the
583 // line content are the same
584 if ( !selected.isValid() || le->property("HexaData") == selected.data(HEXA_DATA_ROLE) )
588 int selType = selected.data(HEXA_TREE_ROLE).toInt();
591 QVariant v = le->property("HexaWidgetType");
592 if ( !v.isValid() ) return false;
593 HexaWidgetType wType = v.value<HexaWidgetType>();
595 // check selection compatibility between selection and widget
596 if ( selType != wType ){
597 SUIT_MessageBox::information( 0, tr("HEXA_INFO"),
598 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg(_strHexaWidgetType[wType]));
601 if (le->property("GeomWidgetType").isValid())
603 DocumentModel::GeomObj* geomObj = getGeomObj(selected);
606 le->setProperty("GeomObj", QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
608 DocumentModel* docModel = getDocumentModel();
609 QString objId = geomObj->shapeName + "," + geomObj->subId;
610 HEXA_NS::SubShape* ssh = docModel->getGeomPtr(objId);
613 TopoDS_Shape shape = ssh->getShape();
615 le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(shape));
617 setCurrentGeomObj(geomObj);
621 //fill the lineEdit if selection is OK
622 le->setText( selected.data().toString() );// name
623 le->setProperty("QModelIndex", QVariant::fromValue(selected));
624 le->setProperty("HexaData", selected.data(HEXA_DATA_ROLE));
625 _index[le] = selected;
627 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(_currentObj);
628 if (selected.isValid() && lineEdit != NULL)
629 setFocusToNextField();
634 // ============================================================== _onSelectionChanged
636 * Puts elements selected in the model (treeview) in the corresponding list widget
637 * of the current dialog box.
639 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QListWidget* lw )
641 QModelIndexList l = sel.indexes();
643 if ( l.count() == 0 ) return false;
646 QVariant v = lw->property("HexaWidgetType");
647 if ( !v.isValid() ) return false;
648 HexaWidgetType wType = v.value<HexaWidgetType>();
650 //fill the listWidget
651 QListWidgetItem* item = NULL;
655 foreach( const QModelIndex& isel, l ){
656 // if ( lw->count() == maxSize) break;
657 selType = isel.data(HEXA_TREE_ROLE).toInt();
658 if ( selType != wType ){ // check selection compatibility between selection and widget
659 SUIT_MessageBox::information( 0,
661 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg( _strHexaWidgetType[wType]) );
664 // add selection to listWidget if selection is OK
665 selName = isel.data().toString();
666 QList<QListWidgetItem *> twice = lw->findItems( selName, Qt::MatchExactly);
667 if ( twice.count() == 0 ){
668 item = new QListWidgetItem( selName );
669 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(isel) );
670 item->setData(LW_DATA_ROLE, isel.data(HEXA_DATA_ROLE));
671 if (lw->property("GeomWidgetType").isValid())
673 DocumentModel::GeomObj* geomObj = getGeomObj(isel);
675 item->setData(LW_ASSOC_ROLE, QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
684 // ============================================================== onSelectionChanged
686 * Puts elements selected in the model in the corresponding widget (list widget or line edit)
687 * of the current dialog box.
689 void HexaBaseDialog::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
691 // * no edition for Info Dialogs
692 if ( _editMode == INFO_MODE )
695 QLineEdit* aLineEdit = NULL;
696 QListWidget* aListWidget = NULL;
698 // * fill the lineedit with selection
699 aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
702 _onSelectionChanged( sel, aLineEdit );
706 // * fill the listWidget with selection
707 aListWidget = dynamic_cast<QListWidget*>(_currentObj);
709 _onSelectionChanged( sel, aListWidget );
712 // ============================================================== showEvent
713 void HexaBaseDialog::showEvent( QShowEvent * event )
715 if ( _editMode == INFO_MODE )
716 getDocumentModel()->allowEdition();
718 getDocumentModel()->disallowEdition();
720 //Connect to salome selection signals
721 if (HEXABLOCKGUI::selectionMgr() != NULL)
723 connect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
724 this, SLOT(onCurrentSelectionChanged()), Qt::UniqueConnection );
727 //connect model selection signals
728 connectDocumentGraphicView();
730 QDialog::showEvent ( event );
734 // ============================================================== hideEvent
735 void HexaBaseDialog::hideEvent ( QHideEvent * event )
737 //Disconnection salome selection signals
738 if (HEXABLOCKGUI::selectionMgr() != NULL)
740 disconnect( HEXABLOCKGUI::selectionMgr() , SIGNAL(currentSelectionChanged()),
741 this, SLOT(onCurrentSelectionChanged()) );
744 //Disconnect vtk window activation signals
745 // if (HEXABLOCKGUI::currentDocGView->getViewWindow() != NULL)
746 // disconnect( HEXABLOCKGUI::currentDocGView->getViewWindow()->getViewManager(),
747 // SIGNAL( activated(SUIT_ViewManager*) ),
748 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
750 //Disconnect occ window activation signals
751 // if (HEXABLOCKGUI::currentOccGView->getViewWindow() != NULL)
752 // disconnect( HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager(),
753 // SIGNAL( activated(SUIT_ViewManager*) ),
754 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
756 //Disconnect model selection signals
757 disconnectDocumentGraphicView();
759 getDocumentModel()->allowEdition();
761 QDialog::hideEvent( event );
764 // ============================================================== updateButtonBox
765 void HexaBaseDialog::updateButtonBox()
769 // ============================================================== updateName
770 void HexaBaseDialog::updateName()
772 const PatternDataModel* patternDataModel = getPatternDataModel();
774 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(sender());
775 if (!lineEdit) return;
776 QString newName = lineEdit->text();
777 if ( newName.isEmpty() ) return;
779 QVariant v = lineEdit->property("QModelIndex");
780 if ( !v.isValid() ) return;
782 QModelIndex index = v.value<QModelIndex>();
783 if ( index.isValid() )
784 getDocumentModel()->setName( patternDataModel->mapToSource(index), newName );
787 // ============================================================== updateDefaultName
788 void HexaBaseDialog::updateDefaultName(QLineEdit* name_field, HEXA_NS::EnumElt type)
790 if (name_field == NULL) return;
792 HEXA_NS::Document* doc = getDocumentModel()->getHexaDocument();
793 if (doc == NULL) return;
795 name_field->setText(doc->getNextName(type).c_str());
798 // ============================================================== selectElementOfModel
799 /*Selects in the model (treeview) elements selected in a listwidget,
800 * or an element in a line edit.*/
801 void HexaBaseDialog::selectElementOfModel()
803 if (getPatternDataSelectionModel() == NULL) return;
805 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
806 if ( !currentListWidget ) return;
808 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
810 getPatternDataSelectionModel()->clearSelection();
811 foreach ( QListWidgetItem *item, sel ){
812 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
813 index = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
814 if ( index.isValid() )
815 getPatternDataSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
819 // ============================================================== _isLineOrListWidget
821 * Return true is the widget is a line or a list
824 bool HexaBaseDialog::_isLineOrListWidget(QObject *widget)
826 if (widget == NULL) return false;
828 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(widget);
829 QListWidget *listWidget = dynamic_cast<QListWidget*>(widget);
830 return (lineEdit != NULL) || (listWidget != NULL);
832 }//_isLineOrListWidget
835 // ============================================================== _highlightWidget
837 * Highlight the given widget with the given color.
839 void HexaBaseDialog::_highlightWidget(QObject *obj, Qt::GlobalColor clr)
841 if (!_isLineOrListWidget(obj)) return;
843 QWidget *widget = dynamic_cast<QWidget*>(obj); //sure it's not NULL (_isLineOrListWidget(obj))
844 QPalette palette1 = widget->palette();
845 palette1.setColor(widget->backgroundRole(), clr);
846 widget->setPalette(palette1);
851 // ============================================================== _updateCurrentObject
852 void HexaBaseDialog::_updateCurrentObject(QObject* obj)
854 _highlightWidget(_currentObj, Qt::white);
856 _highlightWidget(obj, Qt::yellow);
859 // ============================================================== eventFilter
861 * Handles events from the treeview and the dialog boxes.
863 bool HexaBaseDialog::eventFilter(QObject *obj, QEvent *event)
865 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(obj);
866 QListWidget *listWidget = dynamic_cast<QListWidget*>(obj);
868 // * Enter key press ------
869 if ( event->type() == QEvent::KeyPress &&
870 ((QKeyEvent*)event)->key() == Qt::Key_Return)
872 setFocusToNextField();
876 // * Focus out from a list widget ------
877 if ( event->type() == QEvent::FocusOut && listWidget != NULL)
879 QItemSelectionModel * selectionModel = listWidget->selectionModel();
880 selectionModel->clearSelection();
883 if ( event->type() != QEvent::FocusIn )
888 // allow vtk selection
889 if (getObjectViewType(obj) == HEXABLOCKGUI::VTK)
890 _allowVTKSelection( obj );
892 //allow occ selection
893 if (getObjectViewType(obj) == HEXABLOCKGUI::OCC)
894 _allowOCCSelection( obj );
896 //Depending on the focused widget type, get the right selector for it
899 QItemSelectionModel* selector = _getSelector( obj );
900 if ( selector == NULL )
902 _updateCurrentObject(obj);
906 if ( _currentObj != obj && (lineEdit == NULL || listWidget == NULL) )
907 selector->clearSelection();
909 _updateCurrentObject(obj);
911 //If the widget contains an element, select it in model/view
912 if ( lineEdit != NULL ){ //element can be from lineEdit
913 v = lineEdit->property("HexaData");
915 return QObject::eventFilter(obj, event);
916 index = ((SelectionModel*)selector)->indexBy( HEXA_DATA_ROLE, v);
918 selector->select( index, QItemSelectionModel::SelectCurrent );
921 return QObject::eventFilter(obj, event);
924 // ------------------------- VERTEX ----------------------------------
925 // ============================================================== Constructeur
926 VertexDialog::VertexDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
927 HexaBaseDialog(parent, editmode, f),
930 _helpFileName = "gui_vertex.html";
932 _initWidget(editmode);
933 // setFocusProxy( name_le );
935 if ( editmode == NEW_MODE ){
936 setWindowTitle( tr("Vertex Construction") );
937 } else if ( editmode == UPDATE_MODE ){
938 setWindowTitle( tr("Vertex Modification") );
940 else if ( editmode == INFO_MODE){
941 setWindowTitle( tr("Vertex Information") );
945 // ============================================================== Destructeur
946 VertexDialog::~VertexDialog()
950 // ============================================================== _initInputWidget
951 void VertexDialog::_initInputWidget( Mode editmode )
953 // x_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
954 // y_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
955 // z_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
956 QDoubleValidator *doubleValidator = new QDoubleValidator(widget_2);
957 x_spb->setValidator(doubleValidator);
958 y_spb->setValidator(doubleValidator);
959 z_spb->setValidator(doubleValidator);
961 // setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
962 installEventFilter(this);
963 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
964 name_le->installEventFilter(this);
966 if (editmode == INFO_MODE)
968 name_le->setReadOnly(true);
969 x_spb->setReadOnly(true);
970 y_spb->setReadOnly(true);
971 z_spb->setReadOnly(true);
974 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
977 // ============================================================== clear
978 void VertexDialog::clear()
982 modelUnregister(this);
985 // ============================================================== setValue
986 void VertexDialog::setValue(HEXA_NS::Vertex* v)
989 name_le->setText( v->getName() );
992 // x_spb->setValue( v->getX() );
993 // y_spb->setValue( v->getY() );
994 // z_spb->setValue( v->getZ() );
995 x_spb->setText( QString::number(v->getX()) );
996 y_spb->setText( QString::number(v->getY()) );
997 z_spb->setText( QString::number(v->getZ()) );
999 if ( getPatternDataSelectionModel() != NULL ){
1000 QModelIndex iv = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1002 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1003 name_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1008 // ============================================================== getValue
1009 HEXA_NS::Vertex* VertexDialog::getValue()
1015 // ============================================================== apply
1016 bool VertexDialog::apply(QModelIndex& result)
1018 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1021 if ( !getDocumentModel() ) return false;
1022 if ( !getPatternDataSelectionModel() ) return false;
1023 const PatternDataModel* patternDataModel = getPatternDataModel();
1024 if ( !patternDataModel ) return false;
1026 QModelIndex iVertex;
1028 QString xStr = x_spb->text();
1029 QString yStr = y_spb->text();
1030 QString zStr = z_spb->text();
1031 bool isOk = false, validArgs = !xStr.isEmpty() && !yStr.isEmpty() && !zStr.isEmpty();
1033 double newX, newY, newZ;
1036 newX = xStr.toDouble();
1037 newY = yStr.toDouble();
1038 newZ = zStr.toDouble();
1041 if ( _editMode == UPDATE_MODE && validArgs){
1042 QVariant v = property("QModelIndex");
1044 iVertex = patternDataModel->mapToSource( v.value<QModelIndex>() );
1045 if ( iVertex.isValid() )
1046 isOk = getDocumentModel()->updateVertex( iVertex, newX, newY, newZ );
1048 } else if ( _editMode == NEW_MODE && validArgs){
1049 iVertex = getDocumentModel()->addVertex( newX, newY, newZ );
1050 if ( iVertex.isValid() )
1054 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "VERTEX UPDATE/CONSTRUCTION" ) + "\n" + getErrorMsg() );
1058 QString newName = name_le->text();
1059 if ( !newName.isEmpty() )/*{*/
1060 getDocumentModel()->setName( iVertex, newName );
1062 //the default name in the dialog box
1063 HEXA_NS::Vertex* v = getDocumentModel()->getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1065 updateDefaultName(name_le, v->getType());
1067 // to select/highlight result
1068 result = patternDataModel->mapFromSource(iVertex);
1070 // updateDialogBoxName(name_le, result);
1071 // const char *defaultName = getDocumentModel()->getHexaPtr(last)->getName();
1075 // ------------------------- EDGE ----------------------------------
1077 // ============================================================== Constructeur
1078 EdgeDialog::EdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1079 HexaBaseDialog(parent, editmode, f),
1082 _helpFileName = "gui_edge.html";
1084 _initWidget(editmode);
1086 // rb0->setFocusProxy( v0_le_rb0 );
1087 // rb1->setFocusProxy( vex_le_rb1 );
1089 if ( editmode == INFO_MODE ){
1090 setWindowTitle( tr("Edge Information") );
1093 else if ( editmode == UPDATE_MODE ){
1094 setWindowTitle( tr("Edge Modification") );
1100 // ============================================================== Destructeur
1101 EdgeDialog::~EdgeDialog()
1106 // ============================================================== _initInputWidget
1107 void EdgeDialog::_initInputWidget( Mode editmode )
1110 QValidator *validator = new QRegExpValidator(rx, this);
1112 // setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1113 installEventFilter(this);
1115 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1116 name_le->installEventFilter(this);
1118 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1119 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1120 v0_le_rb0->setValidator( validator );
1121 v1_le_rb0->setValidator( validator );
1122 v0_le_rb0->installEventFilter(this);
1123 v1_le_rb0->installEventFilter(this);
1125 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1126 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1127 vex_le_rb1->setValidator( validator );
1128 vec_le_rb1->setValidator( validator );
1129 vex_le_rb1->installEventFilter(this);
1130 vec_le_rb1->installEventFilter(this);
1132 v0_le_rb0->setReadOnly(true);
1133 v1_le_rb0->setReadOnly(true);
1134 vex_le_rb1->setReadOnly(true);
1135 vec_le_rb1->setReadOnly(true);
1137 if (editmode == INFO_MODE)
1138 name_le->setReadOnly(true);
1140 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()) );
1144 // ============================================================== Clear
1145 void EdgeDialog::clear()
1150 modelUnregister(v0_le_rb0);
1153 modelUnregister(v1_le_rb0);
1155 vex_le_rb1->clear();
1156 modelUnregister(vex_le_rb1);
1158 vec_le_rb1->clear();
1159 modelUnregister(vec_le_rb1);
1161 modelUnregister(this);
1164 // ============================================================== setValue
1165 void EdgeDialog::setValue(HEXA_NS::Edge* e)
1167 HEXA_NS::Vertex* v0 = e->getVertex(0);
1168 HEXA_NS::Vertex* v1 = e->getVertex(1);
1170 name_le->setText( e->getName() );
1171 v0_le_rb0->setText( v0->getName() );
1172 v1_le_rb0->setText( v1->getName() );
1174 if ( getPatternDataSelectionModel() ){
1175 QModelIndex ie = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e) );
1176 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1177 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1179 name_le->setProperty( "QModelIndex", QVariant::fromValue(ie) );
1180 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1181 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1186 // ============================================================== getValue
1187 HEXA_NS::Edge* EdgeDialog::getValue()
1192 // ============================================================== apply
1193 bool EdgeDialog::apply(QModelIndex& result)
1195 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1198 if ( !getDocumentModel() ) return false;
1199 const PatternDataModel* patternDataModel = getPatternDataModel();
1200 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1201 if ( !patternDataModel /*|| !patternBuilderModel*/ ) return false;
1205 if ( rb0->isChecked() ){
1206 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1207 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1208 if ( iv0.isValid()&& iv1.isValid() ){
1209 iEdge = getDocumentModel()->addEdgeVertices( iv0, iv1 );
1211 } else if ( rb1->isChecked() ){
1212 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
1213 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb1] );
1214 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
1215 if ( ivex.isValid() && ivec.isValid() ){
1216 iEdge = getDocumentModel()->addEdgeVector( ivex, ivec );
1220 if ( !iEdge.isValid() ){
1221 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD EDGE" ) + "\n" + getErrorMsg() );
1224 _value = iEdge.model()->data(iEdge, HEXA_DATA_ROLE).value<HEXA_NS::Edge*>();
1226 QString newName = name_le->text();
1227 if ( !newName.isEmpty() )/*{*/
1228 getDocumentModel()->setName( iEdge, newName );
1230 //update the default name in the dialog box
1232 updateDefaultName(name_le, _value->getType());
1234 result = patternDataModel->mapFromSource(iEdge);
1239 // ------------------------- QUAD ----------------------------------
1241 // ============================================================== Constructeur
1242 QuadDialog::QuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1243 HexaBaseDialog(parent, editmode, f),
1246 _helpFileName = "gui_quadrangle.html";
1248 _initWidget(editmode);
1251 if ( editmode == INFO_MODE ){
1252 setWindowTitle( tr("Quad Information") );
1256 // ============================================================== Destructeur
1257 QuadDialog::~QuadDialog()
1261 // ============================================================== _initInputWidget
1262 void QuadDialog::_initInputWidget( Mode editmode )
1265 QValidator *validator = new QRegExpValidator(rx, this);
1267 installEventFilter(this);
1268 name_le->installEventFilter(this);
1270 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1271 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1272 v2_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1273 v3_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1275 v0_le_rb0->setValidator( validator );
1276 v1_le_rb0->setValidator( validator );
1277 v2_le_rb0->setValidator( validator );
1278 v3_le_rb0->setValidator( validator );
1279 v0_le_rb0->installEventFilter(this);
1280 v1_le_rb0->installEventFilter(this);
1281 v2_le_rb0->installEventFilter(this);
1282 v3_le_rb0->installEventFilter(this);
1284 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1285 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1286 e2_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1287 e3_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1289 e0_le_rb1->setValidator( validator );
1290 e1_le_rb1->setValidator( validator );
1291 e2_le_rb1->setValidator( validator );
1292 e3_le_rb1->setValidator( validator );
1294 e0_le_rb1->installEventFilter(this);
1295 e1_le_rb1->installEventFilter(this);
1296 e2_le_rb1->installEventFilter(this);
1297 e3_le_rb1->installEventFilter(this);
1299 v0_le_rb0->setReadOnly(true);
1300 v1_le_rb0->setReadOnly(true);
1301 v2_le_rb0->setReadOnly(true);
1302 v3_le_rb0->setReadOnly(true);
1304 e0_le_rb1->setReadOnly(true);
1305 e1_le_rb1->setReadOnly(true);
1306 e2_le_rb1->setReadOnly(true);
1307 e3_le_rb1->setReadOnly(true);
1309 if (editmode == INFO_MODE)
1310 name_le->setReadOnly(true);
1313 // ============================================================== clear
1314 void QuadDialog::clear()
1316 //Clear the dialog and unregister it from the model
1317 QModelIndex invalidIndex;
1322 modelUnregister(v0_le_rb0);
1325 modelUnregister(v1_le_rb0);
1328 modelUnregister(v2_le_rb0);
1331 modelUnregister(v3_le_rb0);
1334 modelUnregister(e0_le_rb1);
1337 modelUnregister(e1_le_rb1);
1340 modelUnregister(e2_le_rb1);
1343 modelUnregister(e3_le_rb1);
1345 modelUnregister(this);
1349 // ============================================================== setValue
1350 void QuadDialog::setValue(HEXA_NS::Quad* q)
1352 Q_ASSERT( q->countEdge() == 4 );
1353 Q_ASSERT( q->countVertex() == 4 );
1356 name_le->setText( q->getName() );
1359 HEXA_NS::Vertex* v0 = q->getVertex(0);
1360 HEXA_NS::Vertex* v1 = q->getVertex(1);
1361 HEXA_NS::Vertex* v2 = q->getVertex(2);
1362 HEXA_NS::Vertex* v3 = q->getVertex(3);
1364 v0_le_rb0->setText( v0->getName() );
1365 v1_le_rb0->setText( v1->getName() );
1366 v2_le_rb0->setText( v2->getName() );
1367 v3_le_rb0->setText( v3->getName() );
1371 HEXA_NS::Edge* e0 = q->getEdge(0);
1372 HEXA_NS::Edge* e1 = q->getEdge(1);
1373 HEXA_NS::Edge* e2 = q->getEdge(2);
1374 HEXA_NS::Edge* e3 = q->getEdge(3);
1376 e0_le_rb1->setText( e0->getName() );
1377 e1_le_rb1->setText( e1->getName() );
1378 e2_le_rb1->setText( e2->getName() );
1379 e3_le_rb1->setText( e3->getName() );
1381 if ( getPatternDataSelectionModel() ){
1382 QModelIndex iq = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(q) );
1384 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1385 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1386 QModelIndex iv2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v2) );
1387 QModelIndex iv3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v3) );
1389 QModelIndex ie0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e0) );
1390 QModelIndex ie1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e1) );
1391 QModelIndex ie2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e2) );
1392 QModelIndex ie3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e3) );
1394 name_le->setProperty( "QModelIndex", QVariant::fromValue(iq) );
1396 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1397 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1398 v2_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv2) );
1399 v3_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv3) );
1401 e0_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie0) );
1402 e1_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie1) );
1403 e2_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie2) );
1404 e3_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie3) );
1410 // ============================================================== getValue
1411 HEXA_NS::Quad* QuadDialog::getValue()
1417 // ============================================================== apply
1418 bool QuadDialog::apply(QModelIndex& result)
1420 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1423 if ( !getDocumentModel() ) return false;
1424 const PatternDataModel* patternDataModel = getPatternDataModel();
1425 if ( !patternDataModel ) return false;
1429 if ( rb0->isChecked() ){ //vertices
1430 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1431 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1432 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb0] );
1433 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb0] );
1439 iQuad = getDocumentModel()->addQuadVertices( iv0, iv1, iv2, iv3 );
1441 } else if ( rb1->isChecked() ){ //edges
1442 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
1443 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
1444 QModelIndex ie2 = patternDataModel->mapToSource( _index[e2_le_rb1] );
1445 QModelIndex ie3 = patternDataModel->mapToSource( _index[e3_le_rb1] );
1451 iQuad = getDocumentModel()->addQuadEdges( ie0, ie1, ie2, ie3 );
1455 if ( !iQuad.isValid() ){
1456 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD QUAD" ) + "\n" + getErrorMsg());
1459 _value = iQuad.model()->data(iQuad, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1461 QString newName = name_le->text();
1462 if ( !newName.isEmpty() )/*{*/
1463 getDocumentModel()->setName( iQuad, newName );
1465 //the default name in the dialog box
1467 updateDefaultName(name_le, _value->getType());
1469 // to select/highlight result
1470 result = patternDataModel->mapFromSource(iQuad);
1476 // ------------------------- HEXA ----------------------------------
1478 // ============================================================== HexaDialog
1480 HexaDialog::HexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1481 HexaBaseDialog(parent, editmode, f),
1484 _helpFileName = "gui_hexahedron.html";
1486 _initWidget(editmode);
1489 if ( editmode == INFO_MODE ){
1490 setWindowTitle( tr("Hexahedron Information") );
1491 quads_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
1492 vertices_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
1496 // ============================================================== Destructeur
1497 HexaDialog::~HexaDialog()
1501 // ============================================================== _initInputWidget
1502 void HexaDialog::_initInputWidget( Mode editmode )
1506 installEventFilter(this);
1507 name_le->installEventFilter(this);
1509 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
1510 quads_lw->installEventFilter(this);
1512 vertices_lw->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1513 vertices_lw->installEventFilter(this);
1515 if ( editmode != INFO_MODE ) {
1516 // delete item from listwidget
1517 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
1518 QShortcut* delVertexShortcut = new QShortcut( QKeySequence(Qt::Key_X), vertices_lw );
1519 delQuadShortcut->setContext( Qt::WidgetShortcut );
1520 delVertexShortcut->setContext( Qt::WidgetShortcut );
1521 connect(delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()));
1522 connect(delVertexShortcut, SIGNAL(activated()), this, SLOT(deleteVertexItem()));
1524 // highlight item on model view (VTK) from listwidget
1525 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1526 connect( vertices_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1528 if ( editmode != INFO_MODE)
1530 connect( vertices_rb, SIGNAL(clicked()), vertices_lw, SLOT(setFocus()));
1531 connect( quads_rb, SIGNAL(clicked()), quads_lw, SLOT(setFocus()));
1534 connect( vertices_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1535 connect( quads_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1537 if (editmode == INFO_MODE)
1538 name_le->setReadOnly(true);
1542 // ============================================================== clear
1543 void HexaDialog::clear()
1548 modelUnregister(quads_lw);
1550 vertices_lw->clear();
1551 modelUnregister(vertices_lw);
1553 modelUnregister(this);
1556 // ============================================================== getAssocsVTK
1558 * Returns elements currently associated to vtk
1560 QModelIndexList HexaDialog::getAssocsVTK()
1562 QModelIndexList assocs;
1563 QModelIndex iQuad, iVertex;
1564 QListWidgetItem* item = NULL;
1566 const PatternDataModel* patternDataModel = getPatternDataModel();
1567 if (patternDataModel == NULL) return assocs;
1568 if (quads_rb->isChecked())
1570 //ListWidget content
1571 int nbQuads = quads_lw->count();
1572 for ( int r = 0; r < nbQuads; ++r ){
1573 item = quads_lw->item(r);
1574 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1575 if ( iQuad.isValid() )
1580 else if (vertices_rb->isChecked())
1582 //ListWidget content
1583 int nbVertices = vertices_lw->count();
1584 for ( int r = 0; r < nbVertices; ++r ){
1585 item = vertices_lw->item(r);
1586 iVertex = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1587 if ( iVertex.isValid() )
1596 // ============================================================== updateButtonBox
1597 void HexaDialog::updateButtonBox()
1599 if ( _editMode == INFO_MODE )
1602 if ( quads_rb->isChecked() ){ // build from quads count() must be between [2,6]
1603 int nbQuads = quads_lw->count();
1604 if ( nbQuads >= 2 && nbQuads <= 6 ){
1605 _applyButton->setEnabled(true);
1607 _applyButton->setEnabled(false);
1609 } else if ( vertices_rb->isChecked() ){ // build from vertices count() must be equals to 8
1610 int nbVertices = vertices_lw->count();
1611 if ( nbVertices == 8 ){
1612 _applyButton->setEnabled(true);
1614 _applyButton->setEnabled(false);
1619 // ============================================================== deleteQuadItem
1620 void HexaDialog::deleteQuadItem()
1622 delete quads_lw->currentItem();
1626 // ============================================================== deleteVertexItem
1627 void HexaDialog::deleteVertexItem()
1629 delete vertices_lw->currentItem();
1633 // ============================================================== _setValueQuads
1634 void HexaDialog::_setValueQuads( HEXA_NS::Hexa* h )
1636 QListWidgetItem *qItem = NULL;
1637 HEXA_NS::Quad *q = NULL;
1639 if (getPatternDataSelectionModel() == NULL) return;
1641 for( int i = 0; i <= 5; ++i ){
1643 qIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(q)) );
1644 qItem = new QListWidgetItem( q->getName() );
1645 qItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(qIndex) );
1646 qItem->setData(LW_DATA_ROLE, qIndex.data(HEXA_DATA_ROLE));
1647 quads_lw->addItem( qItem );
1651 // ============================================================== _setValueVertices
1652 void HexaDialog::_setValueVertices( HEXA_NS::Hexa* h )
1654 QListWidgetItem *vItem = NULL;
1655 HEXA_NS::Vertex* v = NULL;
1657 if (getPatternDataSelectionModel() == NULL) return;
1658 vertices_lw->clear();
1659 for( int i = 0; i <= 7; ++i ){
1660 v = h->getVertex(i);
1661 vIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(v)) );
1662 vItem = new QListWidgetItem( v->getName() );
1663 vItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(vIndex) );
1664 vItem->setData(LW_DATA_ROLE, vIndex.data(HEXA_DATA_ROLE));
1665 vertices_lw->addItem( vItem );
1669 // ============================================================== setValue
1670 void HexaDialog::setValue(HEXA_NS::Hexa* h)
1673 name_le->setText( h->getName() );
1675 if ( getPatternDataSelectionModel()){
1676 QModelIndex hIndex = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(h) );
1677 _setValueVertices(h);
1679 name_le->setProperty( "QModelIndex", QVariant::fromValue(hIndex) );
1684 // ============================================================== getValue
1685 HEXA_NS::Hexa* HexaDialog::getValue()
1690 // ============================================================== apply
1691 bool HexaDialog::apply(QModelIndex& result)
1693 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1696 if ( !getDocumentModel() ) return false;
1697 const PatternDataModel* patternDataModel = getPatternDataModel();
1698 if ( !patternDataModel ) return false;
1702 QListWidget* currentLw = NULL;
1703 QListWidgetItem* item = NULL;
1705 if ( quads_rb->isChecked() )
1706 currentLw = dynamic_cast<QListWidget*>( quads_lw );
1707 else if ( vertices_rb->isChecked() )
1708 currentLw = dynamic_cast<QListWidget*>( vertices_lw );
1711 QModelIndexList iElts;
1712 int nbItems = currentLw->count();
1713 for ( int r = 0; r < nbItems; ++r){
1714 item = currentLw->item(r);
1715 iElt = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1716 if ( iElt.isValid() )
1720 nbItems = iElts.count();
1721 if ( quads_rb->isChecked() and (nbItems>=2 and nbItems<=6) ){ // build from quads iElts.count() should be between [2,6]
1722 iHexa = getDocumentModel()->addHexaQuads( iElts );
1723 } else if ( vertices_rb->isChecked() and nbItems== 8 ){ // build from vertices
1724 iHexa = getDocumentModel()->addHexaVertices( iElts[0], iElts[1], iElts[2], iElts[3],
1725 iElts[4], iElts[5], iElts[6], iElts[7] );
1728 if ( !iHexa.isValid() ){
1729 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD HEXA" ) + "\n" + getErrorMsg() );
1732 _value = iHexa.model()->data(iHexa, HEXA_DATA_ROLE).value<HEXA_NS::Hexa*>();
1734 QString newName = name_le->text();
1735 if ( !newName.isEmpty() )/*{*/
1736 getDocumentModel()->setName( iHexa, newName );
1738 //update the default name in the dialog box
1740 updateDefaultName(name_le, _value->getType());
1742 // to select/highlight result
1743 result = patternDataModel->mapFromSource(iHexa);
1749 // ------------------------- VECTOR ----------------------------------
1751 // ============================================================== Constructeur
1753 VectorDialog::VectorDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1754 HexaBaseDialog(parent, editmode, f),
1757 _helpFileName = "gui_vector.html";
1759 _initWidget(editmode);
1763 if ( editmode == INFO_MODE ){
1764 setWindowTitle( tr("Vector Information") );
1769 // ============================================================== Destructeur
1770 VectorDialog::~VectorDialog()
1774 // ============================================================== _initInputWidget
1775 void VectorDialog::_initInputWidget( Mode editmode )
1778 QValidator *validator = new QRegExpValidator(rx, this);
1780 installEventFilter(this);
1781 name_le->installEventFilter(this);
1783 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1784 v0_le_rb1->setValidator( validator );
1785 v0_le_rb1->installEventFilter(this);
1787 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1788 v1_le_rb1->setValidator( validator );
1789 v1_le_rb1->installEventFilter(this);
1791 if ( editmode == INFO_MODE ){
1792 name_le->setReadOnly(true);
1793 dx_spb_rb0->setReadOnly(true);
1794 dy_spb_rb0->setReadOnly(true);
1795 dz_spb_rb0->setReadOnly(true);
1798 v0_le_rb1->setReadOnly(true);
1799 v1_le_rb1->setReadOnly(true);
1802 // ============================================================== clear
1803 void VectorDialog::clear()
1807 modelUnregister(v0_le_rb1);
1810 modelUnregister(v1_le_rb1);
1812 modelUnregister(this);
1815 // ============================================================== setValue
1816 void VectorDialog::setValue(HEXA_NS::Vector* v)
1818 name_le->setText( v->getName() );
1819 dx_spb_rb0->setValue( v->getDx() );
1820 dy_spb_rb0->setValue( v->getDy() );
1821 dz_spb_rb0->setValue( v->getDz() );
1823 if ( getPatternDataSelectionModel() ){
1824 QModelIndex ivec = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1825 name_le->setProperty( "QModelIndex", QVariant::fromValue(ivec) );
1830 // ============================================================== getValue
1831 HEXA_NS::Vector* VectorDialog::getValue()
1836 // ============================================================== apply
1837 bool VectorDialog::apply(QModelIndex& result)
1839 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1842 if ( !getDocumentModel() ) return false;
1843 const PatternDataModel* patternDataModel = getPatternDataModel();
1844 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1845 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
1847 QModelIndex iVector;
1849 if ( rb0->isChecked() ){ //scalar
1850 double dx = dx_spb_rb0->value();
1851 double dy = dy_spb_rb0->value();
1852 double dz = dz_spb_rb0->value();
1854 iVector = getDocumentModel()->addVector( dx, dy, dz );
1855 } else if ( rb1->isChecked() ){ //vertices
1856 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
1857 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
1861 iVector = getDocumentModel()->addVectorVertices( iv0, iv1 );
1865 if ( !iVector.isValid() ){
1866 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD VECTOR" ) + "\n" + getErrorMsg());
1870 _value = iVector.model()->data(iVector, HEXA_DATA_ROLE).value<HEXA_NS::Vector *>();
1872 QString newName = name_le->text();
1873 if ( !newName.isEmpty() )/*{*/
1874 getDocumentModel()->setName( iVector, newName );
1876 //update the default name in the dialog box
1878 updateDefaultName(name_le, _value->getType());
1880 // to select/highlight result
1881 result = patternDataModel->mapFromSource(iVector);
1882 // result = patternBuilderModel->mapFromSource(iVector);
1887 // ------------------------- MakeGridDialog ----------------------------------
1888 // ============================================================== Constructeur
1890 MakeGridDialog::MakeGridDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
1891 : HexaBaseDialog(parent, editmode, f)
1894 _initWidget(editmode);
1897 _helpFileName = "creategrids.html#guicartgridsimple";
1898 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1899 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1900 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1902 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1903 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1904 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1906 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1907 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1908 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1911 // ============================================================== Destructeur
1912 MakeGridDialog::~MakeGridDialog()
1916 // ============================================================== _initInputWidget
1917 void MakeGridDialog::_initInputWidget( Mode editmode )
1919 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1920 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1921 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1922 vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1924 center_le->setReadOnly(true);
1925 axis_le->setReadOnly(true);
1926 base_le->setReadOnly(true);
1927 vec_le->setReadOnly(true);
1929 installEventFilter(this);
1930 center_le->installEventFilter(this);
1931 axis_le->installEventFilter(this);
1932 base_le->installEventFilter(this);
1933 vec_le->installEventFilter(this);
1935 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
1936 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
1938 angle_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(angle_lw));
1939 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
1941 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
1942 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
1944 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
1945 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
1947 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
1948 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
1950 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
1951 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
1954 // ============================================================== clear
1955 void MakeGridDialog::clear()
1958 modelUnregister(center_le);
1961 modelUnregister(axis_le);
1964 modelUnregister(base_le);
1967 modelUnregister(vec_le);
1969 modelUnregister(this);
1972 // ============================================================== updateHelpFileName
1973 void MakeGridDialog::updateHelpFileName()
1975 if ( sender() == rb0 ){
1976 _helpFileName = "creategrids.html#guicartgridsimple";
1977 } else if ( sender() == rb1 ){
1978 _helpFileName = "creategrids.html#guicartgriduniform";
1979 } else if ( sender() == rb2 ){
1980 _helpFileName = "creategrids.html#guicartgridcustom";
1984 // ============================================================== addRadiusItem
1985 void MakeGridDialog::addRadiusItem()
1987 QListWidgetItem* previousItem = radius_lw->currentItem();
1988 QListWidgetItem* newItem = new QListWidgetItem();
1990 double defaultValue = 1.;
1992 defaultValue = previousItem->data(Qt::EditRole).toDouble();
1994 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
1995 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
1996 radius_lw->addItem(newItem);
1999 // ============================================================== delRadiusItem
2000 void MakeGridDialog::delRadiusItem()
2002 delete radius_lw->currentItem();
2005 // ============================================================== addAngleItem
2006 void MakeGridDialog::addAngleItem()
2008 QListWidgetItem* previousItem = angle_lw->currentItem();
2009 QListWidgetItem* newItem = new QListWidgetItem();
2011 double defaultValue = 1.;
2013 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2015 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2016 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2017 angle_lw->addItem(newItem);
2020 // ============================================================== delAngleItem
2021 void MakeGridDialog::delAngleItem()
2023 delete angle_lw->currentItem();
2026 // ============================================================== addHeightItem
2027 void MakeGridDialog::addHeightItem()
2029 QListWidgetItem* previousItem = height_lw->currentItem();
2030 QListWidgetItem* newItem = new QListWidgetItem();
2032 double defaultValue = 1.;
2034 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2036 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2037 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2038 height_lw->addItem(newItem);
2041 // ============================================================== delHeightItem
2042 void MakeGridDialog::delHeightItem()
2044 delete height_lw->currentItem();
2047 // ============================================================== apply
2048 bool MakeGridDialog::apply(QModelIndex& result)
2050 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2053 DocumentModel* docModel = getDocumentModel();
2054 PatternDataModel* patternDataModel = getPatternDataModel();
2055 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2057 QModelIndex iNewElts;
2058 if ( rb0->isChecked() )
2060 long nx = nx_spb->value();
2061 long ny = ny_spb->value();
2062 long nz = nz_spb->value();
2063 iNewElts = docModel->makeCartesianTop(nx, ny, nz);
2065 else if ( rb1->isChecked() )
2067 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2068 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2069 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2070 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le] );
2071 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2072 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2073 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2075 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2077 double lx = lx_spb->value();
2078 double ly = ly_spb->value();
2079 double lz = lz_spb->value();
2080 double nx = nx_spb->value();
2081 double ny = ny_spb->value();
2082 double nz = nz_spb->value();
2084 iNewElts = docModel->makeCartesianUni( icenter, ibase, ivec, iaxis,
2085 lx, ly, lz, nx, ny, nz);
2088 } else if ( rb2->isChecked() )
2090 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2091 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2092 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2093 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le] );
2094 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2095 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2096 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2098 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2100 QListWidgetItem* item = NULL;
2102 vector<double> radius;
2103 vector<double> angles;
2104 vector<double> heights;
2106 // double somme = 0.;
2107 int nbAngles = angle_lw->count();
2108 for ( int r = 0; r < nbAngles; ++r){
2109 item = angle_lw->item(r);
2110 double itemValue = item->data(Qt::EditRole).toDouble();
2111 angles.push_back(itemValue);
2112 // somme += itemValue;
2114 // if (somme > 360.01)
2116 // SUIT_MessageBox::information( 0,
2118 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2122 int nbRadius = radius_lw->count();
2123 for ( int r = 0; r < nbRadius; ++r){
2124 item = radius_lw->item(r);
2125 radius.push_back(item->data(Qt::EditRole).toDouble());
2128 int nbHeight = height_lw->count();
2129 for ( int r = 0; r < nbHeight; ++r){
2130 item = height_lw->item(r);
2131 heights.push_back(item->data(Qt::EditRole).toDouble());
2134 iNewElts = docModel->makeCartesian( icenter, ibase, ivec, iaxis,
2135 radius, angles, heights);
2140 if ( !iNewElts.isValid() )
2142 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE GRID" ) + "\n" + getErrorMsg() );
2146 result = patternDataModel->mapFromSource(iNewElts);
2147 // result = patternBuilderModel->mapFromSource( iNewElts );
2152 // ============================================================== Constructeur
2154 MakeCylinderDialog::MakeCylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2155 : HexaBaseDialog(parent, editmode, f)
2158 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinder";
2159 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2160 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2161 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2162 _initWidget(editmode);
2167 // ============================================================== Destructeur
2168 MakeCylinderDialog::~MakeCylinderDialog()
2172 void MakeCylinderDialog::_initInputWidget( Mode editmode )
2174 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
2175 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2176 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE));
2178 installEventFilter(this);
2179 origin_le->installEventFilter(this);
2180 axis_le->installEventFilter(this);
2181 base_le->installEventFilter(this);
2183 origin_le->setReadOnly(true);
2184 axis_le->setReadOnly(true);
2185 base_le->setReadOnly(true);
2187 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2188 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2190 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2191 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2193 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2194 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2196 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2197 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2199 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2200 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2202 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2203 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2206 // ============================================================== updateHelpFileName
2207 void MakeCylinderDialog::updateHelpFileName()
2209 if ( sender() == rb0 ){
2210 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindersimple";
2211 } else if ( sender() == rb1 ){
2212 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinderuniform";
2213 } else if ( sender() == rb2 ){
2214 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindercustom";
2218 // ============================================================== addRadiusItem
2219 void MakeCylinderDialog::addRadiusItem()
2221 QListWidgetItem* previousItem = radius_lw->currentItem();
2222 QListWidgetItem* newItem = new QListWidgetItem();
2224 double defaultValue = 1.;
2226 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2228 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2229 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2230 radius_lw->addItem(newItem);
2233 // ============================================================== delRadiusItem
2234 void MakeCylinderDialog::delRadiusItem()
2236 delete radius_lw->currentItem();
2239 // ============================================================== addAngleItem
2240 void MakeCylinderDialog::addAngleItem()
2242 QListWidgetItem* previousItem = angle_lw->currentItem();
2243 QListWidgetItem* newItem = new QListWidgetItem();
2245 double defaultValue = 180.;
2247 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2249 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2250 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2251 angle_lw->addItem(newItem);
2254 // ============================================================== delAngleItem
2255 void MakeCylinderDialog::delAngleItem()
2257 delete angle_lw->currentItem();
2260 // ============================================================== addHeightItem
2261 void MakeCylinderDialog::addHeightItem()
2263 QListWidgetItem* previousItem = height_lw->currentItem();
2264 QListWidgetItem* newItem = new QListWidgetItem();
2266 double defaultValue = 1.;
2268 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2270 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2271 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2272 height_lw->addItem(newItem);
2275 // ============================================================== delHeightItem
2276 void MakeCylinderDialog::delHeightItem()
2278 delete height_lw->currentItem();
2281 // ============================================================== clear
2282 void MakeCylinderDialog::clear()
2285 modelUnregister(origin_le);
2288 modelUnregister(axis_le);
2291 modelUnregister(base_le);
2293 modelUnregister(this);
2296 // ============================================================== apply
2297 bool MakeCylinderDialog::apply(QModelIndex& result)
2299 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2302 DocumentModel* docModel = getDocumentModel();
2303 PatternDataModel* patternDataModel = getPatternDataModel();
2304 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2306 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2307 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2308 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2309 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2310 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2311 double rext = ext_radius_spb->value();
2312 double rint = int_radius_spb->value();
2313 double angle = angle_spb->value();
2314 double height = height_spb->value();
2315 double nr = nr_spb->value();
2316 double na = na_spb->value();
2317 double nh = nh_spb->value();
2320 if (rb0->isChecked())
2321 iElts = docModel->makeCylinderTop(nr, na, nh);
2322 else if (rb1->isChecked())
2324 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2325 iElts = docModel->makeCylinderUni(iorigin, ibase, iaxis, rint,
2326 rext, angle, height, nr, na, nh);
2328 else if (rb2->isChecked())
2330 QListWidgetItem* item = NULL;
2332 vector<double> radius;
2333 vector<double> angles;
2334 vector<double> heights;
2336 // double somme = 0.;
2337 int nbAngles = angle_lw->count();
2338 for ( int r = 0; r < nbAngles; ++r){
2339 item = angle_lw->item(r);
2340 double itemValue = item->data(Qt::EditRole).toDouble();
2341 angles.push_back(itemValue);
2342 // somme += itemValue;
2344 // if (somme > 360.01)
2346 // SUIT_MessageBox::information( 0,
2348 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2352 int nbRadius = radius_lw->count();
2353 for ( int r = 0; r < nbRadius; ++r){
2354 item = radius_lw->item(r);
2355 radius.push_back(item->data(Qt::EditRole).toDouble());
2358 int nbHeight = height_lw->count();
2359 for ( int r = 0; r < nbHeight; ++r){
2360 item = height_lw->item(r);
2361 heights.push_back(item->data(Qt::EditRole).toDouble());
2364 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2365 iElts = docModel->makeCylinder( iorigin, ibase, iaxis, radius, angles, heights);
2369 if ( !iElts.isValid() ){
2370 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDER" ) + "\n" + getErrorMsg() );
2374 result = patternDataModel->mapFromSource(iElts);
2375 // result = patternBuilderModel->mapFromSource(iElts);
2380 //---------------------------------- MakePipeDialog -----------------------------
2381 // ============================================================== Constructeur
2383 MakePipeDialog::MakePipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2384 : HexaBaseDialog(parent, editmode, f)
2387 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipe";
2388 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2389 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2390 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2391 _initWidget(editmode);
2395 // ============================================================== Destructeur
2396 MakePipeDialog::~MakePipeDialog()
2400 // ============================================================== _initInputWidget
2401 void MakePipeDialog::_initInputWidget( Mode editmode )
2403 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2404 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2405 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2407 installEventFilter(this);
2408 origin_le->installEventFilter(this);
2409 axis_le->installEventFilter(this);
2410 base_le->installEventFilter(this);
2412 origin_le->setReadOnly(true);
2413 axis_le->setReadOnly(true);
2414 base_le->setReadOnly(true);
2416 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2417 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2419 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2420 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2422 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2423 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2425 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2426 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2428 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2429 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2431 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2432 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2436 // ============================================================== updateHelpFileName
2437 void MakePipeDialog::updateHelpFileName()
2439 if ( sender() == rb0 ){
2440 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipesimple";
2441 } else if ( sender() == rb1 ){
2442 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipeuniform";
2443 } else if ( sender() == rb2 ){
2444 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipecustom";
2448 // ============================================================== addRadiusItem
2449 void MakePipeDialog::addRadiusItem()
2451 QListWidgetItem* previousItem = radius_lw->currentItem();
2452 QListWidgetItem* newItem = new QListWidgetItem();
2454 double defaultValue = 1.;
2456 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2458 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2459 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2460 radius_lw->addItem(newItem);
2463 // ============================================================== delRadiusItem
2464 void MakePipeDialog::delRadiusItem()
2466 delete radius_lw->currentItem();
2469 // ============================================================== addAngleItem
2470 void MakePipeDialog::addAngleItem()
2472 QListWidgetItem* previousItem = angle_lw->currentItem();
2473 QListWidgetItem* newItem = new QListWidgetItem();
2475 double defaultValue = 180.;
2477 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2479 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2480 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2481 angle_lw->addItem(newItem);
2484 // ============================================================== delAngleItem
2485 void MakePipeDialog::delAngleItem()
2487 delete angle_lw->currentItem();
2490 // ============================================================== addHeightItem
2491 void MakePipeDialog::addHeightItem()
2493 QListWidgetItem* previousItem = height_lw->currentItem();
2494 QListWidgetItem* newItem = new QListWidgetItem();
2496 double defaultValue = 1.;
2498 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2500 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2501 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2502 height_lw->addItem(newItem);
2505 // ============================================================== delHeightItem
2506 void MakePipeDialog::delHeightItem()
2508 delete height_lw->currentItem();
2511 // ============================================================== clear
2512 void MakePipeDialog::clear()
2515 modelUnregister(origin_le);
2518 modelUnregister(axis_le);
2521 modelUnregister(base_le);
2523 modelUnregister(this);
2526 // ============================================================== apply
2527 bool MakePipeDialog::apply(QModelIndex& result)
2529 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2532 DocumentModel* docModel = getDocumentModel();
2533 PatternDataModel* patternDataModel = getPatternDataModel();
2534 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2536 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2537 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2538 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2539 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2540 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2541 double rext = ext_radius_spb->value();
2542 double rint = int_radius_spb->value();
2543 double angle = angle_spb->value();
2544 double height = height_spb->value();
2545 int nr = nr_spb->value();
2546 int na = na_spb->value();
2547 int nh = nh_spb->value();
2551 if (rb0->isChecked())
2552 iElts = docModel->makePipeTop(nr, na, nh);
2553 else if (rb1->isChecked())
2555 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2556 iElts = docModel->makePipeUni(iorigin, ibase, iaxis, rint, rext, angle, height,
2559 else if (rb2->isChecked())
2561 QListWidgetItem* item = NULL;
2563 vector<double> radius;
2564 vector<double> angles;
2565 vector<double> heights;
2567 // double somme = 0.;
2568 int nbAngles = angle_lw->count();
2569 for ( int r = 0; r < nbAngles; ++r){
2570 item = angle_lw->item(r);
2571 double itemValue = item->data(Qt::EditRole).toDouble();
2572 angles.push_back(itemValue);
2573 // somme += itemValue;
2575 // if (somme > 360.01)
2577 // SUIT_MessageBox::information( 0,
2579 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2583 int nbRadius = radius_lw->count();
2584 for ( int r = 0; r < nbRadius; ++r){
2585 item = radius_lw->item(r);
2586 radius.push_back(item->data(Qt::EditRole).toDouble());
2589 int nbHeight = height_lw->count();
2590 for ( int r = 0; r < nbHeight; ++r){
2591 item = height_lw->item(r);
2592 heights.push_back(item->data(Qt::EditRole).toDouble());
2594 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2595 iElts = docModel->makePipe( iorigin, ibase, iaxis, radius, angles, heights );
2598 if ( !iElts.isValid() ){
2599 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPE" ) + "\n" + getErrorMsg() );
2603 // to select/highlight result
2604 result = patternDataModel->mapFromSource(iElts);
2605 // result = patternBuilderModel->mapFromSource(iElts);
2610 //---------------------------------- MakeCylindersDialog -----------------------------
2611 // ============================================================== Constructeur
2613 MakeCylindersDialog::MakeCylindersDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2614 : HexaBaseDialog(parent, editmode, f)
2616 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinders";
2618 _initWidget(editmode);
2621 // ============================================================== Destructeur
2622 MakeCylindersDialog::~MakeCylindersDialog()
2626 void MakeCylindersDialog::_initInputWidget( Mode editmode )
2628 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2629 center2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2630 direction_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2631 direction2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2633 installEventFilter(this);
2634 center_le->installEventFilter(this);
2635 center2_le->installEventFilter(this);
2636 direction_le->installEventFilter(this);
2637 direction2_le->installEventFilter(this);
2639 center_le->setReadOnly(true);
2640 center2_le->setReadOnly(true);
2641 direction_le->setReadOnly(true);
2642 direction2_le->setReadOnly(true);
2645 // ============================================================== clear
2646 void MakeCylindersDialog::clear()
2649 modelUnregister(center_le);
2651 center2_le->clear();
2652 modelUnregister(center2_le);
2654 direction_le->clear();
2655 modelUnregister(direction_le);
2657 direction2_le->clear();
2658 modelUnregister(direction2_le);
2660 modelUnregister(this);
2663 // ============================================================== apply
2664 bool MakeCylindersDialog::apply(QModelIndex& result)
2666 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2669 DocumentModel* docModel = getDocumentModel();
2670 PatternDataModel* patternDataModel = getPatternDataModel();
2671 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2674 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2675 QModelIndex icenter2 = patternDataModel->mapToSource( _index[center2_le] );
2676 QModelIndex idir = patternDataModel->mapToSource( _index[direction_le] );
2677 QModelIndex idir2 = patternDataModel->mapToSource( _index[direction2_le] );
2678 // QModelIndex idir = patternBuilderModel->mapToSource( _index[direction_le] );
2679 // QModelIndex idir2 = patternBuilderModel->mapToSource( _index[direction2_le] );
2681 if ( icenter.isValid() && icenter2.isValid() && idir.isValid() && idir2.isValid()){
2682 double r1 = radius_spb->value();
2683 double h1 = height_spb->value();
2684 double r2 = radius2_spb->value();
2685 double h2 = height2_spb->value();
2686 iElts = docModel->makeCylinders( icenter, idir, r1, h1, icenter2, idir2, r2, h2 );
2689 if ( !iElts.isValid() ){
2690 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDERS" ) + "\n" + getErrorMsg() );
2694 result = patternDataModel->mapFromSource(iElts);
2695 // result = patternBuilderModel->mapFromSource(iElts);
2700 //---------------------------------- MakePipesDialog -----------------------------
2701 // ============================================================== Constructeur
2703 MakePipesDialog::MakePipesDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2704 : HexaBaseDialog(parent, editmode, f)
2706 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipes";
2708 _initWidget(editmode);
2711 // ============================================================== Destructeur
2712 MakePipesDialog::~MakePipesDialog()
2716 // ============================================================== _initInputWidget
2717 void MakePipesDialog::_initInputWidget( Mode editmode )
2719 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2720 origin2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2721 dir_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2722 dir2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2724 installEventFilter(this);
2725 origin_le->installEventFilter(this);
2726 origin2_le->installEventFilter(this);
2727 dir_le->installEventFilter(this);
2728 dir2_le->installEventFilter(this);
2730 origin_le->setReadOnly(true);
2731 origin2_le->setReadOnly(true);
2732 dir_le->setReadOnly(true);
2733 dir2_le->setReadOnly(true);
2736 // ============================================================== clear
2737 void MakePipesDialog::clear()
2740 modelUnregister(origin_le);
2742 origin2_le->clear();
2743 modelUnregister(origin2_le);
2746 modelUnregister(dir_le);
2749 modelUnregister(dir2_le);
2751 modelUnregister(this);
2754 // ============================================================== apply
2755 bool MakePipesDialog::apply(QModelIndex& result)
2757 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2760 DocumentModel* docModel = getDocumentModel();
2761 PatternDataModel* patternDataModel = getPatternDataModel();
2762 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2764 QModelIndex iorigin1 = patternDataModel->mapToSource( _index[origin_le] );
2765 QModelIndex iorigin2 = patternDataModel->mapToSource( _index[origin2_le] );
2766 QModelIndex idir1 = patternDataModel->mapToSource( _index[dir_le] );
2767 QModelIndex idir2 = patternDataModel->mapToSource( _index[dir2_le] );
2768 // QModelIndex idir1 = patternBuilderModel->mapToSource( _index[dir_le] );
2769 // QModelIndex idir2 = patternBuilderModel->mapToSource( _index[dir2_le] );
2770 double rint1 = int_radius_spb->value();
2771 double rext1 = ext_radius_spb->value();
2772 double height1 = height_spb->value();
2773 double rint2 = int_radius2_spb->value();
2774 double rext2 = ext_radius2_spb->value();
2775 double height2 = height_spb->value();
2779 if ( iorigin1.isValid() && iorigin2.isValid() && idir1.isValid() && idir2.isValid())
2780 iElts = docModel->makePipes( iorigin1, idir1, rint1, rext1, height1,
2781 iorigin2, idir2, rint2, rext2, height2);
2783 if ( !iElts.isValid() ){
2784 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPES" ) + "\n" + getErrorMsg() );
2788 result = patternDataModel->mapFromSource(iElts);
2789 // result = patternBuilderModel->mapFromSource(iElts);
2794 //---------------------------------- RemoveHexaDialog -----------------------------
2795 // ============================================================== Constructeur
2797 RemoveHexaDialog::RemoveHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2798 : HexaBaseDialog(parent, editmode, f)
2800 _helpFileName = "gui_remove.html";
2802 _initWidget(editmode);
2805 // ============================================================== Destructeur
2806 RemoveHexaDialog::~RemoveHexaDialog()
2810 // ============================================================== _initInputWidget
2811 void RemoveHexaDialog::_initInputWidget( Mode editmode )
2814 QValidator *validator = new QRegExpValidator(rx, this);
2816 hexa_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
2817 hexa_le->setValidator( validator );
2818 hexa_le->installEventFilter(this);
2819 hexa_le->setReadOnly(true);
2820 autoFocusSwitch = false;
2823 // ============================================================== clear
2824 void RemoveHexaDialog::clear()
2827 modelUnregister(hexa_le);
2829 modelUnregister(this);
2832 // ============================================================== apply
2833 bool RemoveHexaDialog::apply(QModelIndex& result)
2835 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2838 if ( !getDocumentModel() ) return false;
2839 const PatternDataModel* patternDataModel = getPatternDataModel();
2840 if ( !patternDataModel ) return false;
2842 QModelIndex ihexa = patternDataModel->mapToSource( _index[hexa_le] );
2844 bool removed = false;
2845 if ( ihexa.isValid() ){
2846 if ( connected_cb->isChecked() ){
2847 removed = getDocumentModel()->removeConnectedHexa( ihexa );
2849 removed = getDocumentModel()->removeHexa( ihexa );
2853 if ( removed == false ){
2854 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE HEXA" ) + "\n" + getErrorMsg() );
2863 //---------------------------------- PrismQuadDialog -----------------------------
2864 // ============================================================== Constructeur
2866 PrismQuadDialog::PrismQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2867 : HexaBaseDialog(parent, editmode, f)
2870 _helpFileName = "gui_prism_join_quad.html#guiextrudequads";
2871 connect( extrudeTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2872 connect( extrudeUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2873 connect( extrude_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2874 _initWidget(editmode);
2875 extrudeTop_rb->click();
2878 // ============================================================== Destructeur
2879 PrismQuadDialog::~PrismQuadDialog()
2883 // ============================================================== getAssocsVTK
2885 * Returns elements currently associated to vtk
2887 QModelIndexList PrismQuadDialog::getAssocsVTK()
2889 QModelIndexList assocs;
2891 QListWidgetItem* item = NULL;
2893 //ListWidget content
2894 const PatternDataModel* patternDataModel = getPatternDataModel();
2895 if ( !patternDataModel ) return assocs;
2896 int nbQuads = quads_lw->count();
2897 for ( int r = 0; r < nbQuads; ++r ){
2898 item = quads_lw->item(r);
2899 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
2900 if ( iQuad.isValid() )
2906 // ============================================================== _initInputWidget
2907 void PrismQuadDialog::_initInputWidget( Mode editmode )
2909 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
2910 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2912 installEventFilter(this);
2913 quads_lw->installEventFilter(this);
2914 axis_le->installEventFilter(this);
2916 axis_le->setReadOnly(true);
2918 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
2919 delQuadShortcut->setContext( Qt::WidgetShortcut );
2920 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2921 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2923 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
2924 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
2925 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2926 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2929 // ============================================================== updateHelpFileName
2930 void PrismQuadDialog::updateHelpFileName()
2932 if ( sender() == extrudeTop_rb ){
2933 _helpFileName = "gui_prism_join_quad.html#guiextrudequadssimple";
2934 } else if ( sender() == extrudeUni_rb ){
2935 _helpFileName = "gui_prism_join_quad.html#guiextrudequadsuniform";
2936 } else if ( sender() == extrude_rb ){
2937 _helpFileName = "gui_prism_join_quad.html#guiextrudequadscustom";
2941 // ============================================================== clear
2942 void PrismQuadDialog::clear()
2945 modelUnregister(quads_lw);
2948 modelUnregister(axis_le);
2950 modelUnregister(this);
2953 // ============================================================== removeQuad
2954 void PrismQuadDialog::removeQuad()
2956 QListWidgetItem *item = quads_lw->currentItem();
2959 int r = quads_lw->row(item);
2960 quads_lw->takeItem(r);
2965 // ============================================================== addHeightItem
2966 void PrismQuadDialog::addHeightItem()
2968 QListWidgetItem* previousItem = height_lw->currentItem();
2969 QListWidgetItem* newItem = new QListWidgetItem();
2971 double defaultValue = 1.;
2973 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2975 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2976 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2977 height_lw->addItem(newItem);
2980 // ============================================================== delHeightItem
2981 void PrismQuadDialog::delHeightItem()
2983 delete height_lw->currentItem();
2986 // ============================================================== apply
2987 bool PrismQuadDialog::apply(QModelIndex& result)
2989 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2992 DocumentModel* docModel = getDocumentModel();
2993 PatternDataModel* patternDataModel = getPatternDataModel();
2994 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2996 QModelIndexList iquads = getIndexList(quads_lw);
2997 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2998 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2999 double length = length_spb->value();
3000 int nb = nb_spb->value();
3002 vector<double> heights;
3003 QListWidgetItem* item = NULL;
3004 int nbItems = height_lw->count();
3006 for ( int r = 0; r < nbItems; ++r){
3007 item = height_lw->item(r);
3008 heights.push_back( item->data(Qt::EditRole).toDouble() );
3012 int nbQuads = iquads.count();
3014 if (nbQuads == 1 && iquads[0].isValid())
3016 if (extrudeTop_rb->isChecked())
3017 iElts = docModel->extrudeQuadTop(iquads[0], nb);
3018 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3019 iElts = docModel->extrudeQuadUni(iquads[0], iaxis, length, nb);
3020 else if (extrude_rb->isChecked() && iaxis.isValid())
3021 iElts = docModel->extrudeQuad(iquads[0], iaxis, heights);
3023 else if (nbQuads > 1)
3025 if (extrudeTop_rb->isChecked())
3026 iElts = docModel->extrudeQuadsTop(iquads, nb);
3027 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3028 iElts = docModel->extrudeQuadsUni(iquads, iaxis, length, nb);
3029 else if (extrude_rb->isChecked() && iaxis.isValid())
3030 iElts = docModel->extrudeQuads(iquads, iaxis, heights);
3033 if ( !iElts.isValid() ){
3034 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PRISM QUAD(S)" ) + "\n" + getErrorMsg() );
3038 result = patternDataModel->mapFromSource(iElts);
3039 // result = patternBuilderModel->mapFromSource(iElts);
3044 //---------------------------------- JoinQuadDialog -----------------------------
3045 // ============================================================== Constructeur
3047 JoinQuadDialog::JoinQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3048 : HexaBaseDialog(parent, editmode, f)
3051 _helpFileName = "gui_prism_join_quad.html#guijoinquads";
3052 connect( joinUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3053 connect( join_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3054 _initWidget(editmode);
3055 joinUni_rb->click();
3058 // ============================================================== Destructeur
3059 JoinQuadDialog::~JoinQuadDialog()
3063 // ============================================================== getAssocsVTK
3065 * Returns elements currently associated to vtk
3067 QModelIndexList JoinQuadDialog::getAssocsVTK()
3069 QModelIndexList assocs;
3071 QListWidgetItem* item = NULL;
3073 if (getPatternDataSelectionModel() == NULL) return assocs;
3075 //ListWidget content
3076 const PatternDataModel* patternDataModel = getPatternDataModel();
3077 if ( !patternDataModel ) return assocs;
3078 int nbQuads = quads_lw->count();
3079 for ( int r = 0; r < nbQuads; ++r ){
3080 item = quads_lw->item(r);
3081 // iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
3082 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
3083 if ( iQuad.isValid() ) assocs << iQuad;
3088 // ============================================================== _initInputWidget
3089 void JoinQuadDialog::_initInputWidget( Mode editmode )
3091 quad_dest_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3092 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3093 vex0_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3094 vex1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3095 vex2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3096 vex3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3098 installEventFilter(this);
3099 quad_dest_le->installEventFilter(this);
3100 quads_lw->installEventFilter(this);
3101 vex0_le->installEventFilter(this);
3102 vex1_le->installEventFilter(this);
3103 vex2_le->installEventFilter(this);
3104 vex3_le->installEventFilter(this);
3106 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3107 delQuadShortcut->setContext( Qt::WidgetShortcut );
3108 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3110 quad_dest_le->setReadOnly(true);
3111 vex0_le->setReadOnly(true);
3112 vex1_le->setReadOnly(true);
3113 vex2_le->setReadOnly(true);
3114 vex3_le->setReadOnly(true);
3116 _currentObj = quads_lw;
3117 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3118 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3120 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3122 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3123 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3126 // ============================================================== updateHelpFileName
3127 void JoinQuadDialog::updateHelpFileName()
3129 if ( sender() == joinUni_rb ){
3130 _helpFileName = "gui_prism_join_quad.html#guijoinquadsuniform";
3131 } else if ( sender() == join_rb ){
3132 _helpFileName = "gui_prism_join_quad.html#guijoinquadscustom";
3136 // ============================================================== addHeightItem
3137 void JoinQuadDialog::addHeightItem()
3139 QListWidgetItem* previousItem = height_lw->currentItem();
3140 QListWidgetItem* newItem = new QListWidgetItem();
3142 double defaultValue = 1.;
3144 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3146 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3147 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3148 height_lw->addItem(newItem);
3151 // ============================================================== delHeightItem
3152 void JoinQuadDialog::delHeightItem()
3154 delete height_lw->currentItem();
3157 // ============================================================== clear
3158 void JoinQuadDialog::clear()
3160 quad_dest_le->clear();
3161 modelUnregister(quad_dest_le);
3164 modelUnregister(quads_lw);
3167 modelUnregister(vex0_le);
3170 modelUnregister(vex1_le);
3173 modelUnregister(vex2_le);
3176 modelUnregister(vex3_le);
3178 modelUnregister(this);
3181 // ============================================================== removeQuad
3182 void JoinQuadDialog::removeQuad()
3184 QListWidgetItem *item = quads_lw->currentItem();
3187 int r = quads_lw->row(item);
3188 quads_lw->takeItem(r);
3193 // ============================================================== apply
3194 bool JoinQuadDialog::apply(QModelIndex& result)
3196 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3199 DocumentModel* docModel = getDocumentModel();
3200 PatternDataModel* patternDataModel = getPatternDataModel();
3201 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3203 QModelIndexList iquads;
3205 QListWidgetItem* item = NULL;
3206 int nbQuads = quads_lw->count();
3207 for ( int r = 0; r < nbQuads; ++r){
3208 item = quads_lw->item(r);
3209 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3210 if ( iquad.isValid() )
3213 QModelIndex iquaddest = patternDataModel->mapToSource( _index[quad_dest_le] );
3214 QModelIndex ivex0 = patternDataModel->mapToSource( _index[vex0_le] );
3215 QModelIndex ivex1 = patternDataModel->mapToSource( _index[vex1_le] );
3216 QModelIndex ivex2 = patternDataModel->mapToSource( _index[vex2_le] );
3217 QModelIndex ivex3 = patternDataModel->mapToSource( _index[vex3_le] );
3218 double nb = nb_spb->value();
3220 vector<double> heights;
3221 int nbHeight = height_lw->count();
3222 for ( int r = 0; r < nbHeight; ++r){
3223 item = height_lw->item(r);
3224 heights.push_back(item->data(Qt::EditRole).toDouble());
3228 if (nbQuads == 1 && iquads[0].isValid() && iquaddest.isValid() && ivex0.isValid() &&
3229 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3231 if (joinUni_rb->isChecked())
3232 iElts = docModel->joinQuadUni(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3233 else if (join_rb->isChecked())
3234 iElts = docModel->joinQuad(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3236 else if (nbQuads > 1 && iquaddest.isValid() && ivex0.isValid() &&
3237 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3239 if (joinUni_rb->isChecked())
3240 iElts = docModel->joinQuadsUni(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3241 else if (join_rb->isChecked())
3242 iElts = docModel->joinQuads(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3245 if ( !iElts.isValid() ){
3246 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT JOIN QUAD(S)" ) + "\n" + getErrorMsg() );
3249 result = patternDataModel->mapFromSource(iElts);
3250 // result = patternBuilderModel->mapFromSource(iElts);
3255 // ------------------------- MergeDialog ----------------------------------
3256 // ============================================================== Constructeur
3258 MergeDialog::MergeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3259 : HexaBaseDialog(parent, editmode, f)
3262 _initWidget(editmode);
3265 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3266 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3267 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3268 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3270 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3271 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3272 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3274 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3275 connect( rb2, SIGNAL(cliked()), this, SLOT(clearVTKSelection()) );
3276 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3279 // ============================================================== Destructeur
3280 MergeDialog::~MergeDialog()
3284 // ============================================================== _initInputWidget
3285 void MergeDialog::_initInputWidget( Mode editmode )
3288 QValidator *validator = new QRegExpValidator(rx, this);
3290 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3291 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3292 v0_le_rb0->setValidator( validator );
3293 v1_le_rb0->setValidator( validator );
3294 v0_le_rb0->installEventFilter(this);
3295 v1_le_rb0->installEventFilter(this);
3297 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3298 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3299 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3300 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3302 v0_le_rb1->setValidator( validator );
3303 v1_le_rb1->setValidator( validator );
3304 e0_le_rb1->setValidator( validator );
3305 e1_le_rb1->setValidator( validator );
3307 v0_le_rb1->installEventFilter(this);
3308 v1_le_rb1->installEventFilter(this);
3309 e0_le_rb1->installEventFilter(this);
3310 e1_le_rb1->installEventFilter(this);
3312 v0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3313 v1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3314 v2_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3315 v3_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3316 q0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3317 q1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3319 v0_le_rb2->setValidator( validator );
3320 v1_le_rb2->setValidator( validator );
3321 v2_le_rb2->setValidator( validator );
3322 v3_le_rb2->setValidator( validator );
3323 q0_le_rb2->setValidator( validator );
3324 q1_le_rb2->setValidator( validator );
3326 v0_le_rb2->installEventFilter(this);
3327 v1_le_rb2->installEventFilter(this);
3328 v2_le_rb2->installEventFilter(this);
3329 v3_le_rb2->installEventFilter(this);
3330 q0_le_rb2->installEventFilter(this);
3331 q1_le_rb2->installEventFilter(this);
3333 v0_le_rb0->setReadOnly(true);
3334 v1_le_rb0->setReadOnly(true);
3336 v0_le_rb1->setReadOnly(true);
3337 v1_le_rb1->setReadOnly(true);
3338 e0_le_rb1->setReadOnly(true);
3339 e1_le_rb1->setReadOnly(true);
3341 v0_le_rb2->setReadOnly(true);
3342 v1_le_rb2->setReadOnly(true);
3343 v2_le_rb2->setReadOnly(true);
3344 v3_le_rb2->setReadOnly(true);
3345 q0_le_rb2->setReadOnly(true);
3346 q1_le_rb2->setReadOnly(true);
3349 // ============================================================== clear
3350 void MergeDialog::clear()
3353 modelUnregister(v0_le_rb0);
3356 modelUnregister(v1_le_rb0);
3359 modelUnregister(e0_le_rb1);
3362 modelUnregister(e1_le_rb1);
3365 modelUnregister(v0_le_rb1);
3368 modelUnregister(v1_le_rb1);
3371 modelUnregister(q0_le_rb2);
3374 modelUnregister(q1_le_rb2);
3377 modelUnregister(v0_le_rb2);
3380 modelUnregister(v1_le_rb2);
3383 modelUnregister(v2_le_rb2);
3386 modelUnregister(v3_le_rb2);
3388 modelUnregister(this);
3391 // ============================================================== updateHelpFileName
3392 void MergeDialog::updateHelpFileName()
3394 if ( sender() == rb0 ){
3395 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3396 } else if ( sender() == rb1 ){
3397 _helpFileName = "gui_merge_elmts.html#merge-two-edges";
3398 } else if ( sender() == rb2 ){
3399 _helpFileName = "gui_merge_elmts.html#merge-two-quadrangles";
3403 // ============================================================== apply
3404 bool MergeDialog::apply(QModelIndex& result)
3406 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3409 if (getDocumentModel() == NULL) return false;
3410 const PatternDataModel* patternDataModel = getPatternDataModel();
3411 if ( !patternDataModel ) return false;
3413 bool merged = false;
3415 if ( rb0->isChecked() ){
3416 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
3417 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
3421 merged = getDocumentModel()->mergeVertices( iv0, iv1 );
3423 } else if ( rb1->isChecked() ){
3424 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
3425 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
3426 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
3427 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
3433 merged = getDocumentModel()->mergeEdges( ie0, ie1, iv0, iv1);
3435 } else if ( rb2->isChecked() ){
3437 QModelIndex iq0 = patternDataModel->mapToSource( _index[q0_le_rb2] );
3438 QModelIndex iq1 = patternDataModel->mapToSource( _index[q1_le_rb2] );
3439 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb2] );
3440 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb2] );
3441 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb2] );
3442 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb2] );
3450 merged = getDocumentModel()->mergeQuads( iq0, iq1,
3451 iv0, iv1, iv2, iv3 );
3455 if ( merged == false ){
3456 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MERGE" ) + "\n" + getErrorMsg() );
3463 // ------------------------- DisconnectDialog ----------------------------------
3464 // ============================================================== Constructeur
3466 DisconnectDialog::DisconnectDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3467 : HexaBaseDialog(parent, editmode, f)
3470 _initWidget(editmode);
3473 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3475 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3476 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3477 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3479 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3480 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3481 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3483 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3484 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3485 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3487 connect( rb3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3488 connect( rb3, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3489 connect( rb3, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3493 // ============================================================== Destructeur
3494 DisconnectDialog::~DisconnectDialog()
3498 // ============================================================== _initInputWidget
3499 void DisconnectDialog::_initInputWidget( Mode editmode )
3502 QValidator *validator = new QRegExpValidator(rx, this);
3504 installEventFilter(this);
3507 v_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3508 h_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3509 v_le_rb0->setValidator( validator );
3510 h_le_rb0->setValidator( validator );
3511 v_le_rb0->installEventFilter(this);
3512 h_le_rb0->installEventFilter(this);
3515 e_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3516 h_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3517 e_le_rb1->setValidator( validator );
3518 h_le_rb1->setValidator( validator );
3519 e_le_rb1->installEventFilter(this);
3520 h_le_rb1->installEventFilter(this);
3523 q_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3524 h_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3525 q_le_rb2->setValidator( validator );
3526 h_le_rb2->setValidator( validator );
3527 q_le_rb2->installEventFilter(this);
3528 h_le_rb2->installEventFilter(this);
3531 d_edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3532 hexas_lw->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3533 d_edges_lw->installEventFilter(this);
3534 hexas_lw->installEventFilter(this);
3536 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), d_edges_lw);
3537 QShortcut* delHexaShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), hexas_lw);
3538 delEdgeShortcut->setContext( Qt::WidgetShortcut );
3539 delHexaShortcut->setContext( Qt::WidgetShortcut );
3541 v_le_rb0->setReadOnly(true);
3542 h_le_rb0->setReadOnly(true);
3544 e_le_rb1->setReadOnly(true);
3545 h_le_rb1->setReadOnly(true);
3547 q_le_rb2->setReadOnly(true);
3548 h_le_rb2->setReadOnly(true);
3550 connect( d_edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3551 connect( hexas_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3552 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
3553 connect( delHexaShortcut, SIGNAL(activated()), this, SLOT(deleteHexaItem()) );
3554 autoFocusSwitch = false;
3558 // =============================================== getAssocsVTK
3560 * Returns elements in the list
3562 QModelIndexList DisconnectDialog::getAssocsVTK()
3564 QModelIndexList iElts;
3566 QListWidgetItem* item = NULL;
3568 const PatternDataModel* patternDataModel = getPatternDataModel();
3569 if (patternDataModel == NULL || !rb3->isChecked())
3571 //ListWidget content
3572 if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == EDGE_TREE)
3574 int nbEdges = d_edges_lw->count();
3575 for ( int r = 0; r < nbEdges; ++r )
3577 item = d_edges_lw->item(r);
3578 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3579 if ( index.isValid() )
3583 else if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == HEXA_TREE)
3585 int nbHexas = hexas_lw->count();
3586 for ( int r = 0; r < nbHexas; ++r )
3588 item = hexas_lw->item(r);
3589 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3590 if ( index.isValid() )
3597 // ============================================================== clear
3598 void DisconnectDialog::clear()
3601 modelUnregister(v_le_rb0);
3604 modelUnregister(h_le_rb0);
3607 modelUnregister(e_le_rb1);
3610 modelUnregister(h_le_rb1);
3612 d_edges_lw->clear();
3613 modelUnregister(d_edges_lw);
3616 modelUnregister(hexas_lw);
3619 modelUnregister(q_le_rb2);
3622 modelUnregister(h_le_rb2);
3624 modelUnregister(this);
3627 // ============================================================== deleteEdgeItem
3628 void DisconnectDialog::deleteEdgeItem()
3630 delete d_edges_lw->currentItem();
3633 // ============================================================== deleteHexaItem
3634 void DisconnectDialog::deleteHexaItem()
3636 delete hexas_lw->currentItem();
3639 // ============================================================== updateHelpFileName
3640 void DisconnectDialog::updateHelpFileName()
3642 if ( sender() == rb0 ){
3643 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3644 } else if ( sender() == rb1 ){
3645 _helpFileName = "gui_disc_elmts.html#disconnect-an-edge";
3646 } else if ( sender() == rb2 ){
3647 _helpFileName = "gui_disc_elmts.html#disconnect-a-quadrangle";
3648 } else if (sender() == rb3 ){
3649 _helpFileName = "gui_disc_elmts.html#disconnect-edges";
3653 // ============================================================== apply
3654 bool DisconnectDialog::apply(QModelIndex& result)
3656 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3658 if (getDocumentModel() == NULL) return false;
3659 const PatternDataModel* patternDataModel = getPatternDataModel();
3660 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3661 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
3665 if ( rb0->isChecked() ){
3666 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb0] );
3667 QModelIndex ivex = patternDataModel->mapToSource( _index[v_le_rb0] );
3669 if ( ihexa.isValid()
3670 && ivex.isValid() ){
3671 iElts = getDocumentModel()->disconnectVertex( ihexa, ivex );
3673 } else if ( rb1->isChecked() ){
3674 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb1] );
3675 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le_rb1] );
3677 if ( ihexa.isValid()
3678 && iedge.isValid() ){
3679 iElts = getDocumentModel()->disconnectEdge( ihexa, iedge );
3681 } else if ( rb2->isChecked() ){
3682 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb2] );
3683 QModelIndex iquad = patternDataModel->mapToSource( _index[q_le_rb2] );
3685 if ( ihexa.isValid()
3686 && iquad.isValid() ){
3687 iElts = getDocumentModel()->disconnectQuad( ihexa, iquad );
3689 } else if ( rb3->isChecked() ){ //
3691 QModelIndex iedge, ihexa;
3692 QModelIndexList iedges, ihexas;
3693 QListWidgetItem* item = NULL;
3696 int nbEdges = d_edges_lw->count();
3697 for (int r = 0; r < nbEdges; ++r){
3698 item = d_edges_lw->item(r);
3699 iedge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3700 if ( iedge.isValid() )
3705 int nbHexas = hexas_lw->count();
3706 for (int r = 0; r < nbHexas; ++r){
3707 item = hexas_lw->item(r);
3708 ihexa = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3709 if ( ihexa.isValid() )
3713 iElts = getDocumentModel()->disconnectEdges( ihexas, iedges );
3716 if ( !iElts.isValid() ){
3717 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT DISCONNECT" ) + "\n" + getErrorMsg() );
3721 result = patternDataModel->mapFromSource(iElts);
3722 // result = patternBuilderModel->mapFromSource(iElts);
3728 // ------------------------- CutEdgeDialog ----------------------------------
3729 // ============================================================== Constructeur
3731 CutEdgeDialog::CutEdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3732 HexaBaseDialog(parent, editmode, f)
3735 _helpFileName = "gui_cut_hexa.html";
3736 connect( cutUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3737 connect( cut_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3738 _initWidget(editmode);
3743 // ============================================================== Destructeur
3744 CutEdgeDialog::~CutEdgeDialog()
3748 // ============================================================== _initInputWidget
3749 void CutEdgeDialog::_initInputWidget( Mode editmode )
3751 installEventFilter(this);
3753 e_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3754 e_le->installEventFilter(this);
3756 e_le->setReadOnly(true);
3758 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3759 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3761 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3762 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3765 // ============================================================== updateHelpFileName
3766 void CutEdgeDialog::updateHelpFileName()
3768 if ( sender() == cutUni_rb ){
3769 _helpFileName = "gui_cut_hexa.html#guicuthexauniform";
3770 } else if ( sender() == cut_rb ){
3771 _helpFileName = "gui_cut_hexa.html#guicuthexacustom";
3775 // ============================================================== clear
3776 void CutEdgeDialog::clear()
3779 modelUnregister(e_le);
3781 modelUnregister(this);
3784 // ============================================================== addHeightItem
3785 void CutEdgeDialog::addHeightItem()
3787 QListWidgetItem* previousItem = height_lw->currentItem();
3788 QListWidgetItem* newItem = new QListWidgetItem();
3790 double defaultValue = 1.;
3792 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3794 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3795 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3796 height_lw->addItem(newItem);
3799 // ============================================================== delHeightItem
3800 void CutEdgeDialog::delHeightItem()
3802 delete height_lw->currentItem();
3805 // ============================================================== apply
3806 bool CutEdgeDialog::apply(QModelIndex& result)
3808 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3811 DocumentModel* docModel = getDocumentModel();
3812 PatternDataModel* patternDataModel = getPatternDataModel();
3813 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3816 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le] );
3818 if (cutUni_rb->isChecked() && iedge.isValid())
3820 int nbCut = nb_cut_spb->value();
3821 iElts = docModel->cutUni(iedge, nbCut);
3823 else if (cut_rb->isChecked() && iedge.isValid())
3825 vector<double> heights;
3826 QListWidgetItem* item = NULL;
3827 int nbItems = height_lw->count();
3829 for ( int r = 0; r < nbItems; ++r){
3830 item = height_lw->item(r);
3831 heights.push_back( item->data(Qt::EditRole).toDouble() );
3834 iElts = docModel->cut(iedge, heights);
3837 if ( !iElts.isValid() ){
3838 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT CUT EDGE" ) + "\n" + getErrorMsg() );
3842 result = patternDataModel->mapFromSource(iElts);
3843 // result = patternBuilderModel->mapFromSource(iElts);
3845 //Update the line edit
3847 e_le->setProperty("QModelIndex", invalid );
3849 QModelIndex invalidIndex;
3850 _index[e_le] = invalidIndex;
3857 // // ------------------------- MakeTransformationDialog ----------------------------------
3858 // ============================================================== Constructeur
3860 MakeTransformationDialog::MakeTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3861 : HexaBaseDialog(parent, editmode, f)
3864 _initWidget(editmode);
3867 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
3868 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3869 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3870 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3873 // ============================================================== Destructeur
3874 MakeTransformationDialog::~MakeTransformationDialog()
3878 // ============================================================== _initInputWidget
3879 void MakeTransformationDialog::_initInputWidget( Mode editmode )
3882 QValidator *validator = new QRegExpValidator(rx, this);
3884 installEventFilter(this);
3886 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3887 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3889 vec_le_rb0->setValidator( validator );
3890 elts_le_rb0->setValidator( validator );
3891 vec_le_rb0->installEventFilter(this);
3892 elts_le_rb0->installEventFilter(this);
3894 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3895 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3896 vex_le_rb1->setValidator( validator );
3897 elts_le_rb1->setValidator( validator );
3898 vex_le_rb1->installEventFilter(this);
3899 elts_le_rb1->installEventFilter(this);
3901 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3902 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3903 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3904 vex_le_rb2->setValidator( validator );
3905 vec_le_rb2->setValidator( validator );
3906 elts_le_rb2->setValidator( validator );
3907 vex_le_rb2->installEventFilter(this);
3908 vec_le_rb2->installEventFilter(this);
3909 elts_le_rb2->installEventFilter(this);
3911 vec_le_rb0->setReadOnly(true);
3912 elts_le_rb0->setReadOnly(true);
3914 vex_le_rb1->setReadOnly(true);
3915 elts_le_rb1->setReadOnly(true);
3917 vex_le_rb2->setReadOnly(true);
3918 vec_le_rb2->setReadOnly(true);
3919 elts_le_rb2->setReadOnly(true);
3923 // ============================================================== clear
3924 void MakeTransformationDialog::clear()
3926 elts_le_rb0->clear();
3927 modelUnregister(elts_le_rb0);
3929 vec_le_rb0->clear();
3930 modelUnregister(vec_le_rb0);
3932 elts_le_rb1->clear();
3933 modelUnregister(elts_le_rb1);
3935 vex_le_rb1->clear();
3936 modelUnregister(vex_le_rb1);
3938 elts_le_rb2->clear();
3939 modelUnregister(elts_le_rb2);
3941 vex_le_rb2->clear();
3942 modelUnregister(vex_le_rb2);
3944 vec_le_rb2->clear();
3945 modelUnregister(vec_le_rb2);
3947 modelUnregister(this);
3950 // ============================================================== updateHelpFileName
3951 void MakeTransformationDialog::updateHelpFileName()
3953 if ( sender() == rb0 ){
3954 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
3955 } else if ( sender() == rb1 ){
3956 _helpFileName = "gui_make_elmts.html#make-elements-by-scaling";
3957 } else if ( sender() == rb2 ){
3958 _helpFileName = "gui_make_elmts.html#make-elements-by-rotation";
3962 // ============================================================== apply
3963 bool MakeTransformationDialog::apply(QModelIndex& result)
3965 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3968 if (getDocumentModel() == NULL) return false;
3969 const PatternDataModel* patternDataModel = getPatternDataModel();
3970 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3971 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
3973 QModelIndex iNewElts;
3975 if ( rb0->isChecked() ){
3976 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb0] );
3977 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb0] );
3978 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
3979 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
3981 if ( ielts.isValid()
3983 iNewElts = getDocumentModel()->makeTranslation( ielts, ivec );
3985 } else if ( rb1->isChecked() ){
3986 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
3987 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb1] );
3988 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
3989 double k = k_spb->value();
3991 if ( ielts.isValid()
3993 iNewElts = getDocumentModel()->makeScale( ielts, ivex, k );
3995 } else if ( rb2->isChecked() ){
3996 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
3997 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb2] );
3998 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
3999 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4000 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb2] );
4001 double angle = angle_spb->value();
4003 if ( ielts.isValid()
4006 iNewElts = getDocumentModel()->makeRotation( ielts, ivex, ivec, angle );
4009 if ( !iNewElts.isValid() ){
4010 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4014 result = patternDataModel->mapFromSource(iNewElts);
4015 // result = patternBuilderModel->mapFromSource(iNewElts);
4020 // // ------------------------- MakeSymmetryDialog ----------------------------------
4021 // ============================================================== Constructeur
4023 MakeSymmetryDialog::MakeSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4024 HexaBaseDialog(parent, editmode, f)
4027 _initWidget(editmode);
4030 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4031 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4032 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4033 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4036 // ============================================================== Destructeur
4037 MakeSymmetryDialog::~MakeSymmetryDialog()
4041 // ============================================================== _initInputWidget
4042 void MakeSymmetryDialog::_initInputWidget( Mode editmode )
4045 QValidator *validator = new QRegExpValidator(rx, this);
4047 installEventFilter(this);
4049 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4050 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4051 vex_le_rb0->setValidator( validator );
4052 elts_le_rb0->setValidator( validator );
4053 vex_le_rb0->installEventFilter(this);
4054 elts_le_rb0->installEventFilter(this);
4056 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4057 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4058 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4059 vex_le_rb1->setValidator( validator );
4060 vec_le_rb1->setValidator( validator );
4061 elts_le_rb1->setValidator( validator );
4062 vex_le_rb1->installEventFilter(this);
4063 vec_le_rb1->installEventFilter(this);
4064 elts_le_rb1->installEventFilter(this);
4066 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4067 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4068 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4069 vex_le_rb2->setValidator( validator );
4070 vec_le_rb2->setValidator( validator );
4071 elts_le_rb2->setValidator( validator );
4072 vex_le_rb2->installEventFilter(this);
4073 vec_le_rb2->installEventFilter(this);
4074 elts_le_rb2->installEventFilter(this);
4076 vex_le_rb0->setReadOnly(true);
4077 elts_le_rb0->setReadOnly(true);
4078 vex_le_rb1->setReadOnly(true);
4079 vec_le_rb1->setReadOnly(true);
4080 elts_le_rb1->setReadOnly(true);
4081 vex_le_rb2->setReadOnly(true);
4082 vec_le_rb2->setReadOnly(true);
4083 elts_le_rb2->setReadOnly(true);
4086 // ============================================================== clear
4087 void MakeSymmetryDialog::clear()
4089 elts_le_rb0->clear();
4090 modelUnregister(elts_le_rb0);
4092 vex_le_rb0->clear();
4093 modelUnregister(vex_le_rb0);
4095 elts_le_rb1->clear();
4096 modelUnregister(elts_le_rb1);
4098 vex_le_rb1->clear();
4099 modelUnregister(vex_le_rb1);
4101 vec_le_rb1->clear();
4102 modelUnregister(vec_le_rb1);
4104 elts_le_rb2->clear();
4105 modelUnregister(elts_le_rb2);
4107 vex_le_rb2->clear();
4108 modelUnregister(vex_le_rb2);
4110 vec_le_rb2->clear();
4111 modelUnregister(vec_le_rb2);
4113 modelUnregister(this);
4116 // ============================================================== updateHelpFileName
4117 void MakeSymmetryDialog::updateHelpFileName()
4119 if ( sender() == rb0 ){
4120 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4121 } else if ( sender() == rb1 ){
4122 _helpFileName = "gui_make_symmetry.html#make-elements-by-line-symmetry";
4123 } else if ( sender() == rb2 ){
4124 _helpFileName = "gui_make_symmetry.html#make-elements-by-plane-symmetry";
4128 // ============================================================== apply
4129 bool MakeSymmetryDialog::apply(QModelIndex& result)
4131 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4133 if (getDocumentModel() == NULL) return false;
4134 const PatternDataModel* patternDataModel = getPatternDataModel();
4135 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4136 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4138 QModelIndex iNewElts;
4140 if ( rb0->isChecked() ){
4141 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4142 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb0] );
4143 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4145 if ( ielts.isValid()
4147 iNewElts = getDocumentModel()->makeSymmetryPoint( ielts, ivex );
4150 } else if ( rb1->isChecked() ){
4151 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4152 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb1] );
4153 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4154 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4155 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb1] );
4157 if ( ielts.isValid()
4160 iNewElts = getDocumentModel()->makeSymmetryLine( ielts, ivex, ivec );
4162 } else if ( rb2->isChecked() ){
4163 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4164 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4165 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4166 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4167 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4169 if ( ielts.isValid()
4172 iNewElts = getDocumentModel()->makeSymmetryPlane( ielts, ivex, ivec );
4175 if ( !iNewElts.isValid() ){
4176 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4180 // result = patternBuilderModel->mapFromSource(iNewElts);
4181 result = patternDataModel->mapFromSource(iNewElts);
4186 // // ------------------------- PerformTransformationDialog ----------------------------------
4187 // ============================================================== Constructeur
4188 PerformTransformationDialog::PerformTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4189 HexaBaseDialog(parent, editmode, f)
4192 _initWidget(editmode);
4195 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4196 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4197 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4198 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4201 // ============================================================== Destructeur
4202 PerformTransformationDialog::~PerformTransformationDialog()
4206 // ============================================================== _initInputWidget
4207 void PerformTransformationDialog::_initInputWidget( Mode editmode )
4210 QValidator *validator = new QRegExpValidator(rx, this);
4212 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4213 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4214 vec_le_rb0->setValidator( validator );
4215 elts_le_rb0->setValidator( validator );
4216 vec_le_rb0->installEventFilter(this);
4217 elts_le_rb0->installEventFilter(this);
4219 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4220 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4221 vex_le_rb1->setValidator( validator );
4222 elts_le_rb1->setValidator( validator );
4223 vex_le_rb1->installEventFilter(this);
4224 elts_le_rb1->installEventFilter(this);
4227 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4228 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4229 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4230 vex_le_rb2->setValidator( validator );
4231 vec_le_rb2->setValidator( validator );
4232 elts_le_rb2->setValidator( validator );
4233 vex_le_rb2->installEventFilter(this);
4234 vec_le_rb2->installEventFilter(this);
4235 elts_le_rb2->installEventFilter(this);
4237 vec_le_rb0->setReadOnly(true);
4238 elts_le_rb0->setReadOnly(true);
4239 vex_le_rb1->setReadOnly(true);
4240 elts_le_rb1->setReadOnly(true);
4241 vex_le_rb2->setReadOnly(true);
4242 vec_le_rb2->setReadOnly(true);
4243 elts_le_rb2->setReadOnly(true);
4247 // ============================================================== clear
4248 void PerformTransformationDialog::clear()
4250 vec_le_rb0->clear();
4251 modelUnregister(vec_le_rb0);
4253 elts_le_rb0->clear();
4254 modelUnregister(elts_le_rb0);
4256 vex_le_rb1->clear();
4257 modelUnregister(vex_le_rb1);
4259 elts_le_rb1->clear();
4260 modelUnregister(elts_le_rb1);
4262 vex_le_rb2->clear();
4263 modelUnregister(vex_le_rb2);
4265 vec_le_rb2->clear();
4266 modelUnregister(vec_le_rb2);
4268 elts_le_rb2->clear();
4269 modelUnregister(elts_le_rb2);
4271 modelUnregister(this);
4274 // ============================================================== updateHelpFileName
4275 void PerformTransformationDialog::updateHelpFileName()
4277 if ( sender() == rb0 ){
4278 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4279 } else if ( sender() == rb1 ){
4280 _helpFileName = "gui_modify_elmts.html#modify-elements-by-scaling";
4281 } else if ( sender() == rb2 ){
4282 _helpFileName = "gui_modify_elmts.html#modify-elements-by-rotation";
4286 // ============================================================== apply
4287 bool PerformTransformationDialog::apply(QModelIndex& result)
4289 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4292 if (getDocumentModel() == NULL) return false;
4293 const PatternDataModel* patternDataModel = getPatternDataModel();
4294 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4295 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4297 bool performed = false;
4299 if ( rb0->isChecked() ){
4300 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4301 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb0]);
4302 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4303 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb0]);
4305 if ( ielts.isValid()
4307 performed = getDocumentModel()->performTranslation( ielts, ivec );
4309 } else if ( rb1->isChecked() ){
4310 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4311 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb1]);
4312 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4313 double k = k_spb->value();
4315 if ( ielts.isValid()
4317 performed = getDocumentModel()->performScale( ielts, ivex, k );
4319 } else if ( rb2->isChecked() ){
4320 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4321 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4322 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4323 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4324 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4325 double angle = angle_spb->value();
4327 if ( ielts.isValid()
4330 performed = getDocumentModel()->performRotation( ielts, ivex, ivec, angle );
4333 if ( performed == false){
4334 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM TRANSFORMATION" ) + "\n" + getErrorMsg() );
4341 // // ------------------------- PerformSymmetryDialog ----------------------------------
4342 // ============================================================== Constructeur
4343 PerformSymmetryDialog::PerformSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4344 : HexaBaseDialog(parent, editmode, f)
4347 _initWidget( editmode );
4350 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4351 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4352 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4353 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4356 // ============================================================== Destructeur
4357 PerformSymmetryDialog::~PerformSymmetryDialog()
4361 // ============================================================== _initInputWidget
4362 void PerformSymmetryDialog::_initInputWidget( Mode editmode )
4365 QValidator *validator = new QRegExpValidator(rx, this);
4367 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4368 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4369 vex_le_rb0->setValidator( validator );
4370 elts_le_rb0->setValidator( validator );
4371 vex_le_rb0->installEventFilter(this);
4372 elts_le_rb0->installEventFilter(this);
4374 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4375 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4376 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4377 vex_le_rb1->setValidator( validator );
4378 vec_le_rb1->setValidator( validator );
4379 elts_le_rb1->setValidator( validator );
4380 vex_le_rb1->installEventFilter(this);
4381 vec_le_rb1->installEventFilter(this);
4382 elts_le_rb1->installEventFilter(this);
4384 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4385 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4386 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4387 vex_le_rb2->setValidator( validator );
4388 vec_le_rb2->setValidator( validator );
4389 elts_le_rb2->setValidator( validator );
4390 vex_le_rb2->installEventFilter(this);
4391 vec_le_rb2->installEventFilter(this);
4392 elts_le_rb2->installEventFilter(this);
4394 vex_le_rb0->setReadOnly(true);
4395 elts_le_rb0->setReadOnly(true);
4396 vex_le_rb1->setReadOnly(true);
4397 vec_le_rb1->setReadOnly(true);
4398 elts_le_rb1->setReadOnly(true);
4399 vex_le_rb2->setReadOnly(true);
4400 vec_le_rb2->setReadOnly(true);
4401 elts_le_rb2->setReadOnly(true);
4405 // ============================================================== clear
4406 void PerformSymmetryDialog::clear()
4408 vex_le_rb0->clear();
4409 modelUnregister(vex_le_rb0);
4411 elts_le_rb0->clear();
4412 modelUnregister(elts_le_rb0);
4414 elts_le_rb1->clear();
4415 modelUnregister(elts_le_rb1);
4417 vex_le_rb1->clear();
4418 modelUnregister(vex_le_rb1);
4420 vec_le_rb1->clear();
4421 modelUnregister(vec_le_rb1);
4423 elts_le_rb2->clear();
4424 modelUnregister(elts_le_rb2);
4426 vex_le_rb2->clear();
4427 modelUnregister(vex_le_rb2);
4429 vec_le_rb2->clear();
4430 modelUnregister(vec_le_rb2);
4432 modelUnregister(this);
4435 // ============================================================== updateHelpFileName
4436 void PerformSymmetryDialog::updateHelpFileName()
4438 if ( sender() == rb0 ){
4439 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4440 } else if ( sender() == rb1 ){
4441 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-line-symmetry";
4442 } else if ( sender() == rb2 ){
4443 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-plane-symmetry";
4447 // ============================================================== apply
4448 bool PerformSymmetryDialog::apply(QModelIndex& result)
4450 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4453 if (getDocumentModel() == NULL) return false;
4454 const PatternDataModel* patternDataModel = getPatternDataModel();
4455 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4456 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4458 bool performed = false;
4460 if ( rb0->isChecked() ){
4461 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4462 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb0]);
4463 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4465 if ( ielts.isValid()
4467 performed = getDocumentModel()->performSymmetryPoint( ielts, ivex );
4469 } else if ( rb1->isChecked() ){
4470 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4471 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb1]);
4472 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4473 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4474 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb1]);
4476 if ( ielts.isValid()
4479 performed = getDocumentModel()->performSymmetryLine( ielts, ivex, ivec );
4481 } else if ( rb2->isChecked() ){
4482 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4483 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4484 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4485 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4486 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4488 if ( ielts.isValid()
4491 performed = getDocumentModel()->performSymmetryPlane( ielts, ivex, ivec );
4494 if ( performed == false ){
4495 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM SYMMETRY" ) + "\n" + getErrorMsg() );
4502 // // ------------------------- EdgeAssocDialog ----------------------------------
4503 // ============================================================== Constructeur
4504 EdgeAssocDialog::EdgeAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4505 HexaBaseDialog( parent, editmode, f )
4507 _helpFileName ="gui_asso_quad_to_geom.html#one-edge";
4509 _initWidget(editmode);
4514 // ============================================================== Destructeur
4515 EdgeAssocDialog::~EdgeAssocDialog()
4519 // ============================================================== close
4520 void EdgeAssocDialog::close()
4522 HEXABLOCKGUI::assocInProgress = false;
4523 HexaBaseDialog::close();
4526 // ============================================================== _initInputWidget
4527 void EdgeAssocDialog::_initInputWidget( Mode editmode )
4530 QValidator *validator = new QRegExpValidator(rx, this);
4533 first_vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4534 first_vex_le->installEventFilter(this);
4535 first_vex_le->setValidator( validator );
4537 single_edge_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4538 single_edge_le->installEventFilter(this);
4540 edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4541 edges_lw->installEventFilter(this);
4545 lines_lw->setProperty("HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4546 lines_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4547 lines_lw->installEventFilter(this);
4549 single_line_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4550 single_line_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4551 single_line_le->installEventFilter(this);
4554 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), edges_lw);
4555 QShortcut* delLineShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), lines_lw);
4556 delLineShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4557 delEdgeShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4559 pend_spb->setValue(1.);
4561 first_vex_le->setReadOnly(true);
4562 single_edge_le->setReadOnly(true);
4563 single_line_le->setReadOnly(true);
4565 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
4566 connect( delLineShortcut, SIGNAL(activated()), this, SLOT(deleteLineItem()) );
4567 connect( edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
4568 connect( lines_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4569 connect( single_rb, SIGNAL(clicked()), this, SLOT( refreshHighlight()), Qt::UniqueConnection );
4570 connect( multiple_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection );
4571 connect( single_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4572 connect( multiple_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4575 // ============================================================== updateHelpFileName
4576 void EdgeAssocDialog::updateHelpFileName()
4578 if ( sender() == single_rb ){
4579 _helpFileName = "gui_asso_quad_to_geom.html#one-edge";
4580 } else if ( sender() == multiple_rb ){
4581 _helpFileName = "gui_asso_quad_to_geom.html#line";
4585 // ============================================================== getAssocsVTK
4587 * Returns elements currently being associated in vtk side
4589 QModelIndexList EdgeAssocDialog::getAssocsVTK()
4591 QModelIndexList assocs;
4593 QListWidgetItem* item = NULL;
4595 if (getPatternDataSelectionModel() == NULL) return assocs;
4596 if (single_rb->isChecked())
4599 QVariant v = single_edge_le->property("QModelIndex");
4600 if ( !v.isValid() ) return assocs;
4601 assocs << v.value<QModelIndex>();
4604 else if (multiple_rb->isChecked())
4606 //ListWidget content
4607 const PatternDataModel* patternDataModel = getPatternDataModel();
4608 if ( !patternDataModel ) return assocs;
4609 int nbEdges = edges_lw->count();
4610 for ( int r = 0; r < nbEdges; ++r){
4611 item = edges_lw->item(r);
4612 iEdge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4613 if ( iEdge.isValid() ) assocs << iEdge;
4620 // ============================================================== getAssocsGEOM
4622 * Returns elements currently being associated in geom side
4624 QMultiMap<QString, int> EdgeAssocDialog::getAssocsGEOM()
4626 QMultiMap<QString, int> assocs;
4627 QListWidgetItem* item = NULL;
4628 DocumentModel::GeomObj geomObj;
4630 if (single_rb->isChecked())
4633 QVariant v = single_line_le->property("GeomObj");
4634 if ( !v.isValid() ) return assocs;
4635 geomObj = v.value<DocumentModel::GeomObj>();
4636 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4639 else if (multiple_rb->isChecked())
4641 //ListWidget content
4642 unsigned int nbEdges = lines_lw->count();
4643 for ( int r = 0; r < nbEdges; ++r){
4644 item = lines_lw->item(r);
4645 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4646 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4653 // ============================================================== selectElementOfGeom
4654 /*Highlight in the OCC view selected elements in a listwidget,
4655 * or an element in a line edit.*/
4656 void EdgeAssocDialog::selectElementOfGeom()
4658 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4659 if ( !currentListWidget )
4663 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4664 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4665 pgsm->clearSelection();
4666 if (sel.count() == 0)
4669 QListWidgetItem *item = sel[0];
4670 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
4671 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4672 if ( index.isValid() )
4673 pgsm->select( index, QItemSelectionModel::SelectCurrent );
4676 // ============================================================== clear
4677 void EdgeAssocDialog::clear()
4679 first_vex_le->clear();
4680 modelUnregister(first_vex_le);
4683 modelUnregister(edges_lw);
4687 single_edge_le->clear();
4688 modelUnregister(single_edge_le);
4690 single_line_le->clear();
4691 modelUnregister(single_line_le);
4693 modelUnregister(this);
4696 // ============================================================== onWindowActivated
4697 void EdgeAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4699 QString vmType = vm->getType();
4700 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4702 if (single_rb->isChecked())
4703 single_edge_le->setFocus();
4704 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le )
4705 edges_lw->setFocus();
4707 else if ( vmType == OCCViewer_Viewer::Type() ){
4708 if (single_rb->isChecked())
4709 single_line_le->setFocus();
4710 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le)
4711 lines_lw->setFocus();
4715 // ============================================================== apply
4716 bool EdgeAssocDialog::apply(QModelIndex& result)
4718 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4721 bool assocOk = false;
4723 PatternDataModel* patternDataModel = getPatternDataModel();
4724 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4725 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4727 QModelIndex iEdge, iGeomEdge;
4728 QModelIndexList iEdges;
4729 QListWidgetItem* item = NULL;
4730 QList<DocumentModel::GeomObj> assocs;
4731 DocumentModel::GeomObj aLine;
4732 HEXA_NS::SubShape* ssh;
4733 HEXA_NS::EdgeShape* sh;
4734 HEXA_NS::NewShapes shapes;
4735 HEXA_NS::IntVector subIds;
4737 QModelIndexList edges, lines;
4739 if (single_rb->isChecked()){ //Single edge and/or line association
4741 iEdge = patternDataModel->mapToSource( _index[single_edge_le] );
4742 if ( !iEdge.isValid() || myLine == NULL)
4744 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4747 id = myLine->shapeName+","+myLine->subId;
4748 ssh = getDocumentModel()->getGeomPtr(id);
4749 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
4750 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
4751 if (!iGeomEdge.isValid())
4753 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4756 assocOk = getDocumentModel()->addEdgeAssociation(iEdge, iGeomEdge, pstart_spb->value(), pend_spb->value());
4757 edges << _index[single_edge_le];
4760 else { //Multiple edge and/or line association
4763 iEdges = getIndexList(edges_lw, true);
4764 int nbLines = lines_lw->count();
4765 if (iEdges.count() == 0 || nbLines == 0)
4767 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4770 edges = getIndexList(edges_lw, false);
4772 for (int r = 0; r < nbLines; ++r){
4773 item = lines_lw->item(r);
4774 aLine = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4775 id = aLine.shapeName+","+aLine.subId;
4776 ssh = getDocumentModel()->getGeomPtr(id);
4777 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
4780 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4783 shapes.push_back(sh->getParentShape());
4784 subIds.push_back(sh->getIdent());
4785 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
4786 if (iGeomEdge.isValid())
4790 if ( close_cb->isChecked() ){ //closed line
4791 QModelIndex iFirstVertex = patternDataModel->mapToSource( _index[first_vex_le] );
4792 if ( !iFirstVertex.isValid() )
4794 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4797 bool inv = inverse_cb->isChecked();
4798 assocOk = getDocumentModel()->associateClosedLine( iFirstVertex, iEdges, shapes, subIds, pstart_spb->value(), inv );
4802 assocOk = getDocumentModel()->associateOpenedLine( iEdges, shapes, subIds, pstart_spb->value(), pend_spb->value() );
4806 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) + "\n" + getErrorMsg() );
4810 // highlight associated items in the trees
4811 pdsm->unhighlightTreeItems();
4812 pgsm->unhighlightTreeItems();
4813 pdsm->highlightTreeItems(edges);
4814 pgsm->highlightTreeItems(lines);
4816 // highlight associated items in the views
4817 highlightSelectedAssocs();
4822 // ------------------------- QuadAssocDialog ----------------------------------
4823 // ============================================================== Constructeur
4824 QuadAssocDialog::QuadAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4825 HexaBaseDialog(parent, editmode, f)
4827 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-face-or-a-shell-of-the-geometry";
4829 _initWidget(editmode);
4832 // ============================================================== Destructeur
4833 QuadAssocDialog::~QuadAssocDialog()
4835 disconnect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
4836 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(addFace()) );
4837 delete _delFaceShortcut;
4840 // ============================================================== close
4841 void QuadAssocDialog::close()
4843 HEXABLOCKGUI::assocInProgress = false;
4844 HexaBaseDialog::close();
4847 // ============================================================== _initInputWidget
4848 void QuadAssocDialog::_initInputWidget( Mode editmode )
4851 QValidator *validator = new QRegExpValidator(rx, this);
4853 quad_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
4854 quad_le->installEventFilter(this);
4855 quad_le->setValidator( validator );
4858 faces_lw->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
4859 faces_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
4860 faces_lw->installEventFilter(this);
4861 _delFaceShortcut = new QShortcut( QKeySequence(Qt::Key_X/*Qt::Key_Delete*/), faces_lw );
4862 _delFaceShortcut->setContext( Qt::WidgetShortcut );
4864 quad_le->setReadOnly(true);
4866 connect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
4867 connect( faces_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4870 // ============================================================== getAssocsVTK
4872 * Returns elements currently being associated in vtk side
4874 QModelIndexList QuadAssocDialog::getAssocsVTK()
4876 QModelIndexList assocs;
4880 QVariant v = quad_le->property("QModelIndex");
4883 assocs << v.value<QModelIndex>();
4887 // ============================================================== getAssocsGEOM
4889 * Returns elements currently being associated in geom side
4891 QMultiMap<QString, int> QuadAssocDialog::getAssocsGEOM()
4893 QMultiMap<QString, int> assocs;
4894 QListWidgetItem* item = NULL;
4895 DocumentModel::GeomObj geomObj;
4897 //ListWidget content
4898 unsigned int nbFaces = faces_lw->count();
4899 for ( int r = 0; r < nbFaces; ++r){
4900 item = faces_lw->item(r);
4901 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4902 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4907 // ============================================================== selectElementOfGeom
4908 /*Highlight in the OCC view selected elements in a listwidget,
4909 * or an element in a line edit.*/
4911 void QuadAssocDialog::selectElementOfGeom()
4913 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4914 if ( !currentListWidget )
4918 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4919 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4920 pgsm->clearSelection();
4921 if (sel.count() == 0)
4923 QListWidgetItem *item = sel[0];
4924 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
4925 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4926 if ( index.isValid() )
4927 pgsm->select( index, QItemSelectionModel::SelectCurrent );
4930 void QuadAssocDialog::clear()
4933 modelUnregister(quad_le);
4937 modelUnregister(this);
4940 // ============================================================== onWindowActivated
4941 void QuadAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4943 QString vmType = vm->getType();
4944 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4945 quad_le->setFocus();
4946 else if ( vmType == OCCViewer_Viewer::Type() ){
4947 faces_lw->setFocus();
4951 // ============================================================== deleteFaceItem
4952 void QuadAssocDialog::deleteFaceItem()
4954 delete faces_lw->currentItem();
4957 // ============================================================== apply
4958 bool QuadAssocDialog::apply(QModelIndex& result)
4960 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4963 PatternDataModel* patternDataModel = getPatternDataModel();
4964 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4965 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4968 QModelIndex iQuad, iGeomFace;
4969 HEXA_NS::SubShape* ssh;
4970 HEXA_NS::FaceShape* sh;
4974 iQuad = patternDataModel->mapToSource( _index[quad_le] );
4977 QListWidgetItem* item = NULL;
4978 DocumentModel::GeomObj aFace;
4979 QModelIndexList quads, faces;
4980 int nbFaces = faces_lw->count();
4981 for ( int r = 0; r < nbFaces; ++r ){
4982 item = faces_lw->item(r);
4983 aFace = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4984 id = aFace.shapeName+","+aFace.subId;
4985 ssh = getDocumentModel()->getGeomPtr(id);
4986 sh = dynamic_cast<HEXA_NS::FaceShape*>(ssh);
4989 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) );
4992 iGeomFace = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
4993 if (!getDocumentModel()->addQuadAssociation(iQuad, iGeomFace))
4995 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) + "\n" + getErrorMsg() );
4998 else if (iGeomFace.isValid())
5003 if (iQuad.isValid())
5004 quads << _index[quad_le];
5006 // highlight associated items in the trees
5007 pdsm->highlightTreeItems(quads);
5008 pgsm->highlightTreeItems(faces);
5010 // highlight associated items in the views
5011 highlightSelectedAssocs();
5016 // ------------------------- GroupDialog ----------------------------------
5017 // ============================================================== Constructeur
5018 GroupDialog::GroupDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5019 HexaBaseDialog(parent, editmode, f),
5022 _helpFileName = "gui_groups.html#add-group";
5024 _initWidget(editmode);
5025 // setFocusProxy( name_le/*eltBase_lw */);
5027 if ( editmode == NEW_MODE ){
5028 setWindowTitle( tr("Group Construction") );
5029 } else if ( editmode == UPDATE_MODE ){
5030 setWindowTitle( tr("Group Modification") );
5031 } else if ( editmode == INFO_MODE ){
5032 setWindowTitle( tr("Group Information") );
5036 // ============================================================== Destructeur
5037 GroupDialog::~GroupDialog()
5041 // ============================================================== getAssocsVTK
5043 * Returns elements currently being associated in vtk side
5045 QModelIndexList GroupDialog::getAssocsVTK()
5047 QModelIndexList assocs;
5049 QListWidgetItem* item = NULL;
5050 if (getPatternDataSelectionModel() == NULL) return assocs;
5051 //ListWidget content
5052 const PatternDataModel* patternDataModel = getPatternDataModel();
5053 if ( !patternDataModel ) return assocs;
5054 int nbElts = eltBase_lw->count();
5055 for ( int r = 0; r < nbElts; ++r){
5056 item = eltBase_lw->item(r);
5057 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5058 if ( iItem.isValid() ) assocs << iItem;
5063 // ============================================================== _initInputWidget
5064 void GroupDialog::_initInputWidget( Mode editmode )
5066 installEventFilter(this);
5067 name_le->installEventFilter(this);
5070 strKind[ HEXA_NS::HexaCell ] = "HexaCell";
5071 strKind[ HEXA_NS::QuadCell ] = "QuadCell";
5072 strKind[ HEXA_NS::EdgeCell ] = "EdgeCell";
5073 strKind[ HEXA_NS::HexaNode ] = "HexaNode";
5074 strKind[ HEXA_NS::QuadNode ] = "QuadNode";
5075 strKind[ HEXA_NS::EdgeNode ] = "EdgeNode";
5076 strKind[ HEXA_NS::VertexNode ] = "VertexNode";
5078 QMap<HEXA_NS::EnumGroup, QString>::ConstIterator iKind;
5079 for( iKind = strKind.constBegin(); iKind != strKind.constEnd(); ++iKind )
5080 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5082 onKindChanged( kind_cb->currentIndex() );
5083 eltBase_lw->installEventFilter(this);
5085 if ( editmode != INFO_MODE ){
5086 QShortcut* delEltShortcut = new QShortcut( QKeySequence(Qt::Key_X), eltBase_lw );
5087 delEltShortcut->setContext( Qt::WidgetShortcut );
5088 connect(delEltShortcut, SIGNAL(activated()), this, SLOT(removeEltBase()));
5089 connect(kind_cb, SIGNAL(activated(int)), this, SLOT(onKindChanged(int)) );
5092 if ( editmode == INFO_MODE)
5094 name_le->setReadOnly(true);
5095 kind_cb->setEnabled(false);
5096 eltBase_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
5099 connect(eltBase_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5102 // ============================================================== clear
5103 void GroupDialog::clear()
5107 eltBase_lw->clear();
5108 modelUnregister(eltBase_lw);
5110 modelUnregister(this);
5113 // ============================================================== onKindChanged
5114 void GroupDialog::onKindChanged(int index)
5117 switch ( kind_cb->itemData(index).toInt() ){
5118 case HEXA_NS::HexaCell:
5119 case HEXA_NS::HexaNode:
5120 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(HEXA_TREE));
5123 case HEXA_NS::QuadCell:
5124 case HEXA_NS::QuadNode:
5125 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5128 case HEXA_NS::EdgeCell:
5129 case HEXA_NS::EdgeNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
5132 case HEXA_NS::VertexNode:
5133 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
5136 default:Q_ASSERT(false);
5138 eltBase_lw->clear();
5139 eltBase_lw->setFocus();
5142 // ============================================================== setValue
5143 void GroupDialog::setValue(HEXA_NS::Group* g)
5146 name_le->setText( g->getName() );
5150 kind_cb->addItem ( strKind[g->getKind()], QVariant( g->getKind() ) );
5153 HEXA_NS::EltBase* eltBase = NULL;
5154 QListWidgetItem* item = NULL;
5155 QModelIndex iEltBase;
5156 QList<QStandardItem *> eltBaseItems;
5159 if ( !getPatternDataSelectionModel() ) return;
5160 if ( !getGroupsSelectionModel() ) return;
5162 QModelIndex iGroup = getGroupsSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(g) );
5163 name_le->setProperty( "QModelIndex", QVariant::fromValue(iGroup) );
5166 int nbElts = g->countElement();
5167 for ( int nr = 0; nr < nbElts; ++nr ){
5168 eltBase = g->getElement( nr );
5169 switch ( g->getKind() ){
5170 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: v = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
5171 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: v = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
5172 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: v = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
5173 case HEXA_NS::VertexNode: v = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
5175 iEltBase = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, v);
5176 if ( iEltBase.isValid() ){
5177 item = new QListWidgetItem( eltBase->getName() );
5178 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iEltBase) );
5179 item->setData(LW_DATA_ROLE, iEltBase.data(HEXA_DATA_ROLE));
5180 eltBase_lw->addItem( item );
5186 // ============================================================== getValue
5187 HEXA_NS::Group* GroupDialog::getValue()
5192 // ============================================================== removeEltBase
5193 void GroupDialog::removeEltBase()
5195 QListWidgetItem *item = eltBase_lw->currentItem();
5198 int r = eltBase_lw->row(item);
5199 eltBase_lw->takeItem(r);
5205 // ============================================================== apply
5206 bool GroupDialog::apply(QModelIndex& result)
5208 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5211 if ( !getDocumentModel() ) return false;
5212 const PatternDataModel* patternDataModel = getPatternDataModel();
5213 const GroupsModel* groupsModel = getGroupsModel();
5214 if (patternDataModel == NULL || groupsModel == NULL) return false;
5216 QString grpName = name_le->text();
5217 DocumentModel::Group grpKind = static_cast<DocumentModel::Group>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5219 if ( _value == NULL ){ // create group
5220 iGrp = getDocumentModel()->addGroup( grpName, grpKind );
5222 QModelIndexList iGrps = getDocumentModel()->match(
5223 getDocumentModel()->index(0, 0),
5225 QVariant::fromValue( _value ),
5227 Qt::MatchRecursive );
5228 if ( !iGrps.isEmpty() )
5233 if ( !iGrp.isValid() ){
5234 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD GROUP" ) + "\n" + getErrorMsg() );
5238 //fill it and select it
5239 QModelIndex iEltBase;
5240 QListWidgetItem* item = NULL;
5241 bool eltAdded = false;
5242 getDocumentModel()->clearGroupElement(iGrp);
5243 int nbElts = eltBase_lw->count();
5244 for ( int r = 0; r < nbElts; ++r){
5245 item = eltBase_lw->item(r);
5246 iEltBase = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5247 if ( iEltBase.isValid() )
5248 eltAdded = getDocumentModel()->addGroupElement( iGrp, iEltBase );
5251 QString newName = name_le->text();
5252 if ( !newName.isEmpty() )
5253 getDocumentModel()->setName( iGrp, newName );
5255 HEXA_NS::Group* hGroup = getDocumentModel()->data(iGrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
5258 QString groupName = QString::fromStdString(hGroup->getNextName());
5259 name_le->setText(groupName);
5262 result = groupsModel->mapFromSource(iGrp);
5267 // ------------------------- LawDialog ----------------------------------
5268 // ============================================================== Constructeur
5270 LawDialog::LawDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5271 : HexaBaseDialog(parent, editmode, f),
5274 _helpFileName = "gui_discret_law.html#add-law";
5276 _initWidget(editmode);
5277 if ( editmode == NEW_MODE ){
5278 setWindowTitle( tr("Law Construction") );
5279 } else if ( editmode == UPDATE_MODE ){
5280 setWindowTitle( tr("Law Modification") );
5282 else if ( editmode == INFO_MODE){
5283 setWindowTitle( tr("Law Information") );
5287 // ============================================================== Destructeur
5288 LawDialog::~LawDialog()
5292 // ============================================================== _initInputWidget
5293 void LawDialog::_initInputWidget( Mode editmode )
5297 // setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5298 installEventFilter(this);
5300 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5301 name_le->installEventFilter(this);
5304 strKind[ HEXA_NS::Uniform ] = "Uniform";
5305 strKind[ HEXA_NS::Arithmetic ] = "Arithmetic";
5306 strKind[ HEXA_NS::Geometric ] = "Geometric";
5309 QMap<HEXA_NS::KindLaw, QString>::ConstIterator iKind, iEnd;
5310 for( iKind = strKind.constBegin(), iEnd = strKind.constEnd(); iKind != iEnd; ++iKind )
5311 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5313 if (editmode == INFO_MODE)
5315 name_le->setReadOnly(true);
5316 nb_nodes_spb->setReadOnly(true);
5317 coeff_spb->setReadOnly(true);
5318 kind_cb->setEnabled(false);
5322 // ============================================================== clear
5323 void LawDialog::clear()
5327 modelUnregister(this);
5330 // ============================================================== setValue
5331 void LawDialog::setValue(HEXA_NS::Law* l)
5334 name_le->setText( l->getName() );
5336 nb_nodes_spb->setValue( l->getNodes() );
5337 coeff_spb->setValue( l->getCoefficient() );
5339 HEXA_NS::KindLaw k = l->getKind();
5340 kind_cb->setCurrentIndex( kind_cb->findData(k) );
5345 // ============================================================== getValue
5346 HEXA_NS::Law* LawDialog::getValue()
5351 // ============================================================== apply
5352 bool LawDialog::apply(QModelIndex& result)
5354 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5357 if ( !getDocumentModel() ) return false;
5359 const MeshModel* meshModel = getMeshModel();
5360 if (meshModel == NULL) return false;
5362 QString lawName = name_le->text();
5363 int nbnodes = nb_nodes_spb->value();
5364 double coeff = coeff_spb->value();
5365 DocumentModel::KindLaw lawKind = static_cast<DocumentModel::KindLaw>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5368 if ( _value == NULL ){ // create Law
5369 iLaw = getDocumentModel()->addLaw( lawName, nbnodes );
5371 QModelIndexList iLaws = getDocumentModel()->match(
5372 getDocumentModel()->index(0, 0),
5374 QVariant::fromValue( _value ),
5376 Qt::MatchRecursive );
5377 if ( !iLaws.isEmpty() )
5381 if ( !iLaw.isValid() ){
5382 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5385 //fill it and select it
5386 bool setOk = getDocumentModel()->setLaw( iLaw, nbnodes, coeff, lawKind );
5388 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5392 QString newName = name_le->text();
5393 if ( !newName.isEmpty() )/*{*/
5394 getDocumentModel()->setName( iLaw, newName );
5396 HEXA_NS::Law* hLaw = getDocumentModel()->data(iLaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
5400 name_le->setText(hLaw->getNextName(buffer));
5404 result = meshModel->mapFromSource(iLaw);
5409 // ------------------------- PropagationDialog ----------------------------------
5410 // ============================================================== Constructeur
5411 PropagationDialog::PropagationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5412 : HexaBaseDialog(parent, editmode, f),
5415 _helpFileName = "gui_propag.html";
5417 _initWidget(editmode);
5419 if ( editmode == INFO_MODE ){
5420 setWindowTitle( tr("Propagation Information") );
5423 } else if ( editmode == UPDATE_MODE ){
5424 setWindowTitle( tr("Propagation Modification") );
5427 } else if ( editmode == NEW_MODE ){
5428 setWindowTitle( tr("Propagation(s) Setting") );
5432 // ============================================================== Destructeur
5433 PropagationDialog::~PropagationDialog()
5437 // ============================================================== _initInputWidget
5438 void PropagationDialog::_initInputWidget( Mode editmode )
5441 QValidator *validator = new QRegExpValidator(rx, this);
5443 installEventFilter(this);
5446 law_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5447 law_le->installEventFilter(this);
5448 law_le->setValidator( validator );
5450 propagations_lw->setProperty( "HexaWidgetType", QVariant::fromValue(PROPAGATION_TREE) );
5451 propagations_lw->installEventFilter(this);
5453 QShortcut* delPropagationShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), propagations_lw);
5454 delPropagationShortcut->setContext( Qt::WidgetShortcut );
5456 law_le->setReadOnly(true);
5458 if ( editmode == INFO_MODE)
5459 way_cb->setEnabled(false);
5461 connect( delPropagationShortcut, SIGNAL(activated()), this, SLOT(deletePropagationItem()) );
5462 connect( propagations_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
5465 // ============================================================== clear
5466 void PropagationDialog::clear()
5468 propagations_lw->clear();
5469 modelUnregister(propagations_lw);
5472 modelUnregister(law_le);
5474 modelUnregister(this);
5477 // ============================================================== deletePropagationItem
5478 void PropagationDialog::deletePropagationItem()
5480 delete propagations_lw->currentItem();
5483 // ============================================================== setValue
5484 void PropagationDialog::setValue(HEXA_NS::Propagation* p)
5486 if (getMeshSelectionModel() == NULL) return;
5487 HEXA_NS::Law* l = p->getLaw();
5488 bool way = p->getWay();
5491 QModelIndex ip = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
5492 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(ip) );
5494 // law on propagation
5496 law_le->setText( l->getName() );
5497 QModelIndex il = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(l) );
5498 law_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(il) );
5501 // way of propagation
5502 way_cb->setChecked(way);
5507 // ============================================================== selectElementOfModel
5509 /*Selects in the model (treeview) elements selected in a listwidget,
5510 * or an element in a line edit.*/
5512 void PropagationDialog::selectElementOfModel()
5514 if (!getMeshSelectionModel()) return;
5516 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5517 if ( !currentListWidget ) return;
5519 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5521 getMeshSelectionModel()->clearSelection();
5522 foreach ( QListWidgetItem *item, sel ){
5523 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
5524 index = getMeshSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5525 if ( index.isValid() )
5526 getMeshSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
5530 // ============================================================== getValue
5531 HEXA_NS::Propagation* PropagationDialog::getValue()
5536 // ============================================================== apply
5537 bool PropagationDialog::apply(QModelIndex& result)
5539 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5543 if ( !getDocumentModel() ) return false;
5544 const MeshModel* meshModel = getMeshModel();
5545 if (meshModel == NULL) return false;
5547 bool way = way_cb->isChecked();
5548 QListWidgetItem* item = NULL;
5550 QModelIndex iPropagation;
5551 QModelIndex iLaw = meshModel->mapToSource( law_le->property("QModelIndex").value<QModelIndex>() );
5552 if (!iLaw.isValid() ){
5553 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5557 int nbPropagations = propagations_lw->count();
5558 for (int r = 0; r < nbPropagations; ++r){
5559 item = propagations_lw->item(r);
5560 iPropagation = meshModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5561 if ( !iPropagation.isValid() ){
5562 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5566 //fill it and select it
5567 isOk = getDocumentModel()->setPropagation( iPropagation, iLaw, way );
5569 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) + "\n" + getErrorMsg() );
5573 result = meshModel->mapFromSource(iPropagation);
5579 // ------------------------- ComputeMeshDialog ----------------------------------
5580 // ============================================================== Constructeur
5581 ComputeMeshDialog::ComputeMeshDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5582 HexaBaseDialog(parent, editmode, f)
5584 _helpFileName = "gui_mesh.html";
5585 setWindowTitle( tr("Compute mesh") );
5587 _initWidget(editmode);
5590 // ============================================================== Destructeur
5591 ComputeMeshDialog::~ComputeMeshDialog()
5595 // ============================================================== _initInputWidget
5596 void ComputeMeshDialog::_initInputWidget( Mode editmode )
5600 // ============================================================== setDocumentModel
5601 void ComputeMeshDialog::setDocumentModel(DocumentModel* m)
5603 if (m == NULL) return;
5604 _name->setText(m->getName());
5607 // ============================================================== clear
5608 void ComputeMeshDialog::clear()
5610 modelUnregister(this);
5613 // ============================================================== apply
5614 bool ComputeMeshDialog::apply(QModelIndex& result)
5616 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5619 if (getDocumentModel() == NULL) return false;
5620 QString command = QString("import hexablock ; %1 = hexablock.mesh(\"%2\", \"%1\", %3, \"%4\")")
5621 .arg( _name->text() )
5622 .arg( getDocumentModel()->getName() )
5623 .arg( _dim->value() )
5624 .arg( _fact->text() );
5626 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
5627 PyConsole_Console* pyConsole = app->pythonConsole();
5630 pyConsole->exec( command );
5637 // ------------------------- ReplaceHexaDialog ----------------------------------
5638 // ============================================================== Constructeur
5639 ReplaceHexaDialog::ReplaceHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5640 HexaBaseDialog(parent, editmode, f)
5642 _helpFileName = "gui_replace_hexa.html";
5644 _initWidget(editmode);
5647 // ============================================================== Destructeur
5648 ReplaceHexaDialog::~ReplaceHexaDialog()
5652 // ============================================================== getAssocsVTK
5654 * Returns elements currently associated to vtk
5656 QModelIndexList ReplaceHexaDialog::getAssocsVTK()
5658 QModelIndexList assocs;
5660 QListWidgetItem* item = NULL;
5662 //ListWidget content
5663 const PatternDataModel* patternDataModel = getPatternDataModel();
5664 if ( !patternDataModel ) return assocs;
5665 int nbQuads = quads_lw->count();
5666 for ( int r = 0; r < nbQuads; ++r ){
5667 item = quads_lw->item(r);
5668 // iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
5669 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5670 if ( iQuad.isValid() ) assocs << iQuad;
5675 // ============================================================== _initInputWidget
5676 void ReplaceHexaDialog::_initInputWidget( Mode editmode )
5680 installEventFilter(this);
5682 c1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5683 c2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5684 c3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5686 p1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5687 p2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5688 p3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5690 c1_le->installEventFilter(this);
5691 c2_le->installEventFilter(this);
5692 c3_le->installEventFilter(this);
5694 p1_le->installEventFilter(this);
5695 p2_le->installEventFilter(this);
5696 p3_le->installEventFilter(this);
5698 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5699 quads_lw->installEventFilter(this);
5701 if ( editmode == NEW_MODE ){
5702 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5703 delQuadShortcut->setContext( Qt::WidgetShortcut );
5705 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()) );
5706 connect( quads_lw, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5709 c1_le->setReadOnly(true);
5710 c2_le->setReadOnly(true);
5711 c3_le->setReadOnly(true);
5713 p1_le->setReadOnly(true);
5714 p2_le->setReadOnly(true);
5715 p3_le->setReadOnly(true);
5717 connect(quads_lw, SIGNAL(itemSelectionChanged()),
5718 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5721 // ============================================================== clear
5722 void ReplaceHexaDialog::clear()
5725 modelUnregister(quads_lw);
5728 modelUnregister(p1_le);
5731 modelUnregister(p2_le);
5734 modelUnregister(p3_le);
5737 modelUnregister(c1_le);
5740 modelUnregister(c2_le);
5743 modelUnregister(c3_le);
5745 modelUnregister(this);
5748 // ============================================================== updateButtonBox
5749 void ReplaceHexaDialog::updateButtonBox()
5751 int nbQuad = quads_lw->count();
5754 _applyButton->setEnabled(true);
5756 _applyButton->setEnabled(false);
5760 // ============================================================== deleteQuadItem
5761 void ReplaceHexaDialog::deleteQuadItem()
5763 delete quads_lw->currentItem();
5767 // ============================================================== apply
5768 bool ReplaceHexaDialog::apply(QModelIndex& result)
5770 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5773 if ( !getDocumentModel() ) return false;
5774 const PatternDataModel* patternDataModel = getPatternDataModel();
5775 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
5776 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
5778 QModelIndex ielts; //result
5780 QListWidgetItem* item = NULL;
5781 QModelIndexList iquads;
5783 int nbQuads = quads_lw->count();
5784 for ( int r = 0; r < nbQuads; ++r){
5785 item = quads_lw->item(r);
5786 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5787 if ( iquad.isValid() )
5791 QModelIndex ic1 = patternDataModel->mapToSource( _index[c1_le] );
5792 QModelIndex ic2 = patternDataModel->mapToSource( _index[c2_le] );
5793 QModelIndex ic3 = patternDataModel->mapToSource( _index[c3_le] );
5795 QModelIndex ip1 = patternDataModel->mapToSource( _index[p1_le] );
5796 QModelIndex ip2 = patternDataModel->mapToSource( _index[p2_le] );
5797 QModelIndex ip3 = patternDataModel->mapToSource( _index[p3_le] );
5799 if ( ic1.isValid() && ic2.isValid() && ic3.isValid()
5800 && ip1.isValid() && ip2.isValid() && ip3.isValid() ){
5801 ielts = getDocumentModel()->replace( iquads,
5807 if ( !ielts.isValid() ){
5808 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REPLACE HEXA" ) + "\n" + getErrorMsg() );
5811 _value = ielts.model()->data(ielts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
5812 // result = patternBuilderModel->mapFromSource(ielts);
5813 result = patternDataModel->mapFromSource(ielts);
5815 //update the list (indexes)
5816 for ( int r = 0; r < nbQuads; ++r ){
5817 item = quads_lw->item(r);
5818 iquad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5819 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iquad) );
5820 item->setData(LW_DATA_ROLE, iquad.data(HEXA_DATA_ROLE));
5826 // ------------------------- QuadRevolutionDialog ----------------------------------
5827 // ============================================================== Constructeur
5829 QuadRevolutionDialog::QuadRevolutionDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5830 HexaBaseDialog(parent, editmode, f)
5833 _helpFileName = "gui_quad_revolution.html#guiquadsrevolution";
5834 connect( revolutionUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5835 connect( revolution_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5836 _initWidget(editmode);
5837 revolutionUni_rb->click();
5840 // ============================================================== getAssocsVTK
5842 * Returns elements currently associated to vtk
5844 QModelIndexList QuadRevolutionDialog::getAssocsVTK()
5846 QModelIndexList assocs;
5848 QListWidgetItem* item = NULL;
5849 if (getPatternDataSelectionModel() == NULL) return assocs;
5851 //ListWidget content
5852 const PatternDataModel* patternDataModel = getPatternDataModel();
5853 if ( !patternDataModel ) return assocs;
5854 int nbQuads = quads_lw->count();
5855 for ( int r = 0; r < nbQuads; ++r ){
5856 item = quads_lw->item(r);
5857 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5858 if ( iQuad.isValid() )
5864 // ============================================================== Destructeur
5865 QuadRevolutionDialog::~QuadRevolutionDialog()
5869 // ============================================================== _initInputWidget
5870 void QuadRevolutionDialog::_initInputWidget( Mode editmode )
5872 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5873 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5874 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
5876 installEventFilter(this);
5877 quads_lw->installEventFilter(this);
5878 center_le->installEventFilter(this);
5879 axis_le->installEventFilter(this);
5881 center_le->setReadOnly(true);
5882 axis_le->setReadOnly(true);
5884 angles_lw->setItemDelegate( new HexaAngleDoubleSpinBoxDelegate(angles_lw) );
5885 angles_lw->setEditTriggers( QAbstractItemView::DoubleClicked );
5887 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5888 delQuadShortcut->setContext( Qt::WidgetShortcut );
5889 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(delQuadItem()) );
5890 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()));
5891 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()));
5893 connect(quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5896 // ============================================================== updateHelpFileName
5897 void QuadRevolutionDialog::updateHelpFileName()
5899 if ( sender() == revolutionUni_rb ){
5900 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutionuniform";
5901 } else if ( sender() == revolution_rb ){
5902 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutioncustom";
5906 // ============================================================== clear
5907 void QuadRevolutionDialog::clear()
5910 modelUnregister(quads_lw);
5913 modelUnregister(center_le);
5916 modelUnregister(axis_le);
5918 modelUnregister(this);
5921 // ============================================================== addAngleItem
5922 void QuadRevolutionDialog::addAngleItem() //CS_TODO
5924 QListWidgetItem* previousItem = angles_lw->currentItem();
5925 QListWidgetItem* newItem = new QListWidgetItem();
5927 double defaultValue = 180.;
5929 defaultValue = previousItem->data(Qt::EditRole).toDouble();
5931 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
5932 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
5933 angles_lw->addItem(newItem);
5938 // ============================================================== delAngleItem
5939 void QuadRevolutionDialog::delAngleItem()
5941 delete angles_lw->currentItem();
5945 // ============================================================== delQuadItem
5946 void QuadRevolutionDialog::delQuadItem()
5948 delete quads_lw->currentItem();
5952 // ============================================================== apply
5953 bool QuadRevolutionDialog::apply(QModelIndex& result)
5955 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5958 DocumentModel* docModel = getDocumentModel();
5959 PatternDataModel* patternDataModel = getPatternDataModel();
5960 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
5962 QListWidgetItem* item = NULL;
5964 QModelIndexList istartquads;
5966 int nbQuads = quads_lw->count();
5967 for ( int r = 0; r < nbQuads; ++r){
5968 item = quads_lw->item(r);
5969 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5970 if ( iquad.isValid() )
5971 istartquads << iquad;
5974 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
5975 QModelIndex iaxis = patternDataModel->mapToSource(_index[axis_le]);
5976 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
5977 int angle = angle_spb->value();
5978 int nbre = nbre_spb->value();
5980 vector<double> angles;
5981 int nbAngles = angles_lw->count();
5982 for ( int r = 0; r < nbAngles; ++r){
5983 item = angles_lw->item(r);
5984 angles.push_back(item->data(Qt::EditRole).toDouble());
5987 QModelIndex iElts; //result
5988 if (nbQuads == 1 && istartquads[0].isValid() && icenter.isValid() && iaxis.isValid())
5990 if (revolutionUni_rb->isChecked())
5991 iElts = docModel->revolutionQuadUni(istartquads[0], icenter, iaxis, angle, nbre);
5992 else if (revolution_rb->isChecked())
5993 iElts = docModel->revolutionQuad(istartquads[0], icenter, iaxis, angles);
5995 else if (nbQuads > 1 && icenter.isValid() && iaxis.isValid())
5997 if (revolutionUni_rb->isChecked())
5998 iElts = docModel->revolutionQuadsUni(istartquads, icenter, iaxis, angle, nbre);
5999 else if (revolution_rb->isChecked())
6000 iElts = docModel->revolutionQuads(istartquads, icenter, iaxis, angles);
6003 if ( !iElts.isValid() ){
6004 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD REVOLUTION" ) + "\n" + getErrorMsg() );
6007 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6008 result = patternDataModel->mapFromSource(iElts);
6009 // result = patternBuilderModel->mapFromSource(iElts);
6014 // ------------------------- MakeHemiSphereDialog ----------------------------------
6015 // ============================================================== Constructeur
6016 MakeHemiSphereDialog::MakeHemiSphereDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
6017 HexaBaseDialog(parent, editmode, f)
6019 _helpFileName = "gui_hemisphere.html";
6021 _initWidget(editmode);
6024 connect( sphereTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6025 connect( sphereUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6026 connect( sphere2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6027 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6028 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6030 connect( sphericalTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6031 connect( sphericalUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6032 connect( spherical2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6033 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6034 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6036 connect( rindTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6037 connect( rindUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6038 connect( rind2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6039 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6040 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6043 // ============================================================== Destructeur
6044 MakeHemiSphereDialog::~MakeHemiSphereDialog()
6048 // ============================================================== _initInputWidget
6049 void MakeHemiSphereDialog::_initInputWidget( Mode editmode )
6051 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6052 hole_axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6053 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6054 vplan_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6056 installEventFilter(this);
6057 center_le->installEventFilter(this);
6058 hole_axis_le->installEventFilter(this);
6059 base_le->installEventFilter(this);
6060 vplan_le->installEventFilter(this);
6062 center_le->setReadOnly(true);
6063 hole_axis_le->setReadOnly(true);
6064 base_le->setReadOnly(true);
6065 vplan_le->setReadOnly(true);
6067 radius_lw_1->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_1));
6068 radius_lw_1->setEditTriggers(QAbstractItemView::DoubleClicked);
6070 radius_lw_2->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_2));
6071 radius_lw_2->setEditTriggers(QAbstractItemView::DoubleClicked);
6073 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
6074 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6076 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
6077 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6079 connect( add_radius_pb_1, SIGNAL(clicked()), this, SLOT(addRadiusItem1()) );
6080 connect( del_radius_pb_1, SIGNAL(clicked()), this, SLOT(delRadiusItem1()) );
6082 connect( add_radius_pb_2, SIGNAL(clicked()), this, SLOT(addRadiusItem2()) );
6083 connect( del_radius_pb_2, SIGNAL(clicked()), this, SLOT(delRadiusItem2()) );
6085 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
6086 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
6088 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
6089 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
6092 // ============================================================== updateHelpFileName
6093 void MakeHemiSphereDialog::updateHelpFileName()
6095 if ( sender() == sphereTop_rb || sender() == rindTop_rb ){
6096 _helpFileName = "gui_hemisphere.html#guisphereandrindsimple";
6097 } else if ( sender() == sphereUni_rb ){
6098 _helpFileName = "gui_hemisphere.html#guisphereuniform";
6099 } else if ( sender() == sphere2_rb ){
6100 _helpFileName = "gui_hemisphere.html#guispherecustom";
6101 } else if ( sender() == rindUni_rb ){
6102 _helpFileName = "gui_hemisphere.html#guirinduniform";
6103 } else if ( sender() == rind2_rb ){
6104 _helpFileName = "gui_hemisphere.html#guirindcustom";
6105 } else if ( sender() == sphericalTop_rb ){
6106 _helpFileName = "gui_hemisphere.html#guiconcentricsimple";
6107 } else if ( sender() == sphericalUni_rb ){
6108 _helpFileName = "gui_hemisphere.html#guiconcentricuniform";
6109 } else if ( sender() == spherical2_rb ){
6110 _helpFileName = "gui_hemisphere.html#guiconcentriccustom";
6114 // ============================================================== addRadiusItem
6115 void MakeHemiSphereDialog::addRadiusItem1()
6117 QListWidgetItem* previousItem = radius_lw_1->currentItem();
6118 QListWidgetItem* newItem = new QListWidgetItem();
6120 double defaultValue = 1.;
6122 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6124 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6125 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6126 radius_lw_1->addItem(newItem);
6129 // ============================================================== delRadiusItem
6130 void MakeHemiSphereDialog::delRadiusItem1()
6132 delete radius_lw_1->currentItem();
6135 // ============================================================== addRadiusItem
6136 void MakeHemiSphereDialog::addRadiusItem2()
6138 QListWidgetItem* previousItem = radius_lw_2->currentItem();
6139 QListWidgetItem* newItem = new QListWidgetItem();
6141 double defaultValue = 1.;
6143 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6145 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6146 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6147 radius_lw_2->addItem(newItem);
6150 // ============================================================== delRadiusItem
6151 void MakeHemiSphereDialog::delRadiusItem2()
6153 delete radius_lw_2->currentItem();
6156 // ============================================================== addAngleItem
6157 void MakeHemiSphereDialog::addAngleItem()
6159 QListWidgetItem* previousItem = angle_lw->currentItem();
6160 QListWidgetItem* newItem = new QListWidgetItem();
6162 double defaultValue = 180.;
6164 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6166 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6167 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6168 angle_lw->addItem(newItem);
6171 // ============================================================== delAngleItem
6172 void MakeHemiSphereDialog::delAngleItem()
6174 delete angle_lw->currentItem();
6177 // ============================================================== addHeightItem
6178 void MakeHemiSphereDialog::addHeightItem()
6180 QListWidgetItem* previousItem = height_lw->currentItem();
6181 QListWidgetItem* newItem = new QListWidgetItem();
6183 double defaultValue = 1.;
6185 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6187 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6188 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6189 height_lw->addItem(newItem);
6192 // ============================================================== delHeightItem
6193 void MakeHemiSphereDialog::delHeightItem()
6195 delete height_lw->currentItem();
6198 // ============================================================== clear
6199 void MakeHemiSphereDialog::clear()
6202 modelUnregister(center_le);
6204 hole_axis_le->clear();
6205 modelUnregister(hole_axis_le);
6208 modelUnregister(base_le);
6211 modelUnregister(vplan_le);
6213 modelUnregister(this);
6216 // ============================================================== apply
6217 bool MakeHemiSphereDialog::apply(QModelIndex& result)
6219 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6222 DocumentModel* docModel = getDocumentModel();
6223 PatternDataModel* patternDataModel = getPatternDataModel();
6224 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6227 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6228 QModelIndex ivplan = patternDataModel->mapToSource( _index[vplan_le] );
6229 QModelIndex ivecx = patternDataModel->mapToSource(_index[base_le]);
6230 QModelIndex ivecz = patternDataModel->mapToSource(_index[hole_axis_le]);
6231 // QModelIndex ivecx = patternBuilderModel->mapToSource( _index[base_le] );
6232 // QModelIndex ivecz = patternBuilderModel->mapToSource( _index[hole_axis_le] );
6234 double radhole = hole_rad_spb->value();
6235 double radext = sphere_radext_spb->value();
6236 double radint = sphere_radint_spb->value();
6237 double radang = radial_angle_spb->value();
6239 int crit = crit_spb->value();
6240 int nb = nbre_spb->value();
6241 int nrad = ngrid_rad_spb->value();
6242 int nang = ngrid_ang_spb->value();
6243 int nhaut = ngrid_height_spb->value();
6245 //radius, angles and heights collection
6246 QListWidgetItem* item = NULL;
6248 vector<double> radius1;
6249 vector<double> radius2;
6250 vector<double> angles;
6251 vector<double> heights;
6254 // double somme = 0.;
6255 int nbAngles = angle_lw->count();
6256 for ( int r = 0; r < nbAngles; ++r){
6257 item = angle_lw->item(r);
6258 double itemValue = item->data(Qt::EditRole).toDouble();
6259 angles.push_back(itemValue);
6260 // somme += itemValue;
6263 //radius1 collection
6264 int nbRadius = radius_lw_1->count();
6265 for ( int r = 0; r < nbRadius; ++r){
6266 item = radius_lw_1->item(r);
6267 radius1.push_back(item->data(Qt::EditRole).toDouble());
6270 //radius2 collection
6271 nbRadius = radius_lw_2->count();
6272 for ( int r = 0; r < nbRadius; ++r){
6273 item = radius_lw_2->item(r);
6274 radius2.push_back(item->data(Qt::EditRole).toDouble());
6277 //heights collection
6278 int nbHeight = height_lw->count();
6279 for ( int r = 0; r < nbHeight; ++r){
6280 item = height_lw->item(r);
6281 heights.push_back(item->data(Qt::EditRole).toDouble());
6284 if (sphere_rb->isChecked())
6286 if (sphereTop_rb->isChecked())
6287 iElts = docModel->makeSphereTop( nrad, nang, nhaut );
6288 else if (sphereUni_rb->isChecked())
6290 if (icenter.isValid() && ivplan.isValid() && ivecx.isValid() && ivecz.isValid())
6291 iElts = docModel->makeSphereUni(icenter, ivecx, ivecz, radhole, radext, radang,
6292 ivplan, nrad, nang, nhaut);
6294 else if (sphere2_rb->isChecked())
6296 // if (somme > 360.01)
6298 // SUIT_MessageBox::information( 0,
6300 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6303 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6304 iElts = docModel->makeSphere(icenter, ivecx, ivecz, radius2, angles, heights);
6307 else if (spherical_rb->isChecked())
6309 if (sphericalTop_rb->isChecked())
6310 iElts = docModel->makeSphericalTop(nb, crit);
6311 else if (sphericalUni_rb->isChecked())
6313 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6314 iElts = docModel->makeSphericalUni(icenter, ivecx, ivecz, radhole, nb, crit);
6316 else if (spherical2_rb->isChecked())
6318 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6319 iElts = docModel->makeSpherical(icenter, ivecx, ivecz, radius1, crit);
6322 else if (rind_rb->isChecked())
6324 if (rindTop_rb->isChecked())
6325 iElts = docModel->makeRindTop(nrad, nang, nhaut);
6326 else if (rindUni_rb->isChecked())
6328 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid() && ivplan.isValid())
6329 iElts = docModel->makeRindUni(icenter, ivecx, ivecz,
6330 radhole, radint, radext, radang,
6331 ivplan, nrad, nang, nhaut);
6333 else if (rind2_rb->isChecked())
6335 // if (somme > 360.01)
6337 // SUIT_MessageBox::information( 0,
6339 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6342 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6343 iElts = docModel->makeRind(icenter, ivecx, ivecz, radius2, angles, heights);
6347 if ( !iElts.isValid() ){
6348 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) + "\n" + getErrorMsg() );
6351 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6352 result = patternDataModel->mapFromSource(iElts);
6353 // result = patternBuilderModel->mapFromSource(iElts);
6358 // ------------------------- ModelInfoDialog ----------------------------------
6359 ModelInfoDialog::ModelInfoDialog(QWidget* parent, Qt::WindowFlags wf):
6360 HexaBaseDialog(parent, INFO_MODE, wf)
6363 setWindowTitle(HEXABLOCKGUI::tr("MODEL_INFO"));
6366 void ModelInfoDialog::updateInfo()
6368 DocumentModel* docModel = getDocumentModel();
6369 if (docModel == NULL) return;
6372 model_name_le->setText(docModel->getName());
6374 //Nb of elements in the model
6375 total_vertices_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_VERTEX)));
6376 total_edges_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_EDGE)));
6377 total_quads_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_QUAD)));
6378 total_hexas_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_HEXA)));
6380 ///Nb of used elements in the model
6381 used_vertices_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_VERTEX)));
6382 used_edges_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_EDGE)));
6383 used_quads_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_QUAD)));
6384 used_hexas_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_HEXA)));
6386 //Nb of unused elements in the model
6387 unused_vertices_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_VERTEX)));
6388 unused_edges_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_EDGE)));
6389 unused_quads_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_QUAD)));
6390 unused_hexas_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_HEXA)));
6393 void ModelInfoDialog::showEvent( QShowEvent * event )
6396 QDialog::showEvent ( event );
6399 // ============================================================== hideEvent
6400 void ModelInfoDialog::hideEvent ( QHideEvent * event )
6402 QDialog::hideEvent( event );
6405 // ------------------------- AddShapeDialog ----------------------------------
6406 AddShapeDialog::AddShapeDialog(QWidget* parent, Mode editmode, Qt::WindowFlags wf):
6407 HexaBaseDialog(parent, editmode, wf)
6411 _initWidget(editmode);
6412 setWindowTitle(HEXABLOCKGUI::tr("ADD_SHAPE"));
6415 // ============================================================== Destructeur
6416 AddShapeDialog::~AddShapeDialog()
6418 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
6419 this, SLOT(onCurrentSelectionChanged()) );
6422 // ============================================================== close
6423 void AddShapeDialog::close()
6425 HEXABLOCKGUI::assocInProgress = false;
6426 HexaBaseDialog::close();
6429 // ============================================================== _initInputWidget
6430 void AddShapeDialog::_initInputWidget( Mode editmode )
6432 shape_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMSHAPE_TREE) );
6433 shape_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_SHAPE) );
6434 shape_le->installEventFilter(this);
6435 shape_le->setReadOnly(true);
6438 void AddShapeDialog::clear()
6441 shape_le->setProperty("GeomObj", QVariant());
6443 modelUnregister(this);
6446 // ============================================================== onCurrentSelectionChanged
6447 void AddShapeDialog::onCurrentSelectionChanged()
6449 SALOME_ListIO selectedObjects;
6450 HEXABLOCKGUI::currentDocGView->getSelected(selectedObjects);
6451 if (selectedObjects.IsEmpty())
6454 // * extract the TopoDS_Shape of the selected object
6455 TopoDS_Shape selectedTopoShape = GEOMBase::GetTopoFromSelection( selectedObjects );
6456 if (selectedTopoShape.IsNull())
6458 shape_le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(selectedTopoShape));
6460 // * extract the name of the selected shape
6462 GEOMBase::GetNameOfSelectedIObjects( selectedObjects, name, true );
6463 shape_le->setText(name);
6466 // ============================================================== onWindowActivated
6467 void AddShapeDialog::onWindowActivated(SUIT_ViewManager* vm)
6469 QString vmType = vm->getType();
6470 if ( vmType == OCCViewer_Viewer::Type() )
6471 shape_le->setFocus();
6474 // ============================================================== apply
6475 bool AddShapeDialog::apply(QModelIndex& result)
6478 QString shapeName = shape_le->text();
6479 QVariant v = shape_le->property("TopoDS_Shape");
6480 if ( !v.isValid() || shapeName.isEmpty())
6484 TopoDS_Shape shape = v.value<TopoDS_Shape>();
6488 assocOk = getDocumentModel()->addShape(shape, shapeName);
6492 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), HEXABLOCKGUI::tr("ADD_SHAPE_FAILED") + "\n" + getErrorMsg() );