1 // Copyright (C) 2009-2016 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 if ( _editMode == INFO_MODE )
801 getDocumentModel()->allowEdition();
803 getDocumentModel()->disallowEdition();
805 //Connect to salome selection signals
806 if (HEXABLOCKGUI::selectionMgr() != NULL)
808 connect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
809 this, SLOT(onCurrentSelectionChanged()), Qt::UniqueConnection );
812 //connect model selection signals
813 connectDocumentGraphicView();
815 QDialog::showEvent ( event );
819 // ============================================================== hideEvent
820 void HexaBaseDialog::hideEvent ( QHideEvent * event )
822 //Disconnection salome selection signals
823 if (HEXABLOCKGUI::selectionMgr() != NULL)
824 disconnect( HEXABLOCKGUI::selectionMgr() , SIGNAL(currentSelectionChanged()),
825 this, SLOT(onCurrentSelectionChanged()) );
827 //Disconnect vtk window activation signals
828 // if (HEXABLOCKGUI::currentDocGView->getViewWindow() != NULL)
829 // disconnect( HEXABLOCKGUI::currentDocGView->getViewWindow()->getViewManager(),
830 // SIGNAL( activated(SUIT_ViewManager*) ),
831 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
833 //Disconnect occ window activation signals
834 // if (HEXABLOCKGUI::currentOccGView->getViewWindow() != NULL)
835 // disconnect( HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager(),
836 // SIGNAL( activated(SUIT_ViewManager*) ),
837 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
839 //Disconnect model selection signals
840 disconnectDocumentGraphicView();
841 getDocumentModel()->allowEdition();
843 QDialog::hideEvent( event );
846 // ============================================================== updateButtonBox
847 void HexaBaseDialog::updateButtonBox()
851 // ============================================================== updateName
852 void HexaBaseDialog::updateName()
854 const PatternDataModel* patternDataModel = getPatternDataModel();
856 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(sender());
857 if (!lineEdit) return;
858 QString newName = lineEdit->text();
859 if ( newName.isEmpty() ) return;
861 QVariant v = lineEdit->property("QModelIndex");
862 if ( !v.isValid() ) return;
864 QModelIndex index = v.value<QModelIndex>();
865 if ( index.isValid() )
866 getDocumentModel()->setName( patternDataModel->mapToSource(index), newName );
869 // ============================================================== updateDefaultName
870 void HexaBaseDialog::updateDefaultName(QLineEdit* name_field, HEXA_NS::EnumElt type)
872 if (name_field == NULL) return;
874 HEXA_NS::Document* doc = getDocumentModel()->getHexaDocument();
875 if (doc == NULL) return;
877 name_field->setText(doc->getNextName(type).c_str());
880 // ============================================================== selectElementOfModel
881 /*Selects in the model (treeview) elements selected in a listwidget,
882 * or an element in a line edit.*/
883 void HexaBaseDialog::selectElementOfModel()
885 if (getPatternDataSelectionModel() == NULL) return;
887 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
888 if ( !currentListWidget ) return;
890 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
892 getPatternDataSelectionModel()->clearSelection();
893 foreach ( QListWidgetItem *item, sel ){
894 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
895 index = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
896 if ( index.isValid() )
897 getPatternDataSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
901 // ============================================================== _isLineOrListWidget
903 * Return true is the widget is a line or a list
906 bool HexaBaseDialog::_isLineOrListWidget(QObject *widget)
908 if (widget == NULL) return false;
910 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(widget);
911 QListWidget *listWidget = dynamic_cast<QListWidget*>(widget);
912 return (lineEdit != NULL) || (listWidget != NULL);
914 }//_isLineOrListWidget
917 // ============================================================== _highlightWidget
919 * Highlight the given widget with the given color.
921 void HexaBaseDialog::_highlightWidget(QObject *obj, Qt::GlobalColor clr)
923 QDoubleSpinBox* spb = dynamic_cast<QDoubleSpinBox*>(obj);
924 if (!_isLineOrListWidget(obj) && spb == NULL)
927 QWidget *widget = dynamic_cast<QWidget*>(obj);
928 QPalette palette1 = widget->palette();
929 palette1.setColor(QPalette::Active, widget->backgroundRole(), clr);
930 widget->setPalette(palette1);
934 // ============================================================== _updateCurrentObject
935 void HexaBaseDialog::_updateCurrentObject(QObject* obj)
937 _highlightWidget(_currentObj, Qt::white);
939 _highlightWidget(obj, Qt::yellow);
942 // ============================================================== eventFilter
944 * Handles events from the treeview and the dialog boxes.
946 bool HexaBaseDialog::eventFilter(QObject *obj, QEvent *event)
948 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(obj);
949 QListWidget *listWidget = dynamic_cast<QListWidget*>(obj);
951 // * Enter key press ------
952 if ( event->type() == QEvent::KeyPress &&
953 ((QKeyEvent*)event)->key() == Qt::Key_Return)
955 setFocusToNextField();
959 // * Focus out from a list widget ------
960 if ( event->type() == QEvent::FocusOut && listWidget != NULL)
962 QItemSelectionModel * selectionModel = listWidget->selectionModel();
963 selectionModel->clearSelection();
966 if ( event->type() != QEvent::FocusIn )
970 HEXABLOCKGUI::ViewType vtype = getObjectViewType(obj);
971 if (vtype == HEXABLOCKGUI::VTK_OCC)
973 _allowVTKSelection(obj);
974 _allowOCCSelection(obj);
976 else if (vtype == HEXABLOCKGUI::VTK)
977 _allowVTKSelection( obj );
978 else if (vtype == HEXABLOCKGUI::OCC)
979 _allowOCCSelection( obj );
981 //Depending on the focused widget type, get the right selector for it
984 QItemSelectionModel* selector = _getSelector( obj );
985 if ( selector == NULL )
987 _updateCurrentObject(obj);
991 if ( _currentObj != obj && (lineEdit == NULL || listWidget == NULL) )
992 selector->clearSelection();
994 _updateCurrentObject(obj);
996 //If the widget contains an element, select it in model/view
997 if ( lineEdit != NULL ){ //element can be from lineEdit
998 v = lineEdit->property("HexaData");
1000 return QObject::eventFilter(obj, event);
1001 index = ((SelectionModel*)selector)->indexBy( HEXA_DATA_ROLE, v);
1002 if (index.isValid())
1003 selector->select( index, QItemSelectionModel::SelectCurrent );
1006 return QObject::eventFilter(obj, event);
1009 // ------------------------- VERTEX ----------------------------------
1010 // ============================================================== Constructeur
1011 VertexDialog::VertexDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1012 HexaBaseDialog(parent, editmode, f),
1015 _helpFileName = "gui_vertex.html";
1017 _initWidget(editmode);
1019 if ( editmode == NEW_MODE ){
1020 setWindowTitle( tr("Vertex Construction") );
1021 } else if ( editmode == UPDATE_MODE ){
1022 setWindowTitle( tr("Vertex Modification") );
1024 else if ( editmode == INFO_MODE){
1025 setWindowTitle( tr("Vertex Information") );
1029 // ============================================================== Destructeur
1030 VertexDialog::~VertexDialog()
1034 // ============================================================== _initInputWidget
1035 void VertexDialog::_initInputWidget( Mode editmode )
1037 // x_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1038 // y_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1039 // z_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1040 QDoubleValidator *doubleValidator = new QDoubleValidator(widget_2);
1041 x_spb->setValidator(doubleValidator);
1042 y_spb->setValidator(doubleValidator);
1043 z_spb->setValidator(doubleValidator);
1045 // setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1046 installEventFilter(this);
1047 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1048 name_le->installEventFilter(this);
1050 if (editmode == INFO_MODE)
1052 name_le->setReadOnly(true);
1053 x_spb->setReadOnly(true);
1054 y_spb->setReadOnly(true);
1055 z_spb->setReadOnly(true);
1058 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
1061 // ============================================================== clear
1062 void VertexDialog::clear()
1066 modelUnregister(this);
1069 // ============================================================== setValue
1070 void VertexDialog::setValue(HEXA_NS::Vertex* v)
1073 name_le->setText( v->getName() );
1076 // x_spb->setValue( v->getX() );
1077 // y_spb->setValue( v->getY() );
1078 // z_spb->setValue( v->getZ() );
1079 x_spb->setText( QString::number(v->getX()) );
1080 y_spb->setText( QString::number(v->getY()) );
1081 z_spb->setText( QString::number(v->getZ()) );
1083 if ( getPatternDataSelectionModel() != NULL ){
1084 QModelIndex iv = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1086 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1087 name_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1092 // ============================================================== getValue
1093 HEXA_NS::Vertex* VertexDialog::getValue()
1099 // ============================================================== apply
1100 bool VertexDialog::apply(QModelIndex& result)
1102 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1105 if ( !getDocumentModel() ) return false;
1106 if ( !getPatternDataSelectionModel() ) return false;
1107 const PatternDataModel* patternDataModel = getPatternDataModel();
1108 if ( !patternDataModel ) return false;
1110 QModelIndex iVertex;
1112 QString xStr = x_spb->text();
1113 QString yStr = y_spb->text();
1114 QString zStr = z_spb->text();
1115 bool isOk = false, validArgs = !xStr.isEmpty() && !yStr.isEmpty() && !zStr.isEmpty();
1117 double newX, newY, newZ;
1120 newX = xStr.toDouble();
1121 newY = yStr.toDouble();
1122 newZ = zStr.toDouble();
1125 if ( _editMode == UPDATE_MODE && validArgs){
1126 QVariant v = property("QModelIndex");
1128 iVertex = patternDataModel->mapToSource( v.value<QModelIndex>() );
1129 if ( iVertex.isValid() )
1130 isOk = getDocumentModel()->updateVertex( iVertex, newX, newY, newZ );
1132 } else if ( _editMode == NEW_MODE && validArgs){
1133 iVertex = getDocumentModel()->addVertex( newX, newY, newZ );
1134 if ( iVertex.isValid() )
1138 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "VERTEX UPDATE/CONSTRUCTION" ) + "\n" + getErrorMsg() );
1142 QString newName = name_le->text();
1143 if ( !newName.isEmpty() )
1144 getDocumentModel()->setName( iVertex, newName );
1146 //the default name in the dialog box
1147 HEXA_NS::Vertex* v = getDocumentModel()->getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1149 updateDefaultName(name_le, v->getType());
1151 // to select/highlight result
1152 result = patternDataModel->mapFromSource(iVertex);
1157 // ------------------------- EDGE ----------------------------------
1159 // ============================================================== Constructeur
1160 EdgeDialog::EdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1161 HexaBaseDialog(parent, editmode, f),
1164 _helpFileName = "gui_edge.html";
1166 _initWidget(editmode);
1168 if ( editmode == INFO_MODE ){
1169 setWindowTitle( tr("Edge Information") );
1172 else if ( editmode == UPDATE_MODE ){
1173 setWindowTitle( tr("Edge Modification") );
1179 // ============================================================== Destructeur
1180 EdgeDialog::~EdgeDialog()
1185 // ============================================================== _initInputWidget
1186 void EdgeDialog::_initInputWidget( Mode editmode )
1189 QValidator *validator = new QRegExpValidator(rx, this);
1191 // setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1192 installEventFilter(this);
1194 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1195 name_le->installEventFilter(this);
1197 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1198 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1199 v0_le_rb0->setValidator( validator );
1200 v1_le_rb0->setValidator( validator );
1201 v0_le_rb0->installEventFilter(this);
1202 v1_le_rb0->installEventFilter(this);
1204 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1205 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1206 vex_le_rb1->setValidator( validator );
1207 vec_le_rb1->setValidator( validator );
1208 vex_le_rb1->installEventFilter(this);
1209 vec_le_rb1->installEventFilter(this);
1211 v0_le_rb0->setReadOnly(true);
1212 v1_le_rb0->setReadOnly(true);
1213 vex_le_rb1->setReadOnly(true);
1214 vec_le_rb1->setReadOnly(true);
1216 if (editmode == INFO_MODE)
1217 name_le->setReadOnly(true);
1221 // ============================================================== Clear
1222 void EdgeDialog::clear()
1227 modelUnregister(v0_le_rb0);
1230 modelUnregister(v1_le_rb0);
1232 vex_le_rb1->clear();
1233 modelUnregister(vex_le_rb1);
1235 vec_le_rb1->clear();
1236 modelUnregister(vec_le_rb1);
1238 modelUnregister(this);
1241 // ============================================================== setValue
1242 void EdgeDialog::setValue(HEXA_NS::Edge* e)
1244 HEXA_NS::Vertex* v0 = e->getVertex(0);
1245 HEXA_NS::Vertex* v1 = e->getVertex(1);
1247 name_le->setText( e->getName() );
1248 v0_le_rb0->setText( v0->getName() );
1249 v1_le_rb0->setText( v1->getName() );
1251 if ( getPatternDataSelectionModel() ){
1252 QModelIndex ie = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e) );
1253 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1254 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1256 name_le->setProperty( "QModelIndex", QVariant::fromValue(ie) );
1257 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1258 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1263 // ============================================================== getValue
1264 HEXA_NS::Edge* EdgeDialog::getValue()
1269 // ============================================================== apply
1270 bool EdgeDialog::apply(QModelIndex& result)
1272 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1275 if ( !getDocumentModel() ) return false;
1276 const PatternDataModel* patternDataModel = getPatternDataModel();
1277 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1278 if ( !patternDataModel /*|| !patternBuilderModel*/ ) return false;
1282 if ( rb0->isChecked() ){
1283 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1284 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1285 if ( iv0.isValid()&& iv1.isValid() ){
1286 iEdge = getDocumentModel()->addEdgeVertices( iv0, iv1 );
1288 } else if ( rb1->isChecked() ){
1289 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
1290 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb1] );
1291 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
1292 if ( ivex.isValid() && ivec.isValid() ){
1293 iEdge = getDocumentModel()->addEdgeVector( ivex, ivec );
1297 if ( !iEdge.isValid() ){
1298 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD EDGE" ) + "\n" + getErrorMsg() );
1301 _value = iEdge.model()->data(iEdge, HEXA_DATA_ROLE).value<HEXA_NS::Edge*>();
1303 QString newName = name_le->text();
1304 if ( !newName.isEmpty() )/*{*/
1305 getDocumentModel()->setName( iEdge, newName );
1307 //update the default name in the dialog box
1309 updateDefaultName(name_le, _value->getType());
1311 result = patternDataModel->mapFromSource(iEdge);
1316 // ------------------------- QUAD ----------------------------------
1318 // ============================================================== Constructeur
1319 QuadDialog::QuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1320 HexaBaseDialog(parent, editmode, f),
1323 _helpFileName = "gui_quadrangle.html";
1325 _initWidget(editmode);
1328 if ( editmode == INFO_MODE ){
1329 setWindowTitle( tr("Quad Information") );
1333 // ============================================================== Destructeur
1334 QuadDialog::~QuadDialog()
1338 // ============================================================== _initInputWidget
1339 void QuadDialog::_initInputWidget( Mode editmode )
1342 QValidator *validator = new QRegExpValidator(rx, this);
1344 installEventFilter(this);
1345 name_le->installEventFilter(this);
1347 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1348 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1349 v2_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1350 v3_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1352 v0_le_rb0->setValidator( validator );
1353 v1_le_rb0->setValidator( validator );
1354 v2_le_rb0->setValidator( validator );
1355 v3_le_rb0->setValidator( validator );
1356 v0_le_rb0->installEventFilter(this);
1357 v1_le_rb0->installEventFilter(this);
1358 v2_le_rb0->installEventFilter(this);
1359 v3_le_rb0->installEventFilter(this);
1361 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1362 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1363 e2_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1364 e3_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1366 e0_le_rb1->setValidator( validator );
1367 e1_le_rb1->setValidator( validator );
1368 e2_le_rb1->setValidator( validator );
1369 e3_le_rb1->setValidator( validator );
1371 e0_le_rb1->installEventFilter(this);
1372 e1_le_rb1->installEventFilter(this);
1373 e2_le_rb1->installEventFilter(this);
1374 e3_le_rb1->installEventFilter(this);
1376 v0_le_rb0->setReadOnly(true);
1377 v1_le_rb0->setReadOnly(true);
1378 v2_le_rb0->setReadOnly(true);
1379 v3_le_rb0->setReadOnly(true);
1381 e0_le_rb1->setReadOnly(true);
1382 e1_le_rb1->setReadOnly(true);
1383 e2_le_rb1->setReadOnly(true);
1384 e3_le_rb1->setReadOnly(true);
1386 if (editmode == INFO_MODE)
1387 name_le->setReadOnly(true);
1390 // ============================================================== clear
1391 void QuadDialog::clear()
1393 //Clear the dialog and unregister it from the model
1394 QModelIndex invalidIndex;
1399 modelUnregister(v0_le_rb0);
1402 modelUnregister(v1_le_rb0);
1405 modelUnregister(v2_le_rb0);
1408 modelUnregister(v3_le_rb0);
1411 modelUnregister(e0_le_rb1);
1414 modelUnregister(e1_le_rb1);
1417 modelUnregister(e2_le_rb1);
1420 modelUnregister(e3_le_rb1);
1422 modelUnregister(this);
1426 // ============================================================== setValue
1427 void QuadDialog::setValue(HEXA_NS::Quad* q)
1429 Q_ASSERT( q->countEdge() == 4 );
1430 Q_ASSERT( q->countVertex() == 4 );
1433 name_le->setText( q->getName() );
1436 HEXA_NS::Vertex* v0 = q->getVertex(0);
1437 HEXA_NS::Vertex* v1 = q->getVertex(1);
1438 HEXA_NS::Vertex* v2 = q->getVertex(2);
1439 HEXA_NS::Vertex* v3 = q->getVertex(3);
1441 v0_le_rb0->setText( v0->getName() );
1442 v1_le_rb0->setText( v1->getName() );
1443 v2_le_rb0->setText( v2->getName() );
1444 v3_le_rb0->setText( v3->getName() );
1448 HEXA_NS::Edge* e0 = q->getEdge(0);
1449 HEXA_NS::Edge* e1 = q->getEdge(1);
1450 HEXA_NS::Edge* e2 = q->getEdge(2);
1451 HEXA_NS::Edge* e3 = q->getEdge(3);
1453 e0_le_rb1->setText( e0->getName() );
1454 e1_le_rb1->setText( e1->getName() );
1455 e2_le_rb1->setText( e2->getName() );
1456 e3_le_rb1->setText( e3->getName() );
1458 if ( getPatternDataSelectionModel() ){
1459 QModelIndex iq = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(q) );
1461 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1462 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1463 QModelIndex iv2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v2) );
1464 QModelIndex iv3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v3) );
1466 QModelIndex ie0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e0) );
1467 QModelIndex ie1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e1) );
1468 QModelIndex ie2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e2) );
1469 QModelIndex ie3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e3) );
1471 name_le->setProperty( "QModelIndex", QVariant::fromValue(iq) );
1473 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1474 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1475 v2_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv2) );
1476 v3_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv3) );
1478 e0_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie0) );
1479 e1_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie1) );
1480 e2_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie2) );
1481 e3_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie3) );
1487 // ============================================================== getValue
1488 HEXA_NS::Quad* QuadDialog::getValue()
1494 // ============================================================== apply
1495 bool QuadDialog::apply(QModelIndex& result)
1497 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1500 if ( !getDocumentModel() ) return false;
1501 const PatternDataModel* patternDataModel = getPatternDataModel();
1502 if ( !patternDataModel ) return false;
1506 if ( rb0->isChecked() ){ //vertices
1507 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1508 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1509 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb0] );
1510 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb0] );
1516 iQuad = getDocumentModel()->addQuadVertices( iv0, iv1, iv2, iv3 );
1518 } else if ( rb1->isChecked() ){ //edges
1519 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
1520 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
1521 QModelIndex ie2 = patternDataModel->mapToSource( _index[e2_le_rb1] );
1522 QModelIndex ie3 = patternDataModel->mapToSource( _index[e3_le_rb1] );
1528 iQuad = getDocumentModel()->addQuadEdges( ie0, ie1, ie2, ie3 );
1532 if ( !iQuad.isValid() ){
1533 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD QUAD" ) + "\n" + getErrorMsg());
1536 _value = iQuad.model()->data(iQuad, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1538 QString newName = name_le->text();
1539 if ( !newName.isEmpty() )/*{*/
1540 getDocumentModel()->setName( iQuad, newName );
1542 //the default name in the dialog box
1544 updateDefaultName(name_le, _value->getType());
1546 // to select/highlight result
1547 result = patternDataModel->mapFromSource(iQuad);
1553 // ------------------------- HEXA ----------------------------------
1555 // ============================================================== HexaDialog
1557 HexaDialog::HexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1558 HexaBaseDialog(parent, editmode, f),
1561 _helpFileName = "gui_hexahedron.html";
1563 _initWidget(editmode);
1566 if ( editmode == INFO_MODE ){
1567 setWindowTitle( tr("Hexahedron Information") );
1568 quads_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
1569 vertices_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
1573 // ============================================================== Destructeur
1574 HexaDialog::~HexaDialog()
1578 // ============================================================== _initInputWidget
1579 void HexaDialog::_initInputWidget( Mode editmode )
1583 installEventFilter(this);
1584 name_le->installEventFilter(this);
1586 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
1587 quads_lw->installEventFilter(this);
1589 vertices_lw->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1590 vertices_lw->installEventFilter(this);
1592 if ( editmode != INFO_MODE ) {
1593 // delete item from listwidget
1594 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
1595 QShortcut* delVertexShortcut = new QShortcut( QKeySequence(Qt::Key_X), vertices_lw );
1596 delQuadShortcut->setContext( Qt::WidgetShortcut );
1597 delVertexShortcut->setContext( Qt::WidgetShortcut );
1598 connect(delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()));
1599 connect(delVertexShortcut, SIGNAL(activated()), this, SLOT(deleteVertexItem()));
1601 // highlight item on model view (VTK) from listwidget
1602 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1603 connect( vertices_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1605 if ( editmode != INFO_MODE)
1607 connect( vertices_rb, SIGNAL(clicked()), vertices_lw, SLOT(setFocus()));
1608 connect( quads_rb, SIGNAL(clicked()), quads_lw, SLOT(setFocus()));
1611 connect( vertices_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1612 connect( quads_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1614 if (editmode == INFO_MODE)
1615 name_le->setReadOnly(true);
1618 // ============================================================== clear
1619 void HexaDialog::clear()
1624 modelUnregister(quads_lw);
1626 vertices_lw->clear();
1627 modelUnregister(vertices_lw);
1629 modelUnregister(this);
1632 // ============================================================== getAssocsVTK
1634 * Returns elements currently associated to vtk
1636 QModelIndexList HexaDialog::getAssocsVTK()
1638 QModelIndexList assocs;
1639 QModelIndex iQuad, iVertex;
1640 QListWidgetItem* item = NULL;
1642 const PatternDataModel* patternDataModel = getPatternDataModel();
1643 if (patternDataModel == NULL) return assocs;
1644 if (quads_rb->isChecked())
1646 //ListWidget content
1647 int nbQuads = quads_lw->count();
1648 for ( int r = 0; r < nbQuads; ++r ){
1649 item = quads_lw->item(r);
1650 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1651 if ( iQuad.isValid() )
1656 else if (vertices_rb->isChecked())
1658 //ListWidget content
1659 int nbVertices = vertices_lw->count();
1660 for ( int r = 0; r < nbVertices; ++r ){
1661 item = vertices_lw->item(r);
1662 iVertex = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1663 if ( iVertex.isValid() )
1672 // ============================================================== updateButtonBox
1673 void HexaDialog::updateButtonBox()
1675 if ( _editMode == INFO_MODE )
1678 if ( quads_rb->isChecked() ){ // build from quads count() must be between [2,6]
1679 int nbQuads = quads_lw->count();
1680 if ( nbQuads >= 2 && nbQuads <= 6 ){
1681 _applyButton->setEnabled(true);
1683 _applyButton->setEnabled(false);
1685 } else if ( vertices_rb->isChecked() ){ // build from vertices count() must be equals to 8
1686 int nbVertices = vertices_lw->count();
1687 if ( nbVertices == 8 ){
1688 _applyButton->setEnabled(true);
1690 _applyButton->setEnabled(false);
1695 // ============================================================== deleteQuadItem
1696 void HexaDialog::deleteQuadItem()
1698 delete quads_lw->currentItem();
1702 // ============================================================== deleteVertexItem
1703 void HexaDialog::deleteVertexItem()
1705 delete vertices_lw->currentItem();
1709 // ============================================================== _setValueQuads
1710 void HexaDialog::_setValueQuads( HEXA_NS::Hexa* h )
1712 QListWidgetItem *qItem = NULL;
1713 HEXA_NS::Quad *q = NULL;
1715 if (getPatternDataSelectionModel() == NULL) return;
1717 for( int i = 0; i <= 5; ++i ){
1719 qIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(q)) );
1720 qItem = new QListWidgetItem( q->getName() );
1721 qItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(qIndex) );
1722 qItem->setData(LW_DATA_ROLE, qIndex.data(HEXA_DATA_ROLE));
1723 quads_lw->addItem( qItem );
1727 // ============================================================== _setValueVertices
1728 void HexaDialog::_setValueVertices( HEXA_NS::Hexa* h )
1730 QListWidgetItem *vItem = NULL;
1731 HEXA_NS::Vertex* v = NULL;
1733 if (getPatternDataSelectionModel() == NULL) return;
1734 vertices_lw->clear();
1735 for( int i = 0; i <= 7; ++i ){
1736 v = h->getVertex(i);
1737 vIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(v)) );
1738 vItem = new QListWidgetItem( v->getName() );
1739 vItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(vIndex) );
1740 vItem->setData(LW_DATA_ROLE, vIndex.data(HEXA_DATA_ROLE));
1741 vertices_lw->addItem( vItem );
1745 // ============================================================== setValue
1746 void HexaDialog::setValue(HEXA_NS::Hexa* h)
1749 name_le->setText( h->getName() );
1751 if ( getPatternDataSelectionModel()){
1752 QModelIndex hIndex = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(h) );
1753 _setValueVertices(h);
1755 name_le->setProperty( "QModelIndex", QVariant::fromValue(hIndex) );
1760 // ============================================================== getValue
1761 HEXA_NS::Hexa* HexaDialog::getValue()
1766 // ============================================================== apply
1767 bool HexaDialog::apply(QModelIndex& result)
1769 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1772 if ( !getDocumentModel() ) return false;
1773 const PatternDataModel* patternDataModel = getPatternDataModel();
1774 if ( !patternDataModel ) return false;
1778 QListWidget* currentLw = NULL;
1779 QListWidgetItem* item = NULL;
1781 if ( quads_rb->isChecked() )
1782 currentLw = dynamic_cast<QListWidget*>( quads_lw );
1783 else if ( vertices_rb->isChecked() )
1784 currentLw = dynamic_cast<QListWidget*>( vertices_lw );
1787 QModelIndexList iElts;
1788 int nbItems = currentLw->count();
1789 for ( int r = 0; r < nbItems; ++r){
1790 item = currentLw->item(r);
1791 iElt = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1792 if ( iElt.isValid() )
1796 nbItems = iElts.count();
1797 if ( quads_rb->isChecked() && (nbItems>=2 && nbItems<=6) ){ // build from quads iElts.count() should be between [2,6]
1798 iHexa = getDocumentModel()->addHexaQuads( iElts );
1799 } else if ( vertices_rb->isChecked() && nbItems== 8 ){ // build from vertices
1800 iHexa = getDocumentModel()->addHexaVertices( iElts[0], iElts[1], iElts[2], iElts[3],
1801 iElts[4], iElts[5], iElts[6], iElts[7] );
1804 if ( !iHexa.isValid() ){
1805 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD HEXA" ) + "\n" + getErrorMsg() );
1808 _value = iHexa.model()->data(iHexa, HEXA_DATA_ROLE).value<HEXA_NS::Hexa*>();
1810 QString newName = name_le->text();
1811 if ( !newName.isEmpty() )/*{*/
1812 getDocumentModel()->setName( iHexa, newName );
1814 //update the default name in the dialog box
1816 updateDefaultName(name_le, _value->getType());
1818 // to select/highlight result
1819 result = patternDataModel->mapFromSource(iHexa);
1825 // ------------------------- VECTOR ----------------------------------
1827 // ============================================================== Constructeur
1829 VectorDialog::VectorDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1830 HexaBaseDialog(parent, editmode, f),
1833 _helpFileName = "gui_vector.html";
1835 _initWidget(editmode);
1839 if ( editmode == INFO_MODE ){
1840 setWindowTitle( tr("Vector Information") );
1845 // ============================================================== Destructeur
1846 VectorDialog::~VectorDialog()
1850 // ============================================================== _initInputWidget
1851 void VectorDialog::_initInputWidget( Mode editmode )
1854 QValidator *validator = new QRegExpValidator(rx, this);
1856 installEventFilter(this);
1857 name_le->installEventFilter(this);
1859 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1860 v0_le_rb1->setValidator( validator );
1861 v0_le_rb1->installEventFilter(this);
1863 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1864 v1_le_rb1->setValidator( validator );
1865 v1_le_rb1->installEventFilter(this);
1867 if ( editmode == INFO_MODE ){
1868 name_le->setReadOnly(true);
1869 dx_spb_rb0->setReadOnly(true);
1870 dy_spb_rb0->setReadOnly(true);
1871 dz_spb_rb0->setReadOnly(true);
1874 v0_le_rb1->setReadOnly(true);
1875 v1_le_rb1->setReadOnly(true);
1878 // ============================================================== clear
1879 void VectorDialog::clear()
1883 modelUnregister(v0_le_rb1);
1886 modelUnregister(v1_le_rb1);
1888 modelUnregister(this);
1891 // ============================================================== setValue
1892 void VectorDialog::setValue(HEXA_NS::Vector* v)
1894 name_le->setText( v->getName() );
1895 dx_spb_rb0->setValue( v->getDx() );
1896 dy_spb_rb0->setValue( v->getDy() );
1897 dz_spb_rb0->setValue( v->getDz() );
1899 if ( getPatternDataSelectionModel() ){
1900 QModelIndex ivec = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1901 name_le->setProperty( "QModelIndex", QVariant::fromValue(ivec) );
1906 // ============================================================== getValue
1907 HEXA_NS::Vector* VectorDialog::getValue()
1912 // ============================================================== apply
1913 bool VectorDialog::apply(QModelIndex& result)
1915 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1918 if ( !getDocumentModel() ) return false;
1919 const PatternDataModel* patternDataModel = getPatternDataModel();
1920 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1921 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
1923 QModelIndex iVector;
1925 if ( rb0->isChecked() ){ //scalar
1926 double dx = dx_spb_rb0->value();
1927 double dy = dy_spb_rb0->value();
1928 double dz = dz_spb_rb0->value();
1930 iVector = getDocumentModel()->addVector( dx, dy, dz );
1931 } else if ( rb1->isChecked() ){ //vertices
1932 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
1933 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
1937 iVector = getDocumentModel()->addVectorVertices( iv0, iv1 );
1941 if ( !iVector.isValid() ){
1942 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD VECTOR" ) + "\n" + getErrorMsg());
1946 _value = iVector.model()->data(iVector, HEXA_DATA_ROLE).value<HEXA_NS::Vector *>();
1948 QString newName = name_le->text();
1949 if ( !newName.isEmpty() )/*{*/
1950 getDocumentModel()->setName( iVector, newName );
1952 //update the default name in the dialog box
1954 updateDefaultName(name_le, _value->getType());
1956 // to select/highlight result
1957 result = patternDataModel->mapFromSource(iVector);
1958 // result = patternBuilderModel->mapFromSource(iVector);
1963 // ------------------------- MakeGridDialog ----------------------------------
1964 // ============================================================== Constructeur
1966 MakeGridDialog::MakeGridDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
1967 : HexaBaseDialog(parent, editmode, f)
1970 _initWidget(editmode);
1973 _helpFileName = "creategrids.html#guicartgridsimple";
1974 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1975 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1976 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1978 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1979 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1980 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1982 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1983 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1984 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1987 // ============================================================== Destructeur
1988 MakeGridDialog::~MakeGridDialog()
1992 // ============================================================== _initInputWidget
1993 void MakeGridDialog::_initInputWidget( Mode editmode )
1995 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1996 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1997 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1998 vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2000 center_le->setReadOnly(true);
2001 axis_le->setReadOnly(true);
2002 base_le->setReadOnly(true);
2003 vec_le->setReadOnly(true);
2005 installEventFilter(this);
2006 center_le->installEventFilter(this);
2007 axis_le->installEventFilter(this);
2008 base_le->installEventFilter(this);
2009 vec_le->installEventFilter(this);
2011 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2012 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2014 angle_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(angle_lw));
2015 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2017 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2018 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2020 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2021 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2023 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2024 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2026 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2027 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2030 // ============================================================== clear
2031 void MakeGridDialog::clear()
2034 modelUnregister(center_le);
2037 modelUnregister(axis_le);
2040 modelUnregister(base_le);
2043 modelUnregister(vec_le);
2045 modelUnregister(this);
2048 // ============================================================== updateHelpFileName
2049 void MakeGridDialog::updateHelpFileName()
2051 if ( sender() == rb0 ){
2052 _helpFileName = "creategrids.html#guicartgridsimple";
2053 } else if ( sender() == rb1 ){
2054 _helpFileName = "creategrids.html#guicartgriduniform";
2055 } else if ( sender() == rb2 ){
2056 _helpFileName = "creategrids.html#guicartgridcustom";
2060 // ============================================================== addRadiusItem
2061 void MakeGridDialog::addRadiusItem()
2063 QListWidgetItem* previousItem = radius_lw->currentItem();
2064 QListWidgetItem* newItem = new QListWidgetItem();
2066 double defaultValue = 1.;
2068 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2070 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2071 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2072 radius_lw->addItem(newItem);
2075 // ============================================================== delRadiusItem
2076 void MakeGridDialog::delRadiusItem()
2078 delete radius_lw->currentItem();
2081 // ============================================================== addAngleItem
2082 void MakeGridDialog::addAngleItem()
2084 QListWidgetItem* previousItem = angle_lw->currentItem();
2085 QListWidgetItem* newItem = new QListWidgetItem();
2087 double defaultValue = 1.;
2089 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2091 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2092 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2093 angle_lw->addItem(newItem);
2096 // ============================================================== delAngleItem
2097 void MakeGridDialog::delAngleItem()
2099 delete angle_lw->currentItem();
2102 // ============================================================== addHeightItem
2103 void MakeGridDialog::addHeightItem()
2105 QListWidgetItem* previousItem = height_lw->currentItem();
2106 QListWidgetItem* newItem = new QListWidgetItem();
2108 double defaultValue = 1.;
2110 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2112 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2113 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2114 height_lw->addItem(newItem);
2117 // ============================================================== delHeightItem
2118 void MakeGridDialog::delHeightItem()
2120 delete height_lw->currentItem();
2123 // ============================================================== apply
2124 bool MakeGridDialog::apply(QModelIndex& result)
2126 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2129 DocumentModel* docModel = getDocumentModel();
2130 PatternDataModel* patternDataModel = getPatternDataModel();
2131 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2133 QModelIndex iNewElts;
2134 if ( rb0->isChecked() )
2136 long nx = nx_spb->value();
2137 long ny = ny_spb->value();
2138 long nz = nz_spb->value();
2139 iNewElts = docModel->makeCartesianTop(nx, ny, nz);
2141 else if ( rb1->isChecked() )
2143 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2144 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2145 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2146 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le] );
2147 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2148 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2149 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2151 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2153 double lx = lx_spb->value();
2154 double ly = ly_spb->value();
2155 double lz = lz_spb->value();
2156 double nx = nx_spb->value();
2157 double ny = ny_spb->value();
2158 double nz = nz_spb->value();
2160 iNewElts = docModel->makeCartesianUni( icenter, ibase, ivec, iaxis,
2161 lx, ly, lz, nx, ny, nz);
2164 } else if ( rb2->isChecked() )
2166 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2167 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2168 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2169 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le] );
2170 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2171 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2172 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2174 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2176 QListWidgetItem* item = NULL;
2178 vector<double> radius;
2179 vector<double> angles;
2180 vector<double> heights;
2182 // double somme = 0.;
2183 int nbAngles = angle_lw->count();
2184 for ( int r = 0; r < nbAngles; ++r){
2185 item = angle_lw->item(r);
2186 double itemValue = item->data(Qt::EditRole).toDouble();
2187 angles.push_back(itemValue);
2188 // somme += itemValue;
2190 // if (somme > 360.01)
2192 // SUIT_MessageBox::information( 0,
2194 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2198 int nbRadius = radius_lw->count();
2199 for ( int r = 0; r < nbRadius; ++r){
2200 item = radius_lw->item(r);
2201 radius.push_back(item->data(Qt::EditRole).toDouble());
2204 int nbHeight = height_lw->count();
2205 for ( int r = 0; r < nbHeight; ++r){
2206 item = height_lw->item(r);
2207 heights.push_back(item->data(Qt::EditRole).toDouble());
2210 iNewElts = docModel->makeCartesian( icenter, ibase, ivec, iaxis,
2211 radius, angles, heights);
2215 if ( !iNewElts.isValid() )
2217 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE GRID" ) + "\n" + getErrorMsg() );
2221 result = patternDataModel->mapFromSource(iNewElts);
2222 // result = patternBuilderModel->mapFromSource( iNewElts );
2227 // ============================================================== Constructeur
2229 MakeCylinderDialog::MakeCylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2230 : HexaBaseDialog(parent, editmode, f)
2233 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinder";
2234 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2235 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2236 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2237 _initWidget(editmode);
2242 // ============================================================== Destructeur
2243 MakeCylinderDialog::~MakeCylinderDialog()
2247 void MakeCylinderDialog::_initInputWidget( Mode editmode )
2249 installEventFilter(this);
2251 rb0->installEventFilter(this);
2252 rb1->installEventFilter(this);
2253 rb2->installEventFilter(this);
2255 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
2256 origin_le->installEventFilter(this);
2257 origin_le->setReadOnly(true);
2259 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2260 axis_le->installEventFilter(this);
2261 axis_le->setReadOnly(true);
2263 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE));
2264 base_le->installEventFilter(this);
2265 base_le->setReadOnly(true);
2267 ext_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2268 ext_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2269 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2270 ext_radius_spb->installEventFilter(this);
2272 int_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2273 int_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2274 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2275 int_radius_spb->installEventFilter(this);
2277 angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2278 angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2279 angle_spb->setProperty("Angle", QVariant::fromValue(true));
2280 angle_spb->installEventFilter(this);
2282 height_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2283 height_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2284 height_spb->setProperty("Length", QVariant::fromValue(true));
2285 height_spb->installEventFilter(this);
2287 radius_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2288 radius_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2289 radius_lw->setProperty("Radius", QVariant::fromValue(true));
2290 radius_lw->installEventFilter(this);
2293 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2294 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2295 angle_lw->setProperty("Angle", QVariant::fromValue(true));
2296 angle_lw->installEventFilter(this);
2298 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2299 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2300 height_lw->setProperty("Length", QVariant::fromValue(true));
2301 height_lw->installEventFilter(this);
2303 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2304 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2306 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2307 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2309 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2310 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2312 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2313 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2315 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2316 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2318 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2319 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2322 // ============================================================== updateHelpFileName
2323 void MakeCylinderDialog::updateHelpFileName()
2325 if ( sender() == rb0 ){
2326 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindersimple";
2327 } else if ( sender() == rb1 ){
2328 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinderuniform";
2329 } else if ( sender() == rb2 ){
2330 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindercustom";
2334 // ============================================================== addRadiusItem
2335 void MakeCylinderDialog::addRadiusItem()
2337 QListWidgetItem* previousItem = radius_lw->currentItem();
2338 QListWidgetItem* newItem = new QListWidgetItem();
2340 double defaultValue = 1.;
2342 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2344 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2345 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2346 radius_lw->addItem(newItem);
2349 // ============================================================== delRadiusItem
2350 void MakeCylinderDialog::delRadiusItem()
2352 delete radius_lw->currentItem();
2355 // ============================================================== addAngleItem
2356 void MakeCylinderDialog::addAngleItem()
2358 QListWidgetItem* previousItem = angle_lw->currentItem();
2359 QListWidgetItem* newItem = new QListWidgetItem();
2361 double defaultValue = 180.;
2363 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2365 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2366 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2367 angle_lw->addItem(newItem);
2370 // ============================================================== delAngleItem
2371 void MakeCylinderDialog::delAngleItem()
2373 delete angle_lw->currentItem();
2376 // ============================================================== addHeightItem
2377 void MakeCylinderDialog::addHeightItem()
2379 QListWidgetItem* previousItem = height_lw->currentItem();
2380 QListWidgetItem* newItem = new QListWidgetItem();
2382 double defaultValue = 1.;
2384 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2386 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2387 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2388 height_lw->addItem(newItem);
2391 // ============================================================== delHeightItem
2392 void MakeCylinderDialog::delHeightItem()
2394 delete height_lw->currentItem();
2397 // ============================================================== clear
2398 void MakeCylinderDialog::clear()
2401 modelUnregister(origin_le);
2404 modelUnregister(axis_le);
2407 modelUnregister(base_le);
2409 modelUnregister(this);
2412 // ============================================================== apply
2413 bool MakeCylinderDialog::apply(QModelIndex& result)
2415 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2418 DocumentModel* docModel = getDocumentModel();
2419 PatternDataModel* patternDataModel = getPatternDataModel();
2420 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2422 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2423 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2424 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2425 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2426 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2427 double rext = ext_radius_spb->value();
2428 double rint = int_radius_spb->value();
2429 double angle = angle_spb->value();
2430 double height = height_spb->value();
2431 double nr = nr_spb->value();
2432 double na = na_spb->value();
2433 double nh = nh_spb->value();
2436 if (rb0->isChecked())
2437 iElts = docModel->makeCylinderTop(nr, na, nh);
2438 else if (rb1->isChecked())
2440 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2441 iElts = docModel->makeCylinderUni(iorigin, ibase, iaxis, rint,
2442 rext, angle, height, nr, na, nh);
2444 else if (rb2->isChecked())
2446 QListWidgetItem* item = NULL;
2448 vector<double> radius;
2449 vector<double> angles;
2450 vector<double> heights;
2452 // double somme = 0.;
2453 int nbAngles = angle_lw->count();
2454 for ( int r = 0; r < nbAngles; ++r){
2455 item = angle_lw->item(r);
2456 double itemValue = item->data(Qt::EditRole).toDouble();
2457 angles.push_back(itemValue);
2458 // somme += itemValue;
2460 // if (somme > 360.01)
2462 // SUIT_MessageBox::information( 0,
2464 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2468 int nbRadius = radius_lw->count();
2469 for ( int r = 0; r < nbRadius; ++r){
2470 item = radius_lw->item(r);
2471 radius.push_back(item->data(Qt::EditRole).toDouble());
2474 int nbHeight = height_lw->count();
2475 for ( int r = 0; r < nbHeight; ++r){
2476 item = height_lw->item(r);
2477 heights.push_back(item->data(Qt::EditRole).toDouble());
2480 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2481 iElts = docModel->makeCylinder( iorigin, ibase, iaxis, radius, angles, heights);
2485 if ( !iElts.isValid() ){
2486 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDER" ) + "\n" + getErrorMsg() );
2490 result = patternDataModel->mapFromSource(iElts);
2491 // result = patternBuilderModel->mapFromSource(iElts);
2496 //---------------------------------- MakePipeDialog -----------------------------
2497 // ============================================================== Constructeur
2499 MakePipeDialog::MakePipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2500 : HexaBaseDialog(parent, editmode, f)
2503 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipe";
2504 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2505 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2506 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2507 _initWidget(editmode);
2511 // ============================================================== Destructeur
2512 MakePipeDialog::~MakePipeDialog()
2516 // ============================================================== _initInputWidget
2517 void MakePipeDialog::_initInputWidget( Mode editmode )
2519 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2520 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2521 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2523 installEventFilter(this);
2524 origin_le->installEventFilter(this);
2525 axis_le->installEventFilter(this);
2526 base_le->installEventFilter(this);
2528 rb0->installEventFilter(this);
2529 rb1->installEventFilter(this);
2530 rb2->installEventFilter(this);
2532 origin_le->setReadOnly(true);
2533 axis_le->setReadOnly(true);
2534 base_le->setReadOnly(true);
2536 ext_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2537 ext_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2538 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2539 ext_radius_spb->installEventFilter(this);
2541 int_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2542 int_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2543 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2544 int_radius_spb->installEventFilter(this);
2546 angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2547 angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2548 angle_spb->setProperty("Angle", QVariant::fromValue(true));
2549 angle_spb->installEventFilter(this);
2551 height_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2552 height_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2553 height_spb->setProperty("Length", QVariant::fromValue(true));
2554 height_spb->installEventFilter(this);
2556 radius_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2557 radius_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2558 radius_lw->setProperty("Radius", QVariant::fromValue(true));
2559 radius_lw->installEventFilter(this);
2561 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2562 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2563 angle_lw->setProperty("Angle", QVariant::fromValue(true));
2564 angle_lw->installEventFilter(this);
2566 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2567 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2568 height_lw->setProperty("Length", QVariant::fromValue(true));
2569 height_lw->installEventFilter(this);
2571 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2572 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2574 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2575 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2577 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2578 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2580 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2581 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2583 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2584 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2586 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2587 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2591 // ============================================================== updateHelpFileName
2592 void MakePipeDialog::updateHelpFileName()
2594 if ( sender() == rb0 ){
2595 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipesimple";
2596 } else if ( sender() == rb1 ){
2597 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipeuniform";
2598 } else if ( sender() == rb2 ){
2599 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipecustom";
2603 // ============================================================== addRadiusItem
2604 void MakePipeDialog::addRadiusItem()
2606 QListWidgetItem* previousItem = radius_lw->currentItem();
2607 QListWidgetItem* newItem = new QListWidgetItem();
2609 double defaultValue = 1.;
2611 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2613 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2614 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2615 radius_lw->addItem(newItem);
2618 // ============================================================== delRadiusItem
2619 void MakePipeDialog::delRadiusItem()
2621 delete radius_lw->currentItem();
2624 // ============================================================== addAngleItem
2625 void MakePipeDialog::addAngleItem()
2627 QListWidgetItem* previousItem = angle_lw->currentItem();
2628 QListWidgetItem* newItem = new QListWidgetItem();
2630 double defaultValue = 180.;
2632 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2634 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2635 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2636 angle_lw->addItem(newItem);
2639 // ============================================================== delAngleItem
2640 void MakePipeDialog::delAngleItem()
2642 delete angle_lw->currentItem();
2645 // ============================================================== addHeightItem
2646 void MakePipeDialog::addHeightItem()
2648 QListWidgetItem* previousItem = height_lw->currentItem();
2649 QListWidgetItem* newItem = new QListWidgetItem();
2651 double defaultValue = 1.;
2653 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2655 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2656 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2657 height_lw->addItem(newItem);
2660 // ============================================================== delHeightItem
2661 void MakePipeDialog::delHeightItem()
2663 delete height_lw->currentItem();
2666 // ============================================================== clear
2667 void MakePipeDialog::clear()
2670 modelUnregister(origin_le);
2673 modelUnregister(axis_le);
2676 modelUnregister(base_le);
2678 modelUnregister(this);
2681 // ============================================================== apply
2682 bool MakePipeDialog::apply(QModelIndex& result)
2684 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2687 DocumentModel* docModel = getDocumentModel();
2688 PatternDataModel* patternDataModel = getPatternDataModel();
2689 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2691 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2692 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2693 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2694 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2695 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2696 double rext = ext_radius_spb->value();
2697 double rint = int_radius_spb->value();
2698 double angle = angle_spb->value();
2699 double height = height_spb->value();
2700 int nr = nr_spb->value();
2701 int na = na_spb->value();
2702 int nh = nh_spb->value();
2706 if (rb0->isChecked())
2707 iElts = docModel->makePipeTop(nr, na, nh);
2708 else if (rb1->isChecked())
2710 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2711 iElts = docModel->makePipeUni(iorigin, ibase, iaxis, rint, rext, angle, height,
2714 else if (rb2->isChecked())
2716 QListWidgetItem* item = NULL;
2718 vector<double> radius;
2719 vector<double> angles;
2720 vector<double> heights;
2722 // double somme = 0.;
2723 int nbAngles = angle_lw->count();
2724 for ( int r = 0; r < nbAngles; ++r){
2725 item = angle_lw->item(r);
2726 double itemValue = item->data(Qt::EditRole).toDouble();
2727 angles.push_back(itemValue);
2728 // somme += itemValue;
2730 // if (somme > 360.01)
2732 // SUIT_MessageBox::information( 0,
2734 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2738 int nbRadius = radius_lw->count();
2739 for ( int r = 0; r < nbRadius; ++r){
2740 item = radius_lw->item(r);
2741 radius.push_back(item->data(Qt::EditRole).toDouble());
2744 int nbHeight = height_lw->count();
2745 for ( int r = 0; r < nbHeight; ++r){
2746 item = height_lw->item(r);
2747 heights.push_back(item->data(Qt::EditRole).toDouble());
2749 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2750 iElts = docModel->makePipe( iorigin, ibase, iaxis, radius, angles, heights );
2753 if ( !iElts.isValid() ){
2754 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPE" ) + "\n" + getErrorMsg() );
2758 // to select/highlight result
2759 result = patternDataModel->mapFromSource(iElts);
2760 // result = patternBuilderModel->mapFromSource(iElts);
2765 //---------------------------------- MakeCylindersDialog -----------------------------
2766 // ============================================================== Constructeur
2768 MakeCylindersDialog::MakeCylindersDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2769 : HexaBaseDialog(parent, editmode, f)
2771 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinders";
2773 _initWidget(editmode);
2776 // ============================================================== Destructeur
2777 MakeCylindersDialog::~MakeCylindersDialog()
2781 void MakeCylindersDialog::_initInputWidget( Mode editmode )
2783 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2784 center2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2785 direction_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2786 direction2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2788 radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2789 radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2790 radius_spb->setProperty("Radius", QVariant::fromValue(true));
2791 radius_spb->installEventFilter(this);
2793 height_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2794 height_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2795 height_spb->setProperty("Length", QVariant::fromValue(true));
2796 height_spb->installEventFilter(this);
2798 radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2799 radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2800 radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2801 radius2_spb->installEventFilter(this);
2803 height2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2804 height2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2805 height2_spb->setProperty("Length", QVariant::fromValue(true));
2806 height2_spb->installEventFilter(this);
2808 installEventFilter(this);
2809 center_le->installEventFilter(this);
2810 center2_le->installEventFilter(this);
2811 direction_le->installEventFilter(this);
2812 direction2_le->installEventFilter(this);
2814 center_le->setReadOnly(true);
2815 center2_le->setReadOnly(true);
2816 direction_le->setReadOnly(true);
2817 direction2_le->setReadOnly(true);
2820 // ============================================================== clear
2821 void MakeCylindersDialog::clear()
2824 modelUnregister(center_le);
2826 center2_le->clear();
2827 modelUnregister(center2_le);
2829 direction_le->clear();
2830 modelUnregister(direction_le);
2832 direction2_le->clear();
2833 modelUnregister(direction2_le);
2835 modelUnregister(this);
2838 // ============================================================== apply
2839 bool MakeCylindersDialog::apply(QModelIndex& result)
2841 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2844 DocumentModel* docModel = getDocumentModel();
2845 PatternDataModel* patternDataModel = getPatternDataModel();
2846 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2849 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2850 QModelIndex icenter2 = patternDataModel->mapToSource( _index[center2_le] );
2851 QModelIndex idir = patternDataModel->mapToSource( _index[direction_le] );
2852 QModelIndex idir2 = patternDataModel->mapToSource( _index[direction2_le] );
2853 // QModelIndex idir = patternBuilderModel->mapToSource( _index[direction_le] );
2854 // QModelIndex idir2 = patternBuilderModel->mapToSource( _index[direction2_le] );
2856 if ( icenter.isValid() && icenter2.isValid() && idir.isValid() && idir2.isValid()){
2857 double r1 = radius_spb->value();
2858 double h1 = height_spb->value();
2859 double r2 = radius2_spb->value();
2860 double h2 = height2_spb->value();
2861 iElts = docModel->makeCylinders( icenter, idir, r1, h1, icenter2, idir2, r2, h2 );
2864 if ( !iElts.isValid() ){
2865 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDERS" ) + "\n" + getErrorMsg() );
2869 result = patternDataModel->mapFromSource(iElts);
2870 // result = patternBuilderModel->mapFromSource(iElts);
2875 //---------------------------------- MakePipesDialog -----------------------------
2876 // ============================================================== Constructeur
2878 MakePipesDialog::MakePipesDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2879 : HexaBaseDialog(parent, editmode, f)
2881 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipes";
2883 _initWidget(editmode);
2886 // ============================================================== Destructeur
2887 MakePipesDialog::~MakePipesDialog()
2891 // ============================================================== _initInputWidget
2892 void MakePipesDialog::_initInputWidget( Mode editmode )
2894 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2895 origin2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2896 dir_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2897 dir2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2899 ext_radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2900 ext_radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2901 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2902 ext_radius_spb->installEventFilter(this);
2904 int_radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2905 int_radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2906 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2907 int_radius_spb->installEventFilter(this);
2909 height_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2910 height_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2911 height_spb->setProperty("Length", QVariant::fromValue(true));
2912 height_spb->installEventFilter(this);
2914 ext_radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2915 ext_radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2916 ext_radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2917 ext_radius2_spb->installEventFilter(this);
2919 int_radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2920 int_radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2921 int_radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2922 int_radius2_spb->installEventFilter(this);
2924 height2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2925 height2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2926 height2_spb->setProperty("Length", QVariant::fromValue(true));
2927 height2_spb->installEventFilter(this);
2929 origin_le->installEventFilter(this);
2930 origin2_le->installEventFilter(this);
2931 dir_le->installEventFilter(this);
2932 dir2_le->installEventFilter(this);
2934 origin_le->setReadOnly(true);
2935 origin2_le->setReadOnly(true);
2936 dir_le->setReadOnly(true);
2937 dir2_le->setReadOnly(true);
2940 // ============================================================== clear
2941 void MakePipesDialog::clear()
2944 modelUnregister(origin_le);
2946 origin2_le->clear();
2947 modelUnregister(origin2_le);
2950 modelUnregister(dir_le);
2953 modelUnregister(dir2_le);
2955 modelUnregister(this);
2958 // ============================================================== apply
2959 bool MakePipesDialog::apply(QModelIndex& result)
2961 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2964 DocumentModel* docModel = getDocumentModel();
2965 PatternDataModel* patternDataModel = getPatternDataModel();
2966 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2968 QModelIndex iorigin1 = patternDataModel->mapToSource( _index[origin_le] );
2969 QModelIndex iorigin2 = patternDataModel->mapToSource( _index[origin2_le] );
2970 QModelIndex idir1 = patternDataModel->mapToSource( _index[dir_le] );
2971 QModelIndex idir2 = patternDataModel->mapToSource( _index[dir2_le] );
2972 // QModelIndex idir1 = patternBuilderModel->mapToSource( _index[dir_le] );
2973 // QModelIndex idir2 = patternBuilderModel->mapToSource( _index[dir2_le] );
2974 double rint1 = int_radius_spb->value();
2975 double rext1 = ext_radius_spb->value();
2976 double height1 = height_spb->value();
2977 double rint2 = int_radius2_spb->value();
2978 double rext2 = ext_radius2_spb->value();
2979 double height2 = height_spb->value();
2983 if ( iorigin1.isValid() && iorigin2.isValid() && idir1.isValid() && idir2.isValid())
2984 iElts = docModel->makePipes( iorigin1, idir1, rint1, rext1, height1,
2985 iorigin2, idir2, rint2, rext2, height2);
2987 if ( !iElts.isValid() ){
2988 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPES" ) + "\n" + getErrorMsg() );
2992 result = patternDataModel->mapFromSource(iElts);
2993 // result = patternBuilderModel->mapFromSource(iElts);
2998 //---------------------------------- RemoveHexaDialog -----------------------------
2999 // ============================================================== Constructeur
3001 RemoveHexaDialog::RemoveHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3002 : HexaBaseDialog(parent, editmode, f)
3004 _helpFileName = "gui_remove.html";
3006 _initWidget(editmode);
3009 // ============================================================== Destructeur
3010 RemoveHexaDialog::~RemoveHexaDialog()
3014 // ============================================================== _initInputWidget
3015 void RemoveHexaDialog::_initInputWidget( Mode editmode )
3018 QValidator *validator = new QRegExpValidator(rx, this);
3020 hexa_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3021 hexa_le->setValidator( validator );
3022 hexa_le->installEventFilter(this);
3023 hexa_le->setReadOnly(true);
3024 autoFocusSwitch = false;
3027 // ============================================================== clear
3028 void RemoveHexaDialog::clear()
3031 modelUnregister(hexa_le);
3033 modelUnregister(this);
3036 // ============================================================== apply
3037 bool RemoveHexaDialog::apply(QModelIndex& result)
3039 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3042 if ( !getDocumentModel() ) return false;
3043 const PatternDataModel* patternDataModel = getPatternDataModel();
3044 if ( !patternDataModel ) return false;
3046 QModelIndex ihexa = patternDataModel->mapToSource( _index[hexa_le] );
3048 bool removed = false;
3049 if ( ihexa.isValid() ){
3050 if ( connected_cb->isChecked() ){
3051 removed = getDocumentModel()->removeConnectedHexa( ihexa );
3053 removed = getDocumentModel()->removeHexa( ihexa );
3057 if ( removed == false ){
3058 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE HEXA" ) + "\n" + getErrorMsg() );
3067 //---------------------------------- PrismQuadDialog -----------------------------
3068 // ============================================================== Constructeur
3070 PrismQuadDialog::PrismQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3071 : HexaBaseDialog(parent, editmode, f)
3074 _helpFileName = "gui_prism_join_quad.html#guiextrudequads";
3075 connect( extrudeTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3076 connect( extrudeUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3077 connect( extrude_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3078 _initWidget(editmode);
3079 extrudeTop_rb->click();
3082 // ============================================================== Destructeur
3083 PrismQuadDialog::~PrismQuadDialog()
3087 // ============================================================== getAssocsVTK
3089 * Returns elements currently associated to vtk
3091 QModelIndexList PrismQuadDialog::getAssocsVTK()
3093 QModelIndexList assocs;
3095 QListWidgetItem* item = NULL;
3097 //ListWidget content
3098 const PatternDataModel* patternDataModel = getPatternDataModel();
3099 if ( !patternDataModel ) return assocs;
3100 int nbQuads = quads_lw->count();
3101 for ( int r = 0; r < nbQuads; ++r ){
3102 item = quads_lw->item(r);
3103 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3104 if ( iQuad.isValid() )
3110 // ============================================================== _initInputWidget
3111 void PrismQuadDialog::_initInputWidget( Mode editmode )
3113 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3114 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3116 length_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3117 length_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3118 length_spb->setProperty("Length", QVariant::fromValue(true));
3119 length_spb->installEventFilter(this);
3122 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3123 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3124 height_lw->setProperty("Length", QVariant::fromValue(true));
3125 height_lw->installEventFilter(this);
3127 installEventFilter(this);
3128 quads_lw->installEventFilter(this);
3129 axis_le->installEventFilter(this);
3131 extrudeTop_rb->installEventFilter(this);
3132 extrudeUni_rb->installEventFilter(this);
3133 extrude_rb->installEventFilter(this);
3135 axis_le->setReadOnly(true);
3137 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3138 delQuadShortcut->setContext( Qt::WidgetShortcut );
3139 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3140 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3142 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3143 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3144 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3145 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3148 // ============================================================== updateHelpFileName
3149 void PrismQuadDialog::updateHelpFileName()
3151 if ( sender() == extrudeTop_rb ){
3152 _helpFileName = "gui_prism_join_quad.html#guiextrudequadssimple";
3153 } else if ( sender() == extrudeUni_rb ){
3154 _helpFileName = "gui_prism_join_quad.html#guiextrudequadsuniform";
3155 } else if ( sender() == extrude_rb ){
3156 _helpFileName = "gui_prism_join_quad.html#guiextrudequadscustom";
3160 // ============================================================== clear
3161 void PrismQuadDialog::clear()
3164 modelUnregister(quads_lw);
3167 modelUnregister(axis_le);
3169 modelUnregister(this);
3172 // ============================================================== removeQuad
3173 void PrismQuadDialog::removeQuad()
3175 QListWidgetItem *item = quads_lw->currentItem();
3178 int r = quads_lw->row(item);
3179 quads_lw->takeItem(r);
3184 // ============================================================== addHeightItem
3185 void PrismQuadDialog::addHeightItem()
3187 QListWidgetItem* previousItem = height_lw->currentItem();
3188 QListWidgetItem* newItem = new QListWidgetItem();
3190 double defaultValue = 1.;
3192 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3194 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3195 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3196 height_lw->addItem(newItem);
3199 // ============================================================== delHeightItem
3200 void PrismQuadDialog::delHeightItem()
3202 delete height_lw->currentItem();
3205 // ============================================================== apply
3206 bool PrismQuadDialog::apply(QModelIndex& result)
3208 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3211 DocumentModel* docModel = getDocumentModel();
3212 PatternDataModel* patternDataModel = getPatternDataModel();
3213 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3215 QModelIndexList iquads = getIndexList(quads_lw);
3216 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
3217 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
3218 double length = length_spb->value();
3219 int nb = nb_spb->value();
3221 vector<double> heights;
3222 QListWidgetItem* item = NULL;
3223 int nbItems = height_lw->count();
3225 for ( int r = 0; r < nbItems; ++r){
3226 item = height_lw->item(r);
3227 heights.push_back( item->data(Qt::EditRole).toDouble() );
3231 int nbQuads = iquads.count();
3233 if (nbQuads == 1 && iquads[0].isValid())
3235 if (extrudeTop_rb->isChecked())
3236 iElts = docModel->extrudeQuadTop(iquads[0], nb);
3237 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3238 iElts = docModel->extrudeQuadUni(iquads[0], iaxis, length, nb);
3239 else if (extrude_rb->isChecked() && iaxis.isValid())
3240 iElts = docModel->extrudeQuad(iquads[0], iaxis, heights);
3242 else if (nbQuads > 1)
3244 if (extrudeTop_rb->isChecked())
3245 iElts = docModel->extrudeQuadsTop(iquads, nb);
3246 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3247 iElts = docModel->extrudeQuadsUni(iquads, iaxis, length, nb);
3248 else if (extrude_rb->isChecked() && iaxis.isValid())
3249 iElts = docModel->extrudeQuads(iquads, iaxis, heights);
3252 if ( !iElts.isValid() ){
3253 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PRISM QUAD(S)" ) + "\n" + getErrorMsg() );
3257 result = patternDataModel->mapFromSource(iElts);
3258 // result = patternBuilderModel->mapFromSource(iElts);
3263 //---------------------------------- JoinQuadDialog -----------------------------
3264 // ============================================================== Constructeur
3266 JoinQuadDialog::JoinQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3267 : HexaBaseDialog(parent, editmode, f)
3270 _helpFileName = "gui_prism_join_quad.html#guijoinquads";
3271 connect( joinUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3272 connect( join_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3273 _initWidget(editmode);
3274 joinUni_rb->click();
3277 // ============================================================== Destructeur
3278 JoinQuadDialog::~JoinQuadDialog()
3282 // ============================================================== getAssocsVTK
3284 * Returns elements currently associated to vtk
3286 QModelIndexList JoinQuadDialog::getAssocsVTK()
3288 QModelIndexList assocs;
3290 QListWidgetItem* item = NULL;
3292 if (getPatternDataSelectionModel() == NULL) return assocs;
3294 //ListWidget content
3295 const PatternDataModel* patternDataModel = getPatternDataModel();
3296 if ( !patternDataModel ) return assocs;
3297 int nbQuads = quads_lw->count();
3298 for ( int r = 0; r < nbQuads; ++r ){
3299 item = quads_lw->item(r);
3300 // iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
3301 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
3302 if ( iQuad.isValid() ) assocs << iQuad;
3307 // ============================================================== _initInputWidget
3308 void JoinQuadDialog::_initInputWidget( Mode editmode )
3310 quad_dest_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3311 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3312 vex0_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3313 vex1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3314 vex2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3315 vex3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3317 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3318 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3319 height_lw->setProperty("Length", QVariant::fromValue(true));
3320 height_lw->installEventFilter(this);
3322 installEventFilter(this);
3323 quad_dest_le->installEventFilter(this);
3324 quads_lw->installEventFilter(this);
3325 vex0_le->installEventFilter(this);
3326 vex1_le->installEventFilter(this);
3327 vex2_le->installEventFilter(this);
3328 vex3_le->installEventFilter(this);
3330 joinUni_rb->installEventFilter(this);
3331 join_rb->installEventFilter(this);
3333 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3334 delQuadShortcut->setContext( Qt::WidgetShortcut );
3335 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3337 quad_dest_le->setReadOnly(true);
3338 vex0_le->setReadOnly(true);
3339 vex1_le->setReadOnly(true);
3340 vex2_le->setReadOnly(true);
3341 vex3_le->setReadOnly(true);
3343 _currentObj = quads_lw;
3344 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3345 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3347 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3349 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3350 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3353 // ============================================================== updateHelpFileName
3354 void JoinQuadDialog::updateHelpFileName()
3356 if ( sender() == joinUni_rb ){
3357 _helpFileName = "gui_prism_join_quad.html#guijoinquadsuniform";
3358 } else if ( sender() == join_rb ){
3359 _helpFileName = "gui_prism_join_quad.html#guijoinquadscustom";
3363 // ============================================================== addHeightItem
3364 void JoinQuadDialog::addHeightItem()
3366 QListWidgetItem* previousItem = height_lw->currentItem();
3367 QListWidgetItem* newItem = new QListWidgetItem();
3369 double defaultValue = 1.;
3371 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3373 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3374 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3375 height_lw->addItem(newItem);
3378 // ============================================================== delHeightItem
3379 void JoinQuadDialog::delHeightItem()
3381 delete height_lw->currentItem();
3384 // ============================================================== clear
3385 void JoinQuadDialog::clear()
3387 quad_dest_le->clear();
3388 modelUnregister(quad_dest_le);
3391 modelUnregister(quads_lw);
3394 modelUnregister(vex0_le);
3397 modelUnregister(vex1_le);
3400 modelUnregister(vex2_le);
3403 modelUnregister(vex3_le);
3405 modelUnregister(this);
3408 // ============================================================== removeQuad
3409 void JoinQuadDialog::removeQuad()
3411 QListWidgetItem *item = quads_lw->currentItem();
3414 int r = quads_lw->row(item);
3415 quads_lw->takeItem(r);
3420 // ============================================================== apply
3421 bool JoinQuadDialog::apply(QModelIndex& result)
3423 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3426 DocumentModel* docModel = getDocumentModel();
3427 PatternDataModel* patternDataModel = getPatternDataModel();
3428 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3430 QModelIndexList iquads;
3432 QListWidgetItem* item = NULL;
3433 int nbQuads = quads_lw->count();
3434 for ( int r = 0; r < nbQuads; ++r){
3435 item = quads_lw->item(r);
3436 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3437 if ( iquad.isValid() )
3440 QModelIndex iquaddest = patternDataModel->mapToSource( _index[quad_dest_le] );
3441 QModelIndex ivex0 = patternDataModel->mapToSource( _index[vex0_le] );
3442 QModelIndex ivex1 = patternDataModel->mapToSource( _index[vex1_le] );
3443 QModelIndex ivex2 = patternDataModel->mapToSource( _index[vex2_le] );
3444 QModelIndex ivex3 = patternDataModel->mapToSource( _index[vex3_le] );
3445 double nb = nb_spb->value();
3447 vector<double> heights;
3448 int nbHeight = height_lw->count();
3449 for ( int r = 0; r < nbHeight; ++r){
3450 item = height_lw->item(r);
3451 heights.push_back(item->data(Qt::EditRole).toDouble());
3455 if (nbQuads == 1 && iquads[0].isValid() && iquaddest.isValid() && ivex0.isValid() &&
3456 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3458 if (joinUni_rb->isChecked())
3459 iElts = docModel->joinQuadUni(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3460 else if (join_rb->isChecked())
3461 iElts = docModel->joinQuad(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3463 else if (nbQuads > 1 && iquaddest.isValid() && ivex0.isValid() &&
3464 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3466 if (joinUni_rb->isChecked())
3467 iElts = docModel->joinQuadsUni(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3468 else if (join_rb->isChecked())
3469 iElts = docModel->joinQuads(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3472 if ( !iElts.isValid() ){
3473 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT JOIN QUAD(S)" ) + "\n" + getErrorMsg() );
3476 result = patternDataModel->mapFromSource(iElts);
3477 // result = patternBuilderModel->mapFromSource(iElts);
3482 // ------------------------- MergeDialog ----------------------------------
3483 // ============================================================== Constructeur
3485 MergeDialog::MergeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3486 : HexaBaseDialog(parent, editmode, f)
3489 _initWidget(editmode);
3492 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3493 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3494 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3495 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3497 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3498 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3499 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3501 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3502 connect( rb2, SIGNAL(cliked()), this, SLOT(clearVTKSelection()) );
3503 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3506 // ============================================================== Destructeur
3507 MergeDialog::~MergeDialog()
3511 // ============================================================== _initInputWidget
3512 void MergeDialog::_initInputWidget( Mode editmode )
3515 QValidator *validator = new QRegExpValidator(rx, this);
3517 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3518 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3519 v0_le_rb0->setValidator( validator );
3520 v1_le_rb0->setValidator( validator );
3521 v0_le_rb0->installEventFilter(this);
3522 v1_le_rb0->installEventFilter(this);
3524 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3525 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3526 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3527 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3529 v0_le_rb1->setValidator( validator );
3530 v1_le_rb1->setValidator( validator );
3531 e0_le_rb1->setValidator( validator );
3532 e1_le_rb1->setValidator( validator );
3534 v0_le_rb1->installEventFilter(this);
3535 v1_le_rb1->installEventFilter(this);
3536 e0_le_rb1->installEventFilter(this);
3537 e1_le_rb1->installEventFilter(this);
3539 v0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3540 v1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3541 v2_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3542 v3_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3543 q0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3544 q1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3546 v0_le_rb2->setValidator( validator );
3547 v1_le_rb2->setValidator( validator );
3548 v2_le_rb2->setValidator( validator );
3549 v3_le_rb2->setValidator( validator );
3550 q0_le_rb2->setValidator( validator );
3551 q1_le_rb2->setValidator( validator );
3553 v0_le_rb2->installEventFilter(this);
3554 v1_le_rb2->installEventFilter(this);
3555 v2_le_rb2->installEventFilter(this);
3556 v3_le_rb2->installEventFilter(this);
3557 q0_le_rb2->installEventFilter(this);
3558 q1_le_rb2->installEventFilter(this);
3560 v0_le_rb0->setReadOnly(true);
3561 v1_le_rb0->setReadOnly(true);
3563 v0_le_rb1->setReadOnly(true);
3564 v1_le_rb1->setReadOnly(true);
3565 e0_le_rb1->setReadOnly(true);
3566 e1_le_rb1->setReadOnly(true);
3568 v0_le_rb2->setReadOnly(true);
3569 v1_le_rb2->setReadOnly(true);
3570 v2_le_rb2->setReadOnly(true);
3571 v3_le_rb2->setReadOnly(true);
3572 q0_le_rb2->setReadOnly(true);
3573 q1_le_rb2->setReadOnly(true);
3576 // ============================================================== clear
3577 void MergeDialog::clear()
3580 modelUnregister(v0_le_rb0);
3583 modelUnregister(v1_le_rb0);
3586 modelUnregister(e0_le_rb1);
3589 modelUnregister(e1_le_rb1);
3592 modelUnregister(v0_le_rb1);
3595 modelUnregister(v1_le_rb1);
3598 modelUnregister(q0_le_rb2);
3601 modelUnregister(q1_le_rb2);
3604 modelUnregister(v0_le_rb2);
3607 modelUnregister(v1_le_rb2);
3610 modelUnregister(v2_le_rb2);
3613 modelUnregister(v3_le_rb2);
3615 modelUnregister(this);
3618 // ============================================================== updateHelpFileName
3619 void MergeDialog::updateHelpFileName()
3621 if ( sender() == rb0 ){
3622 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3623 } else if ( sender() == rb1 ){
3624 _helpFileName = "gui_merge_elmts.html#merge-two-edges";
3625 } else if ( sender() == rb2 ){
3626 _helpFileName = "gui_merge_elmts.html#merge-two-quadrangles";
3630 // ============================================================== apply
3631 bool MergeDialog::apply(QModelIndex& result)
3633 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3636 if (getDocumentModel() == NULL) return false;
3637 const PatternDataModel* patternDataModel = getPatternDataModel();
3638 if ( !patternDataModel ) return false;
3640 bool merged = false;
3642 if ( rb0->isChecked() ){
3643 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
3644 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
3648 merged = getDocumentModel()->mergeVertices( iv0, iv1 );
3650 } else if ( rb1->isChecked() ){
3651 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
3652 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
3653 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
3654 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
3660 merged = getDocumentModel()->mergeEdges( ie0, ie1, iv0, iv1);
3662 } else if ( rb2->isChecked() ){
3664 QModelIndex iq0 = patternDataModel->mapToSource( _index[q0_le_rb2] );
3665 QModelIndex iq1 = patternDataModel->mapToSource( _index[q1_le_rb2] );
3666 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb2] );
3667 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb2] );
3668 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb2] );
3669 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb2] );
3677 merged = getDocumentModel()->mergeQuads( iq0, iq1,
3678 iv0, iv1, iv2, iv3 );
3682 if ( merged == false ){
3683 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MERGE" ) + "\n" + getErrorMsg() );
3690 // ------------------------- DisconnectDialog ----------------------------------
3691 // ============================================================== Constructeur
3693 DisconnectDialog::DisconnectDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3694 : HexaBaseDialog(parent, editmode, f)
3697 _initWidget(editmode);
3700 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3702 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3703 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3704 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3706 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3707 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3708 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3710 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3711 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3712 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3714 connect( rb3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3715 connect( rb3, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3716 connect( rb3, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3720 // ============================================================== Destructeur
3721 DisconnectDialog::~DisconnectDialog()
3725 // ============================================================== _initInputWidget
3726 void DisconnectDialog::_initInputWidget( Mode editmode )
3729 QValidator *validator = new QRegExpValidator(rx, this);
3731 installEventFilter(this);
3734 v_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3735 h_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3736 v_le_rb0->setValidator( validator );
3737 h_le_rb0->setValidator( validator );
3738 v_le_rb0->installEventFilter(this);
3739 h_le_rb0->installEventFilter(this);
3742 e_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3743 h_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3744 e_le_rb1->setValidator( validator );
3745 h_le_rb1->setValidator( validator );
3746 e_le_rb1->installEventFilter(this);
3747 h_le_rb1->installEventFilter(this);
3750 q_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3751 h_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3752 q_le_rb2->setValidator( validator );
3753 h_le_rb2->setValidator( validator );
3754 q_le_rb2->installEventFilter(this);
3755 h_le_rb2->installEventFilter(this);
3758 d_edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3759 hexas_lw->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3760 d_edges_lw->installEventFilter(this);
3761 hexas_lw->installEventFilter(this);
3763 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), d_edges_lw);
3764 QShortcut* delHexaShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), hexas_lw);
3765 delEdgeShortcut->setContext( Qt::WidgetShortcut );
3766 delHexaShortcut->setContext( Qt::WidgetShortcut );
3768 v_le_rb0->setReadOnly(true);
3769 h_le_rb0->setReadOnly(true);
3771 e_le_rb1->setReadOnly(true);
3772 h_le_rb1->setReadOnly(true);
3774 q_le_rb2->setReadOnly(true);
3775 h_le_rb2->setReadOnly(true);
3777 connect( d_edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3778 connect( hexas_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3779 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
3780 connect( delHexaShortcut, SIGNAL(activated()), this, SLOT(deleteHexaItem()) );
3781 autoFocusSwitch = false;
3785 // =============================================== getAssocsVTK
3787 * Returns elements in the list
3789 QModelIndexList DisconnectDialog::getAssocsVTK()
3791 QModelIndexList iElts;
3793 QListWidgetItem* item = NULL;
3795 const PatternDataModel* patternDataModel = getPatternDataModel();
3796 if (patternDataModel == NULL || !rb3->isChecked())
3798 //ListWidget content
3799 if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == EDGE_TREE)
3801 int nbEdges = d_edges_lw->count();
3802 for ( int r = 0; r < nbEdges; ++r )
3804 item = d_edges_lw->item(r);
3805 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3806 if ( index.isValid() )
3810 else if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == HEXA_TREE)
3812 int nbHexas = hexas_lw->count();
3813 for ( int r = 0; r < nbHexas; ++r )
3815 item = hexas_lw->item(r);
3816 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3817 if ( index.isValid() )
3824 // ============================================================== clear
3825 void DisconnectDialog::clear()
3828 modelUnregister(v_le_rb0);
3831 modelUnregister(h_le_rb0);
3834 modelUnregister(e_le_rb1);
3837 modelUnregister(h_le_rb1);
3839 d_edges_lw->clear();
3840 modelUnregister(d_edges_lw);
3843 modelUnregister(hexas_lw);
3846 modelUnregister(q_le_rb2);
3849 modelUnregister(h_le_rb2);
3851 modelUnregister(this);
3854 // ============================================================== deleteEdgeItem
3855 void DisconnectDialog::deleteEdgeItem()
3857 delete d_edges_lw->currentItem();
3860 // ============================================================== deleteHexaItem
3861 void DisconnectDialog::deleteHexaItem()
3863 delete hexas_lw->currentItem();
3866 // ============================================================== updateHelpFileName
3867 void DisconnectDialog::updateHelpFileName()
3869 if ( sender() == rb0 ){
3870 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3871 } else if ( sender() == rb1 ){
3872 _helpFileName = "gui_disc_elmts.html#disconnect-an-edge";
3873 } else if ( sender() == rb2 ){
3874 _helpFileName = "gui_disc_elmts.html#disconnect-a-quadrangle";
3875 } else if (sender() == rb3 ){
3876 _helpFileName = "gui_disc_elmts.html#disconnect-edges";
3880 // ============================================================== apply
3881 bool DisconnectDialog::apply(QModelIndex& result)
3883 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3885 if (getDocumentModel() == NULL) return false;
3886 const PatternDataModel* patternDataModel = getPatternDataModel();
3887 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3888 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
3892 if ( rb0->isChecked() ){
3893 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb0] );
3894 QModelIndex ivex = patternDataModel->mapToSource( _index[v_le_rb0] );
3896 if ( ihexa.isValid()
3897 && ivex.isValid() ){
3898 iElts = getDocumentModel()->disconnectVertex( ihexa, ivex );
3900 } else if ( rb1->isChecked() ){
3901 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb1] );
3902 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le_rb1] );
3904 if ( ihexa.isValid()
3905 && iedge.isValid() ){
3906 iElts = getDocumentModel()->disconnectEdge( ihexa, iedge );
3908 } else if ( rb2->isChecked() ){
3909 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb2] );
3910 QModelIndex iquad = patternDataModel->mapToSource( _index[q_le_rb2] );
3912 if ( ihexa.isValid()
3913 && iquad.isValid() ){
3914 iElts = getDocumentModel()->disconnectQuad( ihexa, iquad );
3916 } else if ( rb3->isChecked() ){ //
3918 QModelIndex iedge, ihexa;
3919 QModelIndexList iedges, ihexas;
3920 QListWidgetItem* item = NULL;
3923 int nbEdges = d_edges_lw->count();
3924 for (int r = 0; r < nbEdges; ++r){
3925 item = d_edges_lw->item(r);
3926 iedge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3927 if ( iedge.isValid() )
3932 int nbHexas = hexas_lw->count();
3933 for (int r = 0; r < nbHexas; ++r){
3934 item = hexas_lw->item(r);
3935 ihexa = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3936 if ( ihexa.isValid() )
3940 iElts = getDocumentModel()->disconnectEdges( ihexas, iedges );
3943 if ( !iElts.isValid() ){
3944 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT DISCONNECT" ) + "\n" + getErrorMsg() );
3948 result = patternDataModel->mapFromSource(iElts);
3949 // result = patternBuilderModel->mapFromSource(iElts);
3955 // ------------------------- CutEdgeDialog ----------------------------------
3956 // ============================================================== Constructeur
3958 CutEdgeDialog::CutEdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3959 HexaBaseDialog(parent, editmode, f)
3962 _helpFileName = "gui_cut_hexa.html";
3963 connect( cutUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3964 connect( cut_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3965 _initWidget(editmode);
3970 // ============================================================== Destructeur
3971 CutEdgeDialog::~CutEdgeDialog()
3975 // ============================================================== _initInputWidget
3976 void CutEdgeDialog::_initInputWidget( Mode editmode )
3978 installEventFilter(this);
3980 e_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3981 e_le->installEventFilter(this);
3983 cutUni_rb->installEventFilter(this);
3984 cut_rb->installEventFilter(this);
3986 e_le->setReadOnly(true);
3988 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3989 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3990 height_lw->setProperty("Length", QVariant::fromValue(true));
3991 height_lw->installEventFilter(this);
3993 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3994 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3996 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3997 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
4000 // ============================================================== updateHelpFileName
4001 void CutEdgeDialog::updateHelpFileName()
4003 if ( sender() == cutUni_rb ){
4004 _helpFileName = "gui_cut_hexa.html#guicuthexauniform";
4005 } else if ( sender() == cut_rb ){
4006 _helpFileName = "gui_cut_hexa.html#guicuthexacustom";
4010 // ============================================================== clear
4011 void CutEdgeDialog::clear()
4014 modelUnregister(e_le);
4016 modelUnregister(this);
4019 // ============================================================== addHeightItem
4020 void CutEdgeDialog::addHeightItem()
4022 QListWidgetItem* previousItem = height_lw->currentItem();
4023 QListWidgetItem* newItem = new QListWidgetItem();
4025 double defaultValue = 1.;
4027 defaultValue = previousItem->data(Qt::EditRole).toDouble();
4029 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
4030 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
4031 height_lw->addItem(newItem);
4034 // ============================================================== delHeightItem
4035 void CutEdgeDialog::delHeightItem()
4037 delete height_lw->currentItem();
4040 // ============================================================== apply
4041 bool CutEdgeDialog::apply(QModelIndex& result)
4043 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4046 DocumentModel* docModel = getDocumentModel();
4047 PatternDataModel* patternDataModel = getPatternDataModel();
4048 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4051 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le] );
4053 if (cutUni_rb->isChecked() && iedge.isValid())
4055 int nbCut = nb_cut_spb->value();
4056 iElts = docModel->cutUni(iedge, nbCut);
4058 else if (cut_rb->isChecked() && iedge.isValid())
4060 vector<double> heights;
4061 QListWidgetItem* item = NULL;
4062 int nbItems = height_lw->count();
4064 for ( int r = 0; r < nbItems; ++r){
4065 item = height_lw->item(r);
4066 heights.push_back( item->data(Qt::EditRole).toDouble() );
4069 iElts = docModel->cut(iedge, heights);
4072 if ( !iElts.isValid() ){
4073 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT CUT EDGE" ) + "\n" + getErrorMsg() );
4077 result = patternDataModel->mapFromSource(iElts);
4078 // result = patternBuilderModel->mapFromSource(iElts);
4080 //Update the line edit
4082 e_le->setProperty("QModelIndex", invalid );
4084 QModelIndex invalidIndex;
4085 _index[e_le] = invalidIndex;
4092 // // ------------------------- MakeTransformationDialog ----------------------------------
4093 // ============================================================== Constructeur
4095 MakeTransformationDialog::MakeTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4096 : HexaBaseDialog(parent, editmode, f)
4099 _initWidget(editmode);
4102 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
4103 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4104 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4105 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4108 // ============================================================== Destructeur
4109 MakeTransformationDialog::~MakeTransformationDialog()
4113 // ============================================================== _initInputWidget
4114 void MakeTransformationDialog::_initInputWidget( Mode editmode )
4117 QValidator *validator = new QRegExpValidator(rx, this);
4119 installEventFilter(this);
4120 rb0->installEventFilter(this);
4121 rb1->installEventFilter(this);
4122 rb2->installEventFilter(this);
4124 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4125 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4127 vec_le_rb0->setValidator( validator );
4128 elts_le_rb0->setValidator( validator );
4129 vec_le_rb0->installEventFilter(this);
4130 elts_le_rb0->installEventFilter(this);
4132 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4133 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4134 vex_le_rb1->setValidator( validator );
4135 elts_le_rb1->setValidator( validator );
4136 vex_le_rb1->installEventFilter(this);
4137 elts_le_rb1->installEventFilter(this);
4139 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4140 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4141 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4142 vex_le_rb2->setValidator( validator );
4143 vec_le_rb2->setValidator( validator );
4144 elts_le_rb2->setValidator( validator );
4145 vex_le_rb2->installEventFilter(this);
4146 vec_le_rb2->installEventFilter(this);
4147 elts_le_rb2->installEventFilter(this);
4149 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
4150 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
4151 angle_spb->setProperty("Angle", QVariant::fromValue(true));
4152 angle_spb->installEventFilter(this);
4154 vec_le_rb0->setReadOnly(true);
4155 elts_le_rb0->setReadOnly(true);
4157 vex_le_rb1->setReadOnly(true);
4158 elts_le_rb1->setReadOnly(true);
4160 vex_le_rb2->setReadOnly(true);
4161 vec_le_rb2->setReadOnly(true);
4162 elts_le_rb2->setReadOnly(true);
4166 // ============================================================== clear
4167 void MakeTransformationDialog::clear()
4169 elts_le_rb0->clear();
4170 modelUnregister(elts_le_rb0);
4172 vec_le_rb0->clear();
4173 modelUnregister(vec_le_rb0);
4175 elts_le_rb1->clear();
4176 modelUnregister(elts_le_rb1);
4178 vex_le_rb1->clear();
4179 modelUnregister(vex_le_rb1);
4181 elts_le_rb2->clear();
4182 modelUnregister(elts_le_rb2);
4184 vex_le_rb2->clear();
4185 modelUnregister(vex_le_rb2);
4187 vec_le_rb2->clear();
4188 modelUnregister(vec_le_rb2);
4190 modelUnregister(this);
4193 // ============================================================== updateHelpFileName
4194 void MakeTransformationDialog::updateHelpFileName()
4196 if ( sender() == rb0 ){
4197 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
4198 } else if ( sender() == rb1 ){
4199 _helpFileName = "gui_make_elmts.html#make-elements-by-scaling";
4200 } else if ( sender() == rb2 ){
4201 _helpFileName = "gui_make_elmts.html#make-elements-by-rotation";
4205 // ============================================================== apply
4206 bool MakeTransformationDialog::apply(QModelIndex& result)
4208 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4211 if (getDocumentModel() == NULL) return false;
4212 const PatternDataModel* patternDataModel = getPatternDataModel();
4213 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4214 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4216 QModelIndex iNewElts;
4218 if ( rb0->isChecked() ){
4219 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb0] );
4220 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb0] );
4221 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4222 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4224 if ( ielts.isValid()
4226 iNewElts = getDocumentModel()->makeTranslation( ielts, ivec );
4228 } else if ( rb1->isChecked() ){
4229 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4230 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb1] );
4231 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4232 double k = k_spb->value();
4234 if ( ielts.isValid()
4236 iNewElts = getDocumentModel()->makeScale( ielts, ivex, k );
4238 } else if ( rb2->isChecked() ){
4239 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4240 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb2] );
4241 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4242 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4243 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb2] );
4244 double angle = angle_spb->value();
4246 if ( ielts.isValid()
4249 iNewElts = getDocumentModel()->makeRotation( ielts, ivex, ivec, angle );
4252 if ( !iNewElts.isValid() ){
4253 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4257 result = patternDataModel->mapFromSource(iNewElts);
4258 if (result.isValid())
4260 MESSAGE("======> Result is valid!");
4261 HEXA_NS::Elements* elts = getDocumentModel()->getHexaPtr<HEXA_NS::Elements*>(result);
4262 MESSAGE("======> " << elts->getName());
4266 MESSAGE("======> Result is not valid!");
4268 // result = patternBuilderModel->mapFromSource(iNewElts);
4273 // // ------------------------- MakeSymmetryDialog ----------------------------------
4274 // ============================================================== Constructeur
4276 MakeSymmetryDialog::MakeSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4277 HexaBaseDialog(parent, editmode, f)
4280 _initWidget(editmode);
4283 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4284 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4285 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4286 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4289 // ============================================================== Destructeur
4290 MakeSymmetryDialog::~MakeSymmetryDialog()
4294 // ============================================================== _initInputWidget
4295 void MakeSymmetryDialog::_initInputWidget( Mode editmode )
4298 QValidator *validator = new QRegExpValidator(rx, this);
4300 installEventFilter(this);
4302 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4303 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4304 vex_le_rb0->setValidator( validator );
4305 elts_le_rb0->setValidator( validator );
4306 vex_le_rb0->installEventFilter(this);
4307 elts_le_rb0->installEventFilter(this);
4309 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4310 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4311 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4312 vex_le_rb1->setValidator( validator );
4313 vec_le_rb1->setValidator( validator );
4314 elts_le_rb1->setValidator( validator );
4315 vex_le_rb1->installEventFilter(this);
4316 vec_le_rb1->installEventFilter(this);
4317 elts_le_rb1->installEventFilter(this);
4319 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4320 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4321 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4322 vex_le_rb2->setValidator( validator );
4323 vec_le_rb2->setValidator( validator );
4324 elts_le_rb2->setValidator( validator );
4325 vex_le_rb2->installEventFilter(this);
4326 vec_le_rb2->installEventFilter(this);
4327 elts_le_rb2->installEventFilter(this);
4329 vex_le_rb0->setReadOnly(true);
4330 elts_le_rb0->setReadOnly(true);
4331 vex_le_rb1->setReadOnly(true);
4332 vec_le_rb1->setReadOnly(true);
4333 elts_le_rb1->setReadOnly(true);
4334 vex_le_rb2->setReadOnly(true);
4335 vec_le_rb2->setReadOnly(true);
4336 elts_le_rb2->setReadOnly(true);
4339 // ============================================================== clear
4340 void MakeSymmetryDialog::clear()
4342 elts_le_rb0->clear();
4343 modelUnregister(elts_le_rb0);
4345 vex_le_rb0->clear();
4346 modelUnregister(vex_le_rb0);
4348 elts_le_rb1->clear();
4349 modelUnregister(elts_le_rb1);
4351 vex_le_rb1->clear();
4352 modelUnregister(vex_le_rb1);
4354 vec_le_rb1->clear();
4355 modelUnregister(vec_le_rb1);
4357 elts_le_rb2->clear();
4358 modelUnregister(elts_le_rb2);
4360 vex_le_rb2->clear();
4361 modelUnregister(vex_le_rb2);
4363 vec_le_rb2->clear();
4364 modelUnregister(vec_le_rb2);
4366 modelUnregister(this);
4369 // ============================================================== updateHelpFileName
4370 void MakeSymmetryDialog::updateHelpFileName()
4372 if ( sender() == rb0 ){
4373 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4374 } else if ( sender() == rb1 ){
4375 _helpFileName = "gui_make_symmetry.html#make-elements-by-line-symmetry";
4376 } else if ( sender() == rb2 ){
4377 _helpFileName = "gui_make_symmetry.html#make-elements-by-plane-symmetry";
4381 // ============================================================== apply
4382 bool MakeSymmetryDialog::apply(QModelIndex& result)
4384 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4386 if (getDocumentModel() == NULL) return false;
4387 const PatternDataModel* patternDataModel = getPatternDataModel();
4388 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4389 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4391 QModelIndex iNewElts;
4393 if ( rb0->isChecked() ){
4394 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4395 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb0] );
4396 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4398 if ( ielts.isValid()
4400 iNewElts = getDocumentModel()->makeSymmetryPoint( ielts, ivex );
4403 } else if ( rb1->isChecked() ){
4404 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4405 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb1] );
4406 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4407 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4408 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb1] );
4410 if ( ielts.isValid()
4413 iNewElts = getDocumentModel()->makeSymmetryLine( ielts, ivex, ivec );
4415 } else if ( rb2->isChecked() ){
4416 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4417 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4418 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4419 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4420 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4422 if ( ielts.isValid()
4425 iNewElts = getDocumentModel()->makeSymmetryPlane( ielts, ivex, ivec );
4428 if ( !iNewElts.isValid() ){
4429 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4433 // result = patternBuilderModel->mapFromSource(iNewElts);
4434 result = patternDataModel->mapFromSource(iNewElts);
4439 // // ------------------------- PerformTransformationDialog ----------------------------------
4440 // ============================================================== Constructeur
4441 PerformTransformationDialog::PerformTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4442 HexaBaseDialog(parent, editmode, f)
4445 _initWidget(editmode);
4448 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4449 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4450 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4451 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4454 // ============================================================== Destructeur
4455 PerformTransformationDialog::~PerformTransformationDialog()
4459 // ============================================================== _initInputWidget
4460 void PerformTransformationDialog::_initInputWidget( Mode editmode )
4463 QValidator *validator = new QRegExpValidator(rx, this);
4465 installEventFilter(this);
4466 rb0->installEventFilter(this);
4467 rb1->installEventFilter(this);
4468 rb2->installEventFilter(this);
4470 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4471 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4472 vec_le_rb0->setValidator( validator );
4473 elts_le_rb0->setValidator( validator );
4474 vec_le_rb0->installEventFilter(this);
4475 elts_le_rb0->installEventFilter(this);
4477 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4478 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4479 vex_le_rb1->setValidator( validator );
4480 elts_le_rb1->setValidator( validator );
4481 vex_le_rb1->installEventFilter(this);
4482 elts_le_rb1->installEventFilter(this);
4485 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4486 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4487 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4488 vex_le_rb2->setValidator( validator );
4489 vec_le_rb2->setValidator( validator );
4490 elts_le_rb2->setValidator( validator );
4491 vex_le_rb2->installEventFilter(this);
4492 vec_le_rb2->installEventFilter(this);
4493 elts_le_rb2->installEventFilter(this);
4495 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
4496 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
4497 angle_spb->setProperty("Angle", QVariant::fromValue(true));
4498 angle_spb->installEventFilter(this);
4500 vec_le_rb0->setReadOnly(true);
4501 elts_le_rb0->setReadOnly(true);
4502 vex_le_rb1->setReadOnly(true);
4503 elts_le_rb1->setReadOnly(true);
4504 vex_le_rb2->setReadOnly(true);
4505 vec_le_rb2->setReadOnly(true);
4506 elts_le_rb2->setReadOnly(true);
4510 // ============================================================== clear
4511 void PerformTransformationDialog::clear()
4513 vec_le_rb0->clear();
4514 modelUnregister(vec_le_rb0);
4516 elts_le_rb0->clear();
4517 modelUnregister(elts_le_rb0);
4519 vex_le_rb1->clear();
4520 modelUnregister(vex_le_rb1);
4522 elts_le_rb1->clear();
4523 modelUnregister(elts_le_rb1);
4525 vex_le_rb2->clear();
4526 modelUnregister(vex_le_rb2);
4528 vec_le_rb2->clear();
4529 modelUnregister(vec_le_rb2);
4531 elts_le_rb2->clear();
4532 modelUnregister(elts_le_rb2);
4534 modelUnregister(this);
4537 // ============================================================== updateHelpFileName
4538 void PerformTransformationDialog::updateHelpFileName()
4540 if ( sender() == rb0 ){
4541 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4542 } else if ( sender() == rb1 ){
4543 _helpFileName = "gui_modify_elmts.html#modify-elements-by-scaling";
4544 } else if ( sender() == rb2 ){
4545 _helpFileName = "gui_modify_elmts.html#modify-elements-by-rotation";
4549 // ============================================================== apply
4550 bool PerformTransformationDialog::apply(QModelIndex& result)
4552 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4555 if (getDocumentModel() == NULL) return false;
4556 const PatternDataModel* patternDataModel = getPatternDataModel();
4557 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4558 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4560 bool performed = false;
4562 if ( rb0->isChecked() ){
4563 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4564 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb0]);
4565 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4566 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb0]);
4568 if ( ielts.isValid()
4570 performed = getDocumentModel()->performTranslation( ielts, ivec );
4572 } else if ( rb1->isChecked() ){
4573 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4574 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb1]);
4575 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4576 double k = k_spb->value();
4578 if ( ielts.isValid()
4580 performed = getDocumentModel()->performScale( ielts, ivex, k );
4582 } else if ( rb2->isChecked() ){
4583 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4584 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4585 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4586 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4587 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4588 double angle = angle_spb->value();
4590 if ( ielts.isValid()
4593 performed = getDocumentModel()->performRotation( ielts, ivex, ivec, angle );
4596 if ( performed == false){
4597 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM TRANSFORMATION" ) + "\n" + getErrorMsg() );
4604 // // ------------------------- PerformSymmetryDialog ----------------------------------
4605 // ============================================================== Constructeur
4606 PerformSymmetryDialog::PerformSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4607 : HexaBaseDialog(parent, editmode, f)
4610 _initWidget( editmode );
4613 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4614 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4615 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4616 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4619 // ============================================================== Destructeur
4620 PerformSymmetryDialog::~PerformSymmetryDialog()
4624 // ============================================================== _initInputWidget
4625 void PerformSymmetryDialog::_initInputWidget( Mode editmode )
4628 QValidator *validator = new QRegExpValidator(rx, this);
4630 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4631 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4632 vex_le_rb0->setValidator( validator );
4633 elts_le_rb0->setValidator( validator );
4634 vex_le_rb0->installEventFilter(this);
4635 elts_le_rb0->installEventFilter(this);
4637 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4638 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4639 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4640 vex_le_rb1->setValidator( validator );
4641 vec_le_rb1->setValidator( validator );
4642 elts_le_rb1->setValidator( validator );
4643 vex_le_rb1->installEventFilter(this);
4644 vec_le_rb1->installEventFilter(this);
4645 elts_le_rb1->installEventFilter(this);
4647 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4648 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4649 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4650 vex_le_rb2->setValidator( validator );
4651 vec_le_rb2->setValidator( validator );
4652 elts_le_rb2->setValidator( validator );
4653 vex_le_rb2->installEventFilter(this);
4654 vec_le_rb2->installEventFilter(this);
4655 elts_le_rb2->installEventFilter(this);
4657 vex_le_rb0->setReadOnly(true);
4658 elts_le_rb0->setReadOnly(true);
4659 vex_le_rb1->setReadOnly(true);
4660 vec_le_rb1->setReadOnly(true);
4661 elts_le_rb1->setReadOnly(true);
4662 vex_le_rb2->setReadOnly(true);
4663 vec_le_rb2->setReadOnly(true);
4664 elts_le_rb2->setReadOnly(true);
4668 // ============================================================== clear
4669 void PerformSymmetryDialog::clear()
4671 vex_le_rb0->clear();
4672 modelUnregister(vex_le_rb0);
4674 elts_le_rb0->clear();
4675 modelUnregister(elts_le_rb0);
4677 elts_le_rb1->clear();
4678 modelUnregister(elts_le_rb1);
4680 vex_le_rb1->clear();
4681 modelUnregister(vex_le_rb1);
4683 vec_le_rb1->clear();
4684 modelUnregister(vec_le_rb1);
4686 elts_le_rb2->clear();
4687 modelUnregister(elts_le_rb2);
4689 vex_le_rb2->clear();
4690 modelUnregister(vex_le_rb2);
4692 vec_le_rb2->clear();
4693 modelUnregister(vec_le_rb2);
4695 modelUnregister(this);
4698 // ============================================================== updateHelpFileName
4699 void PerformSymmetryDialog::updateHelpFileName()
4701 if ( sender() == rb0 ){
4702 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4703 } else if ( sender() == rb1 ){
4704 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-line-symmetry";
4705 } else if ( sender() == rb2 ){
4706 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-plane-symmetry";
4710 // ============================================================== apply
4711 bool PerformSymmetryDialog::apply(QModelIndex& result)
4713 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4716 if (getDocumentModel() == NULL) return false;
4717 const PatternDataModel* patternDataModel = getPatternDataModel();
4718 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4719 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4721 bool performed = false;
4723 if ( rb0->isChecked() ){
4724 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4725 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb0]);
4726 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4728 if ( ielts.isValid()
4730 performed = getDocumentModel()->performSymmetryPoint( ielts, ivex );
4732 } else if ( rb1->isChecked() ){
4733 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4734 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb1]);
4735 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4736 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4737 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb1]);
4739 if ( ielts.isValid()
4742 performed = getDocumentModel()->performSymmetryLine( ielts, ivex, ivec );
4744 } else if ( rb2->isChecked() ){
4745 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4746 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4747 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4748 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4749 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4751 if ( ielts.isValid()
4754 performed = getDocumentModel()->performSymmetryPlane( ielts, ivex, ivec );
4757 if ( performed == false ){
4758 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM SYMMETRY" ) + "\n" + getErrorMsg() );
4765 // // ------------------------- EdgeAssocDialog ----------------------------------
4766 // ============================================================== Constructeur
4767 EdgeAssocDialog::EdgeAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4768 HexaBaseDialog( parent, editmode, f )
4770 _helpFileName ="gui_asso_quad_to_geom.html#one-edge";
4772 _initWidget(editmode);
4777 // ============================================================== Destructeur
4778 EdgeAssocDialog::~EdgeAssocDialog()
4782 // ============================================================== close
4783 void EdgeAssocDialog::close()
4785 HEXABLOCKGUI::assocInProgress = false;
4786 HexaBaseDialog::close();
4789 // ============================================================== _initInputWidget
4790 void EdgeAssocDialog::_initInputWidget( Mode editmode )
4793 QValidator *validator = new QRegExpValidator(rx, this);
4796 first_vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4797 first_vex_le->installEventFilter(this);
4798 first_vex_le->setValidator( validator );
4800 single_edge_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4801 single_edge_le->installEventFilter(this);
4803 edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4804 edges_lw->installEventFilter(this);
4808 lines_lw->setProperty("HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4809 lines_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4810 lines_lw->installEventFilter(this);
4812 single_line_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4813 single_line_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4814 single_line_le->installEventFilter(this);
4817 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), edges_lw);
4818 QShortcut* delLineShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), lines_lw);
4819 delLineShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4820 delEdgeShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4822 pend_spb->setValue(1.);
4824 first_vex_le->setReadOnly(true);
4825 single_edge_le->setReadOnly(true);
4826 single_line_le->setReadOnly(true);
4828 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
4829 connect( delLineShortcut, SIGNAL(activated()), this, SLOT(deleteLineItem()) );
4830 connect( edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
4831 connect( lines_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4832 connect( single_rb, SIGNAL(clicked()), this, SLOT( refreshHighlight()), Qt::UniqueConnection );
4833 connect( multiple_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection );
4834 connect( single_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4835 connect( multiple_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4838 // ============================================================== updateHelpFileName
4839 void EdgeAssocDialog::updateHelpFileName()
4841 if ( sender() == single_rb ){
4842 _helpFileName = "gui_asso_quad_to_geom.html#one-edge";
4843 } else if ( sender() == multiple_rb ){
4844 _helpFileName = "gui_asso_quad_to_geom.html#line";
4848 // ============================================================== getAssocsVTK
4850 * Returns elements currently being associated in vtk side
4852 QModelIndexList EdgeAssocDialog::getAssocsVTK()
4854 QModelIndexList assocs;
4856 QListWidgetItem* item = NULL;
4858 if (getPatternDataSelectionModel() == NULL) return assocs;
4859 if (single_rb->isChecked())
4862 QVariant v = single_edge_le->property("QModelIndex");
4863 if ( !v.isValid() ) return assocs;
4864 assocs << v.value<QModelIndex>();
4867 else if (multiple_rb->isChecked())
4869 //ListWidget content
4870 const PatternDataModel* patternDataModel = getPatternDataModel();
4871 if ( !patternDataModel ) return assocs;
4872 int nbEdges = edges_lw->count();
4873 for ( int r = 0; r < nbEdges; ++r){
4874 item = edges_lw->item(r);
4875 iEdge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4876 if ( iEdge.isValid() ) assocs << iEdge;
4883 // ============================================================== getAssocsGEOM
4885 * Returns elements currently being associated in geom side
4887 QMultiMap<QString, int> EdgeAssocDialog::getAssocsGEOM()
4889 QMultiMap<QString, int> assocs;
4890 QListWidgetItem* item = NULL;
4891 DocumentModel::GeomObj geomObj;
4893 if (single_rb->isChecked())
4896 QVariant v = single_line_le->property("GeomObj");
4897 if ( !v.isValid() ) return assocs;
4898 geomObj = v.value<DocumentModel::GeomObj>();
4899 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4902 else if (multiple_rb->isChecked())
4904 //ListWidget content
4905 unsigned int nbEdges = lines_lw->count();
4906 for ( int r = 0; r < nbEdges; ++r){
4907 item = lines_lw->item(r);
4908 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4909 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4916 // ============================================================== selectElementOfGeom
4917 /*Highlight in the OCC view selected elements in a listwidget,
4918 * or an element in a line edit.*/
4919 void EdgeAssocDialog::selectElementOfGeom()
4921 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4922 if ( !currentListWidget )
4926 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4927 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4928 pgsm->clearSelection();
4929 if (sel.count() == 0)
4932 QListWidgetItem *item = sel[0];
4933 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
4934 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4935 if ( index.isValid() )
4936 pgsm->select( index, QItemSelectionModel::SelectCurrent );
4939 // ============================================================== clear
4940 void EdgeAssocDialog::clear()
4942 first_vex_le->clear();
4943 modelUnregister(first_vex_le);
4946 modelUnregister(edges_lw);
4950 single_edge_le->clear();
4951 modelUnregister(single_edge_le);
4953 single_line_le->clear();
4954 modelUnregister(single_line_le);
4956 modelUnregister(this);
4959 // ============================================================== onWindowActivated
4960 void EdgeAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4962 QString vmType = vm->getType();
4963 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4965 if (single_rb->isChecked())
4966 single_edge_le->setFocus();
4967 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le )
4968 edges_lw->setFocus();
4970 else if ( vmType == OCCViewer_Viewer::Type() ){
4971 if (single_rb->isChecked())
4972 single_line_le->setFocus();
4973 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le)
4974 lines_lw->setFocus();
4978 // ============================================================== apply
4979 bool EdgeAssocDialog::apply(QModelIndex& result)
4981 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4984 bool assocOk = false;
4986 PatternDataModel* patternDataModel = getPatternDataModel();
4987 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4988 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4990 QModelIndex iEdge, iGeomEdge;
4991 QModelIndexList iEdges;
4992 QListWidgetItem* item = NULL;
4993 QList<DocumentModel::GeomObj> assocs;
4994 DocumentModel::GeomObj aLine;
4995 HEXA_NS::SubShape* ssh;
4996 HEXA_NS::EdgeShape* sh;
4997 HEXA_NS::NewShapes shapes;
4998 HEXA_NS::IntVector subIds;
5000 QModelIndexList edges, lines;
5002 if (single_rb->isChecked()){ //Single edge and/or line association
5004 iEdge = patternDataModel->mapToSource( _index[single_edge_le] );
5005 if ( !iEdge.isValid() || myLine == NULL)
5007 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5010 id = myLine->shapeName+","+myLine->subId;
5011 ssh = getDocumentModel()->getGeomPtr(id);
5012 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
5013 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5014 if (!iGeomEdge.isValid())
5016 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5019 assocOk = getDocumentModel()->addEdgeAssociation(iEdge, iGeomEdge, pstart_spb->value(), pend_spb->value());
5020 edges << _index[single_edge_le];
5023 else { //Multiple edge and/or line association
5026 iEdges = getIndexList(edges_lw, true);
5027 int nbLines = lines_lw->count();
5028 if (iEdges.count() == 0 || nbLines == 0)
5030 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5033 edges = getIndexList(edges_lw, false);
5035 for (int r = 0; r < nbLines; ++r){
5036 item = lines_lw->item(r);
5037 aLine = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5038 id = aLine.shapeName+","+aLine.subId;
5039 ssh = getDocumentModel()->getGeomPtr(id);
5040 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
5043 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5046 shapes.push_back(sh->getParentShape());
5047 subIds.push_back(sh->getIdent());
5048 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5049 if (iGeomEdge.isValid())
5053 if ( close_cb->isChecked() ){ //closed line
5054 QModelIndex iFirstVertex = patternDataModel->mapToSource( _index[first_vex_le] );
5055 if ( !iFirstVertex.isValid() )
5057 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5060 bool inv = inverse_cb->isChecked();
5061 assocOk = getDocumentModel()->associateClosedLine( iFirstVertex, iEdges, shapes, subIds, pstart_spb->value(), inv );
5065 assocOk = getDocumentModel()->associateOpenedLine( iEdges, shapes, subIds, pstart_spb->value(), pend_spb->value() );
5069 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) + "\n" + getErrorMsg() );
5073 // highlight associated items in the trees
5074 pdsm->unhighlightTreeItems();
5075 pgsm->unhighlightTreeItems();
5076 pdsm->highlightTreeItems(edges);
5077 pgsm->highlightTreeItems(lines);
5079 // highlight associated items in the views
5080 highlightSelectedAssocs();
5085 // ------------------------- QuadAssocDialog ----------------------------------
5086 // ============================================================== Constructeur
5087 QuadAssocDialog::QuadAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5088 HexaBaseDialog(parent, editmode, f)
5090 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-face-or-a-shell-of-the-geometry";
5092 _initWidget(editmode);
5095 // ============================================================== Destructeur
5096 QuadAssocDialog::~QuadAssocDialog()
5098 disconnect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
5099 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(addFace()) );
5100 delete _delFaceShortcut;
5103 // ============================================================== close
5104 void QuadAssocDialog::close()
5106 HEXABLOCKGUI::assocInProgress = false;
5107 HexaBaseDialog::close();
5110 // ============================================================== _initInputWidget
5111 void QuadAssocDialog::_initInputWidget( Mode editmode )
5114 QValidator *validator = new QRegExpValidator(rx, this);
5116 quad_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5117 quad_le->installEventFilter(this);
5118 quad_le->setValidator( validator );
5120 faces_lw->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
5121 faces_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
5122 faces_lw->installEventFilter(this);
5123 _delFaceShortcut = new QShortcut( QKeySequence(Qt::Key_X/*Qt::Key_Delete*/), faces_lw );
5124 _delFaceShortcut->setContext( Qt::WidgetShortcut );
5126 quad_le->setReadOnly(true);
5128 connect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
5129 connect( faces_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
5132 // ============================================================== getAssocsVTK
5134 * Returns elements currently being associated in vtk side
5136 QModelIndexList QuadAssocDialog::getAssocsVTK()
5138 QModelIndexList assocs;
5142 QVariant v = quad_le->property("QModelIndex");
5145 assocs << v.value<QModelIndex>();
5149 // ============================================================== getAssocsGEOM
5151 * Returns elements currently being associated in geom side
5153 QMultiMap<QString, int> QuadAssocDialog::getAssocsGEOM()
5155 QMultiMap<QString, int> assocs;
5156 QListWidgetItem* item = NULL;
5157 DocumentModel::GeomObj geomObj;
5159 //ListWidget content
5160 unsigned int nbFaces = faces_lw->count();
5161 for ( int r = 0; r < nbFaces; ++r){
5162 item = faces_lw->item(r);
5163 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5164 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
5169 // ============================================================== selectElementOfGeom
5170 /*Highlight in the OCC view selected elements in a listwidget,
5171 * or an element in a line edit.*/
5173 void QuadAssocDialog::selectElementOfGeom()
5175 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5176 if ( !currentListWidget )
5180 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5181 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
5182 pgsm->clearSelection();
5183 if (sel.count() == 0)
5185 QListWidgetItem *item = sel[0];
5186 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
5187 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5188 if ( index.isValid() )
5189 pgsm->select( index, QItemSelectionModel::SelectCurrent );
5192 void QuadAssocDialog::clear()
5195 modelUnregister(quad_le);
5199 modelUnregister(this);
5202 // ============================================================== onWindowActivated
5203 void QuadAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
5205 QString vmType = vm->getType();
5206 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
5207 quad_le->setFocus();
5208 else if ( vmType == OCCViewer_Viewer::Type() ){
5209 faces_lw->setFocus();
5213 // ============================================================== deleteFaceItem
5214 void QuadAssocDialog::deleteFaceItem()
5216 delete faces_lw->currentItem();
5219 // ============================================================== apply
5220 bool QuadAssocDialog::apply(QModelIndex& result)
5222 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5225 PatternDataModel* patternDataModel = getPatternDataModel();
5226 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
5227 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
5230 QModelIndex iQuad, iGeomFace;
5231 HEXA_NS::SubShape* ssh;
5232 HEXA_NS::FaceShape* sh;
5236 iQuad = patternDataModel->mapToSource( _index[quad_le] );
5239 QListWidgetItem* item = NULL;
5240 DocumentModel::GeomObj aFace;
5241 QModelIndexList quads, faces;
5242 int nbFaces = faces_lw->count();
5243 for ( int r = 0; r < nbFaces; ++r ){
5244 item = faces_lw->item(r);
5245 aFace = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5246 id = aFace.shapeName+","+aFace.subId;
5247 ssh = getDocumentModel()->getGeomPtr(id);
5248 sh = dynamic_cast<HEXA_NS::FaceShape*>(ssh);
5251 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) );
5254 iGeomFace = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5255 if (!getDocumentModel()->addQuadAssociation(iQuad, iGeomFace))
5257 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) + "\n" + getErrorMsg() );
5260 else if (iGeomFace.isValid())
5265 if (iQuad.isValid())
5266 quads << _index[quad_le];
5268 // highlight associated items in the trees
5269 pdsm->highlightTreeItems(quads);
5270 pgsm->highlightTreeItems(faces);
5272 // highlight associated items in the views
5273 highlightSelectedAssocs();
5278 // ------------------------- GroupDialog ----------------------------------
5279 // ============================================================== Constructeur
5280 GroupDialog::GroupDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5281 HexaBaseDialog(parent, editmode, f),
5284 _helpFileName = "gui_groups.html#add-group";
5286 _initWidget(editmode);
5287 // setFocusProxy( name_le/*eltBase_lw */);
5289 if ( editmode == NEW_MODE ){
5290 setWindowTitle( tr("Group Construction") );
5291 } else if ( editmode == UPDATE_MODE ){
5292 setWindowTitle( tr("Group Modification") );
5293 } else if ( editmode == INFO_MODE ){
5294 setWindowTitle( tr("Group Information") );
5298 // ============================================================== Destructeur
5299 GroupDialog::~GroupDialog()
5303 // ============================================================== getAssocsVTK
5305 * Returns elements currently being associated in vtk side
5307 QModelIndexList GroupDialog::getAssocsVTK()
5309 QModelIndexList assocs;
5311 QListWidgetItem* item = NULL;
5312 if (getPatternDataSelectionModel() == NULL) return assocs;
5313 //ListWidget content
5314 const PatternDataModel* patternDataModel = getPatternDataModel();
5315 if ( !patternDataModel ) return assocs;
5316 int nbElts = eltBase_lw->count();
5317 for ( int r = 0; r < nbElts; ++r){
5318 item = eltBase_lw->item(r);
5319 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5320 if ( iItem.isValid() ) assocs << iItem;
5325 // ============================================================== _initInputWidget
5326 void GroupDialog::_initInputWidget( Mode editmode )
5328 installEventFilter(this);
5329 name_le->installEventFilter(this);
5332 strKind[ HEXA_NS::HexaCell ] = "HexaCell";
5333 strKind[ HEXA_NS::QuadCell ] = "QuadCell";
5334 strKind[ HEXA_NS::EdgeCell ] = "EdgeCell";
5335 strKind[ HEXA_NS::HexaNode ] = "HexaNode";
5336 strKind[ HEXA_NS::QuadNode ] = "QuadNode";
5337 strKind[ HEXA_NS::EdgeNode ] = "EdgeNode";
5338 strKind[ HEXA_NS::VertexNode ] = "VertexNode";
5340 QMap<HEXA_NS::EnumGroup, QString>::ConstIterator iKind;
5341 for( iKind = strKind.constBegin(); iKind != strKind.constEnd(); ++iKind )
5342 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5344 onKindChanged( kind_cb->currentIndex() );
5345 eltBase_lw->installEventFilter(this);
5347 if ( editmode != INFO_MODE ){
5348 QShortcut* delEltShortcut = new QShortcut( QKeySequence(Qt::Key_X), eltBase_lw );
5349 delEltShortcut->setContext( Qt::WidgetShortcut );
5350 connect(delEltShortcut, SIGNAL(activated()), this, SLOT(removeEltBase()));
5351 connect(kind_cb, SIGNAL(activated(int)), this, SLOT(onKindChanged(int)) );
5354 if ( editmode == INFO_MODE)
5356 name_le->setReadOnly(true);
5357 kind_cb->setEnabled(false);
5358 eltBase_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
5361 connect(eltBase_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5364 // ============================================================== clear
5365 void GroupDialog::clear()
5369 eltBase_lw->clear();
5370 modelUnregister(eltBase_lw);
5372 modelUnregister(this);
5375 // ============================================================== onKindChanged
5376 void GroupDialog::onKindChanged(int index)
5379 switch ( kind_cb->itemData(index).toInt() ){
5380 case HEXA_NS::HexaCell:
5381 case HEXA_NS::HexaNode:
5382 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(HEXA_TREE));
5385 case HEXA_NS::QuadCell:
5386 case HEXA_NS::QuadNode:
5387 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5390 case HEXA_NS::EdgeCell:
5391 case HEXA_NS::EdgeNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
5394 case HEXA_NS::VertexNode:
5395 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
5398 default:Q_ASSERT(false);
5400 eltBase_lw->clear();
5401 eltBase_lw->setFocus();
5404 // ============================================================== setValue
5405 void GroupDialog::setValue(HEXA_NS::Group* g)
5408 name_le->setText( g->getName() );
5412 kind_cb->addItem ( strKind[g->getKind()], QVariant( g->getKind() ) );
5415 HEXA_NS::EltBase* eltBase = NULL;
5416 QListWidgetItem* item = NULL;
5417 QModelIndex iEltBase;
5418 QList<QStandardItem *> eltBaseItems;
5421 if ( !getPatternDataSelectionModel() ) return;
5422 if ( !getGroupsSelectionModel() ) return;
5424 QModelIndex iGroup = getGroupsSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(g) );
5425 name_le->setProperty( "QModelIndex", QVariant::fromValue(iGroup) );
5428 int nbElts = g->countElement();
5429 for ( int nr = 0; nr < nbElts; ++nr ){
5430 eltBase = g->getElement( nr );
5431 switch ( g->getKind() ){
5432 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: v = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
5433 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: v = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
5434 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: v = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
5435 case HEXA_NS::VertexNode: v = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
5437 iEltBase = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, v);
5438 if ( iEltBase.isValid() ){
5439 item = new QListWidgetItem( eltBase->getName() );
5440 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iEltBase) );
5441 item->setData(LW_DATA_ROLE, iEltBase.data(HEXA_DATA_ROLE));
5442 eltBase_lw->addItem( item );
5448 // ============================================================== getValue
5449 HEXA_NS::Group* GroupDialog::getValue()
5454 // ============================================================== removeEltBase
5455 void GroupDialog::removeEltBase()
5457 QListWidgetItem *item = eltBase_lw->currentItem();
5460 int r = eltBase_lw->row(item);
5461 eltBase_lw->takeItem(r);
5467 // ============================================================== apply
5468 bool GroupDialog::apply(QModelIndex& result)
5470 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5473 if ( !getDocumentModel() ) return false;
5474 const PatternDataModel* patternDataModel = getPatternDataModel();
5475 const GroupsModel* groupsModel = getGroupsModel();
5476 if (patternDataModel == NULL || groupsModel == NULL) return false;
5478 QString grpName = name_le->text();
5479 DocumentModel::Group grpKind = static_cast<DocumentModel::Group>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5481 if ( _value == NULL ){ // create group
5482 iGrp = getDocumentModel()->addGroup( grpName, grpKind );
5484 QModelIndexList iGrps = getDocumentModel()->match(
5485 getDocumentModel()->index(0, 0),
5487 QVariant::fromValue( _value ),
5489 Qt::MatchRecursive );
5490 if ( !iGrps.isEmpty() )
5495 if ( !iGrp.isValid() ){
5496 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD GROUP" ) + "\n" + getErrorMsg() );
5500 //fill it and select it
5501 QModelIndex iEltBase;
5502 QListWidgetItem* item = NULL;
5503 bool eltAdded = false;
5504 getDocumentModel()->clearGroupElement(iGrp);
5505 int nbElts = eltBase_lw->count();
5506 for ( int r = 0; r < nbElts; ++r){
5507 item = eltBase_lw->item(r);
5508 iEltBase = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5509 if ( iEltBase.isValid() )
5510 eltAdded = getDocumentModel()->addGroupElement( iGrp, iEltBase );
5513 QString newName = name_le->text();
5514 if ( !newName.isEmpty() )
5515 getDocumentModel()->setName( iGrp, newName );
5517 HEXA_NS::Group* hGroup = getDocumentModel()->data(iGrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
5520 QString groupName = QString::fromStdString(hGroup->getNextName());
5521 name_le->setText(groupName);
5524 result = groupsModel->mapFromSource(iGrp);
5529 // ------------------------- LawDialog ----------------------------------
5530 // ============================================================== Constructeur
5532 LawDialog::LawDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5533 : HexaBaseDialog(parent, editmode, f),
5536 _helpFileName = "gui_discret_law.html#add-law";
5538 _initWidget(editmode);
5539 if ( editmode == NEW_MODE ){
5540 setWindowTitle( tr("Law Construction") );
5541 } else if ( editmode == UPDATE_MODE ){
5542 setWindowTitle( tr("Law Modification") );
5544 else if ( editmode == INFO_MODE){
5545 setWindowTitle( tr("Law Information") );
5549 // ============================================================== Destructeur
5550 LawDialog::~LawDialog()
5554 // ============================================================== _initInputWidget
5555 void LawDialog::_initInputWidget( Mode editmode )
5559 // setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5560 installEventFilter(this);
5562 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5563 name_le->installEventFilter(this);
5566 strKind[ HEXA_NS::Uniform ] = "Uniform";
5567 strKind[ HEXA_NS::Arithmetic ] = "Arithmetic";
5568 strKind[ HEXA_NS::Geometric ] = "Geometric";
5571 QMap<HEXA_NS::KindLaw, QString>::ConstIterator iKind, iEnd;
5572 for( iKind = strKind.constBegin(), iEnd = strKind.constEnd(); iKind != iEnd; ++iKind )
5573 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5575 if (editmode == INFO_MODE)
5577 name_le->setReadOnly(true);
5578 nb_nodes_spb->setReadOnly(true);
5579 coeff_spb->setReadOnly(true);
5580 kind_cb->setEnabled(false);
5584 // ============================================================== clear
5585 void LawDialog::clear()
5589 modelUnregister(this);
5592 // ============================================================== setValue
5593 void LawDialog::setValue(HEXA_NS::Law* l)
5596 name_le->setText( l->getName() );
5598 nb_nodes_spb->setValue( l->getNodes() );
5599 coeff_spb->setValue( l->getCoefficient() );
5601 HEXA_NS::KindLaw k = l->getKind();
5602 kind_cb->setCurrentIndex( kind_cb->findData(k) );
5607 // ============================================================== getValue
5608 HEXA_NS::Law* LawDialog::getValue()
5613 // ============================================================== apply
5614 bool LawDialog::apply(QModelIndex& result)
5616 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5619 if ( !getDocumentModel() ) return false;
5621 const MeshModel* meshModel = getMeshModel();
5622 if (meshModel == NULL) return false;
5624 QString lawName = name_le->text();
5625 int nbnodes = nb_nodes_spb->value();
5626 double coeff = coeff_spb->value();
5627 DocumentModel::KindLaw lawKind = static_cast<DocumentModel::KindLaw>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5630 if ( _value == NULL ){ // create Law
5631 iLaw = getDocumentModel()->addLaw( lawName, nbnodes );
5633 QModelIndexList iLaws = getDocumentModel()->match(
5634 getDocumentModel()->index(0, 0),
5636 QVariant::fromValue( _value ),
5638 Qt::MatchRecursive );
5639 if ( !iLaws.isEmpty() )
5643 if ( !iLaw.isValid() ){
5644 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5647 //fill it and select it
5648 bool setOk = getDocumentModel()->setLaw( iLaw, nbnodes, coeff, lawKind );
5650 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5654 QString newName = name_le->text();
5655 if ( !newName.isEmpty() )/*{*/
5656 getDocumentModel()->setName( iLaw, newName );
5658 HEXA_NS::Law* hLaw = getDocumentModel()->data(iLaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
5662 name_le->setText(hLaw->getNextName(buffer));
5666 result = meshModel->mapFromSource(iLaw);
5671 // ------------------------- PropagationDialog ----------------------------------
5672 // ============================================================== Constructeur
5673 PropagationDialog::PropagationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5674 : HexaBaseDialog(parent, editmode, f),
5677 _helpFileName = "gui_propag.html";
5679 _initWidget(editmode);
5681 if ( editmode == INFO_MODE ){
5682 setWindowTitle( tr("Propagation Information") );
5685 } else if ( editmode == UPDATE_MODE ){
5686 setWindowTitle( tr("Propagation Modification") );
5689 } else if ( editmode == NEW_MODE ){
5690 setWindowTitle( tr("Propagation(s) Setting") );
5694 // ============================================================== Destructeur
5695 PropagationDialog::~PropagationDialog()
5699 // ============================================================== _initInputWidget
5700 void PropagationDialog::_initInputWidget( Mode editmode )
5703 QValidator *validator = new QRegExpValidator(rx, this);
5705 installEventFilter(this);
5708 law_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5709 law_le->installEventFilter(this);
5710 law_le->setValidator( validator );
5712 propagations_lw->setProperty( "HexaWidgetType", QVariant::fromValue(PROPAGATION_TREE) );
5713 propagations_lw->installEventFilter(this);
5715 QShortcut* delPropagationShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), propagations_lw);
5716 delPropagationShortcut->setContext( Qt::WidgetShortcut );
5718 law_le->setReadOnly(true);
5720 if ( editmode == INFO_MODE)
5721 way_cb->setEnabled(false);
5723 connect( delPropagationShortcut, SIGNAL(activated()), this, SLOT(deletePropagationItem()) );
5724 connect( propagations_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
5727 // ============================================================== clear
5728 void PropagationDialog::clear()
5730 propagations_lw->clear();
5731 modelUnregister(propagations_lw);
5734 modelUnregister(law_le);
5736 modelUnregister(this);
5739 // ============================================================== deletePropagationItem
5740 void PropagationDialog::deletePropagationItem()
5742 delete propagations_lw->currentItem();
5745 // ============================================================== setValue
5746 void PropagationDialog::setValue(HEXA_NS::Propagation* p)
5748 if (getMeshSelectionModel() == NULL) return;
5749 HEXA_NS::Law* l = p->getLaw();
5750 bool way = p->getWay();
5753 QModelIndex ip = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
5754 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(ip) );
5756 // law on propagation
5758 law_le->setText( l->getName() );
5759 QModelIndex il = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(l) );
5760 law_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(il) );
5763 // way of propagation
5764 way_cb->setChecked(way);
5769 // ============================================================== selectElementOfModel
5771 /*Selects in the model (treeview) elements selected in a listwidget,
5772 * or an element in a line edit.*/
5774 void PropagationDialog::selectElementOfModel()
5776 if (!getMeshSelectionModel()) return;
5778 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5779 if ( !currentListWidget ) return;
5781 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5783 getMeshSelectionModel()->clearSelection();
5784 foreach ( QListWidgetItem *item, sel ){
5785 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
5786 index = getMeshSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5787 if ( index.isValid() )
5788 getMeshSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
5792 // ============================================================== getValue
5793 HEXA_NS::Propagation* PropagationDialog::getValue()
5798 // ============================================================== apply
5799 bool PropagationDialog::apply(QModelIndex& result)
5801 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5805 if ( !getDocumentModel() ) return false;
5806 const MeshModel* meshModel = getMeshModel();
5807 if (meshModel == NULL) return false;
5809 bool way = way_cb->isChecked();
5810 QListWidgetItem* item = NULL;
5812 QModelIndex iPropagation;
5813 QModelIndex iLaw = meshModel->mapToSource( law_le->property("QModelIndex").value<QModelIndex>() );
5814 if (!iLaw.isValid() ){
5815 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5819 int nbPropagations = propagations_lw->count();
5820 for (int r = 0; r < nbPropagations; ++r){
5821 item = propagations_lw->item(r);
5822 iPropagation = meshModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5823 if ( !iPropagation.isValid() ){
5824 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5828 //fill it and select it
5829 isOk = getDocumentModel()->setPropagation( iPropagation, iLaw, way );
5831 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) + "\n" + getErrorMsg() );
5835 result = meshModel->mapFromSource(iPropagation);
5841 // ------------------------- ComputeMeshDialog ----------------------------------
5842 // ============================================================== Constructeur
5843 ComputeMeshDialog::ComputeMeshDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5844 HexaBaseDialog(parent, editmode, f)
5846 _helpFileName = "gui_mesh.html";
5847 setWindowTitle( tr("Compute mesh") );
5849 _initWidget(editmode);
5852 // ============================================================== Destructeur
5853 ComputeMeshDialog::~ComputeMeshDialog()
5857 // ============================================================== _initInputWidget
5858 void ComputeMeshDialog::_initInputWidget( Mode editmode )
5862 // ============================================================== setDocumentModel
5863 void ComputeMeshDialog::setDocumentModel(DocumentModel* m)
5865 if (m == NULL) return;
5866 _name->setText(m->getName());
5869 // ============================================================== clear
5870 void ComputeMeshDialog::clear()
5872 modelUnregister(this);
5875 // ============================================================== apply
5876 bool ComputeMeshDialog::apply(QModelIndex& result)
5878 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5881 if (getDocumentModel() == NULL) return false;
5882 #ifndef DISABLE_PYCONSOLE
5883 QString command = QString("import hexablock ; %1 = hexablock.mesh(\"%2\", \"%1\", %3, \"%4\")")
5884 .arg( _name->text() )
5885 .arg( getDocumentModel()->getName() )
5886 .arg( _dim->value() )
5887 .arg( _fact->text() );
5889 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
5890 PyConsole_Console* pyConsole = app->pythonConsole();
5893 pyConsole->exec( command );
5903 // ------------------------- ReplaceHexaDialog ----------------------------------
5904 // ============================================================== Constructeur
5905 ReplaceHexaDialog::ReplaceHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5906 HexaBaseDialog(parent, editmode, f)
5908 _helpFileName = "gui_replace_hexa.html";
5910 _initWidget(editmode);
5913 // ============================================================== Destructeur
5914 ReplaceHexaDialog::~ReplaceHexaDialog()
5918 // ============================================================== getAssocsVTK
5920 * Returns elements currently associated to vtk
5922 QModelIndexList ReplaceHexaDialog::getAssocsVTK()
5924 QModelIndexList assocs;
5926 QListWidgetItem* item = NULL;
5928 //ListWidget content
5929 int nbQuads = quads_lw->count();
5930 for ( int r = 0; r < nbQuads; ++r ){
5931 item = quads_lw->item(r);
5932 //iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
5933 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5934 if ( iQuad.isValid() )
5938 nbQuads = quads_lw_2->count();
5939 for( int i = 0; i < nbQuads; ++i)
5941 item = quads_lw_2->item(i);
5942 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5943 if (iQuad.isValid())
5950 // ============================================================== _initInputWidget
5951 void ReplaceHexaDialog::_initInputWidget( Mode editmode )
5955 installEventFilter(this);
5957 c1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5958 c2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5960 p1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5961 p2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5963 c1_le->installEventFilter(this);
5964 c2_le->installEventFilter(this);
5966 p1_le->installEventFilter(this);
5967 p2_le->installEventFilter(this);
5969 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5970 quads_lw->installEventFilter(this);
5972 quads_lw_2->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5973 quads_lw_2->installEventFilter(this);
5975 if ( editmode == NEW_MODE ){
5976 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5977 QShortcut* delQuadShortcut2 = new QShortcut( QKeySequence(Qt::Key_X), quads_lw_2 );
5978 delQuadShortcut->setContext( Qt::WidgetShortcut );
5979 delQuadShortcut2->setContext( Qt::WidgetShortcut );
5980 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()) );
5981 connect( quads_lw, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5982 connect( delQuadShortcut2, SIGNAL(activated()), this, SLOT(deleteQuadItem2()));
5983 connect( quads_lw_2, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5986 c1_le->setReadOnly(true);
5987 c2_le->setReadOnly(true);
5989 p1_le->setReadOnly(true);
5990 p2_le->setReadOnly(true);
5992 connect(quads_lw, SIGNAL(itemSelectionChanged()),
5993 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5995 connect(quads_lw_2, SIGNAL(itemSelectionChanged()),
5996 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5999 // ============================================================== clear
6000 void ReplaceHexaDialog::clear()
6003 modelUnregister(quads_lw);
6005 quads_lw_2->clear();
6006 modelUnregister(quads_lw_2);
6009 modelUnregister(p1_le);
6012 modelUnregister(p2_le);
6015 modelUnregister(c1_le);
6018 modelUnregister(c2_le);
6020 modelUnregister(this);
6023 // ============================================================== updateButtonBox
6024 void ReplaceHexaDialog::updateButtonBox()
6026 int nbQuad = quads_lw->count();
6029 _applyButton->setEnabled(true);
6031 _applyButton->setEnabled(false);
6035 // ============================================================== deleteQuadItem
6036 void ReplaceHexaDialog::deleteQuadItem()
6038 delete quads_lw->currentItem();
6042 // ============================================================== deleteQuadItem2
6043 void ReplaceHexaDialog::deleteQuadItem2()
6045 delete quads_lw_2->currentItem();
6049 // ============================================================== apply
6050 bool ReplaceHexaDialog::apply(QModelIndex& result)
6052 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6055 if ( !getDocumentModel() ) return false;
6056 const PatternDataModel* patternDataModel = getPatternDataModel();
6057 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6058 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
6060 QModelIndex ielts; //result
6062 QListWidgetItem* item = NULL;
6063 QModelIndexList iquads_source;
6065 int nbQuads = quads_lw->count();
6066 for ( int r = 0; r < nbQuads; ++r){
6067 item = quads_lw->item(r);
6068 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6069 if ( iquad.isValid() )
6070 iquads_source << iquad;
6073 QModelIndexList iquads_dest;
6074 nbQuads = quads_lw_2->count();
6075 for (int i = 0; i < nbQuads; ++i)
6077 item = quads_lw_2->item(i);
6078 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6079 if (iquad.isValid())
6080 iquads_dest << iquad;
6083 QModelIndex ip1_source = patternDataModel->mapToSource( _index[p1_le] );
6084 QModelIndex ip2_source = patternDataModel->mapToSource( _index[p2_le] );
6086 QModelIndex ic1_dest = patternDataModel->mapToSource( _index[c1_le] );
6087 QModelIndex ic2_dest = patternDataModel->mapToSource( _index[c2_le] );
6089 bool ipts_ok = ip1_source.isValid() && ip2_source.isValid() &&
6090 ic1_dest.isValid() && ic2_dest.isValid();
6094 ielts = getDocumentModel()->replace( iquads_source, iquads_dest,
6095 ip1_source, ic1_dest,
6096 ip2_source, ic2_dest );
6099 if ( !ielts.isValid() ){
6100 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REPLACE HEXA" ) + "\n" + getErrorMsg() );
6103 _value = ielts.model()->data(ielts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6104 // result = patternBuilderModel->mapFromSource(ielts);
6105 result = patternDataModel->mapFromSource(ielts);
6107 //update the list (indexes)
6108 for ( int r = 0; r < nbQuads; ++r ){
6109 item = quads_lw->item(r);
6110 iquad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
6111 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iquad) );
6112 item->setData(LW_DATA_ROLE, iquad.data(HEXA_DATA_ROLE));
6118 // ------------------------- QuadRevolutionDialog ----------------------------------
6119 // ============================================================== Constructeur
6121 QuadRevolutionDialog::QuadRevolutionDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
6122 HexaBaseDialog(parent, editmode, f)
6125 _helpFileName = "gui_quad_revolution.html#guiquadsrevolution";
6126 connect( revolutionUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6127 connect( revolution_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6128 _initWidget(editmode);
6129 revolutionUni_rb->click();
6132 // ============================================================== getAssocsVTK
6134 * Returns elements currently associated to vtk
6136 QModelIndexList QuadRevolutionDialog::getAssocsVTK()
6138 QModelIndexList assocs;
6140 QListWidgetItem* item = NULL;
6141 if (getPatternDataSelectionModel() == NULL) return assocs;
6143 //ListWidget content
6144 const PatternDataModel* patternDataModel = getPatternDataModel();
6145 if ( !patternDataModel ) return assocs;
6146 int nbQuads = quads_lw->count();
6147 for ( int r = 0; r < nbQuads; ++r ){
6148 item = quads_lw->item(r);
6149 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6150 if ( iQuad.isValid() )
6156 // ============================================================== Destructeur
6157 QuadRevolutionDialog::~QuadRevolutionDialog()
6161 // ============================================================== _initInputWidget
6162 void QuadRevolutionDialog::_initInputWidget( Mode editmode )
6164 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
6165 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6166 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6168 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
6169 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
6170 angle_spb->setProperty("Angle", QVariant::fromValue(true));
6171 angle_spb->installEventFilter(this);
6173 angles_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
6174 angles_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
6175 angles_lw->setProperty("Angle", QVariant::fromValue(true));
6176 angles_lw->installEventFilter(this);
6178 installEventFilter(this);
6179 revolutionUni_rb->installEventFilter(this);
6180 revolution_rb->installEventFilter(this);
6182 quads_lw->installEventFilter(this);
6183 center_le->installEventFilter(this);
6184 axis_le->installEventFilter(this);
6186 center_le->setReadOnly(true);
6187 axis_le->setReadOnly(true);
6189 angles_lw->setItemDelegate( new HexaAngleDoubleSpinBoxDelegate(angles_lw) );
6190 angles_lw->setEditTriggers( QAbstractItemView::DoubleClicked );
6192 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
6193 delQuadShortcut->setContext( Qt::WidgetShortcut );
6194 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(delQuadItem()) );
6195 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()));
6196 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()));
6198 connect(quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
6201 // ============================================================== updateHelpFileName
6202 void QuadRevolutionDialog::updateHelpFileName()
6204 if ( sender() == revolutionUni_rb ){
6205 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutionuniform";
6206 } else if ( sender() == revolution_rb ){
6207 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutioncustom";
6211 // ============================================================== clear
6212 void QuadRevolutionDialog::clear()
6215 modelUnregister(quads_lw);
6218 modelUnregister(center_le);
6221 modelUnregister(axis_le);
6223 modelUnregister(this);
6226 // ============================================================== addAngleItem
6227 void QuadRevolutionDialog::addAngleItem() //CS_TODO
6229 QListWidgetItem* previousItem = angles_lw->currentItem();
6230 QListWidgetItem* newItem = new QListWidgetItem();
6232 double defaultValue = 180.;
6234 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6236 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6237 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6238 angles_lw->addItem(newItem);
6243 // ============================================================== delAngleItem
6244 void QuadRevolutionDialog::delAngleItem()
6246 delete angles_lw->currentItem();
6250 // ============================================================== delQuadItem
6251 void QuadRevolutionDialog::delQuadItem()
6253 delete quads_lw->currentItem();
6257 // ============================================================== apply
6258 bool QuadRevolutionDialog::apply(QModelIndex& result)
6260 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6263 DocumentModel* docModel = getDocumentModel();
6264 PatternDataModel* patternDataModel = getPatternDataModel();
6265 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6267 QListWidgetItem* item = NULL;
6269 QModelIndexList istartquads;
6271 int nbQuads = quads_lw->count();
6272 for ( int r = 0; r < nbQuads; ++r){
6273 item = quads_lw->item(r);
6274 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6275 if ( iquad.isValid() )
6276 istartquads << iquad;
6279 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6280 QModelIndex iaxis = patternDataModel->mapToSource(_index[axis_le]);
6281 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
6282 int angle = angle_spb->value();
6283 int nbre = nbre_spb->value();
6285 vector<double> angles;
6286 int nbAngles = angles_lw->count();
6287 for ( int r = 0; r < nbAngles; ++r){
6288 item = angles_lw->item(r);
6289 angles.push_back(item->data(Qt::EditRole).toDouble());
6292 QModelIndex iElts; //result
6293 if (nbQuads == 1 && istartquads[0].isValid() && icenter.isValid() && iaxis.isValid())
6295 if (revolutionUni_rb->isChecked())
6296 iElts = docModel->revolutionQuadUni(istartquads[0], icenter, iaxis, angle, nbre);
6297 else if (revolution_rb->isChecked())
6298 iElts = docModel->revolutionQuad(istartquads[0], icenter, iaxis, angles);
6300 else if (nbQuads > 1 && icenter.isValid() && iaxis.isValid())
6302 if (revolutionUni_rb->isChecked())
6303 iElts = docModel->revolutionQuadsUni(istartquads, icenter, iaxis, angle, nbre);
6304 else if (revolution_rb->isChecked())
6305 iElts = docModel->revolutionQuads(istartquads, icenter, iaxis, angles);
6308 if ( !iElts.isValid() ){
6309 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD REVOLUTION" ) + "\n" + getErrorMsg() );
6312 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6313 result = patternDataModel->mapFromSource(iElts);
6314 // result = patternBuilderModel->mapFromSource(iElts);
6319 // ------------------------- MakeHemiSphereDialog ----------------------------------
6320 // ============================================================== Constructeur
6321 MakeHemiSphereDialog::MakeHemiSphereDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
6322 HexaBaseDialog(parent, editmode, f)
6324 _helpFileName = "gui_hemisphere.html";
6326 _initWidget(editmode);
6329 connect( sphereTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6330 connect( sphereUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6331 connect( sphere2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6332 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6333 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6335 connect( sphericalTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6336 connect( sphericalUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6337 connect( spherical2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6338 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6339 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6341 connect( rindTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6342 connect( rindUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6343 connect( rind2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6344 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6345 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6348 // ============================================================== Destructeur
6349 MakeHemiSphereDialog::~MakeHemiSphereDialog()
6353 // ============================================================== _initInputWidget
6354 void MakeHemiSphereDialog::_initInputWidget( Mode editmode )
6356 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6357 hole_axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6358 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6359 vplan_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6361 sphere_radext_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6362 sphere_radext_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6363 sphere_radext_spb->setProperty("Radius", QVariant::fromValue(true));
6365 sphere_radint_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6366 sphere_radint_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6367 sphere_radint_spb->setProperty("Radius", QVariant::fromValue(true));
6369 hole_rad_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6370 hole_rad_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6371 hole_rad_spb->setProperty("Radius", QVariant::fromValue(true));
6373 radial_angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6374 radial_angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6375 radial_angle_spb->setProperty("Angle", QVariant::fromValue(true));
6377 radius_lw_1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6378 radius_lw_1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6379 radius_lw_1->setProperty("Radius", QVariant::fromValue(true));
6381 radius_lw_2->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6382 radius_lw_2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6383 radius_lw_2->setProperty("Radius", QVariant::fromValue(true));
6385 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6386 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6387 height_lw->setProperty("Length", QVariant::fromValue(true));
6389 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6390 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6391 angle_lw->setProperty("Angle", QVariant::fromValue(true));
6393 installEventFilter(this);
6394 center_le->installEventFilter(this);
6395 hole_axis_le->installEventFilter(this);
6396 base_le->installEventFilter(this);
6397 vplan_le->installEventFilter(this);
6399 sphere_radext_spb->installEventFilter(this);
6400 sphere_radint_spb->installEventFilter(this);
6401 hole_rad_spb->installEventFilter(this);
6402 radial_angle_spb->installEventFilter(this);
6403 radius_lw_1->installEventFilter(this);
6404 radius_lw_2->installEventFilter(this);
6405 height_lw->installEventFilter(this);
6406 angle_lw->installEventFilter(this);
6408 sphere_rb->installEventFilter(this);
6409 sphereTop_rb->installEventFilter(this);
6410 sphereUni_rb->installEventFilter(this);
6411 sphere2_rb->installEventFilter(this);
6412 rind_rb->installEventFilter(this);
6413 rindTop_rb->installEventFilter(this);
6414 rindUni_rb->installEventFilter(this);
6415 rind2_rb->installEventFilter(this);
6416 spherical_rb->installEventFilter(this);
6417 sphericalTop_rb->installEventFilter(this);
6418 sphericalUni_rb->installEventFilter(this);
6419 spherical2_rb->installEventFilter(this);
6421 center_le->setReadOnly(true);
6422 hole_axis_le->setReadOnly(true);
6423 base_le->setReadOnly(true);
6424 vplan_le->setReadOnly(true);
6426 radius_lw_1->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_1));
6427 radius_lw_1->setEditTriggers(QAbstractItemView::DoubleClicked);
6429 radius_lw_2->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_2));
6430 radius_lw_2->setEditTriggers(QAbstractItemView::DoubleClicked);
6432 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
6433 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6435 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
6436 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6438 connect( add_radius_pb_1, SIGNAL(clicked()), this, SLOT(addRadiusItem1()) );
6439 connect( del_radius_pb_1, SIGNAL(clicked()), this, SLOT(delRadiusItem1()) );
6441 connect( add_radius_pb_2, SIGNAL(clicked()), this, SLOT(addRadiusItem2()) );
6442 connect( del_radius_pb_2, SIGNAL(clicked()), this, SLOT(delRadiusItem2()) );
6444 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
6445 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
6447 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
6448 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
6451 // ============================================================== updateHelpFileName
6452 void MakeHemiSphereDialog::updateHelpFileName()
6454 if ( sender() == sphereTop_rb || sender() == rindTop_rb ){
6455 _helpFileName = "gui_hemisphere.html#guisphereandrindsimple";
6456 } else if ( sender() == sphereUni_rb ){
6457 _helpFileName = "gui_hemisphere.html#guisphereuniform";
6458 } else if ( sender() == sphere2_rb ){
6459 _helpFileName = "gui_hemisphere.html#guispherecustom";
6460 } else if ( sender() == rindUni_rb ){
6461 _helpFileName = "gui_hemisphere.html#guirinduniform";
6462 } else if ( sender() == rind2_rb ){
6463 _helpFileName = "gui_hemisphere.html#guirindcustom";
6464 } else if ( sender() == sphericalTop_rb ){
6465 _helpFileName = "gui_hemisphere.html#guiconcentricsimple";
6466 } else if ( sender() == sphericalUni_rb ){
6467 _helpFileName = "gui_hemisphere.html#guiconcentricuniform";
6468 } else if ( sender() == spherical2_rb ){
6469 _helpFileName = "gui_hemisphere.html#guiconcentriccustom";
6473 // ============================================================== addRadiusItem
6474 void MakeHemiSphereDialog::addRadiusItem1()
6476 QListWidgetItem* previousItem = radius_lw_1->currentItem();
6477 QListWidgetItem* newItem = new QListWidgetItem();
6479 double defaultValue = 1.;
6481 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6483 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6484 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6485 radius_lw_1->addItem(newItem);
6488 // ============================================================== delRadiusItem
6489 void MakeHemiSphereDialog::delRadiusItem1()
6491 delete radius_lw_1->currentItem();
6494 // ============================================================== addRadiusItem
6495 void MakeHemiSphereDialog::addRadiusItem2()
6497 QListWidgetItem* previousItem = radius_lw_2->currentItem();
6498 QListWidgetItem* newItem = new QListWidgetItem();
6500 double defaultValue = 1.;
6502 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6504 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6505 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6506 radius_lw_2->addItem(newItem);
6509 // ============================================================== delRadiusItem
6510 void MakeHemiSphereDialog::delRadiusItem2()
6512 delete radius_lw_2->currentItem();
6515 // ============================================================== addAngleItem
6516 void MakeHemiSphereDialog::addAngleItem()
6518 QListWidgetItem* previousItem = angle_lw->currentItem();
6519 QListWidgetItem* newItem = new QListWidgetItem();
6521 double defaultValue = 180.;
6523 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6525 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6526 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6527 angle_lw->addItem(newItem);
6530 // ============================================================== delAngleItem
6531 void MakeHemiSphereDialog::delAngleItem()
6533 delete angle_lw->currentItem();
6536 // ============================================================== addHeightItem
6537 void MakeHemiSphereDialog::addHeightItem()
6539 QListWidgetItem* previousItem = height_lw->currentItem();
6540 QListWidgetItem* newItem = new QListWidgetItem();
6542 double defaultValue = 1.;
6544 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6546 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6547 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6548 height_lw->addItem(newItem);
6551 // ============================================================== delHeightItem
6552 void MakeHemiSphereDialog::delHeightItem()
6554 delete height_lw->currentItem();
6557 // ============================================================== clear
6558 void MakeHemiSphereDialog::clear()
6561 modelUnregister(center_le);
6563 hole_axis_le->clear();
6564 modelUnregister(hole_axis_le);
6567 modelUnregister(base_le);
6570 modelUnregister(vplan_le);
6572 modelUnregister(this);
6575 // ============================================================== apply
6576 bool MakeHemiSphereDialog::apply(QModelIndex& result)
6578 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6581 DocumentModel* docModel = getDocumentModel();
6582 PatternDataModel* patternDataModel = getPatternDataModel();
6583 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6586 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6587 QModelIndex ivplan = patternDataModel->mapToSource( _index[vplan_le] );
6588 QModelIndex ivecx = patternDataModel->mapToSource(_index[base_le]);
6589 QModelIndex ivecz = patternDataModel->mapToSource(_index[hole_axis_le]);
6590 // QModelIndex ivecx = patternBuilderModel->mapToSource( _index[base_le] );
6591 // QModelIndex ivecz = patternBuilderModel->mapToSource( _index[hole_axis_le] );
6593 double radhole = hole_rad_spb->value();
6594 double radext = sphere_radext_spb->value();
6595 double radint = sphere_radint_spb->value();
6596 double radang = radial_angle_spb->value();
6598 int crit = crit_spb->value();
6599 int nb = nbre_spb->value();
6600 int nrad = ngrid_rad_spb->value();
6601 int nang = ngrid_ang_spb->value();
6602 int nhaut = ngrid_height_spb->value();
6604 //radius, angles and heights collection
6605 QListWidgetItem* item = NULL;
6607 vector<double> radius1;
6608 vector<double> radius2;
6609 vector<double> angles;
6610 vector<double> heights;
6613 // double somme = 0.;
6614 int nbAngles = angle_lw->count();
6615 for ( int r = 0; r < nbAngles; ++r){
6616 item = angle_lw->item(r);
6617 double itemValue = item->data(Qt::EditRole).toDouble();
6618 angles.push_back(itemValue);
6619 // somme += itemValue;
6622 //radius1 collection
6623 int nbRadius = radius_lw_1->count();
6624 for ( int r = 0; r < nbRadius; ++r){
6625 item = radius_lw_1->item(r);
6626 radius1.push_back(item->data(Qt::EditRole).toDouble());
6629 //radius2 collection
6630 nbRadius = radius_lw_2->count();
6631 for ( int r = 0; r < nbRadius; ++r){
6632 item = radius_lw_2->item(r);
6633 radius2.push_back(item->data(Qt::EditRole).toDouble());
6636 //heights collection
6637 int nbHeight = height_lw->count();
6638 for ( int r = 0; r < nbHeight; ++r){
6639 item = height_lw->item(r);
6640 heights.push_back(item->data(Qt::EditRole).toDouble());
6643 if (sphere_rb->isChecked())
6645 if (sphereTop_rb->isChecked())
6646 iElts = docModel->makeSphereTop( nrad, nang, nhaut );
6647 else if (sphereUni_rb->isChecked())
6649 if (icenter.isValid() && ivplan.isValid() && ivecx.isValid() && ivecz.isValid())
6650 iElts = docModel->makeSphereUni(icenter, ivecx, ivecz, radhole, radext, radang,
6651 ivplan, nrad, nang, nhaut);
6653 else if (sphere2_rb->isChecked())
6655 // if (somme > 360.01)
6657 // SUIT_MessageBox::information( 0,
6659 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6662 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6663 iElts = docModel->makeSphere(icenter, ivecx, ivecz, radius2, angles, heights);
6666 else if (spherical_rb->isChecked())
6668 if (sphericalTop_rb->isChecked())
6669 iElts = docModel->makeSphericalTop(nb, crit);
6670 else if (sphericalUni_rb->isChecked())
6672 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6673 iElts = docModel->makeSphericalUni(icenter, ivecx, ivecz, radhole, nb, crit);
6675 else if (spherical2_rb->isChecked())
6677 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6678 iElts = docModel->makeSpherical(icenter, ivecx, ivecz, radius1, crit);
6681 else if (rind_rb->isChecked())
6683 if (rindTop_rb->isChecked())
6684 iElts = docModel->makeRindTop(nrad, nang, nhaut);
6685 else if (rindUni_rb->isChecked())
6687 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid() && ivplan.isValid())
6688 iElts = docModel->makeRindUni(icenter, ivecx, ivecz,
6689 radhole, radint, radext, radang,
6690 ivplan, nrad, nang, nhaut);
6692 else if (rind2_rb->isChecked())
6694 // if (somme > 360.01)
6696 // SUIT_MessageBox::information( 0,
6698 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6701 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6702 iElts = docModel->makeRind(icenter, ivecx, ivecz, radius2, angles, heights);
6706 if ( !iElts.isValid() ){
6707 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) + "\n" + getErrorMsg() );
6710 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6711 result = patternDataModel->mapFromSource(iElts);
6712 // result = patternBuilderModel->mapFromSource(iElts);
6717 // ------------------------- ModelInfoDialog ----------------------------------
6718 ModelInfoDialog::ModelInfoDialog(QWidget* parent, Qt::WindowFlags wf):
6719 HexaBaseDialog(parent, INFO_MODE, wf)
6722 setWindowTitle(HEXABLOCKGUI::tr("MODEL_INFO"));
6725 void ModelInfoDialog::updateInfo()
6727 DocumentModel* docModel = getDocumentModel();
6728 if (docModel == NULL) return;
6731 model_name_le->setText(docModel->getName());
6733 //Nb of elements in the model
6734 total_vertices_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_VERTEX)));
6735 total_edges_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_EDGE)));
6736 total_quads_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_QUAD)));
6737 total_hexas_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_HEXA)));
6739 ///Nb of used elements in the model
6740 used_vertices_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_VERTEX)));
6741 used_edges_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_EDGE)));
6742 used_quads_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_QUAD)));
6743 used_hexas_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_HEXA)));
6745 //Nb of unused elements in the model
6746 unused_vertices_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_VERTEX)));
6747 unused_edges_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_EDGE)));
6748 unused_quads_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_QUAD)));
6749 unused_hexas_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_HEXA)));
6752 void ModelInfoDialog::showEvent( QShowEvent * event )
6755 QDialog::showEvent ( event );
6758 // ============================================================== hideEvent
6759 void ModelInfoDialog::hideEvent ( QHideEvent * event )
6761 QDialog::hideEvent( event );
6764 // ------------------------- AddShapeDialog ----------------------------------
6765 AddShapeDialog::AddShapeDialog(QWidget* parent, Mode editmode, Qt::WindowFlags wf):
6766 HexaBaseDialog(parent, editmode, wf)
6768 _helpFileName = "gui_add_geometry.html#guiaddgeometry";
6770 _initWidget(editmode);
6771 setWindowTitle(HEXABLOCKGUI::tr("ADD_SHAPE"));
6774 // ============================================================== Destructeur
6775 AddShapeDialog::~AddShapeDialog()
6777 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
6778 this, SLOT(onCurrentSelectionChanged()) );
6781 // ============================================================== close
6782 void AddShapeDialog::close()
6784 HEXABLOCKGUI::assocInProgress = false;
6785 HexaBaseDialog::close();
6788 // ============================================================== _initInputWidget
6789 void AddShapeDialog::_initInputWidget( Mode editmode )
6791 shape_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMSHAPE_TREE) );
6792 shape_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_SHAPE) );
6793 shape_le->installEventFilter(this);
6794 shape_le->setReadOnly(true);
6797 void AddShapeDialog::clear()
6800 shape_le->setProperty("GeomObj", QVariant());
6802 modelUnregister(this);
6805 // ============================================================== onCurrentSelectionChanged
6806 void AddShapeDialog::onCurrentSelectionChanged()
6808 SALOME_ListIO selectedObjects;
6809 HEXABLOCKGUI::currentDocGView->getSelected(selectedObjects);
6810 if (selectedObjects.IsEmpty())
6813 // * extract the TopoDS_Shape of the selected object
6814 TopoDS_Shape selectedTopoShape = GEOMBase::GetTopoFromSelection( selectedObjects );
6815 if (selectedTopoShape.IsNull())
6817 shape_le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(selectedTopoShape));
6819 // * extract the name of the selected shape
6821 GEOMBase::GetNameOfSelectedIObjects( selectedObjects, name, true );
6822 shape_le->setText(name);
6825 // ============================================================== onWindowActivated
6826 void AddShapeDialog::onWindowActivated(SUIT_ViewManager* vm)
6828 QString vmType = vm->getType();
6829 if ( vmType == OCCViewer_Viewer::Type() )
6830 shape_le->setFocus();
6833 // ============================================================== apply
6834 bool AddShapeDialog::apply(QModelIndex& result)
6837 QString shapeName = shape_le->text();
6838 QVariant v = shape_le->property("TopoDS_Shape");
6839 if ( !v.isValid() || shapeName.isEmpty())
6843 TopoDS_Shape shape = v.value<TopoDS_Shape>();
6847 assocOk = getDocumentModel()->addShape(shape, shapeName);
6851 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), HEXABLOCKGUI::tr("ADD_SHAPE_FAILED") + "\n" + getErrorMsg() );