1 // Copyright (C) 2009-2020 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, or (at your option) any later version.
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"
30 #include <QStyledItemDelegate>
32 #include <SalomeApp_Application.h>
33 #include <SalomeApp_Study.h>
34 #ifndef DISABLE_PYCONSOLE
35 #include <PyConsole_Console.h>
37 #include <SalomeApp_Tools.h>
39 #include <Standard_GUID.hxx>
40 #include <TDF_Label.hxx>
42 #include <OCCViewer_ViewManager.h>
45 #include <TopExp_Explorer.hxx>
46 #include <TopoDS_Iterator.hxx>
47 #include <TopTools_MapOfShape.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <TColStd_IndexedMapOfInteger.hxx>
51 #include <SUIT_Session.h>
52 #include <SUIT_Desktop.h>
53 #include <SUIT_OverrideCursor.h>
54 #include <SUIT_MessageBox.h>
55 #include <SUIT_Session.h>
56 #include "SVTK_Selection.h"
57 #include <SVTK_ViewModel.h>
58 #include <VTKViewer_ViewModel.h>
59 #include <SVTK_View.h>
61 #include <SUIT_ResourceMgr.h>
65 #include <utilities.h>
67 #define BUTTON_BOX_MIN_WIDTH 5
68 #define VERTEX_COORD_MIN -1000000
69 #define VERTEX_COORD_MAX 1000000
70 #define SPINBOX_ANGLE_MAX 360
71 #define SPINBOX_DOUBLE_MAX 1000000000
72 #define SPINBOX_POSITIVE_DOUBLE_MIN 0
77 using namespace HEXABLOCK::GUI;
80 Q_DECLARE_METATYPE(HEXABLOCK::GUI::HexaTreeRole);
81 Q_DECLARE_METATYPE(DocumentModel::GeomObj);
82 Q_DECLARE_METATYPE(TopAbs_ShapeEnum);
83 Q_DECLARE_METATYPE(TopoDS_Shape);
85 //General SpinBox Delegate
86 class HexaDoubleSpinBoxDelegate : public QStyledItemDelegate {
88 HexaDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
90 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
91 const QModelIndex &index) const{
92 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
93 sb->setDecimals(NB_DECIMALS);
98 //Angle SpinBox Delegate
99 class HexaAngleDoubleSpinBoxDelegate : public QStyledItemDelegate {
101 HexaAngleDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
103 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
104 const QModelIndex &index) const{
105 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
106 sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
107 sb->setMaximum(SPINBOX_ANGLE_MAX);
108 sb->setDecimals(NB_DECIMALS);
114 //Positive DoubleSpinBox Delegate (for heigth, radius, ...)
115 class HexaPositiveDoubleSpinBoxDelegate : public QStyledItemDelegate {
117 HexaPositiveDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
119 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
120 const QModelIndex &index) const{
121 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
122 sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
123 sb->setMaximum(SPINBOX_DOUBLE_MAX); //10e9
124 sb->setDecimals(NB_DECIMALS);
129 // ======================================================== Constructeur
130 HexaBaseDialog::HexaBaseDialog( QWidget * parent, Mode editmode, Qt::WindowFlags f ):
132 _editMode( editmode ),
135 debugEdgeAssoc(false),
136 autoFocusSwitch(true)
138 _strHexaWidgetType[VERTEX_TREE] = tr( "VERTEX" );
139 _strHexaWidgetType[EDGE_TREE] = tr( "EDGE" );
140 _strHexaWidgetType[QUAD_TREE] = tr( "QUAD" );
141 _strHexaWidgetType[HEXA_TREE] = tr( "HEXA" );
143 _strHexaWidgetType[VECTOR_TREE] = tr( "VECTOR" );
144 // _strHexaWidgetType[CYLINDER_TREE] = tr( "CYLINDER" );
145 // _strHexaWidgetType[PIPE_TREE] = tr( "PIPE" );
146 _strHexaWidgetType[ELEMENTS_TREE] = tr( "ELEMENTS" );
147 _strHexaWidgetType[CROSSELEMENTS_TREE]= tr( "CROSSELEMENTS" );
150 _strHexaWidgetType[GEOMSHAPE_TREE] = tr( "GEOMSHAPE" );
151 _strHexaWidgetType[GEOMPOINT_TREE] = tr( "GEOMPOINT" );
152 _strHexaWidgetType[GEOMEDGE_TREE] = tr( "GEOMEDGE" );
153 _strHexaWidgetType[GEOMFACE_TREE] = tr( "GEOMFACE" );
155 _strHexaWidgetType[GROUP_TREE] = tr( "GROUP" );
156 _strHexaWidgetType[LAW_TREE] = tr( "LAW" );
157 _strHexaWidgetType[PROPAGATION_TREE]= tr( "PROPAGATION" );
160 // ============================================================= getIndexList
161 QModelIndexList HexaBaseDialog::getIndexList(QListWidget* itemsList, bool mapToSource)
163 QModelIndexList iItems;
165 QListWidgetItem* item = NULL;
167 const PatternDataModel* patternDataModel = getPatternDataModel();
168 if (patternDataModel == NULL || itemsList == NULL) return iItems;
170 unsigned int nbItems = itemsList->count();
171 for ( int r = 0; r < nbItems; ++r){
172 item = itemsList->item(r);
174 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
176 iItem = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
183 // ================================================================ computeAndSetDimension
184 void HexaBaseDialog::computeAndSetDimension(const QModelIndex& elt)
186 // * Check if everything is OK for the computing
187 DocumentModel* docModel = getDocumentModel();
188 if (docModel == NULL || _currentObj == NULL)
191 int selectedType = elt.data(HEXA_TREE_ROLE).toInt();
192 if (selectedType != EDGE_TREE && selectedType != GEOMEDGE_TREE)
195 QListWidget* list = dynamic_cast<QListWidget*>(_currentObj);
196 QDoubleSpinBox* spb = dynamic_cast<QDoubleSpinBox*>(_currentObj);
198 if (list == NULL && spb == NULL)
201 // * Compute the value of the dimension
204 if (_currentObj->property("Radius").isValid())
205 value = docModel->getRadius(elt);
206 else if (_currentObj->property("Angle").isValid())
207 value = docModel->getAngle(elt);
208 else if (_currentObj->property("Length").isValid())
209 value = docModel->getLength(elt);
214 // * Set the value to the field (radius, length or height)
217 QListWidgetItem* item = list->currentItem();
222 item->setText(QString::number(value));
223 list->editItem(item);
227 else if (spb != NULL)
229 spb->setValue(value);
235 // ============================================================= resetSizeAndShow
236 void HexaBaseDialog::resetSizeAndShow(QDockWidget* parent)
241 //force the dialog to fit its contain
242 // setMinimumWidth(sizeHint().width());
244 //set the dialog in the dockwidget
245 if (parent->widget())
246 parent->widget()->close();
247 parent->setWidget(this);
248 parent->setWindowTitle(windowTitle());
251 // setMinimumWidth(MIN_WIDTH);
254 QString HexaBaseDialog::getErrorMsg()
256 DocumentModel* docModel = getDocumentModel();
257 Hex::Hex* hex = docModel->getHexaRoot();
258 int nbErrorMsg = hex->sizeofMessage();
259 QString msg, newLine = "\n";
260 for (int i = 1; i < nbErrorMsg; ++i)
261 msg += newLine + hex->getMessageLine(i);
266 //unlink the widget from the model
267 void HexaBaseDialog::modelUnregister(QWidget* widget)
269 if (widget == NULL) return;
271 if (widget->property("GeomWidgetType").isValid())
273 widget->setProperty("GeomObj", QVariant());
274 widget->setProperty("TopoDS_Shape", QVariant());
277 widget->setProperty("HexaData", QVariant());
278 widget->setProperty("QModelIndex", QVariant());
279 _index[widget] = QModelIndex();
281 HexaBaseDialog* diag = dynamic_cast<HexaBaseDialog*>(widget);
283 diag->clearWidgetsIndexes();
286 // ============================================================= connectDocumentGraphicView
287 void HexaBaseDialog::connectDocumentGraphicView(VtkDocumentGraphicView* docGView)
289 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
290 if (docGView == NULL) return;
292 disconnectDocumentGraphicView(docGView); //to avoid double connect
294 //Connect the graphic view and its model to the dialog box
295 connect( docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
296 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
297 // connect( docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
298 // this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
299 connect( docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
300 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
301 connect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
302 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
303 connect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
304 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
307 // ============================================================= disconnectDocumentGraphicView
308 void HexaBaseDialog::disconnectDocumentGraphicView(VtkDocumentGraphicView* docGView)
310 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
311 if (docGView == NULL) return;
314 //Disconnect graphic view signals form the dialog box
315 disconnect(docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
316 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
318 // disconnect(docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
319 // this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
321 disconnect(docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
322 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
324 disconnect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
325 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
327 disconnect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
328 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
331 // ============================================================= onCurrentSelectionChanged
332 void HexaBaseDialog::onCurrentSelectionChanged()
334 highlightSelectedAssocs();
337 // ============================================================= clearCurrentObjectFocus
338 void HexaBaseDialog::clearCurrentObjectFocus()
340 QWidget* currentWidget = dynamic_cast<QWidget*>(_currentObj);
341 if (currentWidget != NULL)
343 currentWidget->clearFocus();
348 // ============================================================= setFocusToNextField
349 //Sets focus to the next field of the current object
350 void HexaBaseDialog::setFocusToNextField()
354 if (!HEXABLOCKGUI::assocInProgress && autoFocusSwitch)
356 _highlightWidget(_currentObj, Qt::white);
361 // ============================================================== _initButtonBox
362 QGroupBox* HexaBaseDialog::_initButtonBox( Mode editmode )
364 if ( editmode == INFO_MODE )
367 QGroupBox* buttonBox = new QGroupBox();
368 buttonBox->setMinimumWidth(BUTTON_BOX_MIN_WIDTH);
369 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
370 QHBoxLayout* buttonsHLayout = new QHBoxLayout();
371 _applyButton = new QPushButton(tr("Apply"));
372 QPushButton* closeButton = new QPushButton(tr("Close"));
373 QPushButton* helpButton = new QPushButton(tr("Help"));
375 connect( _applyButton, SIGNAL(clicked()), this, SLOT(apply()), Qt::UniqueConnection );
376 connect( closeButton, SIGNAL(clicked()), this, SLOT(close()), Qt::UniqueConnection );
377 connect( helpButton, SIGNAL(clicked()), this, SLOT(onHelpRequested()), Qt::UniqueConnection );
379 buttonsHLayout->addWidget( _applyButton );
380 buttonsHLayout->addWidget( closeButton );
381 buttonsHLayout->addStretch(1);
382 buttonsHLayout->addWidget( helpButton );
383 buttonBox->setLayout(buttonsHLayout);
384 layout()->addWidget(buttonBox);
385 buttonBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
389 // ============================================================== _initWidget
390 void HexaBaseDialog::_initWidget( Mode editmode )
392 _initInputWidget( editmode );
393 _initButtonBox( editmode );
396 // ============================================================== apply
397 bool HexaBaseDialog::apply()
400 bool applied = apply(iNew);
403 _selectAndHighlight( iNew );
404 if (!HEXABLOCKGUI::assocInProgress)
405 getDocumentModel()->updateGeomTree();
410 void HexaBaseDialog::clearVTKSelection()
412 HEXABLOCKGUI::currentDocGView->clearSelection();
413 _highlightWidget(_currentObj, Qt::white);
416 void HexaBaseDialog::clearOCCSelection()
418 HEXABLOCKGUI::currentOccGView->clearSelection();
421 // ============================================================== close
422 void HexaBaseDialog::close()
424 //reset the data selection pattern (forget all selections of the current context)
425 getPatternDataSelectionModel()->reset();
426 // getPatternBuilderSelectionModel()->reset();
427 getPatternGeomSelectionModel()->reset();
429 //Clear vtk selection
432 //Clear occ selection
435 //Close the dialog box
437 parentWidget()->close();
439 getPatternDataSelectionModel()->setInfoMode(true);
442 // ============================================================== onHelpRequested
443 void HexaBaseDialog::onHelpRequested()
445 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
447 app->onHelpContextModule( "HEXABLOCK", _helpFileName );
451 platform = "winapplication";
453 platform = "application";
456 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
457 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
458 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( _helpFileName ),
459 QObject::tr( "BUT_OK" ) );
463 // ============================================================== highlightSelectedAssocs
464 void HexaBaseDialog::highlightSelectedAssocs()
466 QMultiMap<QString, int> geomAssocs = getAssocsGEOM();
467 QModelIndexList vtkAssocs = getAssocsVTK();
469 // HEXABLOCKGUI::selectionMgr()->clearSelected();
470 //highlight geom selected elts
471 if (geomAssocs.size() > 0)
472 HEXABLOCKGUI::currentOccGView->highlight(geomAssocs, false);
474 //highlight vtk selected elts
475 if (!vtkAssocs.isEmpty())
476 HEXABLOCKGUI::currentDocGView->highlight(vtkAssocs);
479 // ============================================================== refreshHighlight
480 void HexaBaseDialog::refreshHighlight()
482 HEXABLOCKGUI::selectionMgr()->clearSelected();
483 highlightSelectedAssocs();
486 bool HexaBaseDialog::isDimensionType(const QObject* obj)
491 return (obj->property("Radius").isValid()) ||
492 (obj->property("Angle").isValid()) ||
493 (obj->property("Length").isValid());
496 // ============================================================== getObjectViewType
497 HEXABLOCKGUI::ViewType HexaBaseDialog::getObjectViewType(QObject* obj)
500 return HEXABLOCKGUI::UNKNOWN;
502 QVariant v1 = obj->property("GeomWidgetType");
503 QVariant v2 = obj->property("HexaWidgetType");
505 if (v1.isValid() && v2.isValid() && isDimensionType(obj))
506 return HEXABLOCKGUI::VTK_OCC;
507 else if (v1.isValid())
508 return HEXABLOCKGUI::OCC;
509 else if (v2.isValid())
510 return HEXABLOCKGUI::VTK;
512 return HEXABLOCKGUI::UNKNOWN;
515 // ============================================================== _selectAndHighlight
516 void HexaBaseDialog::_selectAndHighlight( const QModelIndex& i )
518 if ( !i.isValid() ) return;
519 setProperty("QModelIndex", QVariant::fromValue(i));
523 // ============================================================== _allowSelection
524 void HexaBaseDialog::_allowSelection()
526 if ( getDocumentModel() )
527 getDocumentModel()->disallowEdition();
530 // ============================================================== _disallowSelection
531 void HexaBaseDialog::_disallowSelection()
533 if ( getDocumentModel() ){
534 getDocumentModel()->allowEdition();
536 HEXABLOCKGUI::currentDocGView->setAllSelection();
539 // ============================================================== _allowVTKSelection
540 bool HexaBaseDialog::_allowVTKSelection( QObject* obj )
544 QVariant v = obj->property("HexaWidgetType");
545 HexaWidgetType wType = v.value<HexaWidgetType>();
549 HEXABLOCKGUI::currentDocGView->setVertexSelection(); isOk = true;
552 HEXABLOCKGUI::currentDocGView->setEdgeSelection(); isOk = true;
555 HEXABLOCKGUI::currentDocGView->setQuadSelection(); isOk = true;
558 HEXABLOCKGUI::currentDocGView->setHexaSelection(); isOk = true;
560 default: HEXABLOCKGUI::currentDocGView->setAllSelection();
565 // ============================================================== _allowOCCSelection
566 bool HexaBaseDialog::_allowOCCSelection( QObject* obj )
568 QVariant v = obj->property("GeomWidgetType");
569 GeomWidgetType wType = v.value<GeomWidgetType>();
570 HEXABLOCKGUI::currentOccGView->setSelectionMode(wType);
575 // ============================================================== _getSelector
576 QItemSelectionModel* HexaBaseDialog::_getSelector( QObject* obj )
581 QItemSelectionModel* selector = NULL;
583 HexaWidgetType wtype;
584 QVariant v = obj->property("HexaWidgetType");
585 QVariant v2 = obj->property("GeomWidgetType");
586 if ( !v.isValid() || (v2.isValid() && isDimensionType(obj)) )
589 wtype = v.value<HexaWidgetType>();
596 case VECTOR_TREE: selector = getPatternDataSelectionModel(); break;
597 // case CYLINDER_TREE:
599 // case ELEMENTS_TREE:
600 // case CROSSELEMENTS_TREE: selector = getPatternBuilderSelectionModel(); break;
603 case GEOMFACE_TREE: selector = getPatternGeomSelectionModel(); break;
604 case GROUP_TREE: selector = getGroupsSelectionModel(); break;
606 case PROPAGATION_TREE: selector = getMeshSelectionModel(); break;
613 // ============================================================== getGeomObj
614 DocumentModel::GeomObj* HexaBaseDialog::getGeomObj(const QModelIndex& index)
616 HEXA_NS::NewShape* aSh = getDocumentModel()->getHexaPtr<HEXA_NS::NewShape*>(index);
617 DocumentModel::GeomObj* geomObj = NULL;
620 geomObj = new DocumentModel::GeomObj;
621 geomObj->shapeName = aSh->getName();
622 geomObj->subId = QString::number(-1);
626 HEXA_NS::EltBase* aSShElt = getDocumentModel()->getHexaPtr(index);
627 HEXA_NS::SubShape* aSSh = dynamic_cast<HEXA_NS::SubShape*>(aSShElt);
630 geomObj = new DocumentModel::GeomObj;
632 if (aSSh->getParentShape() != NULL)
633 shapeName = aSSh->getParentShape()->getName();
634 geomObj->shapeName = shapeName;
635 geomObj->subId = QString::number(aSSh->getIdent());
641 // ============================================================== _onSelectionChanged
643 * Puts elements selected in the model (treeview) in the corresponding
644 * line edit widget (the one that has the focus) of the current dialog box.
646 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QLineEdit* le )
648 QModelIndexList l = sel.indexes();
649 if ( l.count() == 0 ) return false;
651 // mono selection mode: we just get the first selected element
652 QModelIndex selected = l[0];
654 // we just return if the selection is not valid or the selection and the
655 // line content are the same
656 if ( !selected.isValid() || le->property("HexaData") == selected.data(HEXA_DATA_ROLE) )
660 int selType = selected.data(HEXA_TREE_ROLE).toInt();
663 QVariant v = le->property("HexaWidgetType");
664 if ( !v.isValid() ) return false;
665 HexaWidgetType wType = v.value<HexaWidgetType>();
667 // check selection compatibility between selection and widget
668 if ( selType != wType ){
669 SUIT_MessageBox::information( 0, tr("HEXA_INFO"),
670 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg(_strHexaWidgetType[wType]));
673 if (le->property("GeomWidgetType").isValid())
675 DocumentModel::GeomObj* geomObj = getGeomObj(selected);
678 le->setProperty("GeomObj", QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
680 DocumentModel* docModel = getDocumentModel();
681 QString objId = geomObj->shapeName + "," + geomObj->subId;
682 HEXA_NS::SubShape* ssh = docModel->getGeomPtr(objId);
685 TopoDS_Shape shape = ssh->getShape();
687 le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(shape));
689 setCurrentGeomObj(geomObj);
693 //fill the lineEdit if selection is OK
694 le->setText( selected.data().toString() );// name
695 le->setProperty("QModelIndex", QVariant::fromValue(selected));
696 le->setProperty("HexaData", selected.data(HEXA_DATA_ROLE));
697 _index[le] = selected;
699 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(_currentObj);
700 if (selected.isValid() && lineEdit != NULL)
701 setFocusToNextField();
706 // ============================================================== _onSelectionChanged
708 * Puts elements selected in the model (treeview) in the corresponding list widget
709 * of the current dialog box.
711 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QListWidget* lw )
713 QModelIndexList l = sel.indexes();
715 if ( l.count() == 0 ) return false;
718 QVariant v = lw->property("HexaWidgetType");
719 if ( !v.isValid() ) return false;
720 HexaWidgetType wType = v.value<HexaWidgetType>();
722 //fill the listWidget
723 QListWidgetItem* item = NULL;
727 foreach( const QModelIndex& isel, l ){
728 // if ( lw->count() == maxSize) break;
729 selType = isel.data(HEXA_TREE_ROLE).toInt();
730 if ( selType != wType ){ // check selection compatibility between selection and widget
731 SUIT_MessageBox::information( 0,
733 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg( _strHexaWidgetType[wType]) );
736 // add selection to listWidget if selection is OK
737 selName = isel.data().toString();
738 QList<QListWidgetItem *> twice = lw->findItems( selName, Qt::MatchExactly);
739 if ( twice.count() == 0 ){
740 item = new QListWidgetItem( selName );
741 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(isel) );
742 item->setData(LW_DATA_ROLE, isel.data(HEXA_DATA_ROLE));
743 if (lw->property("GeomWidgetType").isValid())
745 DocumentModel::GeomObj* geomObj = getGeomObj(isel);
747 item->setData(LW_ASSOC_ROLE, QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
756 // ============================================================== onSelectionChanged
758 * Puts elements selected in the model in the corresponding widget (list widget or line edit)
759 * of the current dialog box.
761 void HexaBaseDialog::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
763 QModelIndexList l = sel.indexes();
765 if ( l.count() == 0 )
767 QModelIndex selected = l[0];
769 // * no edition for Info Dialogs
770 if ( _editMode == INFO_MODE || _currentObj == NULL || !selected.isValid())
773 if (isDimensionType(_currentObj))
775 // ** set the dimension of the selected object in the editor **/
776 int selectedType = selected.data(HEXA_TREE_ROLE).toInt();
777 if (selectedType == EDGE_TREE || selectedType == GEOMEDGE_TREE)
778 computeAndSetDimension(selected);
782 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
783 QListWidget* aListWidget = dynamic_cast<QListWidget*>(_currentObj);
785 // * fill the lineedit with selection
788 _onSelectionChanged( sel, aLineEdit );
792 // * fill the listWidget with selection
794 _onSelectionChanged( sel, aListWidget );
797 // ============================================================== showEvent
798 void HexaBaseDialog::showEvent( QShowEvent * event )
800 // Do not disallow edition, otherwise we can't expand group items
801 // (e.g. vertices) when creating an item (e.g. a vertex or an edge).
802 // Hence, no need to allow edition in info mode.
803 //if ( _editMode == INFO_MODE )
804 // getDocumentModel()->allowEdition();
806 // getDocumentModel()->disallowEdition();
808 //Connect to salome selection signals
809 if (HEXABLOCKGUI::selectionMgr() != NULL)
811 connect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
812 this, SLOT(onCurrentSelectionChanged()), Qt::UniqueConnection );
815 //connect model selection signals
816 connectDocumentGraphicView();
818 QDialog::showEvent ( event );
822 // ============================================================== hideEvent
823 void HexaBaseDialog::hideEvent ( QHideEvent * event )
825 //Disconnection salome selection signals
826 if (HEXABLOCKGUI::selectionMgr() != NULL)
827 disconnect( HEXABLOCKGUI::selectionMgr() , SIGNAL(currentSelectionChanged()),
828 this, SLOT(onCurrentSelectionChanged()) );
830 //Disconnect vtk window activation signals
831 // if (HEXABLOCKGUI::currentDocGView->getViewWindow() != NULL)
832 // disconnect( HEXABLOCKGUI::currentDocGView->getViewWindow()->getViewManager(),
833 // SIGNAL( activated(SUIT_ViewManager*) ),
834 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
836 //Disconnect occ window activation signals
837 // if (HEXABLOCKGUI::currentOccGView->getViewWindow() != NULL)
838 // disconnect( HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager(),
839 // SIGNAL( activated(SUIT_ViewManager*) ),
840 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
842 //Disconnect model selection signals
843 disconnectDocumentGraphicView();
844 getDocumentModel()->allowEdition();
846 QDialog::hideEvent( event );
849 // ============================================================== updateButtonBox
850 void HexaBaseDialog::updateButtonBox()
854 // ============================================================== updateName
855 void HexaBaseDialog::updateName()
857 const PatternDataModel* patternDataModel = getPatternDataModel();
859 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(sender());
860 if (!lineEdit) return;
861 QString newName = lineEdit->text();
862 if ( newName.isEmpty() ) return;
864 QVariant v = lineEdit->property("QModelIndex");
865 if ( !v.isValid() ) return;
867 QModelIndex index = v.value<QModelIndex>();
868 if ( index.isValid() )
869 getDocumentModel()->setName( patternDataModel->mapToSource(index), newName );
872 // ============================================================== updateDefaultName
873 void HexaBaseDialog::updateDefaultName(QLineEdit* name_field, HEXA_NS::EnumElt type)
875 if (name_field == NULL) return;
877 HEXA_NS::Document* doc = getDocumentModel()->getHexaDocument();
878 if (doc == NULL) return;
880 name_field->setText(doc->getNextName(type).c_str());
883 // ============================================================== selectElementOfModel
884 /*Selects in the model (treeview) elements selected in a listwidget,
885 * or an element in a line edit.*/
886 void HexaBaseDialog::selectElementOfModel()
888 if (getPatternDataSelectionModel() == NULL) return;
890 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
891 if ( !currentListWidget ) return;
893 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
895 getPatternDataSelectionModel()->clearSelection();
896 foreach ( QListWidgetItem *item, sel ){
897 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
898 index = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
899 if ( index.isValid() )
900 getPatternDataSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
904 // ============================================================== _isLineOrListWidget
906 * Return true is the widget is a line or a list
909 bool HexaBaseDialog::_isLineOrListWidget(QObject *widget)
911 if (widget == NULL) return false;
913 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(widget);
914 QListWidget *listWidget = dynamic_cast<QListWidget*>(widget);
915 return (lineEdit != NULL) || (listWidget != NULL);
917 }//_isLineOrListWidget
920 // ============================================================== _highlightWidget
922 * Highlight the given widget with the given color.
924 void HexaBaseDialog::_highlightWidget(QObject *obj, Qt::GlobalColor clr)
926 QDoubleSpinBox* spb = dynamic_cast<QDoubleSpinBox*>(obj);
927 if (!_isLineOrListWidget(obj) && spb == NULL)
930 QWidget *widget = dynamic_cast<QWidget*>(obj);
931 QPalette palette1 = widget->palette();
932 palette1.setColor(QPalette::Active, widget->backgroundRole(), clr);
933 widget->setPalette(palette1);
937 // ============================================================== _updateCurrentObject
938 void HexaBaseDialog::_updateCurrentObject(QObject* obj)
940 _highlightWidget(_currentObj, Qt::white);
942 _highlightWidget(obj, Qt::yellow);
945 // ============================================================== eventFilter
947 * Handles events from the treeview and the dialog boxes.
949 bool HexaBaseDialog::eventFilter(QObject *obj, QEvent *event)
951 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(obj);
952 QListWidget *listWidget = dynamic_cast<QListWidget*>(obj);
954 // * Enter key press ------
955 if ( event->type() == QEvent::KeyPress &&
956 ((QKeyEvent*)event)->key() == Qt::Key_Return)
958 setFocusToNextField();
962 // * Focus out from a list widget ------
963 if ( event->type() == QEvent::FocusOut && listWidget != NULL)
965 QItemSelectionModel * selectionModel = listWidget->selectionModel();
966 selectionModel->clearSelection();
969 if ( event->type() != QEvent::FocusIn )
973 HEXABLOCKGUI::ViewType vtype = getObjectViewType(obj);
974 if (vtype == HEXABLOCKGUI::VTK_OCC)
976 _allowVTKSelection(obj);
977 _allowOCCSelection(obj);
979 else if (vtype == HEXABLOCKGUI::VTK)
980 _allowVTKSelection( obj );
981 else if (vtype == HEXABLOCKGUI::OCC)
982 _allowOCCSelection( obj );
984 //Depending on the focused widget type, get the right selector for it
987 QItemSelectionModel* selector = _getSelector( obj );
988 if ( selector == NULL )
990 _updateCurrentObject(obj);
994 if ( _currentObj != obj && (lineEdit == NULL || listWidget == NULL) )
995 selector->clearSelection();
997 _updateCurrentObject(obj);
999 //If the widget contains an element, select it in model/view
1000 if ( lineEdit != NULL ){ //element can be from lineEdit
1001 v = lineEdit->property("HexaData");
1003 return QObject::eventFilter(obj, event);
1004 index = ((SelectionModel*)selector)->indexBy( HEXA_DATA_ROLE, v);
1005 if (index.isValid())
1006 selector->select( index, QItemSelectionModel::SelectCurrent );
1009 return QObject::eventFilter(obj, event);
1012 // ------------------------- VERTEX ----------------------------------
1013 // ============================================================== Constructeur
1014 VertexDialog::VertexDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1015 HexaBaseDialog(parent, editmode, f),
1018 _helpFileName = "gui_vertex.html";
1020 _initWidget(editmode);
1022 if ( editmode == NEW_MODE ){
1023 setWindowTitle( tr("Vertex Construction") );
1024 } else if ( editmode == UPDATE_MODE ){
1025 setWindowTitle( tr("Vertex Modification") );
1027 else if ( editmode == INFO_MODE){
1028 setWindowTitle( tr("Vertex Information") );
1032 // ============================================================== Destructeur
1033 VertexDialog::~VertexDialog()
1037 // ============================================================== _initInputWidget
1038 void VertexDialog::_initInputWidget( Mode editmode )
1040 // x_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1041 // y_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1042 // z_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1043 QDoubleValidator *doubleValidator = new QDoubleValidator(widget_2);
1044 x_spb->setValidator(doubleValidator);
1045 y_spb->setValidator(doubleValidator);
1046 z_spb->setValidator(doubleValidator);
1048 // setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1049 installEventFilter(this);
1050 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1051 name_le->installEventFilter(this);
1053 if (editmode == INFO_MODE)
1055 name_le->setReadOnly(true);
1056 x_spb->setReadOnly(true);
1057 y_spb->setReadOnly(true);
1058 z_spb->setReadOnly(true);
1061 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
1064 // ============================================================== clear
1065 void VertexDialog::clear()
1069 modelUnregister(this);
1072 // ============================================================== setValue
1073 void VertexDialog::setValue(HEXA_NS::Vertex* v)
1076 name_le->setText( v->getName() );
1079 // x_spb->setValue( v->getX() );
1080 // y_spb->setValue( v->getY() );
1081 // z_spb->setValue( v->getZ() );
1082 x_spb->setText( QString::number(v->getX()) );
1083 y_spb->setText( QString::number(v->getY()) );
1084 z_spb->setText( QString::number(v->getZ()) );
1086 if ( getPatternDataSelectionModel() != NULL ){
1087 QModelIndex iv = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1089 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1090 name_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1095 // ============================================================== getValue
1096 HEXA_NS::Vertex* VertexDialog::getValue()
1102 // ============================================================== apply
1103 bool VertexDialog::apply(QModelIndex& result)
1105 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1108 if ( !getDocumentModel() ) return false;
1109 if ( !getPatternDataSelectionModel() ) return false;
1110 const PatternDataModel* patternDataModel = getPatternDataModel();
1111 if ( !patternDataModel ) return false;
1113 QModelIndex iVertex;
1115 QString xStr = x_spb->text();
1116 QString yStr = y_spb->text();
1117 QString zStr = z_spb->text();
1118 bool isOk = false, validArgs = !xStr.isEmpty() && !yStr.isEmpty() && !zStr.isEmpty();
1120 double newX, newY, newZ;
1123 newX = xStr.toDouble();
1124 newY = yStr.toDouble();
1125 newZ = zStr.toDouble();
1128 if ( _editMode == UPDATE_MODE && validArgs){
1129 QVariant v = property("QModelIndex");
1131 iVertex = patternDataModel->mapToSource( v.value<QModelIndex>() );
1132 if ( iVertex.isValid() )
1133 isOk = getDocumentModel()->updateVertex( iVertex, newX, newY, newZ );
1135 } else if ( _editMode == NEW_MODE && validArgs){
1136 iVertex = getDocumentModel()->addVertex( newX, newY, newZ );
1137 if ( iVertex.isValid() )
1141 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "VERTEX UPDATE/CONSTRUCTION" ) + "\n" + getErrorMsg() );
1145 QString newName = name_le->text();
1146 if ( !newName.isEmpty() )
1147 getDocumentModel()->setName( iVertex, newName );
1149 //the default name in the dialog box
1150 HEXA_NS::Vertex* v = getDocumentModel()->getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1152 updateDefaultName(name_le, v->getType());
1154 // to select/highlight result
1155 result = patternDataModel->mapFromSource(iVertex);
1160 // ------------------------- EDGE ----------------------------------
1162 // ============================================================== Constructeur
1163 EdgeDialog::EdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1164 HexaBaseDialog(parent, editmode, f),
1167 _helpFileName = "gui_edge.html";
1169 _initWidget(editmode);
1171 if ( editmode == INFO_MODE ){
1172 setWindowTitle( tr("Edge Information") );
1175 else if ( editmode == UPDATE_MODE ){
1176 setWindowTitle( tr("Edge Modification") );
1182 // ============================================================== Destructeur
1183 EdgeDialog::~EdgeDialog()
1188 // ============================================================== _initInputWidget
1189 void EdgeDialog::_initInputWidget( Mode editmode )
1192 QValidator *validator = new QRegExpValidator(rx, this);
1194 // setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1195 installEventFilter(this);
1197 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1198 name_le->installEventFilter(this);
1200 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1201 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1202 v0_le_rb0->setValidator( validator );
1203 v1_le_rb0->setValidator( validator );
1204 v0_le_rb0->installEventFilter(this);
1205 v1_le_rb0->installEventFilter(this);
1207 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1208 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1209 vex_le_rb1->setValidator( validator );
1210 vec_le_rb1->setValidator( validator );
1211 vex_le_rb1->installEventFilter(this);
1212 vec_le_rb1->installEventFilter(this);
1214 v0_le_rb0->setReadOnly(true);
1215 v1_le_rb0->setReadOnly(true);
1216 vex_le_rb1->setReadOnly(true);
1217 vec_le_rb1->setReadOnly(true);
1219 if (editmode == INFO_MODE)
1220 name_le->setReadOnly(true);
1224 // ============================================================== Clear
1225 void EdgeDialog::clear()
1230 modelUnregister(v0_le_rb0);
1233 modelUnregister(v1_le_rb0);
1235 vex_le_rb1->clear();
1236 modelUnregister(vex_le_rb1);
1238 vec_le_rb1->clear();
1239 modelUnregister(vec_le_rb1);
1241 modelUnregister(this);
1244 // ============================================================== setValue
1245 void EdgeDialog::setValue(HEXA_NS::Edge* e)
1247 HEXA_NS::Vertex* v0 = e->getVertex(0);
1248 HEXA_NS::Vertex* v1 = e->getVertex(1);
1250 name_le->setText( e->getName() );
1251 v0_le_rb0->setText( v0->getName() );
1252 v1_le_rb0->setText( v1->getName() );
1254 if ( getPatternDataSelectionModel() ){
1255 QModelIndex ie = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e) );
1256 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1257 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1259 name_le->setProperty( "QModelIndex", QVariant::fromValue(ie) );
1260 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1261 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1266 // ============================================================== getValue
1267 HEXA_NS::Edge* EdgeDialog::getValue()
1272 // ============================================================== apply
1273 bool EdgeDialog::apply(QModelIndex& result)
1275 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1278 if ( !getDocumentModel() ) return false;
1279 const PatternDataModel* patternDataModel = getPatternDataModel();
1280 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1281 if ( !patternDataModel /*|| !patternBuilderModel*/ ) return false;
1285 if ( rb0->isChecked() ){
1286 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1287 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1288 if ( iv0.isValid()&& iv1.isValid() ){
1289 iEdge = getDocumentModel()->addEdgeVertices( iv0, iv1 );
1291 } else if ( rb1->isChecked() ){
1292 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
1293 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb1] );
1294 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
1295 if ( ivex.isValid() && ivec.isValid() ){
1296 iEdge = getDocumentModel()->addEdgeVector( ivex, ivec );
1300 if ( !iEdge.isValid() ){
1301 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD EDGE" ) + "\n" + getErrorMsg() );
1304 _value = iEdge.model()->data(iEdge, HEXA_DATA_ROLE).value<HEXA_NS::Edge*>();
1306 QString newName = name_le->text();
1307 if ( !newName.isEmpty() )/*{*/
1308 getDocumentModel()->setName( iEdge, newName );
1310 //update the default name in the dialog box
1312 updateDefaultName(name_le, _value->getType());
1314 result = patternDataModel->mapFromSource(iEdge);
1319 // ------------------------- QUAD ----------------------------------
1321 // ============================================================== Constructeur
1322 QuadDialog::QuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1323 HexaBaseDialog(parent, editmode, f),
1326 _helpFileName = "gui_quadrangle.html";
1328 _initWidget(editmode);
1331 if ( editmode == INFO_MODE ){
1332 setWindowTitle( tr("Quad Information") );
1336 // ============================================================== Destructeur
1337 QuadDialog::~QuadDialog()
1341 // ============================================================== _initInputWidget
1342 void QuadDialog::_initInputWidget( Mode editmode )
1345 QValidator *validator = new QRegExpValidator(rx, this);
1347 installEventFilter(this);
1348 name_le->installEventFilter(this);
1350 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1351 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1352 v2_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1353 v3_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1355 v0_le_rb0->setValidator( validator );
1356 v1_le_rb0->setValidator( validator );
1357 v2_le_rb0->setValidator( validator );
1358 v3_le_rb0->setValidator( validator );
1359 v0_le_rb0->installEventFilter(this);
1360 v1_le_rb0->installEventFilter(this);
1361 v2_le_rb0->installEventFilter(this);
1362 v3_le_rb0->installEventFilter(this);
1364 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1365 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1366 e2_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1367 e3_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1369 e0_le_rb1->setValidator( validator );
1370 e1_le_rb1->setValidator( validator );
1371 e2_le_rb1->setValidator( validator );
1372 e3_le_rb1->setValidator( validator );
1374 e0_le_rb1->installEventFilter(this);
1375 e1_le_rb1->installEventFilter(this);
1376 e2_le_rb1->installEventFilter(this);
1377 e3_le_rb1->installEventFilter(this);
1379 v0_le_rb0->setReadOnly(true);
1380 v1_le_rb0->setReadOnly(true);
1381 v2_le_rb0->setReadOnly(true);
1382 v3_le_rb0->setReadOnly(true);
1384 e0_le_rb1->setReadOnly(true);
1385 e1_le_rb1->setReadOnly(true);
1386 e2_le_rb1->setReadOnly(true);
1387 e3_le_rb1->setReadOnly(true);
1389 if (editmode == INFO_MODE)
1390 name_le->setReadOnly(true);
1393 // ============================================================== clear
1394 void QuadDialog::clear()
1396 //Clear the dialog and unregister it from the model
1397 QModelIndex invalidIndex;
1402 modelUnregister(v0_le_rb0);
1405 modelUnregister(v1_le_rb0);
1408 modelUnregister(v2_le_rb0);
1411 modelUnregister(v3_le_rb0);
1414 modelUnregister(e0_le_rb1);
1417 modelUnregister(e1_le_rb1);
1420 modelUnregister(e2_le_rb1);
1423 modelUnregister(e3_le_rb1);
1425 modelUnregister(this);
1429 // ============================================================== setValue
1430 void QuadDialog::setValue(HEXA_NS::Quad* q)
1432 Q_ASSERT( q->countEdge() == 4 );
1433 Q_ASSERT( q->countVertex() == 4 );
1436 name_le->setText( q->getName() );
1439 HEXA_NS::Vertex* v0 = q->getVertex(0);
1440 HEXA_NS::Vertex* v1 = q->getVertex(1);
1441 HEXA_NS::Vertex* v2 = q->getVertex(2);
1442 HEXA_NS::Vertex* v3 = q->getVertex(3);
1444 v0_le_rb0->setText( v0->getName() );
1445 v1_le_rb0->setText( v1->getName() );
1446 v2_le_rb0->setText( v2->getName() );
1447 v3_le_rb0->setText( v3->getName() );
1451 HEXA_NS::Edge* e0 = q->getEdge(0);
1452 HEXA_NS::Edge* e1 = q->getEdge(1);
1453 HEXA_NS::Edge* e2 = q->getEdge(2);
1454 HEXA_NS::Edge* e3 = q->getEdge(3);
1456 e0_le_rb1->setText( e0->getName() );
1457 e1_le_rb1->setText( e1->getName() );
1458 e2_le_rb1->setText( e2->getName() );
1459 e3_le_rb1->setText( e3->getName() );
1461 if ( getPatternDataSelectionModel() ){
1462 QModelIndex iq = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(q) );
1464 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1465 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1466 QModelIndex iv2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v2) );
1467 QModelIndex iv3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v3) );
1469 QModelIndex ie0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e0) );
1470 QModelIndex ie1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e1) );
1471 QModelIndex ie2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e2) );
1472 QModelIndex ie3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e3) );
1474 name_le->setProperty( "QModelIndex", QVariant::fromValue(iq) );
1476 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1477 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1478 v2_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv2) );
1479 v3_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv3) );
1481 e0_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie0) );
1482 e1_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie1) );
1483 e2_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie2) );
1484 e3_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie3) );
1490 // ============================================================== getValue
1491 HEXA_NS::Quad* QuadDialog::getValue()
1497 // ============================================================== apply
1498 bool QuadDialog::apply(QModelIndex& result)
1500 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1503 if ( !getDocumentModel() ) return false;
1504 const PatternDataModel* patternDataModel = getPatternDataModel();
1505 if ( !patternDataModel ) return false;
1509 if ( rb0->isChecked() ){ //vertices
1510 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1511 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1512 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb0] );
1513 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb0] );
1519 iQuad = getDocumentModel()->addQuadVertices( iv0, iv1, iv2, iv3 );
1521 } else if ( rb1->isChecked() ){ //edges
1522 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
1523 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
1524 QModelIndex ie2 = patternDataModel->mapToSource( _index[e2_le_rb1] );
1525 QModelIndex ie3 = patternDataModel->mapToSource( _index[e3_le_rb1] );
1531 iQuad = getDocumentModel()->addQuadEdges( ie0, ie1, ie2, ie3 );
1535 if ( !iQuad.isValid() ){
1536 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD QUAD" ) + "\n" + getErrorMsg());
1539 _value = iQuad.model()->data(iQuad, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1541 QString newName = name_le->text();
1542 if ( !newName.isEmpty() )/*{*/
1543 getDocumentModel()->setName( iQuad, newName );
1545 //the default name in the dialog box
1547 updateDefaultName(name_le, _value->getType());
1549 // to select/highlight result
1550 result = patternDataModel->mapFromSource(iQuad);
1556 // ------------------------- HEXA ----------------------------------
1558 // ============================================================== HexaDialog
1560 HexaDialog::HexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1561 HexaBaseDialog(parent, editmode, f),
1564 _helpFileName = "gui_hexahedron.html";
1566 _initWidget(editmode);
1569 if ( editmode == INFO_MODE ){
1570 setWindowTitle( tr("Hexahedron Information") );
1571 quads_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
1572 vertices_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
1576 // ============================================================== Destructeur
1577 HexaDialog::~HexaDialog()
1581 // ============================================================== _initInputWidget
1582 void HexaDialog::_initInputWidget( Mode editmode )
1586 installEventFilter(this);
1587 name_le->installEventFilter(this);
1589 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
1590 quads_lw->installEventFilter(this);
1592 vertices_lw->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1593 vertices_lw->installEventFilter(this);
1595 if ( editmode != INFO_MODE ) {
1596 // delete item from listwidget
1597 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
1598 QShortcut* delVertexShortcut = new QShortcut( QKeySequence(Qt::Key_X), vertices_lw );
1599 delQuadShortcut->setContext( Qt::WidgetShortcut );
1600 delVertexShortcut->setContext( Qt::WidgetShortcut );
1601 connect(delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()));
1602 connect(delVertexShortcut, SIGNAL(activated()), this, SLOT(deleteVertexItem()));
1604 // highlight item on model view (VTK) from listwidget
1605 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1606 connect( vertices_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1608 if ( editmode != INFO_MODE)
1610 connect( vertices_rb, SIGNAL(clicked()), vertices_lw, SLOT(setFocus()));
1611 connect( quads_rb, SIGNAL(clicked()), quads_lw, SLOT(setFocus()));
1614 connect( vertices_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1615 connect( quads_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1617 if (editmode == INFO_MODE)
1618 name_le->setReadOnly(true);
1621 // ============================================================== clear
1622 void HexaDialog::clear()
1627 modelUnregister(quads_lw);
1629 vertices_lw->clear();
1630 modelUnregister(vertices_lw);
1632 modelUnregister(this);
1635 // ============================================================== getAssocsVTK
1637 * Returns elements currently associated to vtk
1639 QModelIndexList HexaDialog::getAssocsVTK()
1641 QModelIndexList assocs;
1642 QModelIndex iQuad, iVertex;
1643 QListWidgetItem* item = NULL;
1645 const PatternDataModel* patternDataModel = getPatternDataModel();
1646 if (patternDataModel == NULL) return assocs;
1647 if (quads_rb->isChecked())
1649 //ListWidget content
1650 int nbQuads = quads_lw->count();
1651 for ( int r = 0; r < nbQuads; ++r ){
1652 item = quads_lw->item(r);
1653 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1654 if ( iQuad.isValid() )
1659 else if (vertices_rb->isChecked())
1661 //ListWidget content
1662 int nbVertices = vertices_lw->count();
1663 for ( int r = 0; r < nbVertices; ++r ){
1664 item = vertices_lw->item(r);
1665 iVertex = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1666 if ( iVertex.isValid() )
1675 // ============================================================== updateButtonBox
1676 void HexaDialog::updateButtonBox()
1678 if ( _editMode == INFO_MODE )
1681 if ( quads_rb->isChecked() ){ // build from quads count() must be between [2,6]
1682 int nbQuads = quads_lw->count();
1683 if ( nbQuads >= 2 && nbQuads <= 6 ){
1684 _applyButton->setEnabled(true);
1686 _applyButton->setEnabled(false);
1688 } else if ( vertices_rb->isChecked() ){ // build from vertices count() must be equals to 8
1689 int nbVertices = vertices_lw->count();
1690 if ( nbVertices == 8 ){
1691 _applyButton->setEnabled(true);
1693 _applyButton->setEnabled(false);
1698 // ============================================================== deleteQuadItem
1699 void HexaDialog::deleteQuadItem()
1701 delete quads_lw->currentItem();
1705 // ============================================================== deleteVertexItem
1706 void HexaDialog::deleteVertexItem()
1708 delete vertices_lw->currentItem();
1712 // ============================================================== _setValueQuads
1713 void HexaDialog::_setValueQuads( HEXA_NS::Hexa* h )
1715 QListWidgetItem *qItem = NULL;
1716 HEXA_NS::Quad *q = NULL;
1718 if (getPatternDataSelectionModel() == NULL) return;
1720 for( int i = 0; i <= 5; ++i ){
1722 qIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(q)) );
1723 qItem = new QListWidgetItem( q->getName() );
1724 qItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(qIndex) );
1725 qItem->setData(LW_DATA_ROLE, qIndex.data(HEXA_DATA_ROLE));
1726 quads_lw->addItem( qItem );
1730 // ============================================================== _setValueVertices
1731 void HexaDialog::_setValueVertices( HEXA_NS::Hexa* h )
1733 QListWidgetItem *vItem = NULL;
1734 HEXA_NS::Vertex* v = NULL;
1736 if (getPatternDataSelectionModel() == NULL) return;
1737 vertices_lw->clear();
1738 for( int i = 0; i <= 7; ++i ){
1739 v = h->getVertex(i);
1740 vIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(v)) );
1741 vItem = new QListWidgetItem( v->getName() );
1742 vItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(vIndex) );
1743 vItem->setData(LW_DATA_ROLE, vIndex.data(HEXA_DATA_ROLE));
1744 vertices_lw->addItem( vItem );
1748 // ============================================================== setValue
1749 void HexaDialog::setValue(HEXA_NS::Hexa* h)
1752 name_le->setText( h->getName() );
1754 if ( getPatternDataSelectionModel()){
1755 QModelIndex hIndex = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(h) );
1756 _setValueVertices(h);
1758 name_le->setProperty( "QModelIndex", QVariant::fromValue(hIndex) );
1763 // ============================================================== getValue
1764 HEXA_NS::Hexa* HexaDialog::getValue()
1769 // ============================================================== apply
1770 bool HexaDialog::apply(QModelIndex& result)
1772 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1775 if ( !getDocumentModel() ) return false;
1776 const PatternDataModel* patternDataModel = getPatternDataModel();
1777 if ( !patternDataModel ) return false;
1781 QListWidget* currentLw = NULL;
1782 QListWidgetItem* item = NULL;
1784 if ( quads_rb->isChecked() )
1785 currentLw = dynamic_cast<QListWidget*>( quads_lw );
1786 else if ( vertices_rb->isChecked() )
1787 currentLw = dynamic_cast<QListWidget*>( vertices_lw );
1790 QModelIndexList iElts;
1791 int nbItems = currentLw->count();
1792 for ( int r = 0; r < nbItems; ++r){
1793 item = currentLw->item(r);
1794 iElt = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1795 if ( iElt.isValid() )
1799 nbItems = iElts.count();
1800 if ( quads_rb->isChecked() && (nbItems>=2 && nbItems<=6) ){ // build from quads iElts.count() should be between [2,6]
1801 iHexa = getDocumentModel()->addHexaQuads( iElts );
1802 } else if ( vertices_rb->isChecked() && nbItems== 8 ){ // build from vertices
1803 iHexa = getDocumentModel()->addHexaVertices( iElts[0], iElts[1], iElts[2], iElts[3],
1804 iElts[4], iElts[5], iElts[6], iElts[7] );
1807 if ( !iHexa.isValid() ){
1808 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD HEXA" ) + "\n" + getErrorMsg() );
1811 _value = iHexa.model()->data(iHexa, HEXA_DATA_ROLE).value<HEXA_NS::Hexa*>();
1813 QString newName = name_le->text();
1814 if ( !newName.isEmpty() )/*{*/
1815 getDocumentModel()->setName( iHexa, newName );
1817 //update the default name in the dialog box
1819 updateDefaultName(name_le, _value->getType());
1821 // to select/highlight result
1822 result = patternDataModel->mapFromSource(iHexa);
1828 // ------------------------- VECTOR ----------------------------------
1830 // ============================================================== Constructeur
1832 VectorDialog::VectorDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1833 HexaBaseDialog(parent, editmode, f),
1836 _helpFileName = "gui_vector.html";
1838 _initWidget(editmode);
1842 if ( editmode == INFO_MODE ){
1843 setWindowTitle( tr("Vector Information") );
1848 // ============================================================== Destructeur
1849 VectorDialog::~VectorDialog()
1853 // ============================================================== _initInputWidget
1854 void VectorDialog::_initInputWidget( Mode editmode )
1857 QValidator *validator = new QRegExpValidator(rx, this);
1859 installEventFilter(this);
1860 name_le->installEventFilter(this);
1862 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1863 v0_le_rb1->setValidator( validator );
1864 v0_le_rb1->installEventFilter(this);
1866 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1867 v1_le_rb1->setValidator( validator );
1868 v1_le_rb1->installEventFilter(this);
1870 if ( editmode == INFO_MODE ){
1871 name_le->setReadOnly(true);
1872 dx_spb_rb0->setReadOnly(true);
1873 dy_spb_rb0->setReadOnly(true);
1874 dz_spb_rb0->setReadOnly(true);
1877 v0_le_rb1->setReadOnly(true);
1878 v1_le_rb1->setReadOnly(true);
1881 // ============================================================== clear
1882 void VectorDialog::clear()
1886 modelUnregister(v0_le_rb1);
1889 modelUnregister(v1_le_rb1);
1891 modelUnregister(this);
1894 // ============================================================== setValue
1895 void VectorDialog::setValue(HEXA_NS::Vector* v)
1897 name_le->setText( v->getName() );
1898 dx_spb_rb0->setValue( v->getDx() );
1899 dy_spb_rb0->setValue( v->getDy() );
1900 dz_spb_rb0->setValue( v->getDz() );
1902 if ( getPatternDataSelectionModel() ){
1903 QModelIndex ivec = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1904 name_le->setProperty( "QModelIndex", QVariant::fromValue(ivec) );
1909 // ============================================================== getValue
1910 HEXA_NS::Vector* VectorDialog::getValue()
1915 // ============================================================== apply
1916 bool VectorDialog::apply(QModelIndex& result)
1918 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1921 if ( !getDocumentModel() ) return false;
1922 const PatternDataModel* patternDataModel = getPatternDataModel();
1923 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1924 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
1926 QModelIndex iVector;
1928 if ( rb0->isChecked() ){ //scalar
1929 double dx = dx_spb_rb0->value();
1930 double dy = dy_spb_rb0->value();
1931 double dz = dz_spb_rb0->value();
1933 iVector = getDocumentModel()->addVector( dx, dy, dz );
1934 } else if ( rb1->isChecked() ){ //vertices
1935 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
1936 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
1940 iVector = getDocumentModel()->addVectorVertices( iv0, iv1 );
1944 if ( !iVector.isValid() ){
1945 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD VECTOR" ) + "\n" + getErrorMsg());
1949 _value = iVector.model()->data(iVector, HEXA_DATA_ROLE).value<HEXA_NS::Vector *>();
1951 QString newName = name_le->text();
1952 if ( !newName.isEmpty() )/*{*/
1953 getDocumentModel()->setName( iVector, newName );
1955 //update the default name in the dialog box
1957 updateDefaultName(name_le, _value->getType());
1959 // to select/highlight result
1960 result = patternDataModel->mapFromSource(iVector);
1961 // result = patternBuilderModel->mapFromSource(iVector);
1966 // ------------------------- MakeGridDialog ----------------------------------
1967 // ============================================================== Constructeur
1969 MakeGridDialog::MakeGridDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
1970 : HexaBaseDialog(parent, editmode, f)
1973 _initWidget(editmode);
1976 _helpFileName = "creategrids.html#guicartgridsimple";
1977 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1978 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1979 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1981 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1982 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1983 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1985 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1986 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1987 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1990 // ============================================================== Destructeur
1991 MakeGridDialog::~MakeGridDialog()
1995 // ============================================================== _initInputWidget
1996 void MakeGridDialog::_initInputWidget( Mode editmode )
1998 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1999 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2000 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2001 vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2003 center_le->setReadOnly(true);
2004 axis_le->setReadOnly(true);
2005 base_le->setReadOnly(true);
2006 vec_le->setReadOnly(true);
2008 installEventFilter(this);
2009 center_le->installEventFilter(this);
2010 axis_le->installEventFilter(this);
2011 base_le->installEventFilter(this);
2012 vec_le->installEventFilter(this);
2014 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2015 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2017 angle_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(angle_lw));
2018 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2020 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2021 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2023 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2024 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2026 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2027 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2029 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2030 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2033 // ============================================================== clear
2034 void MakeGridDialog::clear()
2037 modelUnregister(center_le);
2040 modelUnregister(axis_le);
2043 modelUnregister(base_le);
2046 modelUnregister(vec_le);
2048 modelUnregister(this);
2051 // ============================================================== updateHelpFileName
2052 void MakeGridDialog::updateHelpFileName()
2054 if ( sender() == rb0 ){
2055 _helpFileName = "creategrids.html#guicartgridsimple";
2056 } else if ( sender() == rb1 ){
2057 _helpFileName = "creategrids.html#guicartgriduniform";
2058 } else if ( sender() == rb2 ){
2059 _helpFileName = "creategrids.html#guicartgridcustom";
2063 // ============================================================== addRadiusItem
2064 void MakeGridDialog::addRadiusItem()
2066 QListWidgetItem* previousItem = radius_lw->currentItem();
2067 QListWidgetItem* newItem = new QListWidgetItem();
2069 double defaultValue = 1.;
2071 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2073 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2074 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2075 radius_lw->addItem(newItem);
2078 // ============================================================== delRadiusItem
2079 void MakeGridDialog::delRadiusItem()
2081 delete radius_lw->currentItem();
2084 // ============================================================== addAngleItem
2085 void MakeGridDialog::addAngleItem()
2087 QListWidgetItem* previousItem = angle_lw->currentItem();
2088 QListWidgetItem* newItem = new QListWidgetItem();
2090 double defaultValue = 1.;
2092 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2094 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2095 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2096 angle_lw->addItem(newItem);
2099 // ============================================================== delAngleItem
2100 void MakeGridDialog::delAngleItem()
2102 delete angle_lw->currentItem();
2105 // ============================================================== addHeightItem
2106 void MakeGridDialog::addHeightItem()
2108 QListWidgetItem* previousItem = height_lw->currentItem();
2109 QListWidgetItem* newItem = new QListWidgetItem();
2111 double defaultValue = 1.;
2113 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2115 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2116 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2117 height_lw->addItem(newItem);
2120 // ============================================================== delHeightItem
2121 void MakeGridDialog::delHeightItem()
2123 delete height_lw->currentItem();
2126 // ============================================================== apply
2127 bool MakeGridDialog::apply(QModelIndex& result)
2129 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2132 DocumentModel* docModel = getDocumentModel();
2133 PatternDataModel* patternDataModel = getPatternDataModel();
2134 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2136 QModelIndex iNewElts;
2137 if ( rb0->isChecked() )
2139 long nx = nx_spb->value();
2140 long ny = ny_spb->value();
2141 long nz = nz_spb->value();
2142 iNewElts = docModel->makeCartesianTop(nx, ny, nz);
2144 else if ( rb1->isChecked() )
2146 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2147 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2148 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2149 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le] );
2150 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2151 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2152 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2154 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2156 double lx = lx_spb->value();
2157 double ly = ly_spb->value();
2158 double lz = lz_spb->value();
2159 double nx = nx_spb->value();
2160 double ny = ny_spb->value();
2161 double nz = nz_spb->value();
2163 iNewElts = docModel->makeCartesianUni( icenter, ibase, ivec, iaxis,
2164 lx, ly, lz, nx, ny, nz);
2167 } else if ( rb2->isChecked() )
2169 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2170 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2171 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2172 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le] );
2173 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2174 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2175 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2177 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2179 QListWidgetItem* item = NULL;
2181 vector<double> radius;
2182 vector<double> angles;
2183 vector<double> heights;
2185 // double somme = 0.;
2186 int nbAngles = angle_lw->count();
2187 for ( int r = 0; r < nbAngles; ++r){
2188 item = angle_lw->item(r);
2189 double itemValue = item->data(Qt::EditRole).toDouble();
2190 angles.push_back(itemValue);
2191 // somme += itemValue;
2193 // if (somme > 360.01)
2195 // SUIT_MessageBox::information( 0,
2197 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2201 int nbRadius = radius_lw->count();
2202 for ( int r = 0; r < nbRadius; ++r){
2203 item = radius_lw->item(r);
2204 radius.push_back(item->data(Qt::EditRole).toDouble());
2207 int nbHeight = height_lw->count();
2208 for ( int r = 0; r < nbHeight; ++r){
2209 item = height_lw->item(r);
2210 heights.push_back(item->data(Qt::EditRole).toDouble());
2213 iNewElts = docModel->makeCartesian( icenter, ibase, ivec, iaxis,
2214 radius, angles, heights);
2218 if ( !iNewElts.isValid() )
2220 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE GRID" ) + "\n" + getErrorMsg() );
2224 result = patternDataModel->mapFromSource(iNewElts);
2225 // result = patternBuilderModel->mapFromSource( iNewElts );
2230 // ============================================================== Constructeur
2232 MakeCylinderDialog::MakeCylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2233 : HexaBaseDialog(parent, editmode, f)
2236 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinder";
2237 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2238 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2239 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2240 _initWidget(editmode);
2245 // ============================================================== Destructeur
2246 MakeCylinderDialog::~MakeCylinderDialog()
2250 void MakeCylinderDialog::_initInputWidget( Mode editmode )
2252 installEventFilter(this);
2254 rb0->installEventFilter(this);
2255 rb1->installEventFilter(this);
2256 rb2->installEventFilter(this);
2258 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
2259 origin_le->installEventFilter(this);
2260 origin_le->setReadOnly(true);
2262 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2263 axis_le->installEventFilter(this);
2264 axis_le->setReadOnly(true);
2266 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE));
2267 base_le->installEventFilter(this);
2268 base_le->setReadOnly(true);
2270 ext_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2271 ext_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2272 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2273 ext_radius_spb->installEventFilter(this);
2275 int_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2276 int_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2277 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2278 int_radius_spb->installEventFilter(this);
2280 angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2281 angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2282 angle_spb->setProperty("Angle", QVariant::fromValue(true));
2283 angle_spb->installEventFilter(this);
2285 height_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2286 height_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2287 height_spb->setProperty("Length", QVariant::fromValue(true));
2288 height_spb->installEventFilter(this);
2290 radius_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2291 radius_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2292 radius_lw->setProperty("Radius", QVariant::fromValue(true));
2293 radius_lw->installEventFilter(this);
2296 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2297 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2298 angle_lw->setProperty("Angle", QVariant::fromValue(true));
2299 angle_lw->installEventFilter(this);
2301 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2302 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2303 height_lw->setProperty("Length", QVariant::fromValue(true));
2304 height_lw->installEventFilter(this);
2306 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2307 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2309 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2310 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2312 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2313 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2315 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2316 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2318 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2319 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2321 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2322 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2325 // ============================================================== updateHelpFileName
2326 void MakeCylinderDialog::updateHelpFileName()
2328 if ( sender() == rb0 ){
2329 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindersimple";
2330 } else if ( sender() == rb1 ){
2331 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinderuniform";
2332 } else if ( sender() == rb2 ){
2333 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindercustom";
2337 // ============================================================== addRadiusItem
2338 void MakeCylinderDialog::addRadiusItem()
2340 QListWidgetItem* previousItem = radius_lw->currentItem();
2341 QListWidgetItem* newItem = new QListWidgetItem();
2343 double defaultValue = 1.;
2345 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2347 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2348 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2349 radius_lw->addItem(newItem);
2352 // ============================================================== delRadiusItem
2353 void MakeCylinderDialog::delRadiusItem()
2355 delete radius_lw->currentItem();
2358 // ============================================================== addAngleItem
2359 void MakeCylinderDialog::addAngleItem()
2361 QListWidgetItem* previousItem = angle_lw->currentItem();
2362 QListWidgetItem* newItem = new QListWidgetItem();
2364 double defaultValue = 180.;
2366 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2368 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2369 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2370 angle_lw->addItem(newItem);
2373 // ============================================================== delAngleItem
2374 void MakeCylinderDialog::delAngleItem()
2376 delete angle_lw->currentItem();
2379 // ============================================================== addHeightItem
2380 void MakeCylinderDialog::addHeightItem()
2382 QListWidgetItem* previousItem = height_lw->currentItem();
2383 QListWidgetItem* newItem = new QListWidgetItem();
2385 double defaultValue = 1.;
2387 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2389 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2390 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2391 height_lw->addItem(newItem);
2394 // ============================================================== delHeightItem
2395 void MakeCylinderDialog::delHeightItem()
2397 delete height_lw->currentItem();
2400 // ============================================================== clear
2401 void MakeCylinderDialog::clear()
2404 modelUnregister(origin_le);
2407 modelUnregister(axis_le);
2410 modelUnregister(base_le);
2412 modelUnregister(this);
2415 // ============================================================== apply
2416 bool MakeCylinderDialog::apply(QModelIndex& result)
2418 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2421 DocumentModel* docModel = getDocumentModel();
2422 PatternDataModel* patternDataModel = getPatternDataModel();
2423 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2425 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2426 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2427 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2428 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2429 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2430 double rext = ext_radius_spb->value();
2431 double rint = int_radius_spb->value();
2432 double angle = angle_spb->value();
2433 double height = height_spb->value();
2434 double nr = nr_spb->value();
2435 double na = na_spb->value();
2436 double nh = nh_spb->value();
2439 if (rb0->isChecked())
2440 iElts = docModel->makeCylinderTop(nr, na, nh);
2441 else if (rb1->isChecked())
2443 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2444 iElts = docModel->makeCylinderUni(iorigin, ibase, iaxis, rint,
2445 rext, angle, height, nr, na, nh);
2447 else if (rb2->isChecked())
2449 QListWidgetItem* item = NULL;
2451 vector<double> radius;
2452 vector<double> angles;
2453 vector<double> heights;
2455 // double somme = 0.;
2456 int nbAngles = angle_lw->count();
2457 for ( int r = 0; r < nbAngles; ++r){
2458 item = angle_lw->item(r);
2459 double itemValue = item->data(Qt::EditRole).toDouble();
2460 angles.push_back(itemValue);
2461 // somme += itemValue;
2463 // if (somme > 360.01)
2465 // SUIT_MessageBox::information( 0,
2467 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2471 int nbRadius = radius_lw->count();
2472 for ( int r = 0; r < nbRadius; ++r){
2473 item = radius_lw->item(r);
2474 radius.push_back(item->data(Qt::EditRole).toDouble());
2477 int nbHeight = height_lw->count();
2478 for ( int r = 0; r < nbHeight; ++r){
2479 item = height_lw->item(r);
2480 heights.push_back(item->data(Qt::EditRole).toDouble());
2483 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2484 iElts = docModel->makeCylinder( iorigin, ibase, iaxis, radius, angles, heights);
2488 if ( !iElts.isValid() ){
2489 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDER" ) + "\n" + getErrorMsg() );
2493 result = patternDataModel->mapFromSource(iElts);
2494 // result = patternBuilderModel->mapFromSource(iElts);
2499 //---------------------------------- MakePipeDialog -----------------------------
2500 // ============================================================== Constructeur
2502 MakePipeDialog::MakePipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2503 : HexaBaseDialog(parent, editmode, f)
2506 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipe";
2507 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2508 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2509 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2510 _initWidget(editmode);
2514 // ============================================================== Destructeur
2515 MakePipeDialog::~MakePipeDialog()
2519 // ============================================================== _initInputWidget
2520 void MakePipeDialog::_initInputWidget( Mode editmode )
2522 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2523 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2524 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2526 installEventFilter(this);
2527 origin_le->installEventFilter(this);
2528 axis_le->installEventFilter(this);
2529 base_le->installEventFilter(this);
2531 rb0->installEventFilter(this);
2532 rb1->installEventFilter(this);
2533 rb2->installEventFilter(this);
2535 origin_le->setReadOnly(true);
2536 axis_le->setReadOnly(true);
2537 base_le->setReadOnly(true);
2539 ext_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2540 ext_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2541 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2542 ext_radius_spb->installEventFilter(this);
2544 int_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2545 int_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2546 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2547 int_radius_spb->installEventFilter(this);
2549 angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2550 angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2551 angle_spb->setProperty("Angle", QVariant::fromValue(true));
2552 angle_spb->installEventFilter(this);
2554 height_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2555 height_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2556 height_spb->setProperty("Length", QVariant::fromValue(true));
2557 height_spb->installEventFilter(this);
2559 radius_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2560 radius_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2561 radius_lw->setProperty("Radius", QVariant::fromValue(true));
2562 radius_lw->installEventFilter(this);
2564 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2565 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2566 angle_lw->setProperty("Angle", QVariant::fromValue(true));
2567 angle_lw->installEventFilter(this);
2569 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2570 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2571 height_lw->setProperty("Length", QVariant::fromValue(true));
2572 height_lw->installEventFilter(this);
2574 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2575 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2577 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2578 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2580 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2581 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2583 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2584 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2586 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2587 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2589 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2590 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2594 // ============================================================== updateHelpFileName
2595 void MakePipeDialog::updateHelpFileName()
2597 if ( sender() == rb0 ){
2598 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipesimple";
2599 } else if ( sender() == rb1 ){
2600 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipeuniform";
2601 } else if ( sender() == rb2 ){
2602 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipecustom";
2606 // ============================================================== addRadiusItem
2607 void MakePipeDialog::addRadiusItem()
2609 QListWidgetItem* previousItem = radius_lw->currentItem();
2610 QListWidgetItem* newItem = new QListWidgetItem();
2612 double defaultValue = 1.;
2614 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2616 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2617 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2618 radius_lw->addItem(newItem);
2621 // ============================================================== delRadiusItem
2622 void MakePipeDialog::delRadiusItem()
2624 delete radius_lw->currentItem();
2627 // ============================================================== addAngleItem
2628 void MakePipeDialog::addAngleItem()
2630 QListWidgetItem* previousItem = angle_lw->currentItem();
2631 QListWidgetItem* newItem = new QListWidgetItem();
2633 double defaultValue = 180.;
2635 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2637 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2638 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2639 angle_lw->addItem(newItem);
2642 // ============================================================== delAngleItem
2643 void MakePipeDialog::delAngleItem()
2645 delete angle_lw->currentItem();
2648 // ============================================================== addHeightItem
2649 void MakePipeDialog::addHeightItem()
2651 QListWidgetItem* previousItem = height_lw->currentItem();
2652 QListWidgetItem* newItem = new QListWidgetItem();
2654 double defaultValue = 1.;
2656 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2658 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2659 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2660 height_lw->addItem(newItem);
2663 // ============================================================== delHeightItem
2664 void MakePipeDialog::delHeightItem()
2666 delete height_lw->currentItem();
2669 // ============================================================== clear
2670 void MakePipeDialog::clear()
2673 modelUnregister(origin_le);
2676 modelUnregister(axis_le);
2679 modelUnregister(base_le);
2681 modelUnregister(this);
2684 // ============================================================== apply
2685 bool MakePipeDialog::apply(QModelIndex& result)
2687 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2690 DocumentModel* docModel = getDocumentModel();
2691 PatternDataModel* patternDataModel = getPatternDataModel();
2692 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2694 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2695 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2696 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2697 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2698 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2699 double rext = ext_radius_spb->value();
2700 double rint = int_radius_spb->value();
2701 double angle = angle_spb->value();
2702 double height = height_spb->value();
2703 int nr = nr_spb->value();
2704 int na = na_spb->value();
2705 int nh = nh_spb->value();
2709 if (rb0->isChecked())
2710 iElts = docModel->makePipeTop(nr, na, nh);
2711 else if (rb1->isChecked())
2713 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2714 iElts = docModel->makePipeUni(iorigin, ibase, iaxis, rint, rext, angle, height,
2717 else if (rb2->isChecked())
2719 QListWidgetItem* item = NULL;
2721 vector<double> radius;
2722 vector<double> angles;
2723 vector<double> heights;
2725 // double somme = 0.;
2726 int nbAngles = angle_lw->count();
2727 for ( int r = 0; r < nbAngles; ++r){
2728 item = angle_lw->item(r);
2729 double itemValue = item->data(Qt::EditRole).toDouble();
2730 angles.push_back(itemValue);
2731 // somme += itemValue;
2733 // if (somme > 360.01)
2735 // SUIT_MessageBox::information( 0,
2737 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2741 int nbRadius = radius_lw->count();
2742 for ( int r = 0; r < nbRadius; ++r){
2743 item = radius_lw->item(r);
2744 radius.push_back(item->data(Qt::EditRole).toDouble());
2747 int nbHeight = height_lw->count();
2748 for ( int r = 0; r < nbHeight; ++r){
2749 item = height_lw->item(r);
2750 heights.push_back(item->data(Qt::EditRole).toDouble());
2752 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2753 iElts = docModel->makePipe( iorigin, ibase, iaxis, radius, angles, heights );
2756 if ( !iElts.isValid() ){
2757 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPE" ) + "\n" + getErrorMsg() );
2761 // to select/highlight result
2762 result = patternDataModel->mapFromSource(iElts);
2763 // result = patternBuilderModel->mapFromSource(iElts);
2768 //---------------------------------- MakeCylindersDialog -----------------------------
2769 // ============================================================== Constructeur
2771 MakeCylindersDialog::MakeCylindersDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2772 : HexaBaseDialog(parent, editmode, f)
2774 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinders";
2776 _initWidget(editmode);
2779 // ============================================================== Destructeur
2780 MakeCylindersDialog::~MakeCylindersDialog()
2784 void MakeCylindersDialog::_initInputWidget( Mode editmode )
2786 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2787 center2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2788 direction_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2789 direction2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2791 radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2792 radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2793 radius_spb->setProperty("Radius", QVariant::fromValue(true));
2794 radius_spb->installEventFilter(this);
2796 height_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2797 height_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2798 height_spb->setProperty("Length", QVariant::fromValue(true));
2799 height_spb->installEventFilter(this);
2801 radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2802 radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2803 radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2804 radius2_spb->installEventFilter(this);
2806 height2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2807 height2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2808 height2_spb->setProperty("Length", QVariant::fromValue(true));
2809 height2_spb->installEventFilter(this);
2811 installEventFilter(this);
2812 center_le->installEventFilter(this);
2813 center2_le->installEventFilter(this);
2814 direction_le->installEventFilter(this);
2815 direction2_le->installEventFilter(this);
2817 center_le->setReadOnly(true);
2818 center2_le->setReadOnly(true);
2819 direction_le->setReadOnly(true);
2820 direction2_le->setReadOnly(true);
2823 // ============================================================== clear
2824 void MakeCylindersDialog::clear()
2827 modelUnregister(center_le);
2829 center2_le->clear();
2830 modelUnregister(center2_le);
2832 direction_le->clear();
2833 modelUnregister(direction_le);
2835 direction2_le->clear();
2836 modelUnregister(direction2_le);
2838 modelUnregister(this);
2841 // ============================================================== apply
2842 bool MakeCylindersDialog::apply(QModelIndex& result)
2844 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2847 DocumentModel* docModel = getDocumentModel();
2848 PatternDataModel* patternDataModel = getPatternDataModel();
2849 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2852 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2853 QModelIndex icenter2 = patternDataModel->mapToSource( _index[center2_le] );
2854 QModelIndex idir = patternDataModel->mapToSource( _index[direction_le] );
2855 QModelIndex idir2 = patternDataModel->mapToSource( _index[direction2_le] );
2856 // QModelIndex idir = patternBuilderModel->mapToSource( _index[direction_le] );
2857 // QModelIndex idir2 = patternBuilderModel->mapToSource( _index[direction2_le] );
2859 if ( icenter.isValid() && icenter2.isValid() && idir.isValid() && idir2.isValid()){
2860 double r1 = radius_spb->value();
2861 double h1 = height_spb->value();
2862 double r2 = radius2_spb->value();
2863 double h2 = height2_spb->value();
2864 iElts = docModel->makeCylinders( icenter, idir, r1, h1, icenter2, idir2, r2, h2 );
2867 if ( !iElts.isValid() ){
2868 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDERS" ) + "\n" + getErrorMsg() );
2872 result = patternDataModel->mapFromSource(iElts);
2873 // result = patternBuilderModel->mapFromSource(iElts);
2878 //---------------------------------- MakePipesDialog -----------------------------
2879 // ============================================================== Constructeur
2881 MakePipesDialog::MakePipesDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2882 : HexaBaseDialog(parent, editmode, f)
2884 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipes";
2886 _initWidget(editmode);
2889 // ============================================================== Destructeur
2890 MakePipesDialog::~MakePipesDialog()
2894 // ============================================================== _initInputWidget
2895 void MakePipesDialog::_initInputWidget( Mode editmode )
2897 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2898 origin2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2899 dir_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2900 dir2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2902 ext_radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2903 ext_radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2904 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2905 ext_radius_spb->installEventFilter(this);
2907 int_radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2908 int_radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2909 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2910 int_radius_spb->installEventFilter(this);
2912 height_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2913 height_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2914 height_spb->setProperty("Length", QVariant::fromValue(true));
2915 height_spb->installEventFilter(this);
2917 ext_radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2918 ext_radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2919 ext_radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2920 ext_radius2_spb->installEventFilter(this);
2922 int_radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2923 int_radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2924 int_radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2925 int_radius2_spb->installEventFilter(this);
2927 height2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2928 height2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2929 height2_spb->setProperty("Length", QVariant::fromValue(true));
2930 height2_spb->installEventFilter(this);
2932 origin_le->installEventFilter(this);
2933 origin2_le->installEventFilter(this);
2934 dir_le->installEventFilter(this);
2935 dir2_le->installEventFilter(this);
2937 origin_le->setReadOnly(true);
2938 origin2_le->setReadOnly(true);
2939 dir_le->setReadOnly(true);
2940 dir2_le->setReadOnly(true);
2943 // ============================================================== clear
2944 void MakePipesDialog::clear()
2947 modelUnregister(origin_le);
2949 origin2_le->clear();
2950 modelUnregister(origin2_le);
2953 modelUnregister(dir_le);
2956 modelUnregister(dir2_le);
2958 modelUnregister(this);
2961 // ============================================================== apply
2962 bool MakePipesDialog::apply(QModelIndex& result)
2964 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2967 DocumentModel* docModel = getDocumentModel();
2968 PatternDataModel* patternDataModel = getPatternDataModel();
2969 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2971 QModelIndex iorigin1 = patternDataModel->mapToSource( _index[origin_le] );
2972 QModelIndex iorigin2 = patternDataModel->mapToSource( _index[origin2_le] );
2973 QModelIndex idir1 = patternDataModel->mapToSource( _index[dir_le] );
2974 QModelIndex idir2 = patternDataModel->mapToSource( _index[dir2_le] );
2975 // QModelIndex idir1 = patternBuilderModel->mapToSource( _index[dir_le] );
2976 // QModelIndex idir2 = patternBuilderModel->mapToSource( _index[dir2_le] );
2977 double rint1 = int_radius_spb->value();
2978 double rext1 = ext_radius_spb->value();
2979 double height1 = height_spb->value();
2980 double rint2 = int_radius2_spb->value();
2981 double rext2 = ext_radius2_spb->value();
2982 double height2 = height_spb->value();
2986 if ( iorigin1.isValid() && iorigin2.isValid() && idir1.isValid() && idir2.isValid())
2987 iElts = docModel->makePipes( iorigin1, idir1, rint1, rext1, height1,
2988 iorigin2, idir2, rint2, rext2, height2);
2990 if ( !iElts.isValid() ){
2991 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPES" ) + "\n" + getErrorMsg() );
2995 result = patternDataModel->mapFromSource(iElts);
2996 // result = patternBuilderModel->mapFromSource(iElts);
3001 //---------------------------------- RemoveHexaDialog -----------------------------
3002 // ============================================================== Constructeur
3004 RemoveHexaDialog::RemoveHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3005 : HexaBaseDialog(parent, editmode, f)
3007 _helpFileName = "gui_remove.html";
3009 _initWidget(editmode);
3012 // ============================================================== Destructeur
3013 RemoveHexaDialog::~RemoveHexaDialog()
3017 // ============================================================== _initInputWidget
3018 void RemoveHexaDialog::_initInputWidget( Mode editmode )
3021 QValidator *validator = new QRegExpValidator(rx, this);
3023 hexa_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3024 hexa_le->setValidator( validator );
3025 hexa_le->installEventFilter(this);
3026 hexa_le->setReadOnly(true);
3027 autoFocusSwitch = false;
3030 // ============================================================== clear
3031 void RemoveHexaDialog::clear()
3034 modelUnregister(hexa_le);
3036 modelUnregister(this);
3039 // ============================================================== apply
3040 bool RemoveHexaDialog::apply(QModelIndex& result)
3042 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3045 if ( !getDocumentModel() ) return false;
3046 const PatternDataModel* patternDataModel = getPatternDataModel();
3047 if ( !patternDataModel ) return false;
3049 QModelIndex ihexa = patternDataModel->mapToSource( _index[hexa_le] );
3051 bool removed = false;
3052 if ( ihexa.isValid() ){
3053 if ( connected_cb->isChecked() ){
3054 removed = getDocumentModel()->removeConnectedHexa( ihexa );
3056 removed = getDocumentModel()->removeHexa( ihexa );
3060 if ( removed == false ){
3061 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE HEXA" ) + "\n" + getErrorMsg() );
3070 //---------------------------------- PrismQuadDialog -----------------------------
3071 // ============================================================== Constructeur
3073 PrismQuadDialog::PrismQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3074 : HexaBaseDialog(parent, editmode, f)
3077 _helpFileName = "gui_prism_join_quad.html#guiextrudequads";
3078 connect( extrudeTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3079 connect( extrudeUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3080 connect( extrude_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3081 _initWidget(editmode);
3082 extrudeTop_rb->click();
3085 // ============================================================== Destructeur
3086 PrismQuadDialog::~PrismQuadDialog()
3090 // ============================================================== getAssocsVTK
3092 * Returns elements currently associated to vtk
3094 QModelIndexList PrismQuadDialog::getAssocsVTK()
3096 QModelIndexList assocs;
3098 QListWidgetItem* item = NULL;
3100 //ListWidget content
3101 const PatternDataModel* patternDataModel = getPatternDataModel();
3102 if ( !patternDataModel ) return assocs;
3103 int nbQuads = quads_lw->count();
3104 for ( int r = 0; r < nbQuads; ++r ){
3105 item = quads_lw->item(r);
3106 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3107 if ( iQuad.isValid() )
3113 // ============================================================== _initInputWidget
3114 void PrismQuadDialog::_initInputWidget( Mode editmode )
3116 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3117 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3119 length_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3120 length_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3121 length_spb->setProperty("Length", QVariant::fromValue(true));
3122 length_spb->installEventFilter(this);
3125 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3126 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3127 height_lw->setProperty("Length", QVariant::fromValue(true));
3128 height_lw->installEventFilter(this);
3130 installEventFilter(this);
3131 quads_lw->installEventFilter(this);
3132 axis_le->installEventFilter(this);
3134 extrudeTop_rb->installEventFilter(this);
3135 extrudeUni_rb->installEventFilter(this);
3136 extrude_rb->installEventFilter(this);
3138 axis_le->setReadOnly(true);
3140 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3141 delQuadShortcut->setContext( Qt::WidgetShortcut );
3142 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3143 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3145 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3146 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3147 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3148 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3151 // ============================================================== updateHelpFileName
3152 void PrismQuadDialog::updateHelpFileName()
3154 if ( sender() == extrudeTop_rb ){
3155 _helpFileName = "gui_prism_join_quad.html#guiextrudequadssimple";
3156 } else if ( sender() == extrudeUni_rb ){
3157 _helpFileName = "gui_prism_join_quad.html#guiextrudequadsuniform";
3158 } else if ( sender() == extrude_rb ){
3159 _helpFileName = "gui_prism_join_quad.html#guiextrudequadscustom";
3163 // ============================================================== clear
3164 void PrismQuadDialog::clear()
3167 modelUnregister(quads_lw);
3170 modelUnregister(axis_le);
3172 modelUnregister(this);
3175 // ============================================================== removeQuad
3176 void PrismQuadDialog::removeQuad()
3178 QListWidgetItem *item = quads_lw->currentItem();
3181 int r = quads_lw->row(item);
3182 quads_lw->takeItem(r);
3187 // ============================================================== addHeightItem
3188 void PrismQuadDialog::addHeightItem()
3190 QListWidgetItem* previousItem = height_lw->currentItem();
3191 QListWidgetItem* newItem = new QListWidgetItem();
3193 double defaultValue = 1.;
3195 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3197 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3198 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3199 height_lw->addItem(newItem);
3202 // ============================================================== delHeightItem
3203 void PrismQuadDialog::delHeightItem()
3205 delete height_lw->currentItem();
3208 // ============================================================== apply
3209 bool PrismQuadDialog::apply(QModelIndex& result)
3211 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3214 DocumentModel* docModel = getDocumentModel();
3215 PatternDataModel* patternDataModel = getPatternDataModel();
3216 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3218 QModelIndexList iquads = getIndexList(quads_lw);
3219 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
3220 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
3221 double length = length_spb->value();
3222 int nb = nb_spb->value();
3224 vector<double> heights;
3225 QListWidgetItem* item = NULL;
3226 int nbItems = height_lw->count();
3228 for ( int r = 0; r < nbItems; ++r){
3229 item = height_lw->item(r);
3230 heights.push_back( item->data(Qt::EditRole).toDouble() );
3234 int nbQuads = iquads.count();
3236 if (nbQuads == 1 && iquads[0].isValid())
3238 if (extrudeTop_rb->isChecked())
3239 iElts = docModel->extrudeQuadTop(iquads[0], nb);
3240 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3241 iElts = docModel->extrudeQuadUni(iquads[0], iaxis, length, nb);
3242 else if (extrude_rb->isChecked() && iaxis.isValid())
3243 iElts = docModel->extrudeQuad(iquads[0], iaxis, heights);
3245 else if (nbQuads > 1)
3247 if (extrudeTop_rb->isChecked())
3248 iElts = docModel->extrudeQuadsTop(iquads, nb);
3249 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3250 iElts = docModel->extrudeQuadsUni(iquads, iaxis, length, nb);
3251 else if (extrude_rb->isChecked() && iaxis.isValid())
3252 iElts = docModel->extrudeQuads(iquads, iaxis, heights);
3255 if ( !iElts.isValid() ){
3256 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PRISM QUAD(S)" ) + "\n" + getErrorMsg() );
3260 result = patternDataModel->mapFromSource(iElts);
3261 // result = patternBuilderModel->mapFromSource(iElts);
3266 //---------------------------------- JoinQuadDialog -----------------------------
3267 // ============================================================== Constructeur
3269 JoinQuadDialog::JoinQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3270 : HexaBaseDialog(parent, editmode, f)
3273 _helpFileName = "gui_prism_join_quad.html#guijoinquads";
3274 connect( joinUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3275 connect( join_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3276 _initWidget(editmode);
3277 joinUni_rb->click();
3280 // ============================================================== Destructeur
3281 JoinQuadDialog::~JoinQuadDialog()
3285 // ============================================================== getAssocsVTK
3287 * Returns elements currently associated to vtk
3289 QModelIndexList JoinQuadDialog::getAssocsVTK()
3291 QModelIndexList assocs;
3293 QListWidgetItem* item = NULL;
3295 if (getPatternDataSelectionModel() == NULL) return assocs;
3297 //ListWidget content
3298 const PatternDataModel* patternDataModel = getPatternDataModel();
3299 if ( !patternDataModel ) return assocs;
3300 int nbQuads = quads_lw->count();
3301 for ( int r = 0; r < nbQuads; ++r ){
3302 item = quads_lw->item(r);
3303 // iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
3304 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
3305 if ( iQuad.isValid() ) assocs << iQuad;
3310 // ============================================================== _initInputWidget
3311 void JoinQuadDialog::_initInputWidget( Mode editmode )
3313 quad_dest_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3314 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3315 vex0_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3316 vex1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3317 vex2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3318 vex3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3320 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3321 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3322 height_lw->setProperty("Length", QVariant::fromValue(true));
3323 height_lw->installEventFilter(this);
3325 installEventFilter(this);
3326 quad_dest_le->installEventFilter(this);
3327 quads_lw->installEventFilter(this);
3328 vex0_le->installEventFilter(this);
3329 vex1_le->installEventFilter(this);
3330 vex2_le->installEventFilter(this);
3331 vex3_le->installEventFilter(this);
3333 joinUni_rb->installEventFilter(this);
3334 join_rb->installEventFilter(this);
3336 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3337 delQuadShortcut->setContext( Qt::WidgetShortcut );
3338 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3340 quad_dest_le->setReadOnly(true);
3341 vex0_le->setReadOnly(true);
3342 vex1_le->setReadOnly(true);
3343 vex2_le->setReadOnly(true);
3344 vex3_le->setReadOnly(true);
3346 _currentObj = quads_lw;
3347 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3348 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3350 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3352 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3353 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3356 // ============================================================== updateHelpFileName
3357 void JoinQuadDialog::updateHelpFileName()
3359 if ( sender() == joinUni_rb ){
3360 _helpFileName = "gui_prism_join_quad.html#guijoinquadsuniform";
3361 } else if ( sender() == join_rb ){
3362 _helpFileName = "gui_prism_join_quad.html#guijoinquadscustom";
3366 // ============================================================== addHeightItem
3367 void JoinQuadDialog::addHeightItem()
3369 QListWidgetItem* previousItem = height_lw->currentItem();
3370 QListWidgetItem* newItem = new QListWidgetItem();
3372 double defaultValue = 1.;
3374 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3376 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3377 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3378 height_lw->addItem(newItem);
3381 // ============================================================== delHeightItem
3382 void JoinQuadDialog::delHeightItem()
3384 delete height_lw->currentItem();
3387 // ============================================================== clear
3388 void JoinQuadDialog::clear()
3390 quad_dest_le->clear();
3391 modelUnregister(quad_dest_le);
3394 modelUnregister(quads_lw);
3397 modelUnregister(vex0_le);
3400 modelUnregister(vex1_le);
3403 modelUnregister(vex2_le);
3406 modelUnregister(vex3_le);
3408 modelUnregister(this);
3411 // ============================================================== removeQuad
3412 void JoinQuadDialog::removeQuad()
3414 QListWidgetItem *item = quads_lw->currentItem();
3417 int r = quads_lw->row(item);
3418 quads_lw->takeItem(r);
3423 // ============================================================== apply
3424 bool JoinQuadDialog::apply(QModelIndex& result)
3426 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3429 DocumentModel* docModel = getDocumentModel();
3430 PatternDataModel* patternDataModel = getPatternDataModel();
3431 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3433 QModelIndexList iquads;
3435 QListWidgetItem* item = NULL;
3436 int nbQuads = quads_lw->count();
3437 for ( int r = 0; r < nbQuads; ++r){
3438 item = quads_lw->item(r);
3439 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3440 if ( iquad.isValid() )
3443 QModelIndex iquaddest = patternDataModel->mapToSource( _index[quad_dest_le] );
3444 QModelIndex ivex0 = patternDataModel->mapToSource( _index[vex0_le] ); // from point a
3445 QModelIndex ivex1 = patternDataModel->mapToSource( _index[vex1_le] ); // from point b
3446 QModelIndex ivex2 = patternDataModel->mapToSource( _index[vex2_le] ); // to point a
3447 QModelIndex ivex3 = patternDataModel->mapToSource( _index[vex3_le] ); // to point b
3448 double nb = nb_spb->value();
3450 vector<double> heights;
3451 int nbHeight = height_lw->count();
3452 for ( int r = 0; r < nbHeight; ++r){
3453 item = height_lw->item(r);
3454 heights.push_back(item->data(Qt::EditRole).toDouble());
3458 if (nbQuads == 1 && iquads[0].isValid() && iquaddest.isValid() && ivex0.isValid() &&
3459 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3461 if (joinUni_rb->isChecked())
3462 iElts = docModel->joinQuadUni(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3463 else if (join_rb->isChecked())
3464 iElts = docModel->joinQuad(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3466 else if (nbQuads > 1 && iquaddest.isValid() && ivex0.isValid() &&
3467 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3469 if (joinUni_rb->isChecked())
3470 iElts = docModel->joinQuadsUni(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3471 else if (join_rb->isChecked())
3472 iElts = docModel->joinQuads(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3475 if ( !iElts.isValid() ){
3476 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT JOIN QUAD(S)" ) + "\n" + getErrorMsg() );
3479 result = patternDataModel->mapFromSource(iElts);
3480 // result = patternBuilderModel->mapFromSource(iElts);
3485 // ------------------------- MergeDialog ----------------------------------
3486 // ============================================================== Constructeur
3488 MergeDialog::MergeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3489 : HexaBaseDialog(parent, editmode, f)
3492 _initWidget(editmode);
3495 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3496 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3497 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3498 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3500 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3501 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3502 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3504 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3505 connect( rb2, SIGNAL(cliked()), this, SLOT(clearVTKSelection()) );
3506 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3509 // ============================================================== Destructeur
3510 MergeDialog::~MergeDialog()
3514 // ============================================================== _initInputWidget
3515 void MergeDialog::_initInputWidget( Mode editmode )
3518 QValidator *validator = new QRegExpValidator(rx, this);
3520 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3521 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3522 v0_le_rb0->setValidator( validator );
3523 v1_le_rb0->setValidator( validator );
3524 v0_le_rb0->installEventFilter(this);
3525 v1_le_rb0->installEventFilter(this);
3527 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3528 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3529 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3530 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3532 v0_le_rb1->setValidator( validator );
3533 v1_le_rb1->setValidator( validator );
3534 e0_le_rb1->setValidator( validator );
3535 e1_le_rb1->setValidator( validator );
3537 v0_le_rb1->installEventFilter(this);
3538 v1_le_rb1->installEventFilter(this);
3539 e0_le_rb1->installEventFilter(this);
3540 e1_le_rb1->installEventFilter(this);
3542 v0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3543 v1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3544 v2_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3545 v3_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3546 q0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3547 q1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3549 v0_le_rb2->setValidator( validator );
3550 v1_le_rb2->setValidator( validator );
3551 v2_le_rb2->setValidator( validator );
3552 v3_le_rb2->setValidator( validator );
3553 q0_le_rb2->setValidator( validator );
3554 q1_le_rb2->setValidator( validator );
3556 v0_le_rb2->installEventFilter(this);
3557 v1_le_rb2->installEventFilter(this);
3558 v2_le_rb2->installEventFilter(this);
3559 v3_le_rb2->installEventFilter(this);
3560 q0_le_rb2->installEventFilter(this);
3561 q1_le_rb2->installEventFilter(this);
3563 v0_le_rb0->setReadOnly(true);
3564 v1_le_rb0->setReadOnly(true);
3566 v0_le_rb1->setReadOnly(true);
3567 v1_le_rb1->setReadOnly(true);
3568 e0_le_rb1->setReadOnly(true);
3569 e1_le_rb1->setReadOnly(true);
3571 v0_le_rb2->setReadOnly(true);
3572 v1_le_rb2->setReadOnly(true);
3573 v2_le_rb2->setReadOnly(true);
3574 v3_le_rb2->setReadOnly(true);
3575 q0_le_rb2->setReadOnly(true);
3576 q1_le_rb2->setReadOnly(true);
3579 // ============================================================== clear
3580 void MergeDialog::clear()
3583 modelUnregister(v0_le_rb0);
3586 modelUnregister(v1_le_rb0);
3589 modelUnregister(e0_le_rb1);
3592 modelUnregister(e1_le_rb1);
3595 modelUnregister(v0_le_rb1);
3598 modelUnregister(v1_le_rb1);
3601 modelUnregister(q0_le_rb2);
3604 modelUnregister(q1_le_rb2);
3607 modelUnregister(v0_le_rb2);
3610 modelUnregister(v1_le_rb2);
3613 modelUnregister(v2_le_rb2);
3616 modelUnregister(v3_le_rb2);
3618 modelUnregister(this);
3621 // ============================================================== updateHelpFileName
3622 void MergeDialog::updateHelpFileName()
3624 if ( sender() == rb0 ){
3625 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3626 } else if ( sender() == rb1 ){
3627 _helpFileName = "gui_merge_elmts.html#merge-two-edges";
3628 } else if ( sender() == rb2 ){
3629 _helpFileName = "gui_merge_elmts.html#merge-two-quadrangles";
3633 // ============================================================== apply
3634 bool MergeDialog::apply(QModelIndex& result)
3636 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3639 if (getDocumentModel() == NULL) return false;
3640 const PatternDataModel* patternDataModel = getPatternDataModel();
3641 if ( !patternDataModel ) return false;
3643 bool merged = false;
3645 if ( rb0->isChecked() ){
3646 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
3647 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
3651 merged = getDocumentModel()->mergeVertices( iv0, iv1 );
3653 } else if ( rb1->isChecked() ){
3654 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
3655 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
3656 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
3657 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
3663 merged = getDocumentModel()->mergeEdges( ie0, ie1, iv0, iv1);
3665 } else if ( rb2->isChecked() ){
3667 QModelIndex iq0 = patternDataModel->mapToSource( _index[q0_le_rb2] );
3668 QModelIndex iq1 = patternDataModel->mapToSource( _index[q1_le_rb2] );
3669 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb2] );
3670 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb2] );
3671 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb2] );
3672 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb2] );
3680 merged = getDocumentModel()->mergeQuads( iq0, iq1,
3681 iv0, iv1, iv2, iv3 );
3685 if ( merged == false ){
3686 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MERGE" ) + "\n" + getErrorMsg() );
3693 // ------------------------- DisconnectDialog ----------------------------------
3694 // ============================================================== Constructeur
3696 DisconnectDialog::DisconnectDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3697 : HexaBaseDialog(parent, editmode, f)
3700 _initWidget(editmode);
3703 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3705 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3706 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3707 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3709 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3710 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3711 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3713 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3714 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3715 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3717 connect( rb3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3718 connect( rb3, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3719 connect( rb3, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3723 // ============================================================== Destructeur
3724 DisconnectDialog::~DisconnectDialog()
3728 // ============================================================== _initInputWidget
3729 void DisconnectDialog::_initInputWidget( Mode editmode )
3732 QValidator *validator = new QRegExpValidator(rx, this);
3734 installEventFilter(this);
3737 v_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3738 h_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3739 v_le_rb0->setValidator( validator );
3740 h_le_rb0->setValidator( validator );
3741 v_le_rb0->installEventFilter(this);
3742 h_le_rb0->installEventFilter(this);
3745 e_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3746 h_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3747 e_le_rb1->setValidator( validator );
3748 h_le_rb1->setValidator( validator );
3749 e_le_rb1->installEventFilter(this);
3750 h_le_rb1->installEventFilter(this);
3753 q_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3754 h_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3755 q_le_rb2->setValidator( validator );
3756 h_le_rb2->setValidator( validator );
3757 q_le_rb2->installEventFilter(this);
3758 h_le_rb2->installEventFilter(this);
3761 d_edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3762 hexas_lw->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3763 d_edges_lw->installEventFilter(this);
3764 hexas_lw->installEventFilter(this);
3766 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), d_edges_lw);
3767 QShortcut* delHexaShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), hexas_lw);
3768 delEdgeShortcut->setContext( Qt::WidgetShortcut );
3769 delHexaShortcut->setContext( Qt::WidgetShortcut );
3771 v_le_rb0->setReadOnly(true);
3772 h_le_rb0->setReadOnly(true);
3774 e_le_rb1->setReadOnly(true);
3775 h_le_rb1->setReadOnly(true);
3777 q_le_rb2->setReadOnly(true);
3778 h_le_rb2->setReadOnly(true);
3780 connect( d_edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3781 connect( hexas_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3782 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
3783 connect( delHexaShortcut, SIGNAL(activated()), this, SLOT(deleteHexaItem()) );
3784 autoFocusSwitch = false;
3788 // =============================================== getAssocsVTK
3790 * Returns elements in the list
3792 QModelIndexList DisconnectDialog::getAssocsVTK()
3794 QModelIndexList iElts;
3796 QListWidgetItem* item = NULL;
3798 const PatternDataModel* patternDataModel = getPatternDataModel();
3799 if (patternDataModel == NULL || !rb3->isChecked())
3801 //ListWidget content
3802 if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == EDGE_TREE)
3804 int nbEdges = d_edges_lw->count();
3805 for ( int r = 0; r < nbEdges; ++r )
3807 item = d_edges_lw->item(r);
3808 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3809 if ( index.isValid() )
3813 else if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == HEXA_TREE)
3815 int nbHexas = hexas_lw->count();
3816 for ( int r = 0; r < nbHexas; ++r )
3818 item = hexas_lw->item(r);
3819 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3820 if ( index.isValid() )
3827 // ============================================================== clear
3828 void DisconnectDialog::clear()
3831 modelUnregister(v_le_rb0);
3834 modelUnregister(h_le_rb0);
3837 modelUnregister(e_le_rb1);
3840 modelUnregister(h_le_rb1);
3842 d_edges_lw->clear();
3843 modelUnregister(d_edges_lw);
3846 modelUnregister(hexas_lw);
3849 modelUnregister(q_le_rb2);
3852 modelUnregister(h_le_rb2);
3854 modelUnregister(this);
3857 // ============================================================== deleteEdgeItem
3858 void DisconnectDialog::deleteEdgeItem()
3860 delete d_edges_lw->currentItem();
3863 // ============================================================== deleteHexaItem
3864 void DisconnectDialog::deleteHexaItem()
3866 delete hexas_lw->currentItem();
3869 // ============================================================== updateHelpFileName
3870 void DisconnectDialog::updateHelpFileName()
3872 if ( sender() == rb0 ){
3873 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3874 } else if ( sender() == rb1 ){
3875 _helpFileName = "gui_disc_elmts.html#disconnect-an-edge";
3876 } else if ( sender() == rb2 ){
3877 _helpFileName = "gui_disc_elmts.html#disconnect-a-quadrangle";
3878 } else if (sender() == rb3 ){
3879 _helpFileName = "gui_disc_elmts.html#disconnect-edges";
3883 // ============================================================== apply
3884 bool DisconnectDialog::apply(QModelIndex& result)
3886 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3888 if (getDocumentModel() == NULL) return false;
3889 const PatternDataModel* patternDataModel = getPatternDataModel();
3890 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3891 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
3895 if ( rb0->isChecked() ){
3896 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb0] );
3897 QModelIndex ivex = patternDataModel->mapToSource( _index[v_le_rb0] );
3899 if ( ihexa.isValid()
3900 && ivex.isValid() ){
3901 iElts = getDocumentModel()->disconnectVertex( ihexa, ivex );
3903 } else if ( rb1->isChecked() ){
3904 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb1] );
3905 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le_rb1] );
3907 if ( ihexa.isValid()
3908 && iedge.isValid() ){
3909 iElts = getDocumentModel()->disconnectEdge( ihexa, iedge );
3911 } else if ( rb2->isChecked() ){
3912 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb2] );
3913 QModelIndex iquad = patternDataModel->mapToSource( _index[q_le_rb2] );
3915 if ( ihexa.isValid()
3916 && iquad.isValid() ){
3917 iElts = getDocumentModel()->disconnectQuad( ihexa, iquad );
3919 } else if ( rb3->isChecked() ){ //
3921 QModelIndex iedge, ihexa;
3922 QModelIndexList iedges, ihexas;
3923 QListWidgetItem* item = NULL;
3926 int nbEdges = d_edges_lw->count();
3927 for (int r = 0; r < nbEdges; ++r){
3928 item = d_edges_lw->item(r);
3929 iedge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3930 if ( iedge.isValid() )
3935 int nbHexas = hexas_lw->count();
3936 for (int r = 0; r < nbHexas; ++r){
3937 item = hexas_lw->item(r);
3938 ihexa = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3939 if ( ihexa.isValid() )
3943 iElts = getDocumentModel()->disconnectEdges( ihexas, iedges );
3946 if ( !iElts.isValid() ){
3947 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT DISCONNECT" ) + "\n" + getErrorMsg() );
3951 result = patternDataModel->mapFromSource(iElts);
3952 // result = patternBuilderModel->mapFromSource(iElts);
3958 // ------------------------- CutEdgeDialog ----------------------------------
3959 // ============================================================== Constructeur
3961 CutEdgeDialog::CutEdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3962 HexaBaseDialog(parent, editmode, f)
3965 _helpFileName = "gui_cut_hexa.html";
3966 connect( cutUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3967 connect( cut_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3968 _initWidget(editmode);
3973 // ============================================================== Destructeur
3974 CutEdgeDialog::~CutEdgeDialog()
3978 // ============================================================== _initInputWidget
3979 void CutEdgeDialog::_initInputWidget( Mode editmode )
3981 installEventFilter(this);
3983 e_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3984 e_le->installEventFilter(this);
3986 cutUni_rb->installEventFilter(this);
3987 cut_rb->installEventFilter(this);
3989 e_le->setReadOnly(true);
3991 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3992 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3993 height_lw->setProperty("Length", QVariant::fromValue(true));
3994 height_lw->installEventFilter(this);
3996 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3997 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3999 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
4000 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
4003 // ============================================================== updateHelpFileName
4004 void CutEdgeDialog::updateHelpFileName()
4006 if ( sender() == cutUni_rb ){
4007 _helpFileName = "gui_cut_hexa.html#guicuthexauniform";
4008 } else if ( sender() == cut_rb ){
4009 _helpFileName = "gui_cut_hexa.html#guicuthexacustom";
4013 // ============================================================== clear
4014 void CutEdgeDialog::clear()
4017 modelUnregister(e_le);
4019 modelUnregister(this);
4022 // ============================================================== addHeightItem
4023 void CutEdgeDialog::addHeightItem()
4025 QListWidgetItem* previousItem = height_lw->currentItem();
4026 QListWidgetItem* newItem = new QListWidgetItem();
4028 double defaultValue = 1.;
4030 defaultValue = previousItem->data(Qt::EditRole).toDouble();
4032 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
4033 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
4034 height_lw->addItem(newItem);
4037 // ============================================================== delHeightItem
4038 void CutEdgeDialog::delHeightItem()
4040 delete height_lw->currentItem();
4043 // ============================================================== apply
4044 bool CutEdgeDialog::apply(QModelIndex& result)
4046 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4049 DocumentModel* docModel = getDocumentModel();
4050 PatternDataModel* patternDataModel = getPatternDataModel();
4051 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4054 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le] );
4056 if (cutUni_rb->isChecked() && iedge.isValid())
4058 int nbCut = nb_cut_spb->value();
4059 iElts = docModel->cutUni(iedge, nbCut);
4061 else if (cut_rb->isChecked() && iedge.isValid())
4063 vector<double> heights;
4064 QListWidgetItem* item = NULL;
4065 int nbItems = height_lw->count();
4067 for ( int r = 0; r < nbItems; ++r){
4068 item = height_lw->item(r);
4069 heights.push_back( item->data(Qt::EditRole).toDouble() );
4072 iElts = docModel->cut(iedge, heights);
4075 if ( !iElts.isValid() ){
4076 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT CUT EDGE" ) + "\n" + getErrorMsg() );
4080 result = patternDataModel->mapFromSource(iElts);
4081 // result = patternBuilderModel->mapFromSource(iElts);
4083 //Update the line edit
4085 e_le->setProperty("QModelIndex", invalid );
4087 QModelIndex invalidIndex;
4088 _index[e_le] = invalidIndex;
4095 // // ------------------------- MakeTransformationDialog ----------------------------------
4096 // ============================================================== Constructeur
4098 MakeTransformationDialog::MakeTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4099 : HexaBaseDialog(parent, editmode, f)
4102 _initWidget(editmode);
4105 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
4106 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4107 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4108 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4111 // ============================================================== Destructeur
4112 MakeTransformationDialog::~MakeTransformationDialog()
4116 // ============================================================== _initInputWidget
4117 void MakeTransformationDialog::_initInputWidget( Mode editmode )
4120 QValidator *validator = new QRegExpValidator(rx, this);
4122 installEventFilter(this);
4123 rb0->installEventFilter(this);
4124 rb1->installEventFilter(this);
4125 rb2->installEventFilter(this);
4127 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4128 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4130 vec_le_rb0->setValidator( validator );
4131 elts_le_rb0->setValidator( validator );
4132 vec_le_rb0->installEventFilter(this);
4133 elts_le_rb0->installEventFilter(this);
4135 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4136 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4137 vex_le_rb1->setValidator( validator );
4138 elts_le_rb1->setValidator( validator );
4139 vex_le_rb1->installEventFilter(this);
4140 elts_le_rb1->installEventFilter(this);
4142 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4143 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4144 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4145 vex_le_rb2->setValidator( validator );
4146 vec_le_rb2->setValidator( validator );
4147 elts_le_rb2->setValidator( validator );
4148 vex_le_rb2->installEventFilter(this);
4149 vec_le_rb2->installEventFilter(this);
4150 elts_le_rb2->installEventFilter(this);
4152 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
4153 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
4154 angle_spb->setProperty("Angle", QVariant::fromValue(true));
4155 angle_spb->installEventFilter(this);
4157 vec_le_rb0->setReadOnly(true);
4158 elts_le_rb0->setReadOnly(true);
4160 vex_le_rb1->setReadOnly(true);
4161 elts_le_rb1->setReadOnly(true);
4163 vex_le_rb2->setReadOnly(true);
4164 vec_le_rb2->setReadOnly(true);
4165 elts_le_rb2->setReadOnly(true);
4169 // ============================================================== clear
4170 void MakeTransformationDialog::clear()
4172 elts_le_rb0->clear();
4173 modelUnregister(elts_le_rb0);
4175 vec_le_rb0->clear();
4176 modelUnregister(vec_le_rb0);
4178 elts_le_rb1->clear();
4179 modelUnregister(elts_le_rb1);
4181 vex_le_rb1->clear();
4182 modelUnregister(vex_le_rb1);
4184 elts_le_rb2->clear();
4185 modelUnregister(elts_le_rb2);
4187 vex_le_rb2->clear();
4188 modelUnregister(vex_le_rb2);
4190 vec_le_rb2->clear();
4191 modelUnregister(vec_le_rb2);
4193 modelUnregister(this);
4196 // ============================================================== updateHelpFileName
4197 void MakeTransformationDialog::updateHelpFileName()
4199 if ( sender() == rb0 ){
4200 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
4201 } else if ( sender() == rb1 ){
4202 _helpFileName = "gui_make_elmts.html#make-elements-by-scaling";
4203 } else if ( sender() == rb2 ){
4204 _helpFileName = "gui_make_elmts.html#make-elements-by-rotation";
4208 // ============================================================== apply
4209 bool MakeTransformationDialog::apply(QModelIndex& result)
4211 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4214 if (getDocumentModel() == NULL) return false;
4215 const PatternDataModel* patternDataModel = getPatternDataModel();
4216 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4217 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4219 QModelIndex iNewElts;
4221 if ( rb0->isChecked() ){
4222 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb0] );
4223 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb0] );
4224 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4225 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4227 if ( ielts.isValid()
4229 iNewElts = getDocumentModel()->makeTranslation( ielts, ivec );
4231 } else if ( rb1->isChecked() ){
4232 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4233 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb1] );
4234 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4235 double k = k_spb->value();
4237 if ( ielts.isValid()
4239 iNewElts = getDocumentModel()->makeScale( ielts, ivex, k );
4241 } else if ( rb2->isChecked() ){
4242 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4243 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb2] );
4244 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4245 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4246 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb2] );
4247 double angle = angle_spb->value();
4249 if ( ielts.isValid()
4252 iNewElts = getDocumentModel()->makeRotation( ielts, ivex, ivec, angle );
4255 if ( !iNewElts.isValid() ){
4256 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4260 result = patternDataModel->mapFromSource(iNewElts);
4261 if (result.isValid())
4263 MESSAGE("======> Result is valid!");
4264 HEXA_NS::Elements* elts = getDocumentModel()->getHexaPtr<HEXA_NS::Elements*>(result);
4265 MESSAGE("======> " << elts->getName());
4269 MESSAGE("======> Result is not valid!");
4271 // result = patternBuilderModel->mapFromSource(iNewElts);
4276 // // ------------------------- MakeSymmetryDialog ----------------------------------
4277 // ============================================================== Constructeur
4279 MakeSymmetryDialog::MakeSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4280 HexaBaseDialog(parent, editmode, f)
4283 _initWidget(editmode);
4286 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4287 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4288 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4289 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4292 // ============================================================== Destructeur
4293 MakeSymmetryDialog::~MakeSymmetryDialog()
4297 // ============================================================== _initInputWidget
4298 void MakeSymmetryDialog::_initInputWidget( Mode editmode )
4301 QValidator *validator = new QRegExpValidator(rx, this);
4303 installEventFilter(this);
4305 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4306 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4307 vex_le_rb0->setValidator( validator );
4308 elts_le_rb0->setValidator( validator );
4309 vex_le_rb0->installEventFilter(this);
4310 elts_le_rb0->installEventFilter(this);
4312 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4313 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4314 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4315 vex_le_rb1->setValidator( validator );
4316 vec_le_rb1->setValidator( validator );
4317 elts_le_rb1->setValidator( validator );
4318 vex_le_rb1->installEventFilter(this);
4319 vec_le_rb1->installEventFilter(this);
4320 elts_le_rb1->installEventFilter(this);
4322 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4323 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4324 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4325 vex_le_rb2->setValidator( validator );
4326 vec_le_rb2->setValidator( validator );
4327 elts_le_rb2->setValidator( validator );
4328 vex_le_rb2->installEventFilter(this);
4329 vec_le_rb2->installEventFilter(this);
4330 elts_le_rb2->installEventFilter(this);
4332 vex_le_rb0->setReadOnly(true);
4333 elts_le_rb0->setReadOnly(true);
4334 vex_le_rb1->setReadOnly(true);
4335 vec_le_rb1->setReadOnly(true);
4336 elts_le_rb1->setReadOnly(true);
4337 vex_le_rb2->setReadOnly(true);
4338 vec_le_rb2->setReadOnly(true);
4339 elts_le_rb2->setReadOnly(true);
4342 // ============================================================== clear
4343 void MakeSymmetryDialog::clear()
4345 elts_le_rb0->clear();
4346 modelUnregister(elts_le_rb0);
4348 vex_le_rb0->clear();
4349 modelUnregister(vex_le_rb0);
4351 elts_le_rb1->clear();
4352 modelUnregister(elts_le_rb1);
4354 vex_le_rb1->clear();
4355 modelUnregister(vex_le_rb1);
4357 vec_le_rb1->clear();
4358 modelUnregister(vec_le_rb1);
4360 elts_le_rb2->clear();
4361 modelUnregister(elts_le_rb2);
4363 vex_le_rb2->clear();
4364 modelUnregister(vex_le_rb2);
4366 vec_le_rb2->clear();
4367 modelUnregister(vec_le_rb2);
4369 modelUnregister(this);
4372 // ============================================================== updateHelpFileName
4373 void MakeSymmetryDialog::updateHelpFileName()
4375 if ( sender() == rb0 ){
4376 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4377 } else if ( sender() == rb1 ){
4378 _helpFileName = "gui_make_symmetry.html#make-elements-by-line-symmetry";
4379 } else if ( sender() == rb2 ){
4380 _helpFileName = "gui_make_symmetry.html#make-elements-by-plane-symmetry";
4384 // ============================================================== apply
4385 bool MakeSymmetryDialog::apply(QModelIndex& result)
4387 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4389 if (getDocumentModel() == NULL) return false;
4390 const PatternDataModel* patternDataModel = getPatternDataModel();
4391 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4392 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4394 QModelIndex iNewElts;
4396 if ( rb0->isChecked() ){
4397 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4398 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb0] );
4399 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4401 if ( ielts.isValid()
4403 iNewElts = getDocumentModel()->makeSymmetryPoint( ielts, ivex );
4406 } else if ( rb1->isChecked() ){
4407 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4408 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb1] );
4409 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4410 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4411 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb1] );
4413 if ( ielts.isValid()
4416 iNewElts = getDocumentModel()->makeSymmetryLine( ielts, ivex, ivec );
4418 } else if ( rb2->isChecked() ){
4419 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4420 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4421 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4422 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4423 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4425 if ( ielts.isValid()
4428 iNewElts = getDocumentModel()->makeSymmetryPlane( ielts, ivex, ivec );
4431 if ( !iNewElts.isValid() ){
4432 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4436 // result = patternBuilderModel->mapFromSource(iNewElts);
4437 result = patternDataModel->mapFromSource(iNewElts);
4442 // // ------------------------- PerformTransformationDialog ----------------------------------
4443 // ============================================================== Constructeur
4444 PerformTransformationDialog::PerformTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4445 HexaBaseDialog(parent, editmode, f)
4448 _initWidget(editmode);
4451 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4452 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4453 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4454 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4457 // ============================================================== Destructeur
4458 PerformTransformationDialog::~PerformTransformationDialog()
4462 // ============================================================== _initInputWidget
4463 void PerformTransformationDialog::_initInputWidget( Mode editmode )
4466 QValidator *validator = new QRegExpValidator(rx, this);
4468 installEventFilter(this);
4469 rb0->installEventFilter(this);
4470 rb1->installEventFilter(this);
4471 rb2->installEventFilter(this);
4473 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4474 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4475 vec_le_rb0->setValidator( validator );
4476 elts_le_rb0->setValidator( validator );
4477 vec_le_rb0->installEventFilter(this);
4478 elts_le_rb0->installEventFilter(this);
4480 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4481 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4482 vex_le_rb1->setValidator( validator );
4483 elts_le_rb1->setValidator( validator );
4484 vex_le_rb1->installEventFilter(this);
4485 elts_le_rb1->installEventFilter(this);
4488 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4489 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4490 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4491 vex_le_rb2->setValidator( validator );
4492 vec_le_rb2->setValidator( validator );
4493 elts_le_rb2->setValidator( validator );
4494 vex_le_rb2->installEventFilter(this);
4495 vec_le_rb2->installEventFilter(this);
4496 elts_le_rb2->installEventFilter(this);
4498 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
4499 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
4500 angle_spb->setProperty("Angle", QVariant::fromValue(true));
4501 angle_spb->installEventFilter(this);
4503 vec_le_rb0->setReadOnly(true);
4504 elts_le_rb0->setReadOnly(true);
4505 vex_le_rb1->setReadOnly(true);
4506 elts_le_rb1->setReadOnly(true);
4507 vex_le_rb2->setReadOnly(true);
4508 vec_le_rb2->setReadOnly(true);
4509 elts_le_rb2->setReadOnly(true);
4513 // ============================================================== clear
4514 void PerformTransformationDialog::clear()
4516 vec_le_rb0->clear();
4517 modelUnregister(vec_le_rb0);
4519 elts_le_rb0->clear();
4520 modelUnregister(elts_le_rb0);
4522 vex_le_rb1->clear();
4523 modelUnregister(vex_le_rb1);
4525 elts_le_rb1->clear();
4526 modelUnregister(elts_le_rb1);
4528 vex_le_rb2->clear();
4529 modelUnregister(vex_le_rb2);
4531 vec_le_rb2->clear();
4532 modelUnregister(vec_le_rb2);
4534 elts_le_rb2->clear();
4535 modelUnregister(elts_le_rb2);
4537 modelUnregister(this);
4540 // ============================================================== updateHelpFileName
4541 void PerformTransformationDialog::updateHelpFileName()
4543 if ( sender() == rb0 ){
4544 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4545 } else if ( sender() == rb1 ){
4546 _helpFileName = "gui_modify_elmts.html#modify-elements-by-scaling";
4547 } else if ( sender() == rb2 ){
4548 _helpFileName = "gui_modify_elmts.html#modify-elements-by-rotation";
4552 // ============================================================== apply
4553 bool PerformTransformationDialog::apply(QModelIndex& result)
4555 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4558 if (getDocumentModel() == NULL) return false;
4559 const PatternDataModel* patternDataModel = getPatternDataModel();
4560 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4561 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4563 bool performed = false;
4565 if ( rb0->isChecked() ){
4566 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4567 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb0]);
4568 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4569 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb0]);
4571 if ( ielts.isValid()
4573 performed = getDocumentModel()->performTranslation( ielts, ivec );
4575 } else if ( rb1->isChecked() ){
4576 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4577 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb1]);
4578 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4579 double k = k_spb->value();
4581 if ( ielts.isValid()
4583 performed = getDocumentModel()->performScale( ielts, ivex, k );
4585 } else if ( rb2->isChecked() ){
4586 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4587 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4588 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4589 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4590 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4591 double angle = angle_spb->value();
4593 if ( ielts.isValid()
4596 performed = getDocumentModel()->performRotation( ielts, ivex, ivec, angle );
4599 if ( performed == false){
4600 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM TRANSFORMATION" ) + "\n" + getErrorMsg() );
4607 // // ------------------------- PerformSymmetryDialog ----------------------------------
4608 // ============================================================== Constructeur
4609 PerformSymmetryDialog::PerformSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4610 : HexaBaseDialog(parent, editmode, f)
4613 _initWidget( editmode );
4616 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4617 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4618 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4619 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4622 // ============================================================== Destructeur
4623 PerformSymmetryDialog::~PerformSymmetryDialog()
4627 // ============================================================== _initInputWidget
4628 void PerformSymmetryDialog::_initInputWidget( Mode editmode )
4631 QValidator *validator = new QRegExpValidator(rx, this);
4633 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4634 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4635 vex_le_rb0->setValidator( validator );
4636 elts_le_rb0->setValidator( validator );
4637 vex_le_rb0->installEventFilter(this);
4638 elts_le_rb0->installEventFilter(this);
4640 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4641 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4642 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4643 vex_le_rb1->setValidator( validator );
4644 vec_le_rb1->setValidator( validator );
4645 elts_le_rb1->setValidator( validator );
4646 vex_le_rb1->installEventFilter(this);
4647 vec_le_rb1->installEventFilter(this);
4648 elts_le_rb1->installEventFilter(this);
4650 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4651 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4652 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4653 vex_le_rb2->setValidator( validator );
4654 vec_le_rb2->setValidator( validator );
4655 elts_le_rb2->setValidator( validator );
4656 vex_le_rb2->installEventFilter(this);
4657 vec_le_rb2->installEventFilter(this);
4658 elts_le_rb2->installEventFilter(this);
4660 vex_le_rb0->setReadOnly(true);
4661 elts_le_rb0->setReadOnly(true);
4662 vex_le_rb1->setReadOnly(true);
4663 vec_le_rb1->setReadOnly(true);
4664 elts_le_rb1->setReadOnly(true);
4665 vex_le_rb2->setReadOnly(true);
4666 vec_le_rb2->setReadOnly(true);
4667 elts_le_rb2->setReadOnly(true);
4671 // ============================================================== clear
4672 void PerformSymmetryDialog::clear()
4674 vex_le_rb0->clear();
4675 modelUnregister(vex_le_rb0);
4677 elts_le_rb0->clear();
4678 modelUnregister(elts_le_rb0);
4680 elts_le_rb1->clear();
4681 modelUnregister(elts_le_rb1);
4683 vex_le_rb1->clear();
4684 modelUnregister(vex_le_rb1);
4686 vec_le_rb1->clear();
4687 modelUnregister(vec_le_rb1);
4689 elts_le_rb2->clear();
4690 modelUnregister(elts_le_rb2);
4692 vex_le_rb2->clear();
4693 modelUnregister(vex_le_rb2);
4695 vec_le_rb2->clear();
4696 modelUnregister(vec_le_rb2);
4698 modelUnregister(this);
4701 // ============================================================== updateHelpFileName
4702 void PerformSymmetryDialog::updateHelpFileName()
4704 if ( sender() == rb0 ){
4705 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4706 } else if ( sender() == rb1 ){
4707 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-line-symmetry";
4708 } else if ( sender() == rb2 ){
4709 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-plane-symmetry";
4713 // ============================================================== apply
4714 bool PerformSymmetryDialog::apply(QModelIndex& result)
4716 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4719 if (getDocumentModel() == NULL) return false;
4720 const PatternDataModel* patternDataModel = getPatternDataModel();
4721 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4722 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4724 bool performed = false;
4726 if ( rb0->isChecked() ){
4727 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4728 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb0]);
4729 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4731 if ( ielts.isValid()
4733 performed = getDocumentModel()->performSymmetryPoint( ielts, ivex );
4735 } else if ( rb1->isChecked() ){
4736 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4737 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb1]);
4738 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4739 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4740 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb1]);
4742 if ( ielts.isValid()
4745 performed = getDocumentModel()->performSymmetryLine( ielts, ivex, ivec );
4747 } else if ( rb2->isChecked() ){
4748 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4749 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4750 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4751 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4752 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4754 if ( ielts.isValid()
4757 performed = getDocumentModel()->performSymmetryPlane( ielts, ivex, ivec );
4760 if ( performed == false ){
4761 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM SYMMETRY" ) + "\n" + getErrorMsg() );
4768 // // ------------------------- EdgeAssocDialog ----------------------------------
4769 // ============================================================== Constructeur
4770 EdgeAssocDialog::EdgeAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4771 HexaBaseDialog( parent, editmode, f )
4773 _helpFileName ="gui_asso_quad_to_geom.html#one-edge";
4775 _initWidget(editmode);
4780 // ============================================================== Destructeur
4781 EdgeAssocDialog::~EdgeAssocDialog()
4785 // ============================================================== close
4786 void EdgeAssocDialog::close()
4788 HEXABLOCKGUI::assocInProgress = false;
4789 HexaBaseDialog::close();
4792 // ============================================================== _initInputWidget
4793 void EdgeAssocDialog::_initInputWidget( Mode editmode )
4796 QValidator *validator = new QRegExpValidator(rx, this);
4799 first_vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4800 first_vex_le->installEventFilter(this);
4801 first_vex_le->setValidator( validator );
4803 single_edge_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4804 single_edge_le->installEventFilter(this);
4806 edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4807 edges_lw->installEventFilter(this);
4811 lines_lw->setProperty("HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4812 lines_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4813 lines_lw->installEventFilter(this);
4815 single_line_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4816 single_line_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4817 single_line_le->installEventFilter(this);
4820 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), edges_lw);
4821 QShortcut* delLineShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), lines_lw);
4822 delLineShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4823 delEdgeShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4825 pend_spb->setValue(1.);
4827 first_vex_le->setReadOnly(true);
4828 single_edge_le->setReadOnly(true);
4829 single_line_le->setReadOnly(true);
4831 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
4832 connect( delLineShortcut, SIGNAL(activated()), this, SLOT(deleteLineItem()) );
4833 connect( edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
4834 connect( lines_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4835 connect( single_rb, SIGNAL(clicked()), this, SLOT( refreshHighlight()), Qt::UniqueConnection );
4836 connect( multiple_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection );
4837 connect( single_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4838 connect( multiple_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4841 // ============================================================== updateHelpFileName
4842 void EdgeAssocDialog::updateHelpFileName()
4844 if ( sender() == single_rb ){
4845 _helpFileName = "gui_asso_quad_to_geom.html#one-edge";
4846 } else if ( sender() == multiple_rb ){
4847 _helpFileName = "gui_asso_quad_to_geom.html#line";
4851 // ============================================================== getAssocsVTK
4853 * Returns elements currently being associated in vtk side
4855 QModelIndexList EdgeAssocDialog::getAssocsVTK()
4857 QModelIndexList assocs;
4859 QListWidgetItem* item = NULL;
4861 if (getPatternDataSelectionModel() == NULL) return assocs;
4862 if (single_rb->isChecked())
4865 QVariant v = single_edge_le->property("QModelIndex");
4866 if ( !v.isValid() ) return assocs;
4867 assocs << v.value<QModelIndex>();
4870 else if (multiple_rb->isChecked())
4872 //ListWidget content
4873 const PatternDataModel* patternDataModel = getPatternDataModel();
4874 if ( !patternDataModel ) return assocs;
4875 int nbEdges = edges_lw->count();
4876 for ( int r = 0; r < nbEdges; ++r){
4877 item = edges_lw->item(r);
4878 iEdge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4879 if ( iEdge.isValid() ) assocs << iEdge;
4886 // ============================================================== getAssocsGEOM
4888 * Returns elements currently being associated in geom side
4890 QMultiMap<QString, int> EdgeAssocDialog::getAssocsGEOM()
4892 QMultiMap<QString, int> assocs;
4893 QListWidgetItem* item = NULL;
4894 DocumentModel::GeomObj geomObj;
4896 if (single_rb->isChecked())
4899 QVariant v = single_line_le->property("GeomObj");
4900 if ( !v.isValid() ) return assocs;
4901 geomObj = v.value<DocumentModel::GeomObj>();
4902 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4905 else if (multiple_rb->isChecked())
4907 //ListWidget content
4908 unsigned int nbEdges = lines_lw->count();
4909 for ( int r = 0; r < nbEdges; ++r){
4910 item = lines_lw->item(r);
4911 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4912 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4919 // ============================================================== selectElementOfGeom
4920 /*Highlight in the OCC view selected elements in a listwidget,
4921 * or an element in a line edit.*/
4922 void EdgeAssocDialog::selectElementOfGeom()
4924 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4925 if ( !currentListWidget )
4929 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4930 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4931 pgsm->clearSelection();
4932 if (sel.count() == 0)
4935 QListWidgetItem *item = sel[0];
4936 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
4937 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4938 if ( index.isValid() )
4939 pgsm->select( index, QItemSelectionModel::SelectCurrent );
4942 // ============================================================== clear
4943 void EdgeAssocDialog::clear()
4945 first_vex_le->clear();
4946 modelUnregister(first_vex_le);
4949 modelUnregister(edges_lw);
4953 single_edge_le->clear();
4954 modelUnregister(single_edge_le);
4956 single_line_le->clear();
4957 modelUnregister(single_line_le);
4959 modelUnregister(this);
4962 // ============================================================== onWindowActivated
4963 void EdgeAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4965 QString vmType = vm->getType();
4966 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4968 if (single_rb->isChecked())
4969 single_edge_le->setFocus();
4970 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le )
4971 edges_lw->setFocus();
4973 else if ( vmType == OCCViewer_Viewer::Type() ){
4974 if (single_rb->isChecked())
4975 single_line_le->setFocus();
4976 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le)
4977 lines_lw->setFocus();
4981 // ============================================================== apply
4982 bool EdgeAssocDialog::apply(QModelIndex& result)
4984 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4987 bool assocOk = false;
4989 PatternDataModel* patternDataModel = getPatternDataModel();
4990 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4991 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4993 QModelIndex iEdge, iGeomEdge;
4994 QModelIndexList iEdges;
4995 QListWidgetItem* item = NULL;
4996 QList<DocumentModel::GeomObj> assocs;
4997 DocumentModel::GeomObj aLine;
4998 HEXA_NS::SubShape* ssh;
4999 HEXA_NS::EdgeShape* sh;
5000 HEXA_NS::NewShapes shapes;
5001 HEXA_NS::IntVector subIds;
5003 QModelIndexList edges, lines;
5005 if (single_rb->isChecked()){ //Single edge and/or line association
5007 iEdge = patternDataModel->mapToSource( _index[single_edge_le] );
5008 if ( !iEdge.isValid() || myLine == NULL)
5010 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5013 id = myLine->shapeName+","+myLine->subId;
5014 ssh = getDocumentModel()->getGeomPtr(id);
5015 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
5016 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5017 if (!iGeomEdge.isValid())
5019 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5022 assocOk = getDocumentModel()->addEdgeAssociation(iEdge, iGeomEdge, pstart_spb->value(), pend_spb->value());
5023 edges << _index[single_edge_le];
5026 else { //Multiple edge and/or line association
5029 iEdges = getIndexList(edges_lw, true);
5030 int nbLines = lines_lw->count();
5031 if (iEdges.count() == 0 || nbLines == 0)
5033 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5036 edges = getIndexList(edges_lw, false);
5038 for (int r = 0; r < nbLines; ++r){
5039 item = lines_lw->item(r);
5040 aLine = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5041 id = aLine.shapeName+","+aLine.subId;
5042 ssh = getDocumentModel()->getGeomPtr(id);
5043 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
5046 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5049 shapes.push_back(sh->getParentShape());
5050 subIds.push_back(sh->getIdent());
5051 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5052 if (iGeomEdge.isValid())
5056 if ( close_cb->isChecked() ){ //closed line
5057 QModelIndex iFirstVertex = patternDataModel->mapToSource( _index[first_vex_le] );
5058 if ( !iFirstVertex.isValid() )
5060 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5063 bool inv = inverse_cb->isChecked();
5064 assocOk = getDocumentModel()->associateClosedLine( iFirstVertex, iEdges, shapes, subIds, pstart_spb->value(), inv );
5068 assocOk = getDocumentModel()->associateOpenedLine( iEdges, shapes, subIds, pstart_spb->value(), pend_spb->value() );
5072 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) + "\n" + getErrorMsg() );
5076 // highlight associated items in the trees
5077 pdsm->unhighlightTreeItems();
5078 pgsm->unhighlightTreeItems();
5079 pdsm->highlightTreeItems(edges);
5080 pgsm->highlightTreeItems(lines);
5082 // highlight associated items in the views
5083 highlightSelectedAssocs();
5088 // ------------------------- QuadAssocDialog ----------------------------------
5089 // ============================================================== Constructeur
5090 QuadAssocDialog::QuadAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5091 HexaBaseDialog(parent, editmode, f)
5093 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-face-or-a-shell-of-the-geometry";
5095 _initWidget(editmode);
5098 // ============================================================== Destructeur
5099 QuadAssocDialog::~QuadAssocDialog()
5101 disconnect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
5102 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(addFace()) );
5103 delete _delFaceShortcut;
5106 // ============================================================== close
5107 void QuadAssocDialog::close()
5109 HEXABLOCKGUI::assocInProgress = false;
5110 HexaBaseDialog::close();
5113 // ============================================================== _initInputWidget
5114 void QuadAssocDialog::_initInputWidget( Mode editmode )
5117 QValidator *validator = new QRegExpValidator(rx, this);
5119 quad_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5120 quad_le->installEventFilter(this);
5121 quad_le->setValidator( validator );
5123 faces_lw->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
5124 faces_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
5125 faces_lw->installEventFilter(this);
5126 _delFaceShortcut = new QShortcut( QKeySequence(Qt::Key_X/*Qt::Key_Delete*/), faces_lw );
5127 _delFaceShortcut->setContext( Qt::WidgetShortcut );
5129 quad_le->setReadOnly(true);
5131 connect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
5132 connect( faces_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
5135 // ============================================================== getAssocsVTK
5137 * Returns elements currently being associated in vtk side
5139 QModelIndexList QuadAssocDialog::getAssocsVTK()
5141 QModelIndexList assocs;
5145 QVariant v = quad_le->property("QModelIndex");
5148 assocs << v.value<QModelIndex>();
5152 // ============================================================== getAssocsGEOM
5154 * Returns elements currently being associated in geom side
5156 QMultiMap<QString, int> QuadAssocDialog::getAssocsGEOM()
5158 QMultiMap<QString, int> assocs;
5159 QListWidgetItem* item = NULL;
5160 DocumentModel::GeomObj geomObj;
5162 //ListWidget content
5163 unsigned int nbFaces = faces_lw->count();
5164 for ( int r = 0; r < nbFaces; ++r){
5165 item = faces_lw->item(r);
5166 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5167 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
5172 // ============================================================== selectElementOfGeom
5173 /*Highlight in the OCC view selected elements in a listwidget,
5174 * or an element in a line edit.*/
5176 void QuadAssocDialog::selectElementOfGeom()
5178 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5179 if ( !currentListWidget )
5183 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5184 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
5185 pgsm->clearSelection();
5186 if (sel.count() == 0)
5188 QListWidgetItem *item = sel[0];
5189 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
5190 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5191 if ( index.isValid() )
5192 pgsm->select( index, QItemSelectionModel::SelectCurrent );
5195 void QuadAssocDialog::clear()
5198 modelUnregister(quad_le);
5202 modelUnregister(this);
5205 // ============================================================== onWindowActivated
5206 void QuadAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
5208 QString vmType = vm->getType();
5209 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
5210 quad_le->setFocus();
5211 else if ( vmType == OCCViewer_Viewer::Type() ){
5212 faces_lw->setFocus();
5216 // ============================================================== deleteFaceItem
5217 void QuadAssocDialog::deleteFaceItem()
5219 delete faces_lw->currentItem();
5222 // ============================================================== apply
5223 bool QuadAssocDialog::apply(QModelIndex& result)
5225 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5228 PatternDataModel* patternDataModel = getPatternDataModel();
5229 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
5230 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
5233 QModelIndex iQuad, iGeomFace;
5234 HEXA_NS::SubShape* ssh;
5235 HEXA_NS::FaceShape* sh;
5239 iQuad = patternDataModel->mapToSource( _index[quad_le] );
5242 QListWidgetItem* item = NULL;
5243 DocumentModel::GeomObj aFace;
5244 QModelIndexList quads, faces;
5245 int nbFaces = faces_lw->count();
5246 for ( int r = 0; r < nbFaces; ++r ){
5247 item = faces_lw->item(r);
5248 aFace = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5249 id = aFace.shapeName+","+aFace.subId;
5250 ssh = getDocumentModel()->getGeomPtr(id);
5251 sh = dynamic_cast<HEXA_NS::FaceShape*>(ssh);
5254 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) );
5257 iGeomFace = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5258 if (!getDocumentModel()->addQuadAssociation(iQuad, iGeomFace))
5260 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) + "\n" + getErrorMsg() );
5263 else if (iGeomFace.isValid())
5268 if (iQuad.isValid())
5269 quads << _index[quad_le];
5271 // highlight associated items in the trees
5272 pdsm->highlightTreeItems(quads);
5273 pgsm->highlightTreeItems(faces);
5275 // highlight associated items in the views
5276 highlightSelectedAssocs();
5281 // ------------------------- GroupDialog ----------------------------------
5282 // ============================================================== Constructeur
5283 GroupDialog::GroupDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5284 HexaBaseDialog(parent, editmode, f),
5287 _helpFileName = "gui_groups.html#add-group";
5289 _initWidget(editmode);
5290 // setFocusProxy( name_le/*eltBase_lw */);
5292 if ( editmode == NEW_MODE ){
5293 setWindowTitle( tr("Group Construction") );
5294 } else if ( editmode == UPDATE_MODE ){
5295 setWindowTitle( tr("Group Modification") );
5296 } else if ( editmode == INFO_MODE ){
5297 setWindowTitle( tr("Group Information") );
5301 // ============================================================== Destructeur
5302 GroupDialog::~GroupDialog()
5306 // ============================================================== getAssocsVTK
5308 * Returns elements currently being associated in vtk side
5310 QModelIndexList GroupDialog::getAssocsVTK()
5312 QModelIndexList assocs;
5314 QListWidgetItem* item = NULL;
5315 if (getPatternDataSelectionModel() == NULL) return assocs;
5316 //ListWidget content
5317 const PatternDataModel* patternDataModel = getPatternDataModel();
5318 if ( !patternDataModel ) return assocs;
5319 int nbElts = eltBase_lw->count();
5320 for ( int r = 0; r < nbElts; ++r){
5321 item = eltBase_lw->item(r);
5322 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5323 if ( iItem.isValid() ) assocs << iItem;
5328 // ============================================================== _initInputWidget
5329 void GroupDialog::_initInputWidget( Mode editmode )
5331 installEventFilter(this);
5332 name_le->installEventFilter(this);
5335 strKind[ HEXA_NS::HexaCell ] = "HexaCell";
5336 strKind[ HEXA_NS::QuadCell ] = "QuadCell";
5337 strKind[ HEXA_NS::EdgeCell ] = "EdgeCell";
5338 strKind[ HEXA_NS::HexaNode ] = "HexaNode";
5339 strKind[ HEXA_NS::QuadNode ] = "QuadNode";
5340 strKind[ HEXA_NS::EdgeNode ] = "EdgeNode";
5341 strKind[ HEXA_NS::VertexNode ] = "VertexNode";
5343 QMap<HEXA_NS::EnumGroup, QString>::ConstIterator iKind;
5344 for( iKind = strKind.constBegin(); iKind != strKind.constEnd(); ++iKind )
5345 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5347 onKindChanged( kind_cb->currentIndex() );
5348 eltBase_lw->installEventFilter(this);
5350 if ( editmode != INFO_MODE ){
5351 QShortcut* delEltShortcut = new QShortcut( QKeySequence(Qt::Key_X), eltBase_lw );
5352 delEltShortcut->setContext( Qt::WidgetShortcut );
5353 connect(delEltShortcut, SIGNAL(activated()), this, SLOT(removeEltBase()));
5354 connect(kind_cb, SIGNAL(activated(int)), this, SLOT(onKindChanged(int)) );
5357 if ( editmode == INFO_MODE)
5359 name_le->setReadOnly(true);
5360 kind_cb->setEnabled(false);
5361 eltBase_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
5364 connect(eltBase_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5367 // ============================================================== clear
5368 void GroupDialog::clear()
5372 eltBase_lw->clear();
5373 modelUnregister(eltBase_lw);
5375 modelUnregister(this);
5378 // ============================================================== onKindChanged
5379 void GroupDialog::onKindChanged(int index)
5382 switch ( kind_cb->itemData(index).toInt() ){
5383 case HEXA_NS::HexaCell:
5384 case HEXA_NS::HexaNode:
5385 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(HEXA_TREE));
5388 case HEXA_NS::QuadCell:
5389 case HEXA_NS::QuadNode:
5390 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5393 case HEXA_NS::EdgeCell:
5394 case HEXA_NS::EdgeNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
5397 case HEXA_NS::VertexNode:
5398 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
5401 default:Q_ASSERT(false);
5403 eltBase_lw->clear();
5404 eltBase_lw->setFocus();
5407 // ============================================================== setValue
5408 void GroupDialog::setValue(HEXA_NS::Group* g)
5411 name_le->setText( g->getName() );
5415 kind_cb->addItem ( strKind[g->getKind()], QVariant( g->getKind() ) );
5418 HEXA_NS::EltBase* eltBase = NULL;
5419 QListWidgetItem* item = NULL;
5420 QModelIndex iEltBase;
5421 QList<QStandardItem *> eltBaseItems;
5424 if ( !getPatternDataSelectionModel() ) return;
5425 if ( !getGroupsSelectionModel() ) return;
5427 QModelIndex iGroup = getGroupsSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(g) );
5428 name_le->setProperty( "QModelIndex", QVariant::fromValue(iGroup) );
5431 int nbElts = g->countElement();
5432 for ( int nr = 0; nr < nbElts; ++nr ){
5433 eltBase = g->getElement( nr );
5434 switch ( g->getKind() ){
5435 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: v = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
5436 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: v = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
5437 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: v = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
5438 case HEXA_NS::VertexNode: v = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
5440 iEltBase = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, v);
5441 if ( iEltBase.isValid() ){
5442 item = new QListWidgetItem( eltBase->getName() );
5443 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iEltBase) );
5444 item->setData(LW_DATA_ROLE, iEltBase.data(HEXA_DATA_ROLE));
5445 eltBase_lw->addItem( item );
5451 // ============================================================== getValue
5452 HEXA_NS::Group* GroupDialog::getValue()
5457 // ============================================================== removeEltBase
5458 void GroupDialog::removeEltBase()
5460 QListWidgetItem *item = eltBase_lw->currentItem();
5463 int r = eltBase_lw->row(item);
5464 eltBase_lw->takeItem(r);
5470 // ============================================================== apply
5471 bool GroupDialog::apply(QModelIndex& result)
5473 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5476 if ( !getDocumentModel() ) return false;
5477 const PatternDataModel* patternDataModel = getPatternDataModel();
5478 const GroupsModel* groupsModel = getGroupsModel();
5479 if (patternDataModel == NULL || groupsModel == NULL) return false;
5481 QString grpName = name_le->text();
5482 DocumentModel::Group grpKind = static_cast<DocumentModel::Group>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5484 if ( _value == NULL ){ // create group
5485 iGrp = getDocumentModel()->addGroup( grpName, grpKind );
5487 QModelIndexList iGrps = getDocumentModel()->match(
5488 getDocumentModel()->index(0, 0),
5490 QVariant::fromValue( _value ),
5492 Qt::MatchRecursive );
5493 if ( !iGrps.isEmpty() )
5498 if ( !iGrp.isValid() ){
5499 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD GROUP" ) + "\n" + getErrorMsg() );
5503 //fill it and select it
5504 QModelIndex iEltBase;
5505 QListWidgetItem* item = NULL;
5506 bool eltAdded = false;
5507 getDocumentModel()->clearGroupElement(iGrp);
5508 int nbElts = eltBase_lw->count();
5509 for ( int r = 0; r < nbElts; ++r){
5510 item = eltBase_lw->item(r);
5511 iEltBase = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5512 if ( iEltBase.isValid() )
5513 eltAdded = getDocumentModel()->addGroupElement( iGrp, iEltBase );
5516 QString newName = name_le->text();
5517 if ( !newName.isEmpty() )
5518 getDocumentModel()->setName( iGrp, newName );
5520 HEXA_NS::Group* hGroup = getDocumentModel()->data(iGrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
5523 QString groupName = QString::fromStdString(hGroup->getNextName());
5524 name_le->setText(groupName);
5527 result = groupsModel->mapFromSource(iGrp);
5532 // ------------------------- LawDialog ----------------------------------
5533 // ============================================================== Constructeur
5535 LawDialog::LawDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5536 : HexaBaseDialog(parent, editmode, f),
5539 _helpFileName = "gui_discret_law.html#add-law";
5541 _initWidget(editmode);
5542 if ( editmode == NEW_MODE ){
5543 setWindowTitle( tr("Law Construction") );
5544 } else if ( editmode == UPDATE_MODE ){
5545 setWindowTitle( tr("Law Modification") );
5547 else if ( editmode == INFO_MODE){
5548 setWindowTitle( tr("Law Information") );
5552 // ============================================================== Destructeur
5553 LawDialog::~LawDialog()
5557 // ============================================================== _initInputWidget
5558 void LawDialog::_initInputWidget( Mode editmode )
5562 // setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5563 installEventFilter(this);
5565 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5566 name_le->installEventFilter(this);
5569 strKind[ HEXA_NS::Uniform ] = "Uniform";
5570 strKind[ HEXA_NS::Arithmetic ] = "Arithmetic";
5571 strKind[ HEXA_NS::Geometric ] = "Geometric";
5574 QMap<HEXA_NS::KindLaw, QString>::ConstIterator iKind, iEnd;
5575 for( iKind = strKind.constBegin(), iEnd = strKind.constEnd(); iKind != iEnd; ++iKind )
5576 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5578 if (editmode == INFO_MODE)
5580 name_le->setReadOnly(true);
5581 nb_nodes_spb->setReadOnly(true);
5582 coeff_spb->setReadOnly(true);
5583 kind_cb->setEnabled(false);
5587 // ============================================================== clear
5588 void LawDialog::clear()
5592 modelUnregister(this);
5595 // ============================================================== setValue
5596 void LawDialog::setValue(HEXA_NS::Law* l)
5599 name_le->setText( l->getName() );
5601 nb_nodes_spb->setValue( l->getNodes() );
5602 coeff_spb->setValue( l->getCoefficient() );
5604 HEXA_NS::KindLaw k = l->getKind();
5605 kind_cb->setCurrentIndex( kind_cb->findData(k) );
5610 // ============================================================== getValue
5611 HEXA_NS::Law* LawDialog::getValue()
5616 // ============================================================== apply
5617 bool LawDialog::apply(QModelIndex& result)
5619 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5622 if ( !getDocumentModel() ) return false;
5624 const MeshModel* meshModel = getMeshModel();
5625 if (meshModel == NULL) return false;
5627 QString lawName = name_le->text();
5628 int nbnodes = nb_nodes_spb->value();
5629 double coeff = coeff_spb->value();
5630 DocumentModel::KindLaw lawKind = static_cast<DocumentModel::KindLaw>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5633 if ( _value == NULL ){ // create Law
5634 iLaw = getDocumentModel()->addLaw( lawName, nbnodes );
5636 QModelIndexList iLaws = getDocumentModel()->match(
5637 getDocumentModel()->index(0, 0),
5639 QVariant::fromValue( _value ),
5641 Qt::MatchRecursive );
5642 if ( !iLaws.isEmpty() )
5646 if ( !iLaw.isValid() ){
5647 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5650 //fill it and select it
5651 bool setOk = getDocumentModel()->setLaw( iLaw, nbnodes, coeff, lawKind );
5653 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5657 QString newName = name_le->text();
5658 if ( !newName.isEmpty() )/*{*/
5659 getDocumentModel()->setName( iLaw, newName );
5661 HEXA_NS::Law* hLaw = getDocumentModel()->data(iLaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
5665 name_le->setText(hLaw->getNextName(buffer));
5669 result = meshModel->mapFromSource(iLaw);
5674 // ------------------------- PropagationDialog ----------------------------------
5675 // ============================================================== Constructeur
5676 PropagationDialog::PropagationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5677 : HexaBaseDialog(parent, editmode, f),
5680 _helpFileName = "gui_propag.html";
5682 _initWidget(editmode);
5684 if ( editmode == INFO_MODE ){
5685 setWindowTitle( tr("Propagation Information") );
5688 } else if ( editmode == UPDATE_MODE ){
5689 setWindowTitle( tr("Propagation Modification") );
5692 } else if ( editmode == NEW_MODE ){
5693 setWindowTitle( tr("Propagation(s) Setting") );
5697 // ============================================================== Destructeur
5698 PropagationDialog::~PropagationDialog()
5702 // ============================================================== _initInputWidget
5703 void PropagationDialog::_initInputWidget( Mode editmode )
5706 QValidator *validator = new QRegExpValidator(rx, this);
5708 installEventFilter(this);
5711 law_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5712 law_le->installEventFilter(this);
5713 law_le->setValidator( validator );
5715 propagations_lw->setProperty( "HexaWidgetType", QVariant::fromValue(PROPAGATION_TREE) );
5716 propagations_lw->installEventFilter(this);
5718 QShortcut* delPropagationShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), propagations_lw);
5719 delPropagationShortcut->setContext( Qt::WidgetShortcut );
5721 law_le->setReadOnly(true);
5723 if ( editmode == INFO_MODE)
5724 way_cb->setEnabled(false);
5726 connect( delPropagationShortcut, SIGNAL(activated()), this, SLOT(deletePropagationItem()) );
5727 connect( propagations_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
5730 // ============================================================== clear
5731 void PropagationDialog::clear()
5733 propagations_lw->clear();
5734 modelUnregister(propagations_lw);
5737 modelUnregister(law_le);
5739 modelUnregister(this);
5742 // ============================================================== deletePropagationItem
5743 void PropagationDialog::deletePropagationItem()
5745 delete propagations_lw->currentItem();
5748 // ============================================================== setValue
5749 void PropagationDialog::setValue(HEXA_NS::Propagation* p)
5751 if (getMeshSelectionModel() == NULL) return;
5752 HEXA_NS::Law* l = p->getLaw();
5753 bool way = p->getWay();
5756 QModelIndex ip = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
5757 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(ip) );
5759 // law on propagation
5761 law_le->setText( l->getName() );
5762 QModelIndex il = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(l) );
5763 law_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(il) );
5766 // way of propagation
5767 way_cb->setChecked(way);
5772 // ============================================================== selectElementOfModel
5774 /*Selects in the model (treeview) elements selected in a listwidget,
5775 * or an element in a line edit.*/
5777 void PropagationDialog::selectElementOfModel()
5779 if (!getMeshSelectionModel()) return;
5781 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5782 if ( !currentListWidget ) return;
5784 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5786 getMeshSelectionModel()->clearSelection();
5787 foreach ( QListWidgetItem *item, sel ){
5788 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
5789 index = getMeshSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5790 if ( index.isValid() )
5791 getMeshSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
5795 // ============================================================== getValue
5796 HEXA_NS::Propagation* PropagationDialog::getValue()
5801 // ============================================================== apply
5802 bool PropagationDialog::apply(QModelIndex& result)
5804 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5808 if ( !getDocumentModel() ) return false;
5809 const MeshModel* meshModel = getMeshModel();
5810 if (meshModel == NULL) return false;
5812 bool way = way_cb->isChecked();
5813 QListWidgetItem* item = NULL;
5815 QModelIndex iPropagation;
5816 QModelIndex iLaw = meshModel->mapToSource( law_le->property("QModelIndex").value<QModelIndex>() );
5817 if (!iLaw.isValid() ){
5818 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5822 int nbPropagations = propagations_lw->count();
5823 for (int r = 0; r < nbPropagations; ++r){
5824 item = propagations_lw->item(r);
5825 iPropagation = meshModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5826 if ( !iPropagation.isValid() ){
5827 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5831 //fill it and select it
5832 isOk = getDocumentModel()->setPropagation( iPropagation, iLaw, way );
5834 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) + "\n" + getErrorMsg() );
5838 result = meshModel->mapFromSource(iPropagation);
5844 // ------------------------- ComputeMeshDialog ----------------------------------
5845 // ============================================================== Constructeur
5846 ComputeMeshDialog::ComputeMeshDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5847 HexaBaseDialog(parent, editmode, f)
5849 _helpFileName = "gui_mesh.html";
5850 setWindowTitle( tr("Compute mesh") );
5852 _initWidget(editmode);
5855 // ============================================================== Destructeur
5856 ComputeMeshDialog::~ComputeMeshDialog()
5860 // ============================================================== _initInputWidget
5861 void ComputeMeshDialog::_initInputWidget( Mode editmode )
5865 // ============================================================== setDocumentModel
5866 void ComputeMeshDialog::setDocumentModel(DocumentModel* m)
5868 if (m == NULL) return;
5869 _name->setText(m->getName());
5872 // ============================================================== clear
5873 void ComputeMeshDialog::clear()
5875 modelUnregister(this);
5878 // ============================================================== apply
5879 bool ComputeMeshDialog::apply(QModelIndex& result)
5881 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5884 if (getDocumentModel() == NULL) return false;
5885 #ifndef DISABLE_PYCONSOLE
5886 QString command = QString("import hexablock ; %1 = hexablock.mesh(\"%2\", \"%1\", %3, \"%4\")")
5887 .arg( _name->text() )
5888 .arg( getDocumentModel()->getName() )
5889 .arg( _dim->value() )
5890 .arg( _fact->text() );
5892 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
5893 PyConsole_Console* pyConsole = app->pythonConsole();
5896 pyConsole->exec( command );
5906 // ------------------------- ReplaceHexaDialog ----------------------------------
5907 // ============================================================== Constructeur
5908 ReplaceHexaDialog::ReplaceHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5909 HexaBaseDialog(parent, editmode, f)
5911 _helpFileName = "gui_replace_hexa.html";
5913 _initWidget(editmode);
5916 // ============================================================== Destructeur
5917 ReplaceHexaDialog::~ReplaceHexaDialog()
5921 // ============================================================== getAssocsVTK
5923 * Returns elements currently associated to vtk
5925 QModelIndexList ReplaceHexaDialog::getAssocsVTK()
5927 QModelIndexList assocs;
5929 QListWidgetItem* item = NULL;
5931 //ListWidget content
5932 int nbQuads = quads_lw->count();
5933 for ( int r = 0; r < nbQuads; ++r ){
5934 item = quads_lw->item(r);
5935 //iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
5936 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5937 if ( iQuad.isValid() )
5941 nbQuads = quads_lw_2->count();
5942 for( int i = 0; i < nbQuads; ++i)
5944 item = quads_lw_2->item(i);
5945 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5946 if (iQuad.isValid())
5953 // ============================================================== _initInputWidget
5954 void ReplaceHexaDialog::_initInputWidget( Mode editmode )
5958 installEventFilter(this);
5960 c1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5961 c2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5963 p1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5964 p2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5966 c1_le->installEventFilter(this);
5967 c2_le->installEventFilter(this);
5969 p1_le->installEventFilter(this);
5970 p2_le->installEventFilter(this);
5972 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5973 quads_lw->installEventFilter(this);
5975 quads_lw_2->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5976 quads_lw_2->installEventFilter(this);
5978 if ( editmode == NEW_MODE ){
5979 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5980 QShortcut* delQuadShortcut2 = new QShortcut( QKeySequence(Qt::Key_X), quads_lw_2 );
5981 delQuadShortcut->setContext( Qt::WidgetShortcut );
5982 delQuadShortcut2->setContext( Qt::WidgetShortcut );
5983 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()) );
5984 connect( quads_lw, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5985 connect( delQuadShortcut2, SIGNAL(activated()), this, SLOT(deleteQuadItem2()));
5986 connect( quads_lw_2, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5989 c1_le->setReadOnly(true);
5990 c2_le->setReadOnly(true);
5992 p1_le->setReadOnly(true);
5993 p2_le->setReadOnly(true);
5995 connect(quads_lw, SIGNAL(itemSelectionChanged()),
5996 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5998 connect(quads_lw_2, SIGNAL(itemSelectionChanged()),
5999 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
6002 // ============================================================== clear
6003 void ReplaceHexaDialog::clear()
6006 modelUnregister(quads_lw);
6008 quads_lw_2->clear();
6009 modelUnregister(quads_lw_2);
6012 modelUnregister(p1_le);
6015 modelUnregister(p2_le);
6018 modelUnregister(c1_le);
6021 modelUnregister(c2_le);
6023 modelUnregister(this);
6026 // ============================================================== updateButtonBox
6027 void ReplaceHexaDialog::updateButtonBox()
6029 int nbQuad = quads_lw->count();
6032 _applyButton->setEnabled(true);
6034 _applyButton->setEnabled(false);
6038 // ============================================================== deleteQuadItem
6039 void ReplaceHexaDialog::deleteQuadItem()
6041 delete quads_lw->currentItem();
6045 // ============================================================== deleteQuadItem2
6046 void ReplaceHexaDialog::deleteQuadItem2()
6048 delete quads_lw_2->currentItem();
6052 // ============================================================== apply
6053 bool ReplaceHexaDialog::apply(QModelIndex& result)
6055 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6058 if ( !getDocumentModel() ) return false;
6059 const PatternDataModel* patternDataModel = getPatternDataModel();
6060 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6061 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
6063 QModelIndex ielts; //result
6065 QListWidgetItem* item = NULL;
6066 QModelIndexList iquads_source;
6068 int nbQuads = quads_lw->count();
6069 for ( int r = 0; r < nbQuads; ++r){
6070 item = quads_lw->item(r);
6071 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6072 if ( iquad.isValid() )
6073 iquads_source << iquad;
6076 QModelIndexList iquads_dest;
6077 nbQuads = quads_lw_2->count();
6078 for (int i = 0; i < nbQuads; ++i)
6080 item = quads_lw_2->item(i);
6081 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6082 if (iquad.isValid())
6083 iquads_dest << iquad;
6086 QModelIndex ip1_source = patternDataModel->mapToSource( _index[p1_le] );
6087 QModelIndex ip2_source = patternDataModel->mapToSource( _index[p2_le] );
6089 QModelIndex ic1_dest = patternDataModel->mapToSource( _index[c1_le] );
6090 QModelIndex ic2_dest = patternDataModel->mapToSource( _index[c2_le] );
6092 bool ipts_ok = ip1_source.isValid() && ip2_source.isValid() &&
6093 ic1_dest.isValid() && ic2_dest.isValid();
6097 ielts = getDocumentModel()->replace( iquads_source, iquads_dest,
6098 ip1_source, ic1_dest,
6099 ip2_source, ic2_dest );
6102 if ( !ielts.isValid() ){
6103 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REPLACE HEXA" ) + "\n" + getErrorMsg() );
6106 _value = ielts.model()->data(ielts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6107 // result = patternBuilderModel->mapFromSource(ielts);
6108 result = patternDataModel->mapFromSource(ielts);
6110 //update the list (indexes)
6111 for ( int r = 0; r < nbQuads; ++r ){
6112 item = quads_lw->item(r);
6113 iquad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
6114 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iquad) );
6115 item->setData(LW_DATA_ROLE, iquad.data(HEXA_DATA_ROLE));
6121 // ------------------------- QuadRevolutionDialog ----------------------------------
6122 // ============================================================== Constructeur
6124 QuadRevolutionDialog::QuadRevolutionDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
6125 HexaBaseDialog(parent, editmode, f)
6128 _helpFileName = "gui_quad_revolution.html#guiquadsrevolution";
6129 connect( revolutionUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6130 connect( revolution_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6131 _initWidget(editmode);
6132 revolutionUni_rb->click();
6135 // ============================================================== getAssocsVTK
6137 * Returns elements currently associated to vtk
6139 QModelIndexList QuadRevolutionDialog::getAssocsVTK()
6141 QModelIndexList assocs;
6143 QListWidgetItem* item = NULL;
6144 if (getPatternDataSelectionModel() == NULL) return assocs;
6146 //ListWidget content
6147 const PatternDataModel* patternDataModel = getPatternDataModel();
6148 if ( !patternDataModel ) return assocs;
6149 int nbQuads = quads_lw->count();
6150 for ( int r = 0; r < nbQuads; ++r ){
6151 item = quads_lw->item(r);
6152 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6153 if ( iQuad.isValid() )
6159 // ============================================================== Destructeur
6160 QuadRevolutionDialog::~QuadRevolutionDialog()
6164 // ============================================================== _initInputWidget
6165 void QuadRevolutionDialog::_initInputWidget( Mode editmode )
6167 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
6168 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6169 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6171 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
6172 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
6173 angle_spb->setProperty("Angle", QVariant::fromValue(true));
6174 angle_spb->installEventFilter(this);
6176 angles_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
6177 angles_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
6178 angles_lw->setProperty("Angle", QVariant::fromValue(true));
6179 angles_lw->installEventFilter(this);
6181 installEventFilter(this);
6182 revolutionUni_rb->installEventFilter(this);
6183 revolution_rb->installEventFilter(this);
6185 quads_lw->installEventFilter(this);
6186 center_le->installEventFilter(this);
6187 axis_le->installEventFilter(this);
6189 center_le->setReadOnly(true);
6190 axis_le->setReadOnly(true);
6192 angles_lw->setItemDelegate( new HexaAngleDoubleSpinBoxDelegate(angles_lw) );
6193 angles_lw->setEditTriggers( QAbstractItemView::DoubleClicked );
6195 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
6196 delQuadShortcut->setContext( Qt::WidgetShortcut );
6197 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(delQuadItem()) );
6198 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()));
6199 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()));
6201 connect(quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
6204 // ============================================================== updateHelpFileName
6205 void QuadRevolutionDialog::updateHelpFileName()
6207 if ( sender() == revolutionUni_rb ){
6208 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutionuniform";
6209 } else if ( sender() == revolution_rb ){
6210 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutioncustom";
6214 // ============================================================== clear
6215 void QuadRevolutionDialog::clear()
6218 modelUnregister(quads_lw);
6221 modelUnregister(center_le);
6224 modelUnregister(axis_le);
6226 modelUnregister(this);
6229 // ============================================================== addAngleItem
6230 void QuadRevolutionDialog::addAngleItem() //CS_TODO
6232 QListWidgetItem* previousItem = angles_lw->currentItem();
6233 QListWidgetItem* newItem = new QListWidgetItem();
6235 double defaultValue = 180.;
6237 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6239 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6240 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6241 angles_lw->addItem(newItem);
6246 // ============================================================== delAngleItem
6247 void QuadRevolutionDialog::delAngleItem()
6249 delete angles_lw->currentItem();
6253 // ============================================================== delQuadItem
6254 void QuadRevolutionDialog::delQuadItem()
6256 delete quads_lw->currentItem();
6260 // ============================================================== apply
6261 bool QuadRevolutionDialog::apply(QModelIndex& result)
6263 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6266 DocumentModel* docModel = getDocumentModel();
6267 PatternDataModel* patternDataModel = getPatternDataModel();
6268 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6270 QListWidgetItem* item = NULL;
6272 QModelIndexList istartquads;
6274 int nbQuads = quads_lw->count();
6275 for ( int r = 0; r < nbQuads; ++r){
6276 item = quads_lw->item(r);
6277 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6278 if ( iquad.isValid() )
6279 istartquads << iquad;
6282 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6283 QModelIndex iaxis = patternDataModel->mapToSource(_index[axis_le]);
6284 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
6285 int angle = angle_spb->value();
6286 int nbre = nbre_spb->value();
6288 vector<double> angles;
6289 int nbAngles = angles_lw->count();
6290 for ( int r = 0; r < nbAngles; ++r){
6291 item = angles_lw->item(r);
6292 angles.push_back(item->data(Qt::EditRole).toDouble());
6295 QModelIndex iElts; //result
6296 if (nbQuads == 1 && istartquads[0].isValid() && icenter.isValid() && iaxis.isValid())
6298 if (revolutionUni_rb->isChecked())
6299 iElts = docModel->revolutionQuadUni(istartquads[0], icenter, iaxis, angle, nbre);
6300 else if (revolution_rb->isChecked())
6301 iElts = docModel->revolutionQuad(istartquads[0], icenter, iaxis, angles);
6303 else if (nbQuads > 1 && icenter.isValid() && iaxis.isValid())
6305 if (revolutionUni_rb->isChecked())
6306 iElts = docModel->revolutionQuadsUni(istartquads, icenter, iaxis, angle, nbre);
6307 else if (revolution_rb->isChecked())
6308 iElts = docModel->revolutionQuads(istartquads, icenter, iaxis, angles);
6311 if ( !iElts.isValid() ){
6312 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD REVOLUTION" ) + "\n" + getErrorMsg() );
6315 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6316 result = patternDataModel->mapFromSource(iElts);
6317 // result = patternBuilderModel->mapFromSource(iElts);
6322 // ------------------------- MakeHemiSphereDialog ----------------------------------
6323 // ============================================================== Constructeur
6324 MakeHemiSphereDialog::MakeHemiSphereDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
6325 HexaBaseDialog(parent, editmode, f)
6327 _helpFileName = "gui_hemisphere.html";
6329 _initWidget(editmode);
6332 connect( sphereTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6333 connect( sphereUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6334 connect( sphere2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6335 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6336 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6338 connect( sphericalTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6339 connect( sphericalUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6340 connect( spherical2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6341 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6342 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6344 connect( rindTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6345 connect( rindUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6346 connect( rind2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6347 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6348 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6351 // ============================================================== Destructeur
6352 MakeHemiSphereDialog::~MakeHemiSphereDialog()
6356 // ============================================================== _initInputWidget
6357 void MakeHemiSphereDialog::_initInputWidget( Mode editmode )
6359 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6360 hole_axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6361 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6362 vplan_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6364 sphere_radext_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6365 sphere_radext_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6366 sphere_radext_spb->setProperty("Radius", QVariant::fromValue(true));
6368 sphere_radint_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6369 sphere_radint_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6370 sphere_radint_spb->setProperty("Radius", QVariant::fromValue(true));
6372 hole_rad_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6373 hole_rad_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6374 hole_rad_spb->setProperty("Radius", QVariant::fromValue(true));
6376 radial_angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6377 radial_angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6378 radial_angle_spb->setProperty("Angle", QVariant::fromValue(true));
6380 radius_lw_1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6381 radius_lw_1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6382 radius_lw_1->setProperty("Radius", QVariant::fromValue(true));
6384 radius_lw_2->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6385 radius_lw_2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6386 radius_lw_2->setProperty("Radius", QVariant::fromValue(true));
6388 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6389 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6390 height_lw->setProperty("Length", QVariant::fromValue(true));
6392 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6393 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6394 angle_lw->setProperty("Angle", QVariant::fromValue(true));
6396 installEventFilter(this);
6397 center_le->installEventFilter(this);
6398 hole_axis_le->installEventFilter(this);
6399 base_le->installEventFilter(this);
6400 vplan_le->installEventFilter(this);
6402 sphere_radext_spb->installEventFilter(this);
6403 sphere_radint_spb->installEventFilter(this);
6404 hole_rad_spb->installEventFilter(this);
6405 radial_angle_spb->installEventFilter(this);
6406 radius_lw_1->installEventFilter(this);
6407 radius_lw_2->installEventFilter(this);
6408 height_lw->installEventFilter(this);
6409 angle_lw->installEventFilter(this);
6411 sphere_rb->installEventFilter(this);
6412 sphereTop_rb->installEventFilter(this);
6413 sphereUni_rb->installEventFilter(this);
6414 sphere2_rb->installEventFilter(this);
6415 rind_rb->installEventFilter(this);
6416 rindTop_rb->installEventFilter(this);
6417 rindUni_rb->installEventFilter(this);
6418 rind2_rb->installEventFilter(this);
6419 spherical_rb->installEventFilter(this);
6420 sphericalTop_rb->installEventFilter(this);
6421 sphericalUni_rb->installEventFilter(this);
6422 spherical2_rb->installEventFilter(this);
6424 center_le->setReadOnly(true);
6425 hole_axis_le->setReadOnly(true);
6426 base_le->setReadOnly(true);
6427 vplan_le->setReadOnly(true);
6429 radius_lw_1->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_1));
6430 radius_lw_1->setEditTriggers(QAbstractItemView::DoubleClicked);
6432 radius_lw_2->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_2));
6433 radius_lw_2->setEditTriggers(QAbstractItemView::DoubleClicked);
6435 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
6436 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6438 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
6439 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6441 connect( add_radius_pb_1, SIGNAL(clicked()), this, SLOT(addRadiusItem1()) );
6442 connect( del_radius_pb_1, SIGNAL(clicked()), this, SLOT(delRadiusItem1()) );
6444 connect( add_radius_pb_2, SIGNAL(clicked()), this, SLOT(addRadiusItem2()) );
6445 connect( del_radius_pb_2, SIGNAL(clicked()), this, SLOT(delRadiusItem2()) );
6447 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
6448 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
6450 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
6451 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
6454 // ============================================================== updateHelpFileName
6455 void MakeHemiSphereDialog::updateHelpFileName()
6457 if ( sender() == sphereTop_rb || sender() == rindTop_rb ){
6458 _helpFileName = "gui_hemisphere.html#guisphereandrindsimple";
6459 } else if ( sender() == sphereUni_rb ){
6460 _helpFileName = "gui_hemisphere.html#guisphereuniform";
6461 } else if ( sender() == sphere2_rb ){
6462 _helpFileName = "gui_hemisphere.html#guispherecustom";
6463 } else if ( sender() == rindUni_rb ){
6464 _helpFileName = "gui_hemisphere.html#guirinduniform";
6465 } else if ( sender() == rind2_rb ){
6466 _helpFileName = "gui_hemisphere.html#guirindcustom";
6467 } else if ( sender() == sphericalTop_rb ){
6468 _helpFileName = "gui_hemisphere.html#guiconcentricsimple";
6469 } else if ( sender() == sphericalUni_rb ){
6470 _helpFileName = "gui_hemisphere.html#guiconcentricuniform";
6471 } else if ( sender() == spherical2_rb ){
6472 _helpFileName = "gui_hemisphere.html#guiconcentriccustom";
6476 // ============================================================== addRadiusItem
6477 void MakeHemiSphereDialog::addRadiusItem1()
6479 QListWidgetItem* previousItem = radius_lw_1->currentItem();
6480 QListWidgetItem* newItem = new QListWidgetItem();
6482 double defaultValue = 1.;
6484 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6486 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6487 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6488 radius_lw_1->addItem(newItem);
6491 // ============================================================== delRadiusItem
6492 void MakeHemiSphereDialog::delRadiusItem1()
6494 delete radius_lw_1->currentItem();
6497 // ============================================================== addRadiusItem
6498 void MakeHemiSphereDialog::addRadiusItem2()
6500 QListWidgetItem* previousItem = radius_lw_2->currentItem();
6501 QListWidgetItem* newItem = new QListWidgetItem();
6503 double defaultValue = 1.;
6505 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6507 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6508 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6509 radius_lw_2->addItem(newItem);
6512 // ============================================================== delRadiusItem
6513 void MakeHemiSphereDialog::delRadiusItem2()
6515 delete radius_lw_2->currentItem();
6518 // ============================================================== addAngleItem
6519 void MakeHemiSphereDialog::addAngleItem()
6521 QListWidgetItem* previousItem = angle_lw->currentItem();
6522 QListWidgetItem* newItem = new QListWidgetItem();
6524 double defaultValue = 180.;
6526 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6528 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6529 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6530 angle_lw->addItem(newItem);
6533 // ============================================================== delAngleItem
6534 void MakeHemiSphereDialog::delAngleItem()
6536 delete angle_lw->currentItem();
6539 // ============================================================== addHeightItem
6540 void MakeHemiSphereDialog::addHeightItem()
6542 QListWidgetItem* previousItem = height_lw->currentItem();
6543 QListWidgetItem* newItem = new QListWidgetItem();
6545 double defaultValue = 1.;
6547 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6549 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6550 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6551 height_lw->addItem(newItem);
6554 // ============================================================== delHeightItem
6555 void MakeHemiSphereDialog::delHeightItem()
6557 delete height_lw->currentItem();
6560 // ============================================================== clear
6561 void MakeHemiSphereDialog::clear()
6564 modelUnregister(center_le);
6566 hole_axis_le->clear();
6567 modelUnregister(hole_axis_le);
6570 modelUnregister(base_le);
6573 modelUnregister(vplan_le);
6575 modelUnregister(this);
6578 // ============================================================== apply
6579 bool MakeHemiSphereDialog::apply(QModelIndex& result)
6581 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6584 DocumentModel* docModel = getDocumentModel();
6585 PatternDataModel* patternDataModel = getPatternDataModel();
6586 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6589 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6590 QModelIndex ivplan = patternDataModel->mapToSource( _index[vplan_le] );
6591 QModelIndex ivecx = patternDataModel->mapToSource(_index[base_le]);
6592 QModelIndex ivecz = patternDataModel->mapToSource(_index[hole_axis_le]);
6593 // QModelIndex ivecx = patternBuilderModel->mapToSource( _index[base_le] );
6594 // QModelIndex ivecz = patternBuilderModel->mapToSource( _index[hole_axis_le] );
6596 double radhole = hole_rad_spb->value();
6597 double radext = sphere_radext_spb->value();
6598 double radint = sphere_radint_spb->value();
6599 double radang = radial_angle_spb->value();
6601 int crit = crit_spb->value();
6602 int nb = nbre_spb->value();
6603 int nrad = ngrid_rad_spb->value();
6604 int nang = ngrid_ang_spb->value();
6605 int nhaut = ngrid_height_spb->value();
6607 //radius, angles and heights collection
6608 QListWidgetItem* item = NULL;
6610 vector<double> radius1;
6611 vector<double> radius2;
6612 vector<double> angles;
6613 vector<double> heights;
6616 // double somme = 0.;
6617 int nbAngles = angle_lw->count();
6618 for ( int r = 0; r < nbAngles; ++r){
6619 item = angle_lw->item(r);
6620 double itemValue = item->data(Qt::EditRole).toDouble();
6621 angles.push_back(itemValue);
6622 // somme += itemValue;
6625 //radius1 collection
6626 int nbRadius = radius_lw_1->count();
6627 for ( int r = 0; r < nbRadius; ++r){
6628 item = radius_lw_1->item(r);
6629 radius1.push_back(item->data(Qt::EditRole).toDouble());
6632 //radius2 collection
6633 nbRadius = radius_lw_2->count();
6634 for ( int r = 0; r < nbRadius; ++r){
6635 item = radius_lw_2->item(r);
6636 radius2.push_back(item->data(Qt::EditRole).toDouble());
6639 //heights collection
6640 int nbHeight = height_lw->count();
6641 for ( int r = 0; r < nbHeight; ++r){
6642 item = height_lw->item(r);
6643 heights.push_back(item->data(Qt::EditRole).toDouble());
6646 if (sphere_rb->isChecked())
6648 if (sphereTop_rb->isChecked())
6649 iElts = docModel->makeSphereTop( nrad, nang, nhaut );
6650 else if (sphereUni_rb->isChecked())
6652 if (icenter.isValid() && ivplan.isValid() && ivecx.isValid() && ivecz.isValid())
6653 iElts = docModel->makeSphereUni(icenter, ivecx, ivecz, radhole, radext, radang,
6654 ivplan, nrad, nang, nhaut);
6656 else if (sphere2_rb->isChecked())
6658 // if (somme > 360.01)
6660 // SUIT_MessageBox::information( 0,
6662 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6665 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6666 iElts = docModel->makeSphere(icenter, ivecx, ivecz, radius2, angles, heights);
6669 else if (spherical_rb->isChecked())
6671 if (sphericalTop_rb->isChecked())
6672 iElts = docModel->makeSphericalTop(nb, crit);
6673 else if (sphericalUni_rb->isChecked())
6675 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6676 iElts = docModel->makeSphericalUni(icenter, ivecx, ivecz, radhole, nb, crit);
6678 else if (spherical2_rb->isChecked())
6680 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6681 iElts = docModel->makeSpherical(icenter, ivecx, ivecz, radius1, crit);
6684 else if (rind_rb->isChecked())
6686 if (rindTop_rb->isChecked())
6687 iElts = docModel->makeRindTop(nrad, nang, nhaut);
6688 else if (rindUni_rb->isChecked())
6690 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid() && ivplan.isValid())
6691 iElts = docModel->makeRindUni(icenter, ivecx, ivecz,
6692 radhole, radint, radext, radang,
6693 ivplan, nrad, nang, nhaut);
6695 else if (rind2_rb->isChecked())
6697 // if (somme > 360.01)
6699 // SUIT_MessageBox::information( 0,
6701 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6704 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6705 iElts = docModel->makeRind(icenter, ivecx, ivecz, radius2, angles, heights);
6709 if ( !iElts.isValid() ){
6710 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) + "\n" + getErrorMsg() );
6713 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6714 result = patternDataModel->mapFromSource(iElts);
6715 // result = patternBuilderModel->mapFromSource(iElts);
6720 // ------------------------- ModelInfoDialog ----------------------------------
6721 ModelInfoDialog::ModelInfoDialog(QWidget* parent, Qt::WindowFlags wf):
6722 HexaBaseDialog(parent, INFO_MODE, wf)
6725 setWindowTitle(HEXABLOCKGUI::tr("MODEL_INFO"));
6728 void ModelInfoDialog::updateInfo()
6730 DocumentModel* docModel = getDocumentModel();
6731 if (docModel == NULL) return;
6734 model_name_le->setText(docModel->getName());
6736 //Nb of elements in the model
6737 total_vertices_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_VERTEX)));
6738 total_edges_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_EDGE)));
6739 total_quads_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_QUAD)));
6740 total_hexas_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_HEXA)));
6742 ///Nb of used elements in the model
6743 used_vertices_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_VERTEX)));
6744 used_edges_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_EDGE)));
6745 used_quads_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_QUAD)));
6746 used_hexas_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_HEXA)));
6748 //Nb of unused elements in the model
6749 unused_vertices_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_VERTEX)));
6750 unused_edges_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_EDGE)));
6751 unused_quads_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_QUAD)));
6752 unused_hexas_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_HEXA)));
6755 void ModelInfoDialog::showEvent( QShowEvent * event )
6758 QDialog::showEvent ( event );
6761 // ============================================================== hideEvent
6762 void ModelInfoDialog::hideEvent ( QHideEvent * event )
6764 QDialog::hideEvent( event );
6767 // ------------------------- AddShapeDialog ----------------------------------
6768 AddShapeDialog::AddShapeDialog(QWidget* parent, Mode editmode, Qt::WindowFlags wf):
6769 HexaBaseDialog(parent, editmode, wf)
6771 _helpFileName = "gui_add_geometry.html#guiaddgeometry";
6773 _initWidget(editmode);
6774 setWindowTitle(HEXABLOCKGUI::tr("ADD_SHAPE"));
6777 // ============================================================== Destructeur
6778 AddShapeDialog::~AddShapeDialog()
6780 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
6781 this, SLOT(onCurrentSelectionChanged()) );
6784 // ============================================================== close
6785 void AddShapeDialog::close()
6787 HEXABLOCKGUI::assocInProgress = false;
6788 HexaBaseDialog::close();
6791 // ============================================================== _initInputWidget
6792 void AddShapeDialog::_initInputWidget( Mode editmode )
6794 shape_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMSHAPE_TREE) );
6795 shape_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_SHAPE) );
6796 shape_le->installEventFilter(this);
6797 shape_le->setReadOnly(true);
6800 void AddShapeDialog::clear()
6803 shape_le->setProperty("GeomObj", QVariant());
6805 modelUnregister(this);
6808 // ============================================================== onCurrentSelectionChanged
6809 void AddShapeDialog::onCurrentSelectionChanged()
6811 SALOME_ListIO selectedObjects;
6812 HEXABLOCKGUI::currentDocGView->getSelected(selectedObjects);
6813 if (selectedObjects.IsEmpty())
6816 // * extract the TopoDS_Shape of the selected object
6817 TopoDS_Shape selectedTopoShape = GEOMBase::GetTopoFromSelection( selectedObjects );
6818 if (selectedTopoShape.IsNull())
6820 shape_le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(selectedTopoShape));
6822 // * extract the name of the selected shape
6824 GEOMBase::GetNameOfSelectedIObjects( selectedObjects, name, true );
6825 shape_le->setText(name);
6828 // ============================================================== onWindowActivated
6829 void AddShapeDialog::onWindowActivated(SUIT_ViewManager* vm)
6831 QString vmType = vm->getType();
6832 if ( vmType == OCCViewer_Viewer::Type() )
6833 shape_le->setFocus();
6836 // ============================================================== apply
6837 bool AddShapeDialog::apply(QModelIndex& result)
6840 QString shapeName = shape_le->text();
6841 QVariant v = shape_le->property("TopoDS_Shape");
6842 if ( !v.isValid() || shapeName.isEmpty())
6846 TopoDS_Shape shape = v.value<TopoDS_Shape>();
6850 assocOk = getDocumentModel()->addShape(shape, shapeName);
6854 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), HEXABLOCKGUI::tr("ADD_SHAPE_FAILED") + "\n" + getErrorMsg() );