1 // Copyright (C) 2009-2014 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"
31 #include <SalomeApp_Application.h>
32 #include <SalomeApp_Study.h>
33 #include <PyConsole_Console.h>
34 #include <SalomeApp_Tools.h>
36 #include <Standard_GUID.hxx>
37 #include <TDF_Label.hxx>
39 #include <OCCViewer_ViewManager.h>
42 #include <TopExp_Explorer.hxx>
43 #include <TopoDS_Iterator.hxx>
44 #include <TopTools_MapOfShape.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <TColStd_IndexedMapOfInteger.hxx>
48 #include <SUIT_Session.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_OverrideCursor.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_Session.h>
53 #include "SVTK_Selection.h"
54 #include <SVTK_ViewModel.h>
55 #include <VTKViewer_ViewModel.h>
56 #include <SVTK_View.h>
58 #include <SUIT_ResourceMgr.h>
62 #include <utilities.h>
64 #define BUTTON_BOX_MIN_WIDTH 5
65 #define VERTEX_COORD_MIN -1000000
66 #define VERTEX_COORD_MAX 1000000
67 #define SPINBOX_ANGLE_MAX 360
68 #define SPINBOX_DOUBLE_MAX 1000000000
69 #define SPINBOX_POSITIVE_DOUBLE_MIN 0
74 using namespace HEXABLOCK::GUI;
77 Q_DECLARE_METATYPE(HEXABLOCK::GUI::HexaTreeRole);
78 Q_DECLARE_METATYPE(DocumentModel::GeomObj);
79 Q_DECLARE_METATYPE(TopAbs_ShapeEnum);
80 Q_DECLARE_METATYPE(TopoDS_Shape);
82 //General SpinBox Delegate
83 class HexaDoubleSpinBoxDelegate : public QStyledItemDelegate {
85 HexaDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
87 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
88 const QModelIndex &index) const{
89 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
90 sb->setDecimals(NB_DECIMALS);
95 //Angle SpinBox Delegate
96 class HexaAngleDoubleSpinBoxDelegate : public QStyledItemDelegate {
98 HexaAngleDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
100 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
101 const QModelIndex &index) const{
102 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
103 sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
104 sb->setMaximum(SPINBOX_ANGLE_MAX);
105 sb->setDecimals(NB_DECIMALS);
111 //Positive DoubleSpinBox Delegate (for heigth, radius, ...)
112 class HexaPositiveDoubleSpinBoxDelegate : public QStyledItemDelegate {
114 HexaPositiveDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
116 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
117 const QModelIndex &index) const{
118 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
119 sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
120 sb->setMaximum(SPINBOX_DOUBLE_MAX); //10e9
121 sb->setDecimals(NB_DECIMALS);
126 // ======================================================== Constructeur
127 HexaBaseDialog::HexaBaseDialog( QWidget * parent, Mode editmode, Qt::WindowFlags f ):
129 _editMode( editmode ),
132 debugEdgeAssoc(false),
133 autoFocusSwitch(true)
135 _strHexaWidgetType[VERTEX_TREE] = tr( "VERTEX" );
136 _strHexaWidgetType[EDGE_TREE] = tr( "EDGE" );
137 _strHexaWidgetType[QUAD_TREE] = tr( "QUAD" );
138 _strHexaWidgetType[HEXA_TREE] = tr( "HEXA" );
140 _strHexaWidgetType[VECTOR_TREE] = tr( "VECTOR" );
141 // _strHexaWidgetType[CYLINDER_TREE] = tr( "CYLINDER" );
142 // _strHexaWidgetType[PIPE_TREE] = tr( "PIPE" );
143 _strHexaWidgetType[ELEMENTS_TREE] = tr( "ELEMENTS" );
144 _strHexaWidgetType[CROSSELEMENTS_TREE]= tr( "CROSSELEMENTS" );
147 _strHexaWidgetType[GEOMSHAPE_TREE] = tr( "GEOMSHAPE" );
148 _strHexaWidgetType[GEOMPOINT_TREE] = tr( "GEOMPOINT" );
149 _strHexaWidgetType[GEOMEDGE_TREE] = tr( "GEOMEDGE" );
150 _strHexaWidgetType[GEOMFACE_TREE] = tr( "GEOMFACE" );
152 _strHexaWidgetType[GROUP_TREE] = tr( "GROUP" );
153 _strHexaWidgetType[LAW_TREE] = tr( "LAW" );
154 _strHexaWidgetType[PROPAGATION_TREE]= tr( "PROPAGATION" );
157 // ============================================================= getIndexList
158 QModelIndexList HexaBaseDialog::getIndexList(QListWidget* itemsList, bool mapToSource)
160 QModelIndexList iItems;
162 QListWidgetItem* item = NULL;
164 const PatternDataModel* patternDataModel = getPatternDataModel();
165 if (patternDataModel == NULL || itemsList == NULL) return iItems;
167 unsigned int nbItems = itemsList->count();
168 for ( int r = 0; r < nbItems; ++r){
169 item = itemsList->item(r);
171 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
173 iItem = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
180 // ================================================================ computeAndSetDimension
181 void HexaBaseDialog::computeAndSetDimension(const QModelIndex& elt)
183 // * Check if everything is OK for the computing
184 DocumentModel* docModel = getDocumentModel();
185 if (docModel == NULL || _currentObj == NULL)
188 int selectedType = elt.data(HEXA_TREE_ROLE).toInt();
189 if (selectedType != EDGE_TREE && selectedType != GEOMEDGE_TREE)
192 QListWidget* list = dynamic_cast<QListWidget*>(_currentObj);
193 QDoubleSpinBox* spb = dynamic_cast<QDoubleSpinBox*>(_currentObj);
195 if (list == NULL && spb == NULL)
198 // * Compute the value of the dimension
201 if (_currentObj->property("Radius").isValid())
202 value = docModel->getRadius(elt);
203 else if (_currentObj->property("Angle").isValid())
204 value = docModel->getAngle(elt);
205 else if (_currentObj->property("Length").isValid())
206 value = docModel->getLength(elt);
211 // * Set the value to the field (radius, length or height)
214 QListWidgetItem* item = list->currentItem();
219 item->setText(QString::number(value));
220 list->editItem(item);
224 else if (spb != NULL)
226 spb->setValue(value);
232 // ============================================================= resetSizeAndShow
233 void HexaBaseDialog::resetSizeAndShow(QDockWidget* parent)
238 //force the dialog to fit its contain
239 // setMinimumWidth(sizeHint().width());
241 //set the dialog in the dockwidget
242 if (parent->widget())
243 parent->widget()->close();
244 parent->setWidget(this);
245 parent->setWindowTitle(windowTitle());
248 // setMinimumWidth(MIN_WIDTH);
251 QString HexaBaseDialog::getErrorMsg()
253 DocumentModel* docModel = getDocumentModel();
254 Hex::Hex* hex = docModel->getHexaRoot();
255 int nbErrorMsg = hex->sizeofMessage();
256 QString msg, newLine = "\n";
257 for (int i = 1; i < nbErrorMsg; ++i)
258 msg += newLine + hex->getMessageLine(i);
263 //unlink the widget from the model
264 void HexaBaseDialog::modelUnregister(QWidget* widget)
266 if (widget == NULL) return;
268 if (widget->property("GeomWidgetType").isValid())
270 widget->setProperty("GeomObj", QVariant());
271 widget->setProperty("TopoDS_Shape", QVariant());
274 widget->setProperty("HexaData", QVariant());
275 widget->setProperty("QModelIndex", QVariant());
276 _index[widget] = QModelIndex();
278 HexaBaseDialog* diag = dynamic_cast<HexaBaseDialog*>(widget);
280 diag->clearWidgetsIndexes();
283 // ============================================================= connectDocumentGraphicView
284 void HexaBaseDialog::connectDocumentGraphicView(VtkDocumentGraphicView* docGView)
286 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
287 if (docGView == NULL) return;
289 disconnectDocumentGraphicView(docGView); //to avoid double connect
291 //Connect the graphic view and its model to the dialog box
292 connect( docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
293 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
294 // connect( docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
295 // this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
296 connect( docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
297 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
298 connect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
299 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
300 connect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
301 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
304 // ============================================================= disconnectDocumentGraphicView
305 void HexaBaseDialog::disconnectDocumentGraphicView(VtkDocumentGraphicView* docGView)
307 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
308 if (docGView == NULL) return;
311 //Disconnect graphic view signals form the dialog box
312 disconnect(docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
313 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
315 // disconnect(docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
316 // this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
318 disconnect(docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
319 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
321 disconnect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
322 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
324 disconnect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
325 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
328 // ============================================================= onCurrentSelectionChanged
329 void HexaBaseDialog::onCurrentSelectionChanged()
331 highlightSelectedAssocs();
334 // ============================================================= clearCurrentObjectFocus
335 void HexaBaseDialog::clearCurrentObjectFocus()
337 QWidget* currentWidget = dynamic_cast<QWidget*>(_currentObj);
338 if (currentWidget != NULL)
340 currentWidget->clearFocus();
345 // ============================================================= setFocusToNextField
346 //Sets focus to the next field of the current object
347 void HexaBaseDialog::setFocusToNextField()
351 if (!HEXABLOCKGUI::assocInProgress && autoFocusSwitch)
353 _highlightWidget(_currentObj, Qt::white);
358 // ============================================================== _initButtonBox
359 QGroupBox* HexaBaseDialog::_initButtonBox( Mode editmode )
361 if ( editmode == INFO_MODE )
364 QGroupBox* buttonBox = new QGroupBox();
365 buttonBox->setMinimumWidth(BUTTON_BOX_MIN_WIDTH);
366 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
367 QHBoxLayout* buttonsHLayout = new QHBoxLayout();
368 _applyButton = new QPushButton(tr("Apply"));
369 QPushButton* closeButton = new QPushButton(tr("Close"));
370 QPushButton* helpButton = new QPushButton(tr("Help"));
372 connect( _applyButton, SIGNAL(clicked()), this, SLOT(apply()), Qt::UniqueConnection );
373 connect( closeButton, SIGNAL(clicked()), this, SLOT(close()), Qt::UniqueConnection );
374 connect( helpButton, SIGNAL(clicked()), this, SLOT(onHelpRequested()), Qt::UniqueConnection );
376 buttonsHLayout->addWidget( _applyButton );
377 buttonsHLayout->addWidget( closeButton );
378 buttonsHLayout->addStretch(1);
379 buttonsHLayout->addWidget( helpButton );
380 buttonBox->setLayout(buttonsHLayout);
381 layout()->addWidget(buttonBox);
382 buttonBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
386 // ============================================================== _initWidget
387 void HexaBaseDialog::_initWidget( Mode editmode )
389 _initInputWidget( editmode );
390 _initButtonBox( editmode );
393 // ============================================================== apply
394 bool HexaBaseDialog::apply()
397 bool applied = apply(iNew);
400 _selectAndHighlight( iNew );
401 if (!HEXABLOCKGUI::assocInProgress)
402 getDocumentModel()->updateGeomTree();
407 void HexaBaseDialog::clearVTKSelection()
409 HEXABLOCKGUI::currentDocGView->clearSelection();
410 _highlightWidget(_currentObj, Qt::white);
413 void HexaBaseDialog::clearOCCSelection()
415 HEXABLOCKGUI::currentOccGView->clearSelection();
418 // ============================================================== close
419 void HexaBaseDialog::close()
421 //reset the data selection pattern (forget all selections of the current context)
422 getPatternDataSelectionModel()->reset();
423 // getPatternBuilderSelectionModel()->reset();
424 getPatternGeomSelectionModel()->reset();
426 //Clear vtk selection
429 //Clear occ selection
432 //Close the dialog box
434 parentWidget()->close();
436 getPatternDataSelectionModel()->setInfoMode(true);
439 // ============================================================== onHelpRequested
440 void HexaBaseDialog::onHelpRequested()
442 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
444 app->onHelpContextModule( "HEXABLOCK", _helpFileName );
448 platform = "winapplication";
450 platform = "application";
453 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
454 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
455 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( _helpFileName ),
456 QObject::tr( "BUT_OK" ) );
460 // ============================================================== highlightSelectedAssocs
461 void HexaBaseDialog::highlightSelectedAssocs()
463 QMultiMap<QString, int> geomAssocs = getAssocsGEOM();
464 QModelIndexList vtkAssocs = getAssocsVTK();
466 // HEXABLOCKGUI::selectionMgr()->clearSelected();
467 //highlight geom selected elts
468 if (geomAssocs.size() > 0)
469 HEXABLOCKGUI::currentOccGView->highlight(geomAssocs, false);
471 //highlight vtk selected elts
472 if (!vtkAssocs.isEmpty())
473 HEXABLOCKGUI::currentDocGView->highlight(vtkAssocs);
476 // ============================================================== refreshHighlight
477 void HexaBaseDialog::refreshHighlight()
479 HEXABLOCKGUI::selectionMgr()->clearSelected();
480 highlightSelectedAssocs();
483 bool HexaBaseDialog::isDimensionType(const QObject* obj)
488 return (obj->property("Radius").isValid()) ||
489 (obj->property("Angle").isValid()) ||
490 (obj->property("Length").isValid());
493 // ============================================================== getObjectViewType
494 HEXABLOCKGUI::ViewType HexaBaseDialog::getObjectViewType(QObject* obj)
497 return HEXABLOCKGUI::UNKNOWN;
499 QVariant v1 = obj->property("GeomWidgetType");
500 QVariant v2 = obj->property("HexaWidgetType");
502 if (v1.isValid() && v2.isValid() && isDimensionType(obj))
503 return HEXABLOCKGUI::VTK_OCC;
504 else if (v1.isValid())
505 return HEXABLOCKGUI::OCC;
506 else if (v2.isValid())
507 return HEXABLOCKGUI::VTK;
509 return HEXABLOCKGUI::UNKNOWN;
512 // ============================================================== _selectAndHighlight
513 void HexaBaseDialog::_selectAndHighlight( const QModelIndex& i )
515 if ( !i.isValid() ) return;
516 setProperty("QModelIndex", QVariant::fromValue(i));
520 // ============================================================== _allowSelection
521 void HexaBaseDialog::_allowSelection()
523 if ( getDocumentModel() )
524 getDocumentModel()->disallowEdition();
527 // ============================================================== _disallowSelection
528 void HexaBaseDialog::_disallowSelection()
530 if ( getDocumentModel() ){
531 getDocumentModel()->allowEdition();
533 HEXABLOCKGUI::currentDocGView->setAllSelection();
536 // ============================================================== _allowVTKSelection
537 bool HexaBaseDialog::_allowVTKSelection( QObject* obj )
541 QVariant v = obj->property("HexaWidgetType");
542 HexaWidgetType wType = v.value<HexaWidgetType>();
546 HEXABLOCKGUI::currentDocGView->setVertexSelection(); isOk = true;
549 HEXABLOCKGUI::currentDocGView->setEdgeSelection(); isOk = true;
552 HEXABLOCKGUI::currentDocGView->setQuadSelection(); isOk = true;
555 HEXABLOCKGUI::currentDocGView->setHexaSelection(); isOk = true;
557 default: HEXABLOCKGUI::currentDocGView->setAllSelection();
562 // ============================================================== _allowOCCSelection
563 bool HexaBaseDialog::_allowOCCSelection( QObject* obj )
565 QVariant v = obj->property("GeomWidgetType");
566 GeomWidgetType wType = v.value<GeomWidgetType>();
567 HEXABLOCKGUI::currentOccGView->setSelectionMode(wType);
572 // ============================================================== _getSelector
573 QItemSelectionModel* HexaBaseDialog::_getSelector( QObject* obj )
578 QItemSelectionModel* selector = NULL;
580 HexaWidgetType wtype;
581 QVariant v = obj->property("HexaWidgetType");
582 QVariant v2 = obj->property("GeomWidgetType");
583 if ( !v.isValid() || (v2.isValid() && isDimensionType(obj)) )
586 wtype = v.value<HexaWidgetType>();
593 case VECTOR_TREE: selector = getPatternDataSelectionModel(); break;
594 // case CYLINDER_TREE:
596 // case ELEMENTS_TREE:
597 // case CROSSELEMENTS_TREE: selector = getPatternBuilderSelectionModel(); break;
600 case GEOMFACE_TREE: selector = getPatternGeomSelectionModel(); break;
601 case GROUP_TREE: selector = getGroupsSelectionModel(); break;
603 case PROPAGATION_TREE: selector = getMeshSelectionModel(); break;
610 // ============================================================== getGeomObj
611 DocumentModel::GeomObj* HexaBaseDialog::getGeomObj(const QModelIndex& index)
613 HEXA_NS::NewShape* aSh = getDocumentModel()->getHexaPtr<HEXA_NS::NewShape*>(index);
614 DocumentModel::GeomObj* geomObj = NULL;
617 geomObj = new DocumentModel::GeomObj;
618 geomObj->shapeName = aSh->getName();
619 geomObj->subId = QString::number(-1);
623 HEXA_NS::EltBase* aSShElt = getDocumentModel()->getHexaPtr(index);
624 HEXA_NS::SubShape* aSSh = dynamic_cast<HEXA_NS::SubShape*>(aSShElt);
627 geomObj = new DocumentModel::GeomObj;
629 if (aSSh->getParentShape() != NULL)
630 shapeName = aSSh->getParentShape()->getName();
631 geomObj->shapeName = shapeName;
632 geomObj->subId = QString::number(aSSh->getIdent());
638 // ============================================================== _onSelectionChanged
640 * Puts elements selected in the model (treeview) in the corresponding
641 * line edit widget (the one that has the focus) of the current dialog box.
643 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QLineEdit* le )
645 QModelIndexList l = sel.indexes();
646 if ( l.count() == 0 ) return false;
648 // mono selection mode: we just get the first selected element
649 QModelIndex selected = l[0];
651 // we just return if the selection is not valid or the selection and the
652 // line content are the same
653 if ( !selected.isValid() || le->property("HexaData") == selected.data(HEXA_DATA_ROLE) )
657 int selType = selected.data(HEXA_TREE_ROLE).toInt();
660 QVariant v = le->property("HexaWidgetType");
661 if ( !v.isValid() ) return false;
662 HexaWidgetType wType = v.value<HexaWidgetType>();
664 // check selection compatibility between selection and widget
665 if ( selType != wType ){
666 SUIT_MessageBox::information( 0, tr("HEXA_INFO"),
667 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg(_strHexaWidgetType[wType]));
670 if (le->property("GeomWidgetType").isValid())
672 DocumentModel::GeomObj* geomObj = getGeomObj(selected);
675 le->setProperty("GeomObj", QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
677 DocumentModel* docModel = getDocumentModel();
678 QString objId = geomObj->shapeName + "," + geomObj->subId;
679 HEXA_NS::SubShape* ssh = docModel->getGeomPtr(objId);
682 TopoDS_Shape shape = ssh->getShape();
684 le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(shape));
686 setCurrentGeomObj(geomObj);
690 //fill the lineEdit if selection is OK
691 le->setText( selected.data().toString() );// name
692 le->setProperty("QModelIndex", QVariant::fromValue(selected));
693 le->setProperty("HexaData", selected.data(HEXA_DATA_ROLE));
694 _index[le] = selected;
696 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(_currentObj);
697 if (selected.isValid() && lineEdit != NULL)
698 setFocusToNextField();
703 // ============================================================== _onSelectionChanged
705 * Puts elements selected in the model (treeview) in the corresponding list widget
706 * of the current dialog box.
708 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QListWidget* lw )
710 QModelIndexList l = sel.indexes();
712 if ( l.count() == 0 ) return false;
715 QVariant v = lw->property("HexaWidgetType");
716 if ( !v.isValid() ) return false;
717 HexaWidgetType wType = v.value<HexaWidgetType>();
719 //fill the listWidget
720 QListWidgetItem* item = NULL;
724 foreach( const QModelIndex& isel, l ){
725 // if ( lw->count() == maxSize) break;
726 selType = isel.data(HEXA_TREE_ROLE).toInt();
727 if ( selType != wType ){ // check selection compatibility between selection and widget
728 SUIT_MessageBox::information( 0,
730 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg( _strHexaWidgetType[wType]) );
733 // add selection to listWidget if selection is OK
734 selName = isel.data().toString();
735 QList<QListWidgetItem *> twice = lw->findItems( selName, Qt::MatchExactly);
736 if ( twice.count() == 0 ){
737 item = new QListWidgetItem( selName );
738 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(isel) );
739 item->setData(LW_DATA_ROLE, isel.data(HEXA_DATA_ROLE));
740 if (lw->property("GeomWidgetType").isValid())
742 DocumentModel::GeomObj* geomObj = getGeomObj(isel);
744 item->setData(LW_ASSOC_ROLE, QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
753 // ============================================================== onSelectionChanged
755 * Puts elements selected in the model in the corresponding widget (list widget or line edit)
756 * of the current dialog box.
758 void HexaBaseDialog::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
760 QModelIndexList l = sel.indexes();
762 if ( l.count() == 0 )
764 QModelIndex selected = l[0];
766 // * no edition for Info Dialogs
767 if ( _editMode == INFO_MODE || _currentObj == NULL || !selected.isValid())
770 if (isDimensionType(_currentObj))
772 // ** set the dimension of the selected object in the editor **/
773 int selectedType = selected.data(HEXA_TREE_ROLE).toInt();
774 if (selectedType == EDGE_TREE || selectedType == GEOMEDGE_TREE)
775 computeAndSetDimension(selected);
779 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
780 QListWidget* aListWidget = dynamic_cast<QListWidget*>(_currentObj);
782 // * fill the lineedit with selection
785 _onSelectionChanged( sel, aLineEdit );
789 // * fill the listWidget with selection
791 _onSelectionChanged( sel, aListWidget );
794 // ============================================================== showEvent
795 void HexaBaseDialog::showEvent( QShowEvent * event )
797 if ( _editMode == INFO_MODE )
798 getDocumentModel()->allowEdition();
800 getDocumentModel()->disallowEdition();
802 //Connect to salome selection signals
803 if (HEXABLOCKGUI::selectionMgr() != NULL)
805 connect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
806 this, SLOT(onCurrentSelectionChanged()), Qt::UniqueConnection );
809 //connect model selection signals
810 connectDocumentGraphicView();
812 QDialog::showEvent ( event );
816 // ============================================================== hideEvent
817 void HexaBaseDialog::hideEvent ( QHideEvent * event )
819 //Disconnection salome selection signals
820 if (HEXABLOCKGUI::selectionMgr() != NULL)
821 disconnect( HEXABLOCKGUI::selectionMgr() , SIGNAL(currentSelectionChanged()),
822 this, SLOT(onCurrentSelectionChanged()) );
824 //Disconnect vtk window activation signals
825 // if (HEXABLOCKGUI::currentDocGView->getViewWindow() != NULL)
826 // disconnect( HEXABLOCKGUI::currentDocGView->getViewWindow()->getViewManager(),
827 // SIGNAL( activated(SUIT_ViewManager*) ),
828 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
830 //Disconnect occ window activation signals
831 // if (HEXABLOCKGUI::currentOccGView->getViewWindow() != NULL)
832 // disconnect( HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager(),
833 // SIGNAL( activated(SUIT_ViewManager*) ),
834 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
836 //Disconnect model selection signals
837 disconnectDocumentGraphicView();
838 getDocumentModel()->allowEdition();
840 QDialog::hideEvent( event );
843 // ============================================================== updateButtonBox
844 void HexaBaseDialog::updateButtonBox()
848 // ============================================================== updateName
849 void HexaBaseDialog::updateName()
851 const PatternDataModel* patternDataModel = getPatternDataModel();
853 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(sender());
854 if (!lineEdit) return;
855 QString newName = lineEdit->text();
856 if ( newName.isEmpty() ) return;
858 QVariant v = lineEdit->property("QModelIndex");
859 if ( !v.isValid() ) return;
861 QModelIndex index = v.value<QModelIndex>();
862 if ( index.isValid() )
863 getDocumentModel()->setName( patternDataModel->mapToSource(index), newName );
866 // ============================================================== updateDefaultName
867 void HexaBaseDialog::updateDefaultName(QLineEdit* name_field, HEXA_NS::EnumElt type)
869 if (name_field == NULL) return;
871 HEXA_NS::Document* doc = getDocumentModel()->getHexaDocument();
872 if (doc == NULL) return;
874 name_field->setText(doc->getNextName(type).c_str());
877 // ============================================================== selectElementOfModel
878 /*Selects in the model (treeview) elements selected in a listwidget,
879 * or an element in a line edit.*/
880 void HexaBaseDialog::selectElementOfModel()
882 if (getPatternDataSelectionModel() == NULL) return;
884 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
885 if ( !currentListWidget ) return;
887 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
889 getPatternDataSelectionModel()->clearSelection();
890 foreach ( QListWidgetItem *item, sel ){
891 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
892 index = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
893 if ( index.isValid() )
894 getPatternDataSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
898 // ============================================================== _isLineOrListWidget
900 * Return true is the widget is a line or a list
903 bool HexaBaseDialog::_isLineOrListWidget(QObject *widget)
905 if (widget == NULL) return false;
907 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(widget);
908 QListWidget *listWidget = dynamic_cast<QListWidget*>(widget);
909 return (lineEdit != NULL) || (listWidget != NULL);
911 }//_isLineOrListWidget
914 // ============================================================== _highlightWidget
916 * Highlight the given widget with the given color.
918 void HexaBaseDialog::_highlightWidget(QObject *obj, Qt::GlobalColor clr)
920 QDoubleSpinBox* spb = dynamic_cast<QDoubleSpinBox*>(obj);
921 if (!_isLineOrListWidget(obj) && spb == NULL)
924 QWidget *widget = dynamic_cast<QWidget*>(obj);
925 QPalette palette1 = widget->palette();
926 palette1.setColor(QPalette::Active, widget->backgroundRole(), clr);
927 widget->setPalette(palette1);
931 // ============================================================== _updateCurrentObject
932 void HexaBaseDialog::_updateCurrentObject(QObject* obj)
934 _highlightWidget(_currentObj, Qt::white);
936 _highlightWidget(obj, Qt::yellow);
939 // ============================================================== eventFilter
941 * Handles events from the treeview and the dialog boxes.
943 bool HexaBaseDialog::eventFilter(QObject *obj, QEvent *event)
945 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(obj);
946 QListWidget *listWidget = dynamic_cast<QListWidget*>(obj);
948 // * Enter key press ------
949 if ( event->type() == QEvent::KeyPress &&
950 ((QKeyEvent*)event)->key() == Qt::Key_Return)
952 setFocusToNextField();
956 // * Focus out from a list widget ------
957 if ( event->type() == QEvent::FocusOut && listWidget != NULL)
959 QItemSelectionModel * selectionModel = listWidget->selectionModel();
960 selectionModel->clearSelection();
963 if ( event->type() != QEvent::FocusIn )
967 HEXABLOCKGUI::ViewType vtype = getObjectViewType(obj);
968 if (vtype == HEXABLOCKGUI::VTK_OCC)
970 _allowVTKSelection(obj);
971 _allowOCCSelection(obj);
973 else if (vtype == HEXABLOCKGUI::VTK)
974 _allowVTKSelection( obj );
975 else if (vtype == HEXABLOCKGUI::OCC)
976 _allowOCCSelection( obj );
978 //Depending on the focused widget type, get the right selector for it
981 QItemSelectionModel* selector = _getSelector( obj );
982 if ( selector == NULL )
984 _updateCurrentObject(obj);
988 if ( _currentObj != obj && (lineEdit == NULL || listWidget == NULL) )
989 selector->clearSelection();
991 _updateCurrentObject(obj);
993 //If the widget contains an element, select it in model/view
994 if ( lineEdit != NULL ){ //element can be from lineEdit
995 v = lineEdit->property("HexaData");
997 return QObject::eventFilter(obj, event);
998 index = ((SelectionModel*)selector)->indexBy( HEXA_DATA_ROLE, v);
1000 selector->select( index, QItemSelectionModel::SelectCurrent );
1003 return QObject::eventFilter(obj, event);
1006 // ------------------------- VERTEX ----------------------------------
1007 // ============================================================== Constructeur
1008 VertexDialog::VertexDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1009 HexaBaseDialog(parent, editmode, f),
1012 _helpFileName = "gui_vertex.html";
1014 _initWidget(editmode);
1016 if ( editmode == NEW_MODE ){
1017 setWindowTitle( tr("Vertex Construction") );
1018 } else if ( editmode == UPDATE_MODE ){
1019 setWindowTitle( tr("Vertex Modification") );
1021 else if ( editmode == INFO_MODE){
1022 setWindowTitle( tr("Vertex Information") );
1026 // ============================================================== Destructeur
1027 VertexDialog::~VertexDialog()
1031 // ============================================================== _initInputWidget
1032 void VertexDialog::_initInputWidget( Mode editmode )
1034 // x_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1035 // y_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1036 // z_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1037 QDoubleValidator *doubleValidator = new QDoubleValidator(widget_2);
1038 x_spb->setValidator(doubleValidator);
1039 y_spb->setValidator(doubleValidator);
1040 z_spb->setValidator(doubleValidator);
1042 // setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1043 installEventFilter(this);
1044 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1045 name_le->installEventFilter(this);
1047 if (editmode == INFO_MODE)
1049 name_le->setReadOnly(true);
1050 x_spb->setReadOnly(true);
1051 y_spb->setReadOnly(true);
1052 z_spb->setReadOnly(true);
1055 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
1058 // ============================================================== clear
1059 void VertexDialog::clear()
1063 modelUnregister(this);
1066 // ============================================================== setValue
1067 void VertexDialog::setValue(HEXA_NS::Vertex* v)
1070 name_le->setText( v->getName() );
1073 // x_spb->setValue( v->getX() );
1074 // y_spb->setValue( v->getY() );
1075 // z_spb->setValue( v->getZ() );
1076 x_spb->setText( QString::number(v->getX()) );
1077 y_spb->setText( QString::number(v->getY()) );
1078 z_spb->setText( QString::number(v->getZ()) );
1080 if ( getPatternDataSelectionModel() != NULL ){
1081 QModelIndex iv = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1083 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1084 name_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1089 // ============================================================== getValue
1090 HEXA_NS::Vertex* VertexDialog::getValue()
1096 // ============================================================== apply
1097 bool VertexDialog::apply(QModelIndex& result)
1099 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1102 if ( !getDocumentModel() ) return false;
1103 if ( !getPatternDataSelectionModel() ) return false;
1104 const PatternDataModel* patternDataModel = getPatternDataModel();
1105 if ( !patternDataModel ) return false;
1107 QModelIndex iVertex;
1109 QString xStr = x_spb->text();
1110 QString yStr = y_spb->text();
1111 QString zStr = z_spb->text();
1112 bool isOk = false, validArgs = !xStr.isEmpty() && !yStr.isEmpty() && !zStr.isEmpty();
1114 double newX, newY, newZ;
1117 newX = xStr.toDouble();
1118 newY = yStr.toDouble();
1119 newZ = zStr.toDouble();
1122 if ( _editMode == UPDATE_MODE && validArgs){
1123 QVariant v = property("QModelIndex");
1125 iVertex = patternDataModel->mapToSource( v.value<QModelIndex>() );
1126 if ( iVertex.isValid() )
1127 isOk = getDocumentModel()->updateVertex( iVertex, newX, newY, newZ );
1129 } else if ( _editMode == NEW_MODE && validArgs){
1130 iVertex = getDocumentModel()->addVertex( newX, newY, newZ );
1131 if ( iVertex.isValid() )
1135 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "VERTEX UPDATE/CONSTRUCTION" ) + "\n" + getErrorMsg() );
1139 QString newName = name_le->text();
1140 if ( !newName.isEmpty() )
1141 getDocumentModel()->setName( iVertex, newName );
1143 //the default name in the dialog box
1144 HEXA_NS::Vertex* v = getDocumentModel()->getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1146 updateDefaultName(name_le, v->getType());
1148 // to select/highlight result
1149 result = patternDataModel->mapFromSource(iVertex);
1154 // ------------------------- EDGE ----------------------------------
1156 // ============================================================== Constructeur
1157 EdgeDialog::EdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1158 HexaBaseDialog(parent, editmode, f),
1161 _helpFileName = "gui_edge.html";
1163 _initWidget(editmode);
1165 if ( editmode == INFO_MODE ){
1166 setWindowTitle( tr("Edge Information") );
1169 else if ( editmode == UPDATE_MODE ){
1170 setWindowTitle( tr("Edge Modification") );
1176 // ============================================================== Destructeur
1177 EdgeDialog::~EdgeDialog()
1182 // ============================================================== _initInputWidget
1183 void EdgeDialog::_initInputWidget( Mode editmode )
1186 QValidator *validator = new QRegExpValidator(rx, this);
1188 // setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1189 installEventFilter(this);
1191 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1192 name_le->installEventFilter(this);
1194 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1195 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1196 v0_le_rb0->setValidator( validator );
1197 v1_le_rb0->setValidator( validator );
1198 v0_le_rb0->installEventFilter(this);
1199 v1_le_rb0->installEventFilter(this);
1201 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1202 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1203 vex_le_rb1->setValidator( validator );
1204 vec_le_rb1->setValidator( validator );
1205 vex_le_rb1->installEventFilter(this);
1206 vec_le_rb1->installEventFilter(this);
1208 v0_le_rb0->setReadOnly(true);
1209 v1_le_rb0->setReadOnly(true);
1210 vex_le_rb1->setReadOnly(true);
1211 vec_le_rb1->setReadOnly(true);
1213 if (editmode == INFO_MODE)
1214 name_le->setReadOnly(true);
1218 // ============================================================== Clear
1219 void EdgeDialog::clear()
1224 modelUnregister(v0_le_rb0);
1227 modelUnregister(v1_le_rb0);
1229 vex_le_rb1->clear();
1230 modelUnregister(vex_le_rb1);
1232 vec_le_rb1->clear();
1233 modelUnregister(vec_le_rb1);
1235 modelUnregister(this);
1238 // ============================================================== setValue
1239 void EdgeDialog::setValue(HEXA_NS::Edge* e)
1241 HEXA_NS::Vertex* v0 = e->getVertex(0);
1242 HEXA_NS::Vertex* v1 = e->getVertex(1);
1244 name_le->setText( e->getName() );
1245 v0_le_rb0->setText( v0->getName() );
1246 v1_le_rb0->setText( v1->getName() );
1248 if ( getPatternDataSelectionModel() ){
1249 QModelIndex ie = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e) );
1250 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1251 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1253 name_le->setProperty( "QModelIndex", QVariant::fromValue(ie) );
1254 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1255 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1260 // ============================================================== getValue
1261 HEXA_NS::Edge* EdgeDialog::getValue()
1266 // ============================================================== apply
1267 bool EdgeDialog::apply(QModelIndex& result)
1269 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1272 if ( !getDocumentModel() ) return false;
1273 const PatternDataModel* patternDataModel = getPatternDataModel();
1274 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1275 if ( !patternDataModel /*|| !patternBuilderModel*/ ) return false;
1279 if ( rb0->isChecked() ){
1280 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1281 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1282 if ( iv0.isValid()&& iv1.isValid() ){
1283 iEdge = getDocumentModel()->addEdgeVertices( iv0, iv1 );
1285 } else if ( rb1->isChecked() ){
1286 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
1287 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb1] );
1288 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
1289 if ( ivex.isValid() && ivec.isValid() ){
1290 iEdge = getDocumentModel()->addEdgeVector( ivex, ivec );
1294 if ( !iEdge.isValid() ){
1295 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD EDGE" ) + "\n" + getErrorMsg() );
1298 _value = iEdge.model()->data(iEdge, HEXA_DATA_ROLE).value<HEXA_NS::Edge*>();
1300 QString newName = name_le->text();
1301 if ( !newName.isEmpty() )/*{*/
1302 getDocumentModel()->setName( iEdge, newName );
1304 //update the default name in the dialog box
1306 updateDefaultName(name_le, _value->getType());
1308 result = patternDataModel->mapFromSource(iEdge);
1313 // ------------------------- QUAD ----------------------------------
1315 // ============================================================== Constructeur
1316 QuadDialog::QuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1317 HexaBaseDialog(parent, editmode, f),
1320 _helpFileName = "gui_quadrangle.html";
1322 _initWidget(editmode);
1325 if ( editmode == INFO_MODE ){
1326 setWindowTitle( tr("Quad Information") );
1330 // ============================================================== Destructeur
1331 QuadDialog::~QuadDialog()
1335 // ============================================================== _initInputWidget
1336 void QuadDialog::_initInputWidget( Mode editmode )
1339 QValidator *validator = new QRegExpValidator(rx, this);
1341 installEventFilter(this);
1342 name_le->installEventFilter(this);
1344 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1345 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1346 v2_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1347 v3_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1349 v0_le_rb0->setValidator( validator );
1350 v1_le_rb0->setValidator( validator );
1351 v2_le_rb0->setValidator( validator );
1352 v3_le_rb0->setValidator( validator );
1353 v0_le_rb0->installEventFilter(this);
1354 v1_le_rb0->installEventFilter(this);
1355 v2_le_rb0->installEventFilter(this);
1356 v3_le_rb0->installEventFilter(this);
1358 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1359 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1360 e2_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1361 e3_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1363 e0_le_rb1->setValidator( validator );
1364 e1_le_rb1->setValidator( validator );
1365 e2_le_rb1->setValidator( validator );
1366 e3_le_rb1->setValidator( validator );
1368 e0_le_rb1->installEventFilter(this);
1369 e1_le_rb1->installEventFilter(this);
1370 e2_le_rb1->installEventFilter(this);
1371 e3_le_rb1->installEventFilter(this);
1373 v0_le_rb0->setReadOnly(true);
1374 v1_le_rb0->setReadOnly(true);
1375 v2_le_rb0->setReadOnly(true);
1376 v3_le_rb0->setReadOnly(true);
1378 e0_le_rb1->setReadOnly(true);
1379 e1_le_rb1->setReadOnly(true);
1380 e2_le_rb1->setReadOnly(true);
1381 e3_le_rb1->setReadOnly(true);
1383 if (editmode == INFO_MODE)
1384 name_le->setReadOnly(true);
1387 // ============================================================== clear
1388 void QuadDialog::clear()
1390 //Clear the dialog and unregister it from the model
1391 QModelIndex invalidIndex;
1396 modelUnregister(v0_le_rb0);
1399 modelUnregister(v1_le_rb0);
1402 modelUnregister(v2_le_rb0);
1405 modelUnregister(v3_le_rb0);
1408 modelUnregister(e0_le_rb1);
1411 modelUnregister(e1_le_rb1);
1414 modelUnregister(e2_le_rb1);
1417 modelUnregister(e3_le_rb1);
1419 modelUnregister(this);
1423 // ============================================================== setValue
1424 void QuadDialog::setValue(HEXA_NS::Quad* q)
1426 Q_ASSERT( q->countEdge() == 4 );
1427 Q_ASSERT( q->countVertex() == 4 );
1430 name_le->setText( q->getName() );
1433 HEXA_NS::Vertex* v0 = q->getVertex(0);
1434 HEXA_NS::Vertex* v1 = q->getVertex(1);
1435 HEXA_NS::Vertex* v2 = q->getVertex(2);
1436 HEXA_NS::Vertex* v3 = q->getVertex(3);
1438 v0_le_rb0->setText( v0->getName() );
1439 v1_le_rb0->setText( v1->getName() );
1440 v2_le_rb0->setText( v2->getName() );
1441 v3_le_rb0->setText( v3->getName() );
1445 HEXA_NS::Edge* e0 = q->getEdge(0);
1446 HEXA_NS::Edge* e1 = q->getEdge(1);
1447 HEXA_NS::Edge* e2 = q->getEdge(2);
1448 HEXA_NS::Edge* e3 = q->getEdge(3);
1450 e0_le_rb1->setText( e0->getName() );
1451 e1_le_rb1->setText( e1->getName() );
1452 e2_le_rb1->setText( e2->getName() );
1453 e3_le_rb1->setText( e3->getName() );
1455 if ( getPatternDataSelectionModel() ){
1456 QModelIndex iq = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(q) );
1458 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1459 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1460 QModelIndex iv2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v2) );
1461 QModelIndex iv3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v3) );
1463 QModelIndex ie0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e0) );
1464 QModelIndex ie1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e1) );
1465 QModelIndex ie2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e2) );
1466 QModelIndex ie3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e3) );
1468 name_le->setProperty( "QModelIndex", QVariant::fromValue(iq) );
1470 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1471 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1472 v2_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv2) );
1473 v3_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv3) );
1475 e0_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie0) );
1476 e1_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie1) );
1477 e2_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie2) );
1478 e3_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie3) );
1484 // ============================================================== getValue
1485 HEXA_NS::Quad* QuadDialog::getValue()
1491 // ============================================================== apply
1492 bool QuadDialog::apply(QModelIndex& result)
1494 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1497 if ( !getDocumentModel() ) return false;
1498 const PatternDataModel* patternDataModel = getPatternDataModel();
1499 if ( !patternDataModel ) return false;
1503 if ( rb0->isChecked() ){ //vertices
1504 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1505 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1506 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb0] );
1507 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb0] );
1513 iQuad = getDocumentModel()->addQuadVertices( iv0, iv1, iv2, iv3 );
1515 } else if ( rb1->isChecked() ){ //edges
1516 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
1517 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
1518 QModelIndex ie2 = patternDataModel->mapToSource( _index[e2_le_rb1] );
1519 QModelIndex ie3 = patternDataModel->mapToSource( _index[e3_le_rb1] );
1525 iQuad = getDocumentModel()->addQuadEdges( ie0, ie1, ie2, ie3 );
1529 if ( !iQuad.isValid() ){
1530 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD QUAD" ) + "\n" + getErrorMsg());
1533 _value = iQuad.model()->data(iQuad, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1535 QString newName = name_le->text();
1536 if ( !newName.isEmpty() )/*{*/
1537 getDocumentModel()->setName( iQuad, newName );
1539 //the default name in the dialog box
1541 updateDefaultName(name_le, _value->getType());
1543 // to select/highlight result
1544 result = patternDataModel->mapFromSource(iQuad);
1550 // ------------------------- HEXA ----------------------------------
1552 // ============================================================== HexaDialog
1554 HexaDialog::HexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1555 HexaBaseDialog(parent, editmode, f),
1558 _helpFileName = "gui_hexahedron.html";
1560 _initWidget(editmode);
1563 if ( editmode == INFO_MODE ){
1564 setWindowTitle( tr("Hexahedron Information") );
1565 quads_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
1566 vertices_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
1570 // ============================================================== Destructeur
1571 HexaDialog::~HexaDialog()
1575 // ============================================================== _initInputWidget
1576 void HexaDialog::_initInputWidget( Mode editmode )
1580 installEventFilter(this);
1581 name_le->installEventFilter(this);
1583 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
1584 quads_lw->installEventFilter(this);
1586 vertices_lw->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1587 vertices_lw->installEventFilter(this);
1589 if ( editmode != INFO_MODE ) {
1590 // delete item from listwidget
1591 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
1592 QShortcut* delVertexShortcut = new QShortcut( QKeySequence(Qt::Key_X), vertices_lw );
1593 delQuadShortcut->setContext( Qt::WidgetShortcut );
1594 delVertexShortcut->setContext( Qt::WidgetShortcut );
1595 connect(delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()));
1596 connect(delVertexShortcut, SIGNAL(activated()), this, SLOT(deleteVertexItem()));
1598 // highlight item on model view (VTK) from listwidget
1599 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1600 connect( vertices_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1602 if ( editmode != INFO_MODE)
1604 connect( vertices_rb, SIGNAL(clicked()), vertices_lw, SLOT(setFocus()));
1605 connect( quads_rb, SIGNAL(clicked()), quads_lw, SLOT(setFocus()));
1608 connect( vertices_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1609 connect( quads_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1611 if (editmode == INFO_MODE)
1612 name_le->setReadOnly(true);
1615 // ============================================================== clear
1616 void HexaDialog::clear()
1621 modelUnregister(quads_lw);
1623 vertices_lw->clear();
1624 modelUnregister(vertices_lw);
1626 modelUnregister(this);
1629 // ============================================================== getAssocsVTK
1631 * Returns elements currently associated to vtk
1633 QModelIndexList HexaDialog::getAssocsVTK()
1635 QModelIndexList assocs;
1636 QModelIndex iQuad, iVertex;
1637 QListWidgetItem* item = NULL;
1639 const PatternDataModel* patternDataModel = getPatternDataModel();
1640 if (patternDataModel == NULL) return assocs;
1641 if (quads_rb->isChecked())
1643 //ListWidget content
1644 int nbQuads = quads_lw->count();
1645 for ( int r = 0; r < nbQuads; ++r ){
1646 item = quads_lw->item(r);
1647 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1648 if ( iQuad.isValid() )
1653 else if (vertices_rb->isChecked())
1655 //ListWidget content
1656 int nbVertices = vertices_lw->count();
1657 for ( int r = 0; r < nbVertices; ++r ){
1658 item = vertices_lw->item(r);
1659 iVertex = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1660 if ( iVertex.isValid() )
1669 // ============================================================== updateButtonBox
1670 void HexaDialog::updateButtonBox()
1672 if ( _editMode == INFO_MODE )
1675 if ( quads_rb->isChecked() ){ // build from quads count() must be between [2,6]
1676 int nbQuads = quads_lw->count();
1677 if ( nbQuads >= 2 && nbQuads <= 6 ){
1678 _applyButton->setEnabled(true);
1680 _applyButton->setEnabled(false);
1682 } else if ( vertices_rb->isChecked() ){ // build from vertices count() must be equals to 8
1683 int nbVertices = vertices_lw->count();
1684 if ( nbVertices == 8 ){
1685 _applyButton->setEnabled(true);
1687 _applyButton->setEnabled(false);
1692 // ============================================================== deleteQuadItem
1693 void HexaDialog::deleteQuadItem()
1695 delete quads_lw->currentItem();
1699 // ============================================================== deleteVertexItem
1700 void HexaDialog::deleteVertexItem()
1702 delete vertices_lw->currentItem();
1706 // ============================================================== _setValueQuads
1707 void HexaDialog::_setValueQuads( HEXA_NS::Hexa* h )
1709 QListWidgetItem *qItem = NULL;
1710 HEXA_NS::Quad *q = NULL;
1712 if (getPatternDataSelectionModel() == NULL) return;
1714 for( int i = 0; i <= 5; ++i ){
1716 qIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(q)) );
1717 qItem = new QListWidgetItem( q->getName() );
1718 qItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(qIndex) );
1719 qItem->setData(LW_DATA_ROLE, qIndex.data(HEXA_DATA_ROLE));
1720 quads_lw->addItem( qItem );
1724 // ============================================================== _setValueVertices
1725 void HexaDialog::_setValueVertices( HEXA_NS::Hexa* h )
1727 QListWidgetItem *vItem = NULL;
1728 HEXA_NS::Vertex* v = NULL;
1730 if (getPatternDataSelectionModel() == NULL) return;
1731 vertices_lw->clear();
1732 for( int i = 0; i <= 7; ++i ){
1733 v = h->getVertex(i);
1734 vIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(v)) );
1735 vItem = new QListWidgetItem( v->getName() );
1736 vItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(vIndex) );
1737 vItem->setData(LW_DATA_ROLE, vIndex.data(HEXA_DATA_ROLE));
1738 vertices_lw->addItem( vItem );
1742 // ============================================================== setValue
1743 void HexaDialog::setValue(HEXA_NS::Hexa* h)
1746 name_le->setText( h->getName() );
1748 if ( getPatternDataSelectionModel()){
1749 QModelIndex hIndex = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(h) );
1750 _setValueVertices(h);
1752 name_le->setProperty( "QModelIndex", QVariant::fromValue(hIndex) );
1757 // ============================================================== getValue
1758 HEXA_NS::Hexa* HexaDialog::getValue()
1763 // ============================================================== apply
1764 bool HexaDialog::apply(QModelIndex& result)
1766 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1769 if ( !getDocumentModel() ) return false;
1770 const PatternDataModel* patternDataModel = getPatternDataModel();
1771 if ( !patternDataModel ) return false;
1775 QListWidget* currentLw = NULL;
1776 QListWidgetItem* item = NULL;
1778 if ( quads_rb->isChecked() )
1779 currentLw = dynamic_cast<QListWidget*>( quads_lw );
1780 else if ( vertices_rb->isChecked() )
1781 currentLw = dynamic_cast<QListWidget*>( vertices_lw );
1784 QModelIndexList iElts;
1785 int nbItems = currentLw->count();
1786 for ( int r = 0; r < nbItems; ++r){
1787 item = currentLw->item(r);
1788 iElt = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1789 if ( iElt.isValid() )
1793 nbItems = iElts.count();
1794 if ( quads_rb->isChecked() && (nbItems>=2 && nbItems<=6) ){ // build from quads iElts.count() should be between [2,6]
1795 iHexa = getDocumentModel()->addHexaQuads( iElts );
1796 } else if ( vertices_rb->isChecked() && nbItems== 8 ){ // build from vertices
1797 iHexa = getDocumentModel()->addHexaVertices( iElts[0], iElts[1], iElts[2], iElts[3],
1798 iElts[4], iElts[5], iElts[6], iElts[7] );
1801 if ( !iHexa.isValid() ){
1802 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD HEXA" ) + "\n" + getErrorMsg() );
1805 _value = iHexa.model()->data(iHexa, HEXA_DATA_ROLE).value<HEXA_NS::Hexa*>();
1807 QString newName = name_le->text();
1808 if ( !newName.isEmpty() )/*{*/
1809 getDocumentModel()->setName( iHexa, newName );
1811 //update the default name in the dialog box
1813 updateDefaultName(name_le, _value->getType());
1815 // to select/highlight result
1816 result = patternDataModel->mapFromSource(iHexa);
1822 // ------------------------- VECTOR ----------------------------------
1824 // ============================================================== Constructeur
1826 VectorDialog::VectorDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1827 HexaBaseDialog(parent, editmode, f),
1830 _helpFileName = "gui_vector.html";
1832 _initWidget(editmode);
1836 if ( editmode == INFO_MODE ){
1837 setWindowTitle( tr("Vector Information") );
1842 // ============================================================== Destructeur
1843 VectorDialog::~VectorDialog()
1847 // ============================================================== _initInputWidget
1848 void VectorDialog::_initInputWidget( Mode editmode )
1851 QValidator *validator = new QRegExpValidator(rx, this);
1853 installEventFilter(this);
1854 name_le->installEventFilter(this);
1856 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1857 v0_le_rb1->setValidator( validator );
1858 v0_le_rb1->installEventFilter(this);
1860 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1861 v1_le_rb1->setValidator( validator );
1862 v1_le_rb1->installEventFilter(this);
1864 if ( editmode == INFO_MODE ){
1865 name_le->setReadOnly(true);
1866 dx_spb_rb0->setReadOnly(true);
1867 dy_spb_rb0->setReadOnly(true);
1868 dz_spb_rb0->setReadOnly(true);
1871 v0_le_rb1->setReadOnly(true);
1872 v1_le_rb1->setReadOnly(true);
1875 // ============================================================== clear
1876 void VectorDialog::clear()
1880 modelUnregister(v0_le_rb1);
1883 modelUnregister(v1_le_rb1);
1885 modelUnregister(this);
1888 // ============================================================== setValue
1889 void VectorDialog::setValue(HEXA_NS::Vector* v)
1891 name_le->setText( v->getName() );
1892 dx_spb_rb0->setValue( v->getDx() );
1893 dy_spb_rb0->setValue( v->getDy() );
1894 dz_spb_rb0->setValue( v->getDz() );
1896 if ( getPatternDataSelectionModel() ){
1897 QModelIndex ivec = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1898 name_le->setProperty( "QModelIndex", QVariant::fromValue(ivec) );
1903 // ============================================================== getValue
1904 HEXA_NS::Vector* VectorDialog::getValue()
1909 // ============================================================== apply
1910 bool VectorDialog::apply(QModelIndex& result)
1912 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1915 if ( !getDocumentModel() ) return false;
1916 const PatternDataModel* patternDataModel = getPatternDataModel();
1917 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1918 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
1920 QModelIndex iVector;
1922 if ( rb0->isChecked() ){ //scalar
1923 double dx = dx_spb_rb0->value();
1924 double dy = dy_spb_rb0->value();
1925 double dz = dz_spb_rb0->value();
1927 iVector = getDocumentModel()->addVector( dx, dy, dz );
1928 } else if ( rb1->isChecked() ){ //vertices
1929 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
1930 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
1934 iVector = getDocumentModel()->addVectorVertices( iv0, iv1 );
1938 if ( !iVector.isValid() ){
1939 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD VECTOR" ) + "\n" + getErrorMsg());
1943 _value = iVector.model()->data(iVector, HEXA_DATA_ROLE).value<HEXA_NS::Vector *>();
1945 QString newName = name_le->text();
1946 if ( !newName.isEmpty() )/*{*/
1947 getDocumentModel()->setName( iVector, newName );
1949 //update the default name in the dialog box
1951 updateDefaultName(name_le, _value->getType());
1953 // to select/highlight result
1954 result = patternDataModel->mapFromSource(iVector);
1955 // result = patternBuilderModel->mapFromSource(iVector);
1960 // ------------------------- MakeGridDialog ----------------------------------
1961 // ============================================================== Constructeur
1963 MakeGridDialog::MakeGridDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
1964 : HexaBaseDialog(parent, editmode, f)
1967 _initWidget(editmode);
1970 _helpFileName = "creategrids.html#guicartgridsimple";
1971 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1972 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1973 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1975 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1976 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1977 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1979 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1980 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1981 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1984 // ============================================================== Destructeur
1985 MakeGridDialog::~MakeGridDialog()
1989 // ============================================================== _initInputWidget
1990 void MakeGridDialog::_initInputWidget( Mode editmode )
1992 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1993 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1994 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1995 vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1997 center_le->setReadOnly(true);
1998 axis_le->setReadOnly(true);
1999 base_le->setReadOnly(true);
2000 vec_le->setReadOnly(true);
2002 installEventFilter(this);
2003 center_le->installEventFilter(this);
2004 axis_le->installEventFilter(this);
2005 base_le->installEventFilter(this);
2006 vec_le->installEventFilter(this);
2008 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2009 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2011 angle_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(angle_lw));
2012 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2014 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2015 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2017 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2018 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2020 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2021 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2023 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2024 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2027 // ============================================================== clear
2028 void MakeGridDialog::clear()
2031 modelUnregister(center_le);
2034 modelUnregister(axis_le);
2037 modelUnregister(base_le);
2040 modelUnregister(vec_le);
2042 modelUnregister(this);
2045 // ============================================================== updateHelpFileName
2046 void MakeGridDialog::updateHelpFileName()
2048 if ( sender() == rb0 ){
2049 _helpFileName = "creategrids.html#guicartgridsimple";
2050 } else if ( sender() == rb1 ){
2051 _helpFileName = "creategrids.html#guicartgriduniform";
2052 } else if ( sender() == rb2 ){
2053 _helpFileName = "creategrids.html#guicartgridcustom";
2057 // ============================================================== addRadiusItem
2058 void MakeGridDialog::addRadiusItem()
2060 QListWidgetItem* previousItem = radius_lw->currentItem();
2061 QListWidgetItem* newItem = new QListWidgetItem();
2063 double defaultValue = 1.;
2065 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2067 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2068 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2069 radius_lw->addItem(newItem);
2072 // ============================================================== delRadiusItem
2073 void MakeGridDialog::delRadiusItem()
2075 delete radius_lw->currentItem();
2078 // ============================================================== addAngleItem
2079 void MakeGridDialog::addAngleItem()
2081 QListWidgetItem* previousItem = angle_lw->currentItem();
2082 QListWidgetItem* newItem = new QListWidgetItem();
2084 double defaultValue = 1.;
2086 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2088 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2089 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2090 angle_lw->addItem(newItem);
2093 // ============================================================== delAngleItem
2094 void MakeGridDialog::delAngleItem()
2096 delete angle_lw->currentItem();
2099 // ============================================================== addHeightItem
2100 void MakeGridDialog::addHeightItem()
2102 QListWidgetItem* previousItem = height_lw->currentItem();
2103 QListWidgetItem* newItem = new QListWidgetItem();
2105 double defaultValue = 1.;
2107 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2109 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2110 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2111 height_lw->addItem(newItem);
2114 // ============================================================== delHeightItem
2115 void MakeGridDialog::delHeightItem()
2117 delete height_lw->currentItem();
2120 // ============================================================== apply
2121 bool MakeGridDialog::apply(QModelIndex& result)
2123 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2126 DocumentModel* docModel = getDocumentModel();
2127 PatternDataModel* patternDataModel = getPatternDataModel();
2128 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2130 QModelIndex iNewElts;
2131 if ( rb0->isChecked() )
2133 long nx = nx_spb->value();
2134 long ny = ny_spb->value();
2135 long nz = nz_spb->value();
2136 iNewElts = docModel->makeCartesianTop(nx, ny, nz);
2138 else if ( rb1->isChecked() )
2140 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2141 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2142 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2143 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le] );
2144 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2145 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2146 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2148 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2150 double lx = lx_spb->value();
2151 double ly = ly_spb->value();
2152 double lz = lz_spb->value();
2153 double nx = nx_spb->value();
2154 double ny = ny_spb->value();
2155 double nz = nz_spb->value();
2157 iNewElts = docModel->makeCartesianUni( icenter, ibase, ivec, iaxis,
2158 lx, ly, lz, nx, ny, nz);
2161 } else if ( rb2->isChecked() )
2163 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2164 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2165 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2166 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le] );
2167 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2168 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2169 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2171 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2173 QListWidgetItem* item = NULL;
2175 vector<double> radius;
2176 vector<double> angles;
2177 vector<double> heights;
2179 // double somme = 0.;
2180 int nbAngles = angle_lw->count();
2181 for ( int r = 0; r < nbAngles; ++r){
2182 item = angle_lw->item(r);
2183 double itemValue = item->data(Qt::EditRole).toDouble();
2184 angles.push_back(itemValue);
2185 // somme += itemValue;
2187 // if (somme > 360.01)
2189 // SUIT_MessageBox::information( 0,
2191 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2195 int nbRadius = radius_lw->count();
2196 for ( int r = 0; r < nbRadius; ++r){
2197 item = radius_lw->item(r);
2198 radius.push_back(item->data(Qt::EditRole).toDouble());
2201 int nbHeight = height_lw->count();
2202 for ( int r = 0; r < nbHeight; ++r){
2203 item = height_lw->item(r);
2204 heights.push_back(item->data(Qt::EditRole).toDouble());
2207 iNewElts = docModel->makeCartesian( icenter, ibase, ivec, iaxis,
2208 radius, angles, heights);
2212 if ( !iNewElts.isValid() )
2214 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE GRID" ) + "\n" + getErrorMsg() );
2218 result = patternDataModel->mapFromSource(iNewElts);
2219 // result = patternBuilderModel->mapFromSource( iNewElts );
2224 // ============================================================== Constructeur
2226 MakeCylinderDialog::MakeCylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2227 : HexaBaseDialog(parent, editmode, f)
2230 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinder";
2231 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2232 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2233 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2234 _initWidget(editmode);
2239 // ============================================================== Destructeur
2240 MakeCylinderDialog::~MakeCylinderDialog()
2244 void MakeCylinderDialog::_initInputWidget( Mode editmode )
2246 installEventFilter(this);
2248 rb0->installEventFilter(this);
2249 rb1->installEventFilter(this);
2250 rb2->installEventFilter(this);
2252 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
2253 origin_le->installEventFilter(this);
2254 origin_le->setReadOnly(true);
2256 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2257 axis_le->installEventFilter(this);
2258 axis_le->setReadOnly(true);
2260 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE));
2261 base_le->installEventFilter(this);
2262 base_le->setReadOnly(true);
2264 ext_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2265 ext_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2266 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2267 ext_radius_spb->installEventFilter(this);
2269 int_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2270 int_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2271 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2272 int_radius_spb->installEventFilter(this);
2274 angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2275 angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2276 angle_spb->setProperty("Angle", QVariant::fromValue(true));
2277 angle_spb->installEventFilter(this);
2279 height_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2280 height_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2281 height_spb->setProperty("Length", QVariant::fromValue(true));
2282 height_spb->installEventFilter(this);
2284 radius_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2285 radius_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2286 radius_lw->setProperty("Radius", QVariant::fromValue(true));
2287 radius_lw->installEventFilter(this);
2290 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2291 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2292 angle_lw->setProperty("Angle", QVariant::fromValue(true));
2293 angle_lw->installEventFilter(this);
2295 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2296 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2297 height_lw->setProperty("Length", QVariant::fromValue(true));
2298 height_lw->installEventFilter(this);
2300 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2301 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2303 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2304 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2306 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2307 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2309 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2310 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2312 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2313 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2315 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2316 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2319 // ============================================================== updateHelpFileName
2320 void MakeCylinderDialog::updateHelpFileName()
2322 if ( sender() == rb0 ){
2323 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindersimple";
2324 } else if ( sender() == rb1 ){
2325 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinderuniform";
2326 } else if ( sender() == rb2 ){
2327 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindercustom";
2331 // ============================================================== addRadiusItem
2332 void MakeCylinderDialog::addRadiusItem()
2334 QListWidgetItem* previousItem = radius_lw->currentItem();
2335 QListWidgetItem* newItem = new QListWidgetItem();
2337 double defaultValue = 1.;
2339 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2341 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2342 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2343 radius_lw->addItem(newItem);
2346 // ============================================================== delRadiusItem
2347 void MakeCylinderDialog::delRadiusItem()
2349 delete radius_lw->currentItem();
2352 // ============================================================== addAngleItem
2353 void MakeCylinderDialog::addAngleItem()
2355 QListWidgetItem* previousItem = angle_lw->currentItem();
2356 QListWidgetItem* newItem = new QListWidgetItem();
2358 double defaultValue = 180.;
2360 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2362 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2363 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2364 angle_lw->addItem(newItem);
2367 // ============================================================== delAngleItem
2368 void MakeCylinderDialog::delAngleItem()
2370 delete angle_lw->currentItem();
2373 // ============================================================== addHeightItem
2374 void MakeCylinderDialog::addHeightItem()
2376 QListWidgetItem* previousItem = height_lw->currentItem();
2377 QListWidgetItem* newItem = new QListWidgetItem();
2379 double defaultValue = 1.;
2381 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2383 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2384 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2385 height_lw->addItem(newItem);
2388 // ============================================================== delHeightItem
2389 void MakeCylinderDialog::delHeightItem()
2391 delete height_lw->currentItem();
2394 // ============================================================== clear
2395 void MakeCylinderDialog::clear()
2398 modelUnregister(origin_le);
2401 modelUnregister(axis_le);
2404 modelUnregister(base_le);
2406 modelUnregister(this);
2409 // ============================================================== apply
2410 bool MakeCylinderDialog::apply(QModelIndex& result)
2412 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2415 DocumentModel* docModel = getDocumentModel();
2416 PatternDataModel* patternDataModel = getPatternDataModel();
2417 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2419 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2420 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2421 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2422 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2423 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2424 double rext = ext_radius_spb->value();
2425 double rint = int_radius_spb->value();
2426 double angle = angle_spb->value();
2427 double height = height_spb->value();
2428 double nr = nr_spb->value();
2429 double na = na_spb->value();
2430 double nh = nh_spb->value();
2433 if (rb0->isChecked())
2434 iElts = docModel->makeCylinderTop(nr, na, nh);
2435 else if (rb1->isChecked())
2437 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2438 iElts = docModel->makeCylinderUni(iorigin, ibase, iaxis, rint,
2439 rext, angle, height, nr, na, nh);
2441 else if (rb2->isChecked())
2443 QListWidgetItem* item = NULL;
2445 vector<double> radius;
2446 vector<double> angles;
2447 vector<double> heights;
2449 // double somme = 0.;
2450 int nbAngles = angle_lw->count();
2451 for ( int r = 0; r < nbAngles; ++r){
2452 item = angle_lw->item(r);
2453 double itemValue = item->data(Qt::EditRole).toDouble();
2454 angles.push_back(itemValue);
2455 // somme += itemValue;
2457 // if (somme > 360.01)
2459 // SUIT_MessageBox::information( 0,
2461 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2465 int nbRadius = radius_lw->count();
2466 for ( int r = 0; r < nbRadius; ++r){
2467 item = radius_lw->item(r);
2468 radius.push_back(item->data(Qt::EditRole).toDouble());
2471 int nbHeight = height_lw->count();
2472 for ( int r = 0; r < nbHeight; ++r){
2473 item = height_lw->item(r);
2474 heights.push_back(item->data(Qt::EditRole).toDouble());
2477 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2478 iElts = docModel->makeCylinder( iorigin, ibase, iaxis, radius, angles, heights);
2482 if ( !iElts.isValid() ){
2483 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDER" ) + "\n" + getErrorMsg() );
2487 result = patternDataModel->mapFromSource(iElts);
2488 // result = patternBuilderModel->mapFromSource(iElts);
2493 //---------------------------------- MakePipeDialog -----------------------------
2494 // ============================================================== Constructeur
2496 MakePipeDialog::MakePipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2497 : HexaBaseDialog(parent, editmode, f)
2500 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipe";
2501 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2502 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2503 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2504 _initWidget(editmode);
2508 // ============================================================== Destructeur
2509 MakePipeDialog::~MakePipeDialog()
2513 // ============================================================== _initInputWidget
2514 void MakePipeDialog::_initInputWidget( Mode editmode )
2516 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2517 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2518 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2520 installEventFilter(this);
2521 origin_le->installEventFilter(this);
2522 axis_le->installEventFilter(this);
2523 base_le->installEventFilter(this);
2525 rb0->installEventFilter(this);
2526 rb1->installEventFilter(this);
2527 rb2->installEventFilter(this);
2529 origin_le->setReadOnly(true);
2530 axis_le->setReadOnly(true);
2531 base_le->setReadOnly(true);
2533 ext_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2534 ext_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2535 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2536 ext_radius_spb->installEventFilter(this);
2538 int_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2539 int_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2540 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2541 int_radius_spb->installEventFilter(this);
2543 angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2544 angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2545 angle_spb->setProperty("Angle", QVariant::fromValue(true));
2546 angle_spb->installEventFilter(this);
2548 height_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2549 height_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2550 height_spb->setProperty("Length", QVariant::fromValue(true));
2551 height_spb->installEventFilter(this);
2553 radius_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2554 radius_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2555 radius_lw->setProperty("Radius", QVariant::fromValue(true));
2556 radius_lw->installEventFilter(this);
2558 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2559 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2560 angle_lw->setProperty("Angle", QVariant::fromValue(true));
2561 angle_lw->installEventFilter(this);
2563 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2564 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2565 height_lw->setProperty("Length", QVariant::fromValue(true));
2566 height_lw->installEventFilter(this);
2568 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2569 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2571 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2572 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2574 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2575 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2577 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2578 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2580 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2581 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2583 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2584 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2588 // ============================================================== updateHelpFileName
2589 void MakePipeDialog::updateHelpFileName()
2591 if ( sender() == rb0 ){
2592 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipesimple";
2593 } else if ( sender() == rb1 ){
2594 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipeuniform";
2595 } else if ( sender() == rb2 ){
2596 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipecustom";
2600 // ============================================================== addRadiusItem
2601 void MakePipeDialog::addRadiusItem()
2603 QListWidgetItem* previousItem = radius_lw->currentItem();
2604 QListWidgetItem* newItem = new QListWidgetItem();
2606 double defaultValue = 1.;
2608 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2610 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2611 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2612 radius_lw->addItem(newItem);
2615 // ============================================================== delRadiusItem
2616 void MakePipeDialog::delRadiusItem()
2618 delete radius_lw->currentItem();
2621 // ============================================================== addAngleItem
2622 void MakePipeDialog::addAngleItem()
2624 QListWidgetItem* previousItem = angle_lw->currentItem();
2625 QListWidgetItem* newItem = new QListWidgetItem();
2627 double defaultValue = 180.;
2629 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2631 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2632 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2633 angle_lw->addItem(newItem);
2636 // ============================================================== delAngleItem
2637 void MakePipeDialog::delAngleItem()
2639 delete angle_lw->currentItem();
2642 // ============================================================== addHeightItem
2643 void MakePipeDialog::addHeightItem()
2645 QListWidgetItem* previousItem = height_lw->currentItem();
2646 QListWidgetItem* newItem = new QListWidgetItem();
2648 double defaultValue = 1.;
2650 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2652 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2653 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2654 height_lw->addItem(newItem);
2657 // ============================================================== delHeightItem
2658 void MakePipeDialog::delHeightItem()
2660 delete height_lw->currentItem();
2663 // ============================================================== clear
2664 void MakePipeDialog::clear()
2667 modelUnregister(origin_le);
2670 modelUnregister(axis_le);
2673 modelUnregister(base_le);
2675 modelUnregister(this);
2678 // ============================================================== apply
2679 bool MakePipeDialog::apply(QModelIndex& result)
2681 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2684 DocumentModel* docModel = getDocumentModel();
2685 PatternDataModel* patternDataModel = getPatternDataModel();
2686 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2688 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2689 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2690 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2691 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2692 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2693 double rext = ext_radius_spb->value();
2694 double rint = int_radius_spb->value();
2695 double angle = angle_spb->value();
2696 double height = height_spb->value();
2697 int nr = nr_spb->value();
2698 int na = na_spb->value();
2699 int nh = nh_spb->value();
2703 if (rb0->isChecked())
2704 iElts = docModel->makePipeTop(nr, na, nh);
2705 else if (rb1->isChecked())
2707 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2708 iElts = docModel->makePipeUni(iorigin, ibase, iaxis, rint, rext, angle, height,
2711 else if (rb2->isChecked())
2713 QListWidgetItem* item = NULL;
2715 vector<double> radius;
2716 vector<double> angles;
2717 vector<double> heights;
2719 // double somme = 0.;
2720 int nbAngles = angle_lw->count();
2721 for ( int r = 0; r < nbAngles; ++r){
2722 item = angle_lw->item(r);
2723 double itemValue = item->data(Qt::EditRole).toDouble();
2724 angles.push_back(itemValue);
2725 // somme += itemValue;
2727 // if (somme > 360.01)
2729 // SUIT_MessageBox::information( 0,
2731 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2735 int nbRadius = radius_lw->count();
2736 for ( int r = 0; r < nbRadius; ++r){
2737 item = radius_lw->item(r);
2738 radius.push_back(item->data(Qt::EditRole).toDouble());
2741 int nbHeight = height_lw->count();
2742 for ( int r = 0; r < nbHeight; ++r){
2743 item = height_lw->item(r);
2744 heights.push_back(item->data(Qt::EditRole).toDouble());
2746 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2747 iElts = docModel->makePipe( iorigin, ibase, iaxis, radius, angles, heights );
2750 if ( !iElts.isValid() ){
2751 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPE" ) + "\n" + getErrorMsg() );
2755 // to select/highlight result
2756 result = patternDataModel->mapFromSource(iElts);
2757 // result = patternBuilderModel->mapFromSource(iElts);
2762 //---------------------------------- MakeCylindersDialog -----------------------------
2763 // ============================================================== Constructeur
2765 MakeCylindersDialog::MakeCylindersDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2766 : HexaBaseDialog(parent, editmode, f)
2768 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinders";
2770 _initWidget(editmode);
2773 // ============================================================== Destructeur
2774 MakeCylindersDialog::~MakeCylindersDialog()
2778 void MakeCylindersDialog::_initInputWidget( Mode editmode )
2780 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2781 center2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2782 direction_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2783 direction2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2785 radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2786 radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2787 radius_spb->setProperty("Radius", QVariant::fromValue(true));
2788 radius_spb->installEventFilter(this);
2790 height_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2791 height_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2792 height_spb->setProperty("Length", QVariant::fromValue(true));
2793 height_spb->installEventFilter(this);
2795 radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2796 radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2797 radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2798 radius2_spb->installEventFilter(this);
2800 height2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2801 height2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2802 height2_spb->setProperty("Length", QVariant::fromValue(true));
2803 height2_spb->installEventFilter(this);
2805 installEventFilter(this);
2806 center_le->installEventFilter(this);
2807 center2_le->installEventFilter(this);
2808 direction_le->installEventFilter(this);
2809 direction2_le->installEventFilter(this);
2811 center_le->setReadOnly(true);
2812 center2_le->setReadOnly(true);
2813 direction_le->setReadOnly(true);
2814 direction2_le->setReadOnly(true);
2817 // ============================================================== clear
2818 void MakeCylindersDialog::clear()
2821 modelUnregister(center_le);
2823 center2_le->clear();
2824 modelUnregister(center2_le);
2826 direction_le->clear();
2827 modelUnregister(direction_le);
2829 direction2_le->clear();
2830 modelUnregister(direction2_le);
2832 modelUnregister(this);
2835 // ============================================================== apply
2836 bool MakeCylindersDialog::apply(QModelIndex& result)
2838 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2841 DocumentModel* docModel = getDocumentModel();
2842 PatternDataModel* patternDataModel = getPatternDataModel();
2843 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2846 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2847 QModelIndex icenter2 = patternDataModel->mapToSource( _index[center2_le] );
2848 QModelIndex idir = patternDataModel->mapToSource( _index[direction_le] );
2849 QModelIndex idir2 = patternDataModel->mapToSource( _index[direction2_le] );
2850 // QModelIndex idir = patternBuilderModel->mapToSource( _index[direction_le] );
2851 // QModelIndex idir2 = patternBuilderModel->mapToSource( _index[direction2_le] );
2853 if ( icenter.isValid() && icenter2.isValid() && idir.isValid() && idir2.isValid()){
2854 double r1 = radius_spb->value();
2855 double h1 = height_spb->value();
2856 double r2 = radius2_spb->value();
2857 double h2 = height2_spb->value();
2858 iElts = docModel->makeCylinders( icenter, idir, r1, h1, icenter2, idir2, r2, h2 );
2861 if ( !iElts.isValid() ){
2862 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDERS" ) + "\n" + getErrorMsg() );
2866 result = patternDataModel->mapFromSource(iElts);
2867 // result = patternBuilderModel->mapFromSource(iElts);
2872 //---------------------------------- MakePipesDialog -----------------------------
2873 // ============================================================== Constructeur
2875 MakePipesDialog::MakePipesDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2876 : HexaBaseDialog(parent, editmode, f)
2878 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipes";
2880 _initWidget(editmode);
2883 // ============================================================== Destructeur
2884 MakePipesDialog::~MakePipesDialog()
2888 // ============================================================== _initInputWidget
2889 void MakePipesDialog::_initInputWidget( Mode editmode )
2891 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2892 origin2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2893 dir_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2894 dir2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2896 ext_radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2897 ext_radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2898 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2899 ext_radius_spb->installEventFilter(this);
2901 int_radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2902 int_radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2903 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2904 int_radius_spb->installEventFilter(this);
2906 height_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2907 height_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2908 height_spb->setProperty("Length", QVariant::fromValue(true));
2909 height_spb->installEventFilter(this);
2911 ext_radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2912 ext_radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2913 ext_radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2914 ext_radius2_spb->installEventFilter(this);
2916 int_radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2917 int_radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2918 int_radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2919 int_radius2_spb->installEventFilter(this);
2921 height2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2922 height2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2923 height2_spb->setProperty("Length", QVariant::fromValue(true));
2924 height2_spb->installEventFilter(this);
2926 origin_le->installEventFilter(this);
2927 origin2_le->installEventFilter(this);
2928 dir_le->installEventFilter(this);
2929 dir2_le->installEventFilter(this);
2931 origin_le->setReadOnly(true);
2932 origin2_le->setReadOnly(true);
2933 dir_le->setReadOnly(true);
2934 dir2_le->setReadOnly(true);
2937 // ============================================================== clear
2938 void MakePipesDialog::clear()
2941 modelUnregister(origin_le);
2943 origin2_le->clear();
2944 modelUnregister(origin2_le);
2947 modelUnregister(dir_le);
2950 modelUnregister(dir2_le);
2952 modelUnregister(this);
2955 // ============================================================== apply
2956 bool MakePipesDialog::apply(QModelIndex& result)
2958 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2961 DocumentModel* docModel = getDocumentModel();
2962 PatternDataModel* patternDataModel = getPatternDataModel();
2963 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2965 QModelIndex iorigin1 = patternDataModel->mapToSource( _index[origin_le] );
2966 QModelIndex iorigin2 = patternDataModel->mapToSource( _index[origin2_le] );
2967 QModelIndex idir1 = patternDataModel->mapToSource( _index[dir_le] );
2968 QModelIndex idir2 = patternDataModel->mapToSource( _index[dir2_le] );
2969 // QModelIndex idir1 = patternBuilderModel->mapToSource( _index[dir_le] );
2970 // QModelIndex idir2 = patternBuilderModel->mapToSource( _index[dir2_le] );
2971 double rint1 = int_radius_spb->value();
2972 double rext1 = ext_radius_spb->value();
2973 double height1 = height_spb->value();
2974 double rint2 = int_radius2_spb->value();
2975 double rext2 = ext_radius2_spb->value();
2976 double height2 = height_spb->value();
2980 if ( iorigin1.isValid() && iorigin2.isValid() && idir1.isValid() && idir2.isValid())
2981 iElts = docModel->makePipes( iorigin1, idir1, rint1, rext1, height1,
2982 iorigin2, idir2, rint2, rext2, height2);
2984 if ( !iElts.isValid() ){
2985 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPES" ) + "\n" + getErrorMsg() );
2989 result = patternDataModel->mapFromSource(iElts);
2990 // result = patternBuilderModel->mapFromSource(iElts);
2995 //---------------------------------- RemoveHexaDialog -----------------------------
2996 // ============================================================== Constructeur
2998 RemoveHexaDialog::RemoveHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2999 : HexaBaseDialog(parent, editmode, f)
3001 _helpFileName = "gui_remove.html";
3003 _initWidget(editmode);
3006 // ============================================================== Destructeur
3007 RemoveHexaDialog::~RemoveHexaDialog()
3011 // ============================================================== _initInputWidget
3012 void RemoveHexaDialog::_initInputWidget( Mode editmode )
3015 QValidator *validator = new QRegExpValidator(rx, this);
3017 hexa_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3018 hexa_le->setValidator( validator );
3019 hexa_le->installEventFilter(this);
3020 hexa_le->setReadOnly(true);
3021 autoFocusSwitch = false;
3024 // ============================================================== clear
3025 void RemoveHexaDialog::clear()
3028 modelUnregister(hexa_le);
3030 modelUnregister(this);
3033 // ============================================================== apply
3034 bool RemoveHexaDialog::apply(QModelIndex& result)
3036 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3039 if ( !getDocumentModel() ) return false;
3040 const PatternDataModel* patternDataModel = getPatternDataModel();
3041 if ( !patternDataModel ) return false;
3043 QModelIndex ihexa = patternDataModel->mapToSource( _index[hexa_le] );
3045 bool removed = false;
3046 if ( ihexa.isValid() ){
3047 if ( connected_cb->isChecked() ){
3048 removed = getDocumentModel()->removeConnectedHexa( ihexa );
3050 removed = getDocumentModel()->removeHexa( ihexa );
3054 if ( removed == false ){
3055 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE HEXA" ) + "\n" + getErrorMsg() );
3064 //---------------------------------- PrismQuadDialog -----------------------------
3065 // ============================================================== Constructeur
3067 PrismQuadDialog::PrismQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3068 : HexaBaseDialog(parent, editmode, f)
3071 _helpFileName = "gui_prism_join_quad.html#guiextrudequads";
3072 connect( extrudeTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3073 connect( extrudeUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3074 connect( extrude_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3075 _initWidget(editmode);
3076 extrudeTop_rb->click();
3079 // ============================================================== Destructeur
3080 PrismQuadDialog::~PrismQuadDialog()
3084 // ============================================================== getAssocsVTK
3086 * Returns elements currently associated to vtk
3088 QModelIndexList PrismQuadDialog::getAssocsVTK()
3090 QModelIndexList assocs;
3092 QListWidgetItem* item = NULL;
3094 //ListWidget content
3095 const PatternDataModel* patternDataModel = getPatternDataModel();
3096 if ( !patternDataModel ) return assocs;
3097 int nbQuads = quads_lw->count();
3098 for ( int r = 0; r < nbQuads; ++r ){
3099 item = quads_lw->item(r);
3100 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3101 if ( iQuad.isValid() )
3107 // ============================================================== _initInputWidget
3108 void PrismQuadDialog::_initInputWidget( Mode editmode )
3110 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3111 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3113 length_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3114 length_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3115 length_spb->setProperty("Length", QVariant::fromValue(true));
3116 length_spb->installEventFilter(this);
3119 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3120 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3121 height_lw->setProperty("Length", QVariant::fromValue(true));
3122 height_lw->installEventFilter(this);
3124 installEventFilter(this);
3125 quads_lw->installEventFilter(this);
3126 axis_le->installEventFilter(this);
3128 extrudeTop_rb->installEventFilter(this);
3129 extrudeUni_rb->installEventFilter(this);
3130 extrude_rb->installEventFilter(this);
3132 axis_le->setReadOnly(true);
3134 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3135 delQuadShortcut->setContext( Qt::WidgetShortcut );
3136 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3137 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3139 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3140 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3141 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3142 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3145 // ============================================================== updateHelpFileName
3146 void PrismQuadDialog::updateHelpFileName()
3148 if ( sender() == extrudeTop_rb ){
3149 _helpFileName = "gui_prism_join_quad.html#guiextrudequadssimple";
3150 } else if ( sender() == extrudeUni_rb ){
3151 _helpFileName = "gui_prism_join_quad.html#guiextrudequadsuniform";
3152 } else if ( sender() == extrude_rb ){
3153 _helpFileName = "gui_prism_join_quad.html#guiextrudequadscustom";
3157 // ============================================================== clear
3158 void PrismQuadDialog::clear()
3161 modelUnregister(quads_lw);
3164 modelUnregister(axis_le);
3166 modelUnregister(this);
3169 // ============================================================== removeQuad
3170 void PrismQuadDialog::removeQuad()
3172 QListWidgetItem *item = quads_lw->currentItem();
3175 int r = quads_lw->row(item);
3176 quads_lw->takeItem(r);
3181 // ============================================================== addHeightItem
3182 void PrismQuadDialog::addHeightItem()
3184 QListWidgetItem* previousItem = height_lw->currentItem();
3185 QListWidgetItem* newItem = new QListWidgetItem();
3187 double defaultValue = 1.;
3189 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3191 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3192 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3193 height_lw->addItem(newItem);
3196 // ============================================================== delHeightItem
3197 void PrismQuadDialog::delHeightItem()
3199 delete height_lw->currentItem();
3202 // ============================================================== apply
3203 bool PrismQuadDialog::apply(QModelIndex& result)
3205 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3208 DocumentModel* docModel = getDocumentModel();
3209 PatternDataModel* patternDataModel = getPatternDataModel();
3210 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3212 QModelIndexList iquads = getIndexList(quads_lw);
3213 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
3214 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
3215 double length = length_spb->value();
3216 int nb = nb_spb->value();
3218 vector<double> heights;
3219 QListWidgetItem* item = NULL;
3220 int nbItems = height_lw->count();
3222 for ( int r = 0; r < nbItems; ++r){
3223 item = height_lw->item(r);
3224 heights.push_back( item->data(Qt::EditRole).toDouble() );
3228 int nbQuads = iquads.count();
3230 if (nbQuads == 1 && iquads[0].isValid())
3232 if (extrudeTop_rb->isChecked())
3233 iElts = docModel->extrudeQuadTop(iquads[0], nb);
3234 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3235 iElts = docModel->extrudeQuadUni(iquads[0], iaxis, length, nb);
3236 else if (extrude_rb->isChecked() && iaxis.isValid())
3237 iElts = docModel->extrudeQuad(iquads[0], iaxis, heights);
3239 else if (nbQuads > 1)
3241 if (extrudeTop_rb->isChecked())
3242 iElts = docModel->extrudeQuadsTop(iquads, nb);
3243 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3244 iElts = docModel->extrudeQuadsUni(iquads, iaxis, length, nb);
3245 else if (extrude_rb->isChecked() && iaxis.isValid())
3246 iElts = docModel->extrudeQuads(iquads, iaxis, heights);
3249 if ( !iElts.isValid() ){
3250 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PRISM QUAD(S)" ) + "\n" + getErrorMsg() );
3254 result = patternDataModel->mapFromSource(iElts);
3255 // result = patternBuilderModel->mapFromSource(iElts);
3260 //---------------------------------- JoinQuadDialog -----------------------------
3261 // ============================================================== Constructeur
3263 JoinQuadDialog::JoinQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3264 : HexaBaseDialog(parent, editmode, f)
3267 _helpFileName = "gui_prism_join_quad.html#guijoinquads";
3268 connect( joinUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3269 connect( join_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3270 _initWidget(editmode);
3271 joinUni_rb->click();
3274 // ============================================================== Destructeur
3275 JoinQuadDialog::~JoinQuadDialog()
3279 // ============================================================== getAssocsVTK
3281 * Returns elements currently associated to vtk
3283 QModelIndexList JoinQuadDialog::getAssocsVTK()
3285 QModelIndexList assocs;
3287 QListWidgetItem* item = NULL;
3289 if (getPatternDataSelectionModel() == NULL) return assocs;
3291 //ListWidget content
3292 const PatternDataModel* patternDataModel = getPatternDataModel();
3293 if ( !patternDataModel ) return assocs;
3294 int nbQuads = quads_lw->count();
3295 for ( int r = 0; r < nbQuads; ++r ){
3296 item = quads_lw->item(r);
3297 // iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
3298 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
3299 if ( iQuad.isValid() ) assocs << iQuad;
3304 // ============================================================== _initInputWidget
3305 void JoinQuadDialog::_initInputWidget( Mode editmode )
3307 quad_dest_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3308 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3309 vex0_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3310 vex1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3311 vex2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3312 vex3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3314 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3315 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3316 height_lw->setProperty("Length", QVariant::fromValue(true));
3317 height_lw->installEventFilter(this);
3319 installEventFilter(this);
3320 quad_dest_le->installEventFilter(this);
3321 quads_lw->installEventFilter(this);
3322 vex0_le->installEventFilter(this);
3323 vex1_le->installEventFilter(this);
3324 vex2_le->installEventFilter(this);
3325 vex3_le->installEventFilter(this);
3327 joinUni_rb->installEventFilter(this);
3328 join_rb->installEventFilter(this);
3330 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3331 delQuadShortcut->setContext( Qt::WidgetShortcut );
3332 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3334 quad_dest_le->setReadOnly(true);
3335 vex0_le->setReadOnly(true);
3336 vex1_le->setReadOnly(true);
3337 vex2_le->setReadOnly(true);
3338 vex3_le->setReadOnly(true);
3340 _currentObj = quads_lw;
3341 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3342 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3344 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3346 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3347 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3350 // ============================================================== updateHelpFileName
3351 void JoinQuadDialog::updateHelpFileName()
3353 if ( sender() == joinUni_rb ){
3354 _helpFileName = "gui_prism_join_quad.html#guijoinquadsuniform";
3355 } else if ( sender() == join_rb ){
3356 _helpFileName = "gui_prism_join_quad.html#guijoinquadscustom";
3360 // ============================================================== addHeightItem
3361 void JoinQuadDialog::addHeightItem()
3363 QListWidgetItem* previousItem = height_lw->currentItem();
3364 QListWidgetItem* newItem = new QListWidgetItem();
3366 double defaultValue = 1.;
3368 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3370 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3371 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3372 height_lw->addItem(newItem);
3375 // ============================================================== delHeightItem
3376 void JoinQuadDialog::delHeightItem()
3378 delete height_lw->currentItem();
3381 // ============================================================== clear
3382 void JoinQuadDialog::clear()
3384 quad_dest_le->clear();
3385 modelUnregister(quad_dest_le);
3388 modelUnregister(quads_lw);
3391 modelUnregister(vex0_le);
3394 modelUnregister(vex1_le);
3397 modelUnregister(vex2_le);
3400 modelUnregister(vex3_le);
3402 modelUnregister(this);
3405 // ============================================================== removeQuad
3406 void JoinQuadDialog::removeQuad()
3408 QListWidgetItem *item = quads_lw->currentItem();
3411 int r = quads_lw->row(item);
3412 quads_lw->takeItem(r);
3417 // ============================================================== apply
3418 bool JoinQuadDialog::apply(QModelIndex& result)
3420 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3423 DocumentModel* docModel = getDocumentModel();
3424 PatternDataModel* patternDataModel = getPatternDataModel();
3425 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3427 QModelIndexList iquads;
3429 QListWidgetItem* item = NULL;
3430 int nbQuads = quads_lw->count();
3431 for ( int r = 0; r < nbQuads; ++r){
3432 item = quads_lw->item(r);
3433 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3434 if ( iquad.isValid() )
3437 QModelIndex iquaddest = patternDataModel->mapToSource( _index[quad_dest_le] );
3438 QModelIndex ivex0 = patternDataModel->mapToSource( _index[vex0_le] );
3439 QModelIndex ivex1 = patternDataModel->mapToSource( _index[vex1_le] );
3440 QModelIndex ivex2 = patternDataModel->mapToSource( _index[vex2_le] );
3441 QModelIndex ivex3 = patternDataModel->mapToSource( _index[vex3_le] );
3442 double nb = nb_spb->value();
3444 vector<double> heights;
3445 int nbHeight = height_lw->count();
3446 for ( int r = 0; r < nbHeight; ++r){
3447 item = height_lw->item(r);
3448 heights.push_back(item->data(Qt::EditRole).toDouble());
3452 if (nbQuads == 1 && iquads[0].isValid() && iquaddest.isValid() && ivex0.isValid() &&
3453 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3455 if (joinUni_rb->isChecked())
3456 iElts = docModel->joinQuadUni(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3457 else if (join_rb->isChecked())
3458 iElts = docModel->joinQuad(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3460 else if (nbQuads > 1 && iquaddest.isValid() && ivex0.isValid() &&
3461 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3463 if (joinUni_rb->isChecked())
3464 iElts = docModel->joinQuadsUni(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3465 else if (join_rb->isChecked())
3466 iElts = docModel->joinQuads(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3469 if ( !iElts.isValid() ){
3470 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT JOIN QUAD(S)" ) + "\n" + getErrorMsg() );
3473 result = patternDataModel->mapFromSource(iElts);
3474 // result = patternBuilderModel->mapFromSource(iElts);
3479 // ------------------------- MergeDialog ----------------------------------
3480 // ============================================================== Constructeur
3482 MergeDialog::MergeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3483 : HexaBaseDialog(parent, editmode, f)
3486 _initWidget(editmode);
3489 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3490 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3491 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3492 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3494 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3495 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3496 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3498 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3499 connect( rb2, SIGNAL(cliked()), this, SLOT(clearVTKSelection()) );
3500 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3503 // ============================================================== Destructeur
3504 MergeDialog::~MergeDialog()
3508 // ============================================================== _initInputWidget
3509 void MergeDialog::_initInputWidget( Mode editmode )
3512 QValidator *validator = new QRegExpValidator(rx, this);
3514 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3515 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3516 v0_le_rb0->setValidator( validator );
3517 v1_le_rb0->setValidator( validator );
3518 v0_le_rb0->installEventFilter(this);
3519 v1_le_rb0->installEventFilter(this);
3521 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3522 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3523 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3524 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3526 v0_le_rb1->setValidator( validator );
3527 v1_le_rb1->setValidator( validator );
3528 e0_le_rb1->setValidator( validator );
3529 e1_le_rb1->setValidator( validator );
3531 v0_le_rb1->installEventFilter(this);
3532 v1_le_rb1->installEventFilter(this);
3533 e0_le_rb1->installEventFilter(this);
3534 e1_le_rb1->installEventFilter(this);
3536 v0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3537 v1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3538 v2_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3539 v3_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3540 q0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3541 q1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3543 v0_le_rb2->setValidator( validator );
3544 v1_le_rb2->setValidator( validator );
3545 v2_le_rb2->setValidator( validator );
3546 v3_le_rb2->setValidator( validator );
3547 q0_le_rb2->setValidator( validator );
3548 q1_le_rb2->setValidator( validator );
3550 v0_le_rb2->installEventFilter(this);
3551 v1_le_rb2->installEventFilter(this);
3552 v2_le_rb2->installEventFilter(this);
3553 v3_le_rb2->installEventFilter(this);
3554 q0_le_rb2->installEventFilter(this);
3555 q1_le_rb2->installEventFilter(this);
3557 v0_le_rb0->setReadOnly(true);
3558 v1_le_rb0->setReadOnly(true);
3560 v0_le_rb1->setReadOnly(true);
3561 v1_le_rb1->setReadOnly(true);
3562 e0_le_rb1->setReadOnly(true);
3563 e1_le_rb1->setReadOnly(true);
3565 v0_le_rb2->setReadOnly(true);
3566 v1_le_rb2->setReadOnly(true);
3567 v2_le_rb2->setReadOnly(true);
3568 v3_le_rb2->setReadOnly(true);
3569 q0_le_rb2->setReadOnly(true);
3570 q1_le_rb2->setReadOnly(true);
3573 // ============================================================== clear
3574 void MergeDialog::clear()
3577 modelUnregister(v0_le_rb0);
3580 modelUnregister(v1_le_rb0);
3583 modelUnregister(e0_le_rb1);
3586 modelUnregister(e1_le_rb1);
3589 modelUnregister(v0_le_rb1);
3592 modelUnregister(v1_le_rb1);
3595 modelUnregister(q0_le_rb2);
3598 modelUnregister(q1_le_rb2);
3601 modelUnregister(v0_le_rb2);
3604 modelUnregister(v1_le_rb2);
3607 modelUnregister(v2_le_rb2);
3610 modelUnregister(v3_le_rb2);
3612 modelUnregister(this);
3615 // ============================================================== updateHelpFileName
3616 void MergeDialog::updateHelpFileName()
3618 if ( sender() == rb0 ){
3619 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3620 } else if ( sender() == rb1 ){
3621 _helpFileName = "gui_merge_elmts.html#merge-two-edges";
3622 } else if ( sender() == rb2 ){
3623 _helpFileName = "gui_merge_elmts.html#merge-two-quadrangles";
3627 // ============================================================== apply
3628 bool MergeDialog::apply(QModelIndex& result)
3630 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3633 if (getDocumentModel() == NULL) return false;
3634 const PatternDataModel* patternDataModel = getPatternDataModel();
3635 if ( !patternDataModel ) return false;
3637 bool merged = false;
3639 if ( rb0->isChecked() ){
3640 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
3641 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
3645 merged = getDocumentModel()->mergeVertices( iv0, iv1 );
3647 } else if ( rb1->isChecked() ){
3648 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
3649 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
3650 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
3651 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
3657 merged = getDocumentModel()->mergeEdges( ie0, ie1, iv0, iv1);
3659 } else if ( rb2->isChecked() ){
3661 QModelIndex iq0 = patternDataModel->mapToSource( _index[q0_le_rb2] );
3662 QModelIndex iq1 = patternDataModel->mapToSource( _index[q1_le_rb2] );
3663 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb2] );
3664 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb2] );
3665 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb2] );
3666 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb2] );
3674 merged = getDocumentModel()->mergeQuads( iq0, iq1,
3675 iv0, iv1, iv2, iv3 );
3679 if ( merged == false ){
3680 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MERGE" ) + "\n" + getErrorMsg() );
3687 // ------------------------- DisconnectDialog ----------------------------------
3688 // ============================================================== Constructeur
3690 DisconnectDialog::DisconnectDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3691 : HexaBaseDialog(parent, editmode, f)
3694 _initWidget(editmode);
3697 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3699 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3700 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3701 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3703 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3704 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3705 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3707 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3708 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3709 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3711 connect( rb3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3712 connect( rb3, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3713 connect( rb3, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3717 // ============================================================== Destructeur
3718 DisconnectDialog::~DisconnectDialog()
3722 // ============================================================== _initInputWidget
3723 void DisconnectDialog::_initInputWidget( Mode editmode )
3726 QValidator *validator = new QRegExpValidator(rx, this);
3728 installEventFilter(this);
3731 v_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3732 h_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3733 v_le_rb0->setValidator( validator );
3734 h_le_rb0->setValidator( validator );
3735 v_le_rb0->installEventFilter(this);
3736 h_le_rb0->installEventFilter(this);
3739 e_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3740 h_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3741 e_le_rb1->setValidator( validator );
3742 h_le_rb1->setValidator( validator );
3743 e_le_rb1->installEventFilter(this);
3744 h_le_rb1->installEventFilter(this);
3747 q_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3748 h_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3749 q_le_rb2->setValidator( validator );
3750 h_le_rb2->setValidator( validator );
3751 q_le_rb2->installEventFilter(this);
3752 h_le_rb2->installEventFilter(this);
3755 d_edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3756 hexas_lw->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3757 d_edges_lw->installEventFilter(this);
3758 hexas_lw->installEventFilter(this);
3760 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), d_edges_lw);
3761 QShortcut* delHexaShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), hexas_lw);
3762 delEdgeShortcut->setContext( Qt::WidgetShortcut );
3763 delHexaShortcut->setContext( Qt::WidgetShortcut );
3765 v_le_rb0->setReadOnly(true);
3766 h_le_rb0->setReadOnly(true);
3768 e_le_rb1->setReadOnly(true);
3769 h_le_rb1->setReadOnly(true);
3771 q_le_rb2->setReadOnly(true);
3772 h_le_rb2->setReadOnly(true);
3774 connect( d_edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3775 connect( hexas_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3776 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
3777 connect( delHexaShortcut, SIGNAL(activated()), this, SLOT(deleteHexaItem()) );
3778 autoFocusSwitch = false;
3782 // =============================================== getAssocsVTK
3784 * Returns elements in the list
3786 QModelIndexList DisconnectDialog::getAssocsVTK()
3788 QModelIndexList iElts;
3790 QListWidgetItem* item = NULL;
3792 const PatternDataModel* patternDataModel = getPatternDataModel();
3793 if (patternDataModel == NULL || !rb3->isChecked())
3795 //ListWidget content
3796 if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == EDGE_TREE)
3798 int nbEdges = d_edges_lw->count();
3799 for ( int r = 0; r < nbEdges; ++r )
3801 item = d_edges_lw->item(r);
3802 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3803 if ( index.isValid() )
3807 else if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == HEXA_TREE)
3809 int nbHexas = hexas_lw->count();
3810 for ( int r = 0; r < nbHexas; ++r )
3812 item = hexas_lw->item(r);
3813 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3814 if ( index.isValid() )
3821 // ============================================================== clear
3822 void DisconnectDialog::clear()
3825 modelUnregister(v_le_rb0);
3828 modelUnregister(h_le_rb0);
3831 modelUnregister(e_le_rb1);
3834 modelUnregister(h_le_rb1);
3836 d_edges_lw->clear();
3837 modelUnregister(d_edges_lw);
3840 modelUnregister(hexas_lw);
3843 modelUnregister(q_le_rb2);
3846 modelUnregister(h_le_rb2);
3848 modelUnregister(this);
3851 // ============================================================== deleteEdgeItem
3852 void DisconnectDialog::deleteEdgeItem()
3854 delete d_edges_lw->currentItem();
3857 // ============================================================== deleteHexaItem
3858 void DisconnectDialog::deleteHexaItem()
3860 delete hexas_lw->currentItem();
3863 // ============================================================== updateHelpFileName
3864 void DisconnectDialog::updateHelpFileName()
3866 if ( sender() == rb0 ){
3867 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3868 } else if ( sender() == rb1 ){
3869 _helpFileName = "gui_disc_elmts.html#disconnect-an-edge";
3870 } else if ( sender() == rb2 ){
3871 _helpFileName = "gui_disc_elmts.html#disconnect-a-quadrangle";
3872 } else if (sender() == rb3 ){
3873 _helpFileName = "gui_disc_elmts.html#disconnect-edges";
3877 // ============================================================== apply
3878 bool DisconnectDialog::apply(QModelIndex& result)
3880 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3882 if (getDocumentModel() == NULL) return false;
3883 const PatternDataModel* patternDataModel = getPatternDataModel();
3884 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3885 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
3889 if ( rb0->isChecked() ){
3890 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb0] );
3891 QModelIndex ivex = patternDataModel->mapToSource( _index[v_le_rb0] );
3893 if ( ihexa.isValid()
3894 && ivex.isValid() ){
3895 iElts = getDocumentModel()->disconnectVertex( ihexa, ivex );
3897 } else if ( rb1->isChecked() ){
3898 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb1] );
3899 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le_rb1] );
3901 if ( ihexa.isValid()
3902 && iedge.isValid() ){
3903 iElts = getDocumentModel()->disconnectEdge( ihexa, iedge );
3905 } else if ( rb2->isChecked() ){
3906 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb2] );
3907 QModelIndex iquad = patternDataModel->mapToSource( _index[q_le_rb2] );
3909 if ( ihexa.isValid()
3910 && iquad.isValid() ){
3911 iElts = getDocumentModel()->disconnectQuad( ihexa, iquad );
3913 } else if ( rb3->isChecked() ){ //
3915 QModelIndex iedge, ihexa;
3916 QModelIndexList iedges, ihexas;
3917 QListWidgetItem* item = NULL;
3920 int nbEdges = d_edges_lw->count();
3921 for (int r = 0; r < nbEdges; ++r){
3922 item = d_edges_lw->item(r);
3923 iedge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3924 if ( iedge.isValid() )
3929 int nbHexas = hexas_lw->count();
3930 for (int r = 0; r < nbHexas; ++r){
3931 item = hexas_lw->item(r);
3932 ihexa = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3933 if ( ihexa.isValid() )
3937 iElts = getDocumentModel()->disconnectEdges( ihexas, iedges );
3940 if ( !iElts.isValid() ){
3941 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT DISCONNECT" ) + "\n" + getErrorMsg() );
3945 result = patternDataModel->mapFromSource(iElts);
3946 // result = patternBuilderModel->mapFromSource(iElts);
3952 // ------------------------- CutEdgeDialog ----------------------------------
3953 // ============================================================== Constructeur
3955 CutEdgeDialog::CutEdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3956 HexaBaseDialog(parent, editmode, f)
3959 _helpFileName = "gui_cut_hexa.html";
3960 connect( cutUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3961 connect( cut_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3962 _initWidget(editmode);
3967 // ============================================================== Destructeur
3968 CutEdgeDialog::~CutEdgeDialog()
3972 // ============================================================== _initInputWidget
3973 void CutEdgeDialog::_initInputWidget( Mode editmode )
3975 installEventFilter(this);
3977 e_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3978 e_le->installEventFilter(this);
3980 cutUni_rb->installEventFilter(this);
3981 cut_rb->installEventFilter(this);
3983 e_le->setReadOnly(true);
3985 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3986 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3987 height_lw->setProperty("Length", QVariant::fromValue(true));
3988 height_lw->installEventFilter(this);
3990 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3991 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3993 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3994 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3997 // ============================================================== updateHelpFileName
3998 void CutEdgeDialog::updateHelpFileName()
4000 if ( sender() == cutUni_rb ){
4001 _helpFileName = "gui_cut_hexa.html#guicuthexauniform";
4002 } else if ( sender() == cut_rb ){
4003 _helpFileName = "gui_cut_hexa.html#guicuthexacustom";
4007 // ============================================================== clear
4008 void CutEdgeDialog::clear()
4011 modelUnregister(e_le);
4013 modelUnregister(this);
4016 // ============================================================== addHeightItem
4017 void CutEdgeDialog::addHeightItem()
4019 QListWidgetItem* previousItem = height_lw->currentItem();
4020 QListWidgetItem* newItem = new QListWidgetItem();
4022 double defaultValue = 1.;
4024 defaultValue = previousItem->data(Qt::EditRole).toDouble();
4026 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
4027 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
4028 height_lw->addItem(newItem);
4031 // ============================================================== delHeightItem
4032 void CutEdgeDialog::delHeightItem()
4034 delete height_lw->currentItem();
4037 // ============================================================== apply
4038 bool CutEdgeDialog::apply(QModelIndex& result)
4040 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4043 DocumentModel* docModel = getDocumentModel();
4044 PatternDataModel* patternDataModel = getPatternDataModel();
4045 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4048 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le] );
4050 if (cutUni_rb->isChecked() && iedge.isValid())
4052 int nbCut = nb_cut_spb->value();
4053 iElts = docModel->cutUni(iedge, nbCut);
4055 else if (cut_rb->isChecked() && iedge.isValid())
4057 vector<double> heights;
4058 QListWidgetItem* item = NULL;
4059 int nbItems = height_lw->count();
4061 for ( int r = 0; r < nbItems; ++r){
4062 item = height_lw->item(r);
4063 heights.push_back( item->data(Qt::EditRole).toDouble() );
4066 iElts = docModel->cut(iedge, heights);
4069 if ( !iElts.isValid() ){
4070 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT CUT EDGE" ) + "\n" + getErrorMsg() );
4074 result = patternDataModel->mapFromSource(iElts);
4075 // result = patternBuilderModel->mapFromSource(iElts);
4077 //Update the line edit
4079 e_le->setProperty("QModelIndex", invalid );
4081 QModelIndex invalidIndex;
4082 _index[e_le] = invalidIndex;
4089 // // ------------------------- MakeTransformationDialog ----------------------------------
4090 // ============================================================== Constructeur
4092 MakeTransformationDialog::MakeTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4093 : HexaBaseDialog(parent, editmode, f)
4096 _initWidget(editmode);
4099 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
4100 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4101 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4102 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4105 // ============================================================== Destructeur
4106 MakeTransformationDialog::~MakeTransformationDialog()
4110 // ============================================================== _initInputWidget
4111 void MakeTransformationDialog::_initInputWidget( Mode editmode )
4114 QValidator *validator = new QRegExpValidator(rx, this);
4116 installEventFilter(this);
4117 rb0->installEventFilter(this);
4118 rb1->installEventFilter(this);
4119 rb2->installEventFilter(this);
4121 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4122 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4124 vec_le_rb0->setValidator( validator );
4125 elts_le_rb0->setValidator( validator );
4126 vec_le_rb0->installEventFilter(this);
4127 elts_le_rb0->installEventFilter(this);
4129 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4130 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4131 vex_le_rb1->setValidator( validator );
4132 elts_le_rb1->setValidator( validator );
4133 vex_le_rb1->installEventFilter(this);
4134 elts_le_rb1->installEventFilter(this);
4136 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4137 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4138 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4139 vex_le_rb2->setValidator( validator );
4140 vec_le_rb2->setValidator( validator );
4141 elts_le_rb2->setValidator( validator );
4142 vex_le_rb2->installEventFilter(this);
4143 vec_le_rb2->installEventFilter(this);
4144 elts_le_rb2->installEventFilter(this);
4146 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
4147 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
4148 angle_spb->setProperty("Angle", QVariant::fromValue(true));
4149 angle_spb->installEventFilter(this);
4151 vec_le_rb0->setReadOnly(true);
4152 elts_le_rb0->setReadOnly(true);
4154 vex_le_rb1->setReadOnly(true);
4155 elts_le_rb1->setReadOnly(true);
4157 vex_le_rb2->setReadOnly(true);
4158 vec_le_rb2->setReadOnly(true);
4159 elts_le_rb2->setReadOnly(true);
4163 // ============================================================== clear
4164 void MakeTransformationDialog::clear()
4166 elts_le_rb0->clear();
4167 modelUnregister(elts_le_rb0);
4169 vec_le_rb0->clear();
4170 modelUnregister(vec_le_rb0);
4172 elts_le_rb1->clear();
4173 modelUnregister(elts_le_rb1);
4175 vex_le_rb1->clear();
4176 modelUnregister(vex_le_rb1);
4178 elts_le_rb2->clear();
4179 modelUnregister(elts_le_rb2);
4181 vex_le_rb2->clear();
4182 modelUnregister(vex_le_rb2);
4184 vec_le_rb2->clear();
4185 modelUnregister(vec_le_rb2);
4187 modelUnregister(this);
4190 // ============================================================== updateHelpFileName
4191 void MakeTransformationDialog::updateHelpFileName()
4193 if ( sender() == rb0 ){
4194 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
4195 } else if ( sender() == rb1 ){
4196 _helpFileName = "gui_make_elmts.html#make-elements-by-scaling";
4197 } else if ( sender() == rb2 ){
4198 _helpFileName = "gui_make_elmts.html#make-elements-by-rotation";
4202 // ============================================================== apply
4203 bool MakeTransformationDialog::apply(QModelIndex& result)
4205 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4208 if (getDocumentModel() == NULL) return false;
4209 const PatternDataModel* patternDataModel = getPatternDataModel();
4210 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4211 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4213 QModelIndex iNewElts;
4215 if ( rb0->isChecked() ){
4216 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb0] );
4217 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb0] );
4218 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4219 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4221 if ( ielts.isValid()
4223 iNewElts = getDocumentModel()->makeTranslation( ielts, ivec );
4225 } else if ( rb1->isChecked() ){
4226 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4227 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb1] );
4228 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4229 double k = k_spb->value();
4231 if ( ielts.isValid()
4233 iNewElts = getDocumentModel()->makeScale( ielts, ivex, k );
4235 } else if ( rb2->isChecked() ){
4236 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4237 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb2] );
4238 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4239 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4240 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb2] );
4241 double angle = angle_spb->value();
4243 if ( ielts.isValid()
4246 iNewElts = getDocumentModel()->makeRotation( ielts, ivex, ivec, angle );
4249 if ( !iNewElts.isValid() ){
4250 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4254 result = patternDataModel->mapFromSource(iNewElts);
4255 if (result.isValid())
4257 MESSAGE("======> Result is valid!");
4258 HEXA_NS::Elements* elts = getDocumentModel()->getHexaPtr<HEXA_NS::Elements*>(result);
4259 MESSAGE("======> " << elts->getName());
4263 MESSAGE("======> Result is not valid!");
4265 // result = patternBuilderModel->mapFromSource(iNewElts);
4270 // // ------------------------- MakeSymmetryDialog ----------------------------------
4271 // ============================================================== Constructeur
4273 MakeSymmetryDialog::MakeSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4274 HexaBaseDialog(parent, editmode, f)
4277 _initWidget(editmode);
4280 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4281 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4282 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4283 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4286 // ============================================================== Destructeur
4287 MakeSymmetryDialog::~MakeSymmetryDialog()
4291 // ============================================================== _initInputWidget
4292 void MakeSymmetryDialog::_initInputWidget( Mode editmode )
4295 QValidator *validator = new QRegExpValidator(rx, this);
4297 installEventFilter(this);
4299 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4300 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4301 vex_le_rb0->setValidator( validator );
4302 elts_le_rb0->setValidator( validator );
4303 vex_le_rb0->installEventFilter(this);
4304 elts_le_rb0->installEventFilter(this);
4306 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4307 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4308 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4309 vex_le_rb1->setValidator( validator );
4310 vec_le_rb1->setValidator( validator );
4311 elts_le_rb1->setValidator( validator );
4312 vex_le_rb1->installEventFilter(this);
4313 vec_le_rb1->installEventFilter(this);
4314 elts_le_rb1->installEventFilter(this);
4316 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4317 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4318 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4319 vex_le_rb2->setValidator( validator );
4320 vec_le_rb2->setValidator( validator );
4321 elts_le_rb2->setValidator( validator );
4322 vex_le_rb2->installEventFilter(this);
4323 vec_le_rb2->installEventFilter(this);
4324 elts_le_rb2->installEventFilter(this);
4326 vex_le_rb0->setReadOnly(true);
4327 elts_le_rb0->setReadOnly(true);
4328 vex_le_rb1->setReadOnly(true);
4329 vec_le_rb1->setReadOnly(true);
4330 elts_le_rb1->setReadOnly(true);
4331 vex_le_rb2->setReadOnly(true);
4332 vec_le_rb2->setReadOnly(true);
4333 elts_le_rb2->setReadOnly(true);
4336 // ============================================================== clear
4337 void MakeSymmetryDialog::clear()
4339 elts_le_rb0->clear();
4340 modelUnregister(elts_le_rb0);
4342 vex_le_rb0->clear();
4343 modelUnregister(vex_le_rb0);
4345 elts_le_rb1->clear();
4346 modelUnregister(elts_le_rb1);
4348 vex_le_rb1->clear();
4349 modelUnregister(vex_le_rb1);
4351 vec_le_rb1->clear();
4352 modelUnregister(vec_le_rb1);
4354 elts_le_rb2->clear();
4355 modelUnregister(elts_le_rb2);
4357 vex_le_rb2->clear();
4358 modelUnregister(vex_le_rb2);
4360 vec_le_rb2->clear();
4361 modelUnregister(vec_le_rb2);
4363 modelUnregister(this);
4366 // ============================================================== updateHelpFileName
4367 void MakeSymmetryDialog::updateHelpFileName()
4369 if ( sender() == rb0 ){
4370 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4371 } else if ( sender() == rb1 ){
4372 _helpFileName = "gui_make_symmetry.html#make-elements-by-line-symmetry";
4373 } else if ( sender() == rb2 ){
4374 _helpFileName = "gui_make_symmetry.html#make-elements-by-plane-symmetry";
4378 // ============================================================== apply
4379 bool MakeSymmetryDialog::apply(QModelIndex& result)
4381 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4383 if (getDocumentModel() == NULL) return false;
4384 const PatternDataModel* patternDataModel = getPatternDataModel();
4385 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4386 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4388 QModelIndex iNewElts;
4390 if ( rb0->isChecked() ){
4391 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4392 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb0] );
4393 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4395 if ( ielts.isValid()
4397 iNewElts = getDocumentModel()->makeSymmetryPoint( ielts, ivex );
4400 } else if ( rb1->isChecked() ){
4401 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4402 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb1] );
4403 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4404 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4405 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb1] );
4407 if ( ielts.isValid()
4410 iNewElts = getDocumentModel()->makeSymmetryLine( ielts, ivex, ivec );
4412 } else if ( rb2->isChecked() ){
4413 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4414 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4415 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4416 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4417 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4419 if ( ielts.isValid()
4422 iNewElts = getDocumentModel()->makeSymmetryPlane( ielts, ivex, ivec );
4425 if ( !iNewElts.isValid() ){
4426 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4430 // result = patternBuilderModel->mapFromSource(iNewElts);
4431 result = patternDataModel->mapFromSource(iNewElts);
4436 // // ------------------------- PerformTransformationDialog ----------------------------------
4437 // ============================================================== Constructeur
4438 PerformTransformationDialog::PerformTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4439 HexaBaseDialog(parent, editmode, f)
4442 _initWidget(editmode);
4445 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4446 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4447 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4448 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4451 // ============================================================== Destructeur
4452 PerformTransformationDialog::~PerformTransformationDialog()
4456 // ============================================================== _initInputWidget
4457 void PerformTransformationDialog::_initInputWidget( Mode editmode )
4460 QValidator *validator = new QRegExpValidator(rx, this);
4462 installEventFilter(this);
4463 rb0->installEventFilter(this);
4464 rb1->installEventFilter(this);
4465 rb2->installEventFilter(this);
4467 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4468 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4469 vec_le_rb0->setValidator( validator );
4470 elts_le_rb0->setValidator( validator );
4471 vec_le_rb0->installEventFilter(this);
4472 elts_le_rb0->installEventFilter(this);
4474 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4475 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4476 vex_le_rb1->setValidator( validator );
4477 elts_le_rb1->setValidator( validator );
4478 vex_le_rb1->installEventFilter(this);
4479 elts_le_rb1->installEventFilter(this);
4482 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4483 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4484 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4485 vex_le_rb2->setValidator( validator );
4486 vec_le_rb2->setValidator( validator );
4487 elts_le_rb2->setValidator( validator );
4488 vex_le_rb2->installEventFilter(this);
4489 vec_le_rb2->installEventFilter(this);
4490 elts_le_rb2->installEventFilter(this);
4492 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
4493 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
4494 angle_spb->setProperty("Angle", QVariant::fromValue(true));
4495 angle_spb->installEventFilter(this);
4497 vec_le_rb0->setReadOnly(true);
4498 elts_le_rb0->setReadOnly(true);
4499 vex_le_rb1->setReadOnly(true);
4500 elts_le_rb1->setReadOnly(true);
4501 vex_le_rb2->setReadOnly(true);
4502 vec_le_rb2->setReadOnly(true);
4503 elts_le_rb2->setReadOnly(true);
4507 // ============================================================== clear
4508 void PerformTransformationDialog::clear()
4510 vec_le_rb0->clear();
4511 modelUnregister(vec_le_rb0);
4513 elts_le_rb0->clear();
4514 modelUnregister(elts_le_rb0);
4516 vex_le_rb1->clear();
4517 modelUnregister(vex_le_rb1);
4519 elts_le_rb1->clear();
4520 modelUnregister(elts_le_rb1);
4522 vex_le_rb2->clear();
4523 modelUnregister(vex_le_rb2);
4525 vec_le_rb2->clear();
4526 modelUnregister(vec_le_rb2);
4528 elts_le_rb2->clear();
4529 modelUnregister(elts_le_rb2);
4531 modelUnregister(this);
4534 // ============================================================== updateHelpFileName
4535 void PerformTransformationDialog::updateHelpFileName()
4537 if ( sender() == rb0 ){
4538 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4539 } else if ( sender() == rb1 ){
4540 _helpFileName = "gui_modify_elmts.html#modify-elements-by-scaling";
4541 } else if ( sender() == rb2 ){
4542 _helpFileName = "gui_modify_elmts.html#modify-elements-by-rotation";
4546 // ============================================================== apply
4547 bool PerformTransformationDialog::apply(QModelIndex& result)
4549 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4552 if (getDocumentModel() == NULL) return false;
4553 const PatternDataModel* patternDataModel = getPatternDataModel();
4554 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4555 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4557 bool performed = false;
4559 if ( rb0->isChecked() ){
4560 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4561 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb0]);
4562 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4563 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb0]);
4565 if ( ielts.isValid()
4567 performed = getDocumentModel()->performTranslation( ielts, ivec );
4569 } else if ( rb1->isChecked() ){
4570 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4571 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb1]);
4572 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4573 double k = k_spb->value();
4575 if ( ielts.isValid()
4577 performed = getDocumentModel()->performScale( ielts, ivex, k );
4579 } else if ( rb2->isChecked() ){
4580 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4581 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4582 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4583 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4584 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4585 double angle = angle_spb->value();
4587 if ( ielts.isValid()
4590 performed = getDocumentModel()->performRotation( ielts, ivex, ivec, angle );
4593 if ( performed == false){
4594 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM TRANSFORMATION" ) + "\n" + getErrorMsg() );
4601 // // ------------------------- PerformSymmetryDialog ----------------------------------
4602 // ============================================================== Constructeur
4603 PerformSymmetryDialog::PerformSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4604 : HexaBaseDialog(parent, editmode, f)
4607 _initWidget( editmode );
4610 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4611 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4612 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4613 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4616 // ============================================================== Destructeur
4617 PerformSymmetryDialog::~PerformSymmetryDialog()
4621 // ============================================================== _initInputWidget
4622 void PerformSymmetryDialog::_initInputWidget( Mode editmode )
4625 QValidator *validator = new QRegExpValidator(rx, this);
4627 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4628 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4629 vex_le_rb0->setValidator( validator );
4630 elts_le_rb0->setValidator( validator );
4631 vex_le_rb0->installEventFilter(this);
4632 elts_le_rb0->installEventFilter(this);
4634 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4635 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4636 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4637 vex_le_rb1->setValidator( validator );
4638 vec_le_rb1->setValidator( validator );
4639 elts_le_rb1->setValidator( validator );
4640 vex_le_rb1->installEventFilter(this);
4641 vec_le_rb1->installEventFilter(this);
4642 elts_le_rb1->installEventFilter(this);
4644 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4645 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4646 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4647 vex_le_rb2->setValidator( validator );
4648 vec_le_rb2->setValidator( validator );
4649 elts_le_rb2->setValidator( validator );
4650 vex_le_rb2->installEventFilter(this);
4651 vec_le_rb2->installEventFilter(this);
4652 elts_le_rb2->installEventFilter(this);
4654 vex_le_rb0->setReadOnly(true);
4655 elts_le_rb0->setReadOnly(true);
4656 vex_le_rb1->setReadOnly(true);
4657 vec_le_rb1->setReadOnly(true);
4658 elts_le_rb1->setReadOnly(true);
4659 vex_le_rb2->setReadOnly(true);
4660 vec_le_rb2->setReadOnly(true);
4661 elts_le_rb2->setReadOnly(true);
4665 // ============================================================== clear
4666 void PerformSymmetryDialog::clear()
4668 vex_le_rb0->clear();
4669 modelUnregister(vex_le_rb0);
4671 elts_le_rb0->clear();
4672 modelUnregister(elts_le_rb0);
4674 elts_le_rb1->clear();
4675 modelUnregister(elts_le_rb1);
4677 vex_le_rb1->clear();
4678 modelUnregister(vex_le_rb1);
4680 vec_le_rb1->clear();
4681 modelUnregister(vec_le_rb1);
4683 elts_le_rb2->clear();
4684 modelUnregister(elts_le_rb2);
4686 vex_le_rb2->clear();
4687 modelUnregister(vex_le_rb2);
4689 vec_le_rb2->clear();
4690 modelUnregister(vec_le_rb2);
4692 modelUnregister(this);
4695 // ============================================================== updateHelpFileName
4696 void PerformSymmetryDialog::updateHelpFileName()
4698 if ( sender() == rb0 ){
4699 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4700 } else if ( sender() == rb1 ){
4701 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-line-symmetry";
4702 } else if ( sender() == rb2 ){
4703 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-plane-symmetry";
4707 // ============================================================== apply
4708 bool PerformSymmetryDialog::apply(QModelIndex& result)
4710 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4713 if (getDocumentModel() == NULL) return false;
4714 const PatternDataModel* patternDataModel = getPatternDataModel();
4715 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4716 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4718 bool performed = false;
4720 if ( rb0->isChecked() ){
4721 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4722 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb0]);
4723 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4725 if ( ielts.isValid()
4727 performed = getDocumentModel()->performSymmetryPoint( ielts, ivex );
4729 } else if ( rb1->isChecked() ){
4730 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4731 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb1]);
4732 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4733 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4734 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb1]);
4736 if ( ielts.isValid()
4739 performed = getDocumentModel()->performSymmetryLine( ielts, ivex, ivec );
4741 } else if ( rb2->isChecked() ){
4742 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4743 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4744 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4745 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4746 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4748 if ( ielts.isValid()
4751 performed = getDocumentModel()->performSymmetryPlane( ielts, ivex, ivec );
4754 if ( performed == false ){
4755 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM SYMMETRY" ) + "\n" + getErrorMsg() );
4762 // // ------------------------- EdgeAssocDialog ----------------------------------
4763 // ============================================================== Constructeur
4764 EdgeAssocDialog::EdgeAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4765 HexaBaseDialog( parent, editmode, f )
4767 _helpFileName ="gui_asso_quad_to_geom.html#one-edge";
4769 _initWidget(editmode);
4774 // ============================================================== Destructeur
4775 EdgeAssocDialog::~EdgeAssocDialog()
4779 // ============================================================== close
4780 void EdgeAssocDialog::close()
4782 HEXABLOCKGUI::assocInProgress = false;
4783 HexaBaseDialog::close();
4786 // ============================================================== _initInputWidget
4787 void EdgeAssocDialog::_initInputWidget( Mode editmode )
4790 QValidator *validator = new QRegExpValidator(rx, this);
4793 first_vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4794 first_vex_le->installEventFilter(this);
4795 first_vex_le->setValidator( validator );
4797 single_edge_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4798 single_edge_le->installEventFilter(this);
4800 edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4801 edges_lw->installEventFilter(this);
4805 lines_lw->setProperty("HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4806 lines_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4807 lines_lw->installEventFilter(this);
4809 single_line_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4810 single_line_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4811 single_line_le->installEventFilter(this);
4814 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), edges_lw);
4815 QShortcut* delLineShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), lines_lw);
4816 delLineShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4817 delEdgeShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4819 pend_spb->setValue(1.);
4821 first_vex_le->setReadOnly(true);
4822 single_edge_le->setReadOnly(true);
4823 single_line_le->setReadOnly(true);
4825 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
4826 connect( delLineShortcut, SIGNAL(activated()), this, SLOT(deleteLineItem()) );
4827 connect( edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
4828 connect( lines_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4829 connect( single_rb, SIGNAL(clicked()), this, SLOT( refreshHighlight()), Qt::UniqueConnection );
4830 connect( multiple_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection );
4831 connect( single_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4832 connect( multiple_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4835 // ============================================================== updateHelpFileName
4836 void EdgeAssocDialog::updateHelpFileName()
4838 if ( sender() == single_rb ){
4839 _helpFileName = "gui_asso_quad_to_geom.html#one-edge";
4840 } else if ( sender() == multiple_rb ){
4841 _helpFileName = "gui_asso_quad_to_geom.html#line";
4845 // ============================================================== getAssocsVTK
4847 * Returns elements currently being associated in vtk side
4849 QModelIndexList EdgeAssocDialog::getAssocsVTK()
4851 QModelIndexList assocs;
4853 QListWidgetItem* item = NULL;
4855 if (getPatternDataSelectionModel() == NULL) return assocs;
4856 if (single_rb->isChecked())
4859 QVariant v = single_edge_le->property("QModelIndex");
4860 if ( !v.isValid() ) return assocs;
4861 assocs << v.value<QModelIndex>();
4864 else if (multiple_rb->isChecked())
4866 //ListWidget content
4867 const PatternDataModel* patternDataModel = getPatternDataModel();
4868 if ( !patternDataModel ) return assocs;
4869 int nbEdges = edges_lw->count();
4870 for ( int r = 0; r < nbEdges; ++r){
4871 item = edges_lw->item(r);
4872 iEdge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4873 if ( iEdge.isValid() ) assocs << iEdge;
4880 // ============================================================== getAssocsGEOM
4882 * Returns elements currently being associated in geom side
4884 QMultiMap<QString, int> EdgeAssocDialog::getAssocsGEOM()
4886 QMultiMap<QString, int> assocs;
4887 QListWidgetItem* item = NULL;
4888 DocumentModel::GeomObj geomObj;
4890 if (single_rb->isChecked())
4893 QVariant v = single_line_le->property("GeomObj");
4894 if ( !v.isValid() ) return assocs;
4895 geomObj = v.value<DocumentModel::GeomObj>();
4896 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4899 else if (multiple_rb->isChecked())
4901 //ListWidget content
4902 unsigned int nbEdges = lines_lw->count();
4903 for ( int r = 0; r < nbEdges; ++r){
4904 item = lines_lw->item(r);
4905 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4906 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4913 // ============================================================== selectElementOfGeom
4914 /*Highlight in the OCC view selected elements in a listwidget,
4915 * or an element in a line edit.*/
4916 void EdgeAssocDialog::selectElementOfGeom()
4918 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4919 if ( !currentListWidget )
4923 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4924 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4925 pgsm->clearSelection();
4926 if (sel.count() == 0)
4929 QListWidgetItem *item = sel[0];
4930 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
4931 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4932 if ( index.isValid() )
4933 pgsm->select( index, QItemSelectionModel::SelectCurrent );
4936 // ============================================================== clear
4937 void EdgeAssocDialog::clear()
4939 first_vex_le->clear();
4940 modelUnregister(first_vex_le);
4943 modelUnregister(edges_lw);
4947 single_edge_le->clear();
4948 modelUnregister(single_edge_le);
4950 single_line_le->clear();
4951 modelUnregister(single_line_le);
4953 modelUnregister(this);
4956 // ============================================================== onWindowActivated
4957 void EdgeAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4959 QString vmType = vm->getType();
4960 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4962 if (single_rb->isChecked())
4963 single_edge_le->setFocus();
4964 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le )
4965 edges_lw->setFocus();
4967 else if ( vmType == OCCViewer_Viewer::Type() ){
4968 if (single_rb->isChecked())
4969 single_line_le->setFocus();
4970 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le)
4971 lines_lw->setFocus();
4975 // ============================================================== apply
4976 bool EdgeAssocDialog::apply(QModelIndex& result)
4978 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4981 bool assocOk = false;
4983 PatternDataModel* patternDataModel = getPatternDataModel();
4984 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4985 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4987 QModelIndex iEdge, iGeomEdge;
4988 QModelIndexList iEdges;
4989 QListWidgetItem* item = NULL;
4990 QList<DocumentModel::GeomObj> assocs;
4991 DocumentModel::GeomObj aLine;
4992 HEXA_NS::SubShape* ssh;
4993 HEXA_NS::EdgeShape* sh;
4994 HEXA_NS::NewShapes shapes;
4995 HEXA_NS::IntVector subIds;
4997 QModelIndexList edges, lines;
4999 if (single_rb->isChecked()){ //Single edge and/or line association
5001 iEdge = patternDataModel->mapToSource( _index[single_edge_le] );
5002 if ( !iEdge.isValid() || myLine == NULL)
5004 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5007 id = myLine->shapeName+","+myLine->subId;
5008 ssh = getDocumentModel()->getGeomPtr(id);
5009 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
5010 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5011 if (!iGeomEdge.isValid())
5013 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5016 assocOk = getDocumentModel()->addEdgeAssociation(iEdge, iGeomEdge, pstart_spb->value(), pend_spb->value());
5017 edges << _index[single_edge_le];
5020 else { //Multiple edge and/or line association
5023 iEdges = getIndexList(edges_lw, true);
5024 int nbLines = lines_lw->count();
5025 if (iEdges.count() == 0 || nbLines == 0)
5027 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5030 edges = getIndexList(edges_lw, false);
5032 for (int r = 0; r < nbLines; ++r){
5033 item = lines_lw->item(r);
5034 aLine = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5035 id = aLine.shapeName+","+aLine.subId;
5036 ssh = getDocumentModel()->getGeomPtr(id);
5037 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
5040 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5043 shapes.push_back(sh->getParentShape());
5044 subIds.push_back(sh->getIdent());
5045 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5046 if (iGeomEdge.isValid())
5050 if ( close_cb->isChecked() ){ //closed line
5051 QModelIndex iFirstVertex = patternDataModel->mapToSource( _index[first_vex_le] );
5052 if ( !iFirstVertex.isValid() )
5054 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5057 bool inv = inverse_cb->isChecked();
5058 assocOk = getDocumentModel()->associateClosedLine( iFirstVertex, iEdges, shapes, subIds, pstart_spb->value(), inv );
5062 assocOk = getDocumentModel()->associateOpenedLine( iEdges, shapes, subIds, pstart_spb->value(), pend_spb->value() );
5066 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) + "\n" + getErrorMsg() );
5070 // highlight associated items in the trees
5071 pdsm->unhighlightTreeItems();
5072 pgsm->unhighlightTreeItems();
5073 pdsm->highlightTreeItems(edges);
5074 pgsm->highlightTreeItems(lines);
5076 // highlight associated items in the views
5077 highlightSelectedAssocs();
5082 // ------------------------- QuadAssocDialog ----------------------------------
5083 // ============================================================== Constructeur
5084 QuadAssocDialog::QuadAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5085 HexaBaseDialog(parent, editmode, f)
5087 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-face-or-a-shell-of-the-geometry";
5089 _initWidget(editmode);
5092 // ============================================================== Destructeur
5093 QuadAssocDialog::~QuadAssocDialog()
5095 disconnect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
5096 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(addFace()) );
5097 delete _delFaceShortcut;
5100 // ============================================================== close
5101 void QuadAssocDialog::close()
5103 HEXABLOCKGUI::assocInProgress = false;
5104 HexaBaseDialog::close();
5107 // ============================================================== _initInputWidget
5108 void QuadAssocDialog::_initInputWidget( Mode editmode )
5111 QValidator *validator = new QRegExpValidator(rx, this);
5113 quad_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5114 quad_le->installEventFilter(this);
5115 quad_le->setValidator( validator );
5117 faces_lw->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
5118 faces_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
5119 faces_lw->installEventFilter(this);
5120 _delFaceShortcut = new QShortcut( QKeySequence(Qt::Key_X/*Qt::Key_Delete*/), faces_lw );
5121 _delFaceShortcut->setContext( Qt::WidgetShortcut );
5123 quad_le->setReadOnly(true);
5125 connect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
5126 connect( faces_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
5129 // ============================================================== getAssocsVTK
5131 * Returns elements currently being associated in vtk side
5133 QModelIndexList QuadAssocDialog::getAssocsVTK()
5135 QModelIndexList assocs;
5139 QVariant v = quad_le->property("QModelIndex");
5142 assocs << v.value<QModelIndex>();
5146 // ============================================================== getAssocsGEOM
5148 * Returns elements currently being associated in geom side
5150 QMultiMap<QString, int> QuadAssocDialog::getAssocsGEOM()
5152 QMultiMap<QString, int> assocs;
5153 QListWidgetItem* item = NULL;
5154 DocumentModel::GeomObj geomObj;
5156 //ListWidget content
5157 unsigned int nbFaces = faces_lw->count();
5158 for ( int r = 0; r < nbFaces; ++r){
5159 item = faces_lw->item(r);
5160 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5161 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
5166 // ============================================================== selectElementOfGeom
5167 /*Highlight in the OCC view selected elements in a listwidget,
5168 * or an element in a line edit.*/
5170 void QuadAssocDialog::selectElementOfGeom()
5172 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5173 if ( !currentListWidget )
5177 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5178 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
5179 pgsm->clearSelection();
5180 if (sel.count() == 0)
5182 QListWidgetItem *item = sel[0];
5183 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
5184 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5185 if ( index.isValid() )
5186 pgsm->select( index, QItemSelectionModel::SelectCurrent );
5189 void QuadAssocDialog::clear()
5192 modelUnregister(quad_le);
5196 modelUnregister(this);
5199 // ============================================================== onWindowActivated
5200 void QuadAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
5202 QString vmType = vm->getType();
5203 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
5204 quad_le->setFocus();
5205 else if ( vmType == OCCViewer_Viewer::Type() ){
5206 faces_lw->setFocus();
5210 // ============================================================== deleteFaceItem
5211 void QuadAssocDialog::deleteFaceItem()
5213 delete faces_lw->currentItem();
5216 // ============================================================== apply
5217 bool QuadAssocDialog::apply(QModelIndex& result)
5219 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5222 PatternDataModel* patternDataModel = getPatternDataModel();
5223 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
5224 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
5227 QModelIndex iQuad, iGeomFace;
5228 HEXA_NS::SubShape* ssh;
5229 HEXA_NS::FaceShape* sh;
5233 iQuad = patternDataModel->mapToSource( _index[quad_le] );
5236 QListWidgetItem* item = NULL;
5237 DocumentModel::GeomObj aFace;
5238 QModelIndexList quads, faces;
5239 int nbFaces = faces_lw->count();
5240 for ( int r = 0; r < nbFaces; ++r ){
5241 item = faces_lw->item(r);
5242 aFace = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5243 id = aFace.shapeName+","+aFace.subId;
5244 ssh = getDocumentModel()->getGeomPtr(id);
5245 sh = dynamic_cast<HEXA_NS::FaceShape*>(ssh);
5248 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) );
5251 iGeomFace = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5252 if (!getDocumentModel()->addQuadAssociation(iQuad, iGeomFace))
5254 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) + "\n" + getErrorMsg() );
5257 else if (iGeomFace.isValid())
5262 if (iQuad.isValid())
5263 quads << _index[quad_le];
5265 // highlight associated items in the trees
5266 pdsm->highlightTreeItems(quads);
5267 pgsm->highlightTreeItems(faces);
5269 // highlight associated items in the views
5270 highlightSelectedAssocs();
5275 // ------------------------- GroupDialog ----------------------------------
5276 // ============================================================== Constructeur
5277 GroupDialog::GroupDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5278 HexaBaseDialog(parent, editmode, f),
5281 _helpFileName = "gui_groups.html#add-group";
5283 _initWidget(editmode);
5284 // setFocusProxy( name_le/*eltBase_lw */);
5286 if ( editmode == NEW_MODE ){
5287 setWindowTitle( tr("Group Construction") );
5288 } else if ( editmode == UPDATE_MODE ){
5289 setWindowTitle( tr("Group Modification") );
5290 } else if ( editmode == INFO_MODE ){
5291 setWindowTitle( tr("Group Information") );
5295 // ============================================================== Destructeur
5296 GroupDialog::~GroupDialog()
5300 // ============================================================== getAssocsVTK
5302 * Returns elements currently being associated in vtk side
5304 QModelIndexList GroupDialog::getAssocsVTK()
5306 QModelIndexList assocs;
5308 QListWidgetItem* item = NULL;
5309 if (getPatternDataSelectionModel() == NULL) return assocs;
5310 //ListWidget content
5311 const PatternDataModel* patternDataModel = getPatternDataModel();
5312 if ( !patternDataModel ) return assocs;
5313 int nbElts = eltBase_lw->count();
5314 for ( int r = 0; r < nbElts; ++r){
5315 item = eltBase_lw->item(r);
5316 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5317 if ( iItem.isValid() ) assocs << iItem;
5322 // ============================================================== _initInputWidget
5323 void GroupDialog::_initInputWidget( Mode editmode )
5325 installEventFilter(this);
5326 name_le->installEventFilter(this);
5329 strKind[ HEXA_NS::HexaCell ] = "HexaCell";
5330 strKind[ HEXA_NS::QuadCell ] = "QuadCell";
5331 strKind[ HEXA_NS::EdgeCell ] = "EdgeCell";
5332 strKind[ HEXA_NS::HexaNode ] = "HexaNode";
5333 strKind[ HEXA_NS::QuadNode ] = "QuadNode";
5334 strKind[ HEXA_NS::EdgeNode ] = "EdgeNode";
5335 strKind[ HEXA_NS::VertexNode ] = "VertexNode";
5337 QMap<HEXA_NS::EnumGroup, QString>::ConstIterator iKind;
5338 for( iKind = strKind.constBegin(); iKind != strKind.constEnd(); ++iKind )
5339 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5341 onKindChanged( kind_cb->currentIndex() );
5342 eltBase_lw->installEventFilter(this);
5344 if ( editmode != INFO_MODE ){
5345 QShortcut* delEltShortcut = new QShortcut( QKeySequence(Qt::Key_X), eltBase_lw );
5346 delEltShortcut->setContext( Qt::WidgetShortcut );
5347 connect(delEltShortcut, SIGNAL(activated()), this, SLOT(removeEltBase()));
5348 connect(kind_cb, SIGNAL(activated(int)), this, SLOT(onKindChanged(int)) );
5351 if ( editmode == INFO_MODE)
5353 name_le->setReadOnly(true);
5354 kind_cb->setEnabled(false);
5355 eltBase_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
5358 connect(eltBase_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5361 // ============================================================== clear
5362 void GroupDialog::clear()
5366 eltBase_lw->clear();
5367 modelUnregister(eltBase_lw);
5369 modelUnregister(this);
5372 // ============================================================== onKindChanged
5373 void GroupDialog::onKindChanged(int index)
5376 switch ( kind_cb->itemData(index).toInt() ){
5377 case HEXA_NS::HexaCell:
5378 case HEXA_NS::HexaNode:
5379 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(HEXA_TREE));
5382 case HEXA_NS::QuadCell:
5383 case HEXA_NS::QuadNode:
5384 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5387 case HEXA_NS::EdgeCell:
5388 case HEXA_NS::EdgeNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
5391 case HEXA_NS::VertexNode:
5392 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
5395 default:Q_ASSERT(false);
5397 eltBase_lw->clear();
5398 eltBase_lw->setFocus();
5401 // ============================================================== setValue
5402 void GroupDialog::setValue(HEXA_NS::Group* g)
5405 name_le->setText( g->getName() );
5409 kind_cb->addItem ( strKind[g->getKind()], QVariant( g->getKind() ) );
5412 HEXA_NS::EltBase* eltBase = NULL;
5413 QListWidgetItem* item = NULL;
5414 QModelIndex iEltBase;
5415 QList<QStandardItem *> eltBaseItems;
5418 if ( !getPatternDataSelectionModel() ) return;
5419 if ( !getGroupsSelectionModel() ) return;
5421 QModelIndex iGroup = getGroupsSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(g) );
5422 name_le->setProperty( "QModelIndex", QVariant::fromValue(iGroup) );
5425 int nbElts = g->countElement();
5426 for ( int nr = 0; nr < nbElts; ++nr ){
5427 eltBase = g->getElement( nr );
5428 switch ( g->getKind() ){
5429 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: v = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
5430 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: v = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
5431 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: v = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
5432 case HEXA_NS::VertexNode: v = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
5434 iEltBase = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, v);
5435 if ( iEltBase.isValid() ){
5436 item = new QListWidgetItem( eltBase->getName() );
5437 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iEltBase) );
5438 item->setData(LW_DATA_ROLE, iEltBase.data(HEXA_DATA_ROLE));
5439 eltBase_lw->addItem( item );
5445 // ============================================================== getValue
5446 HEXA_NS::Group* GroupDialog::getValue()
5451 // ============================================================== removeEltBase
5452 void GroupDialog::removeEltBase()
5454 QListWidgetItem *item = eltBase_lw->currentItem();
5457 int r = eltBase_lw->row(item);
5458 eltBase_lw->takeItem(r);
5464 // ============================================================== apply
5465 bool GroupDialog::apply(QModelIndex& result)
5467 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5470 if ( !getDocumentModel() ) return false;
5471 const PatternDataModel* patternDataModel = getPatternDataModel();
5472 const GroupsModel* groupsModel = getGroupsModel();
5473 if (patternDataModel == NULL || groupsModel == NULL) return false;
5475 QString grpName = name_le->text();
5476 DocumentModel::Group grpKind = static_cast<DocumentModel::Group>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5478 if ( _value == NULL ){ // create group
5479 iGrp = getDocumentModel()->addGroup( grpName, grpKind );
5481 QModelIndexList iGrps = getDocumentModel()->match(
5482 getDocumentModel()->index(0, 0),
5484 QVariant::fromValue( _value ),
5486 Qt::MatchRecursive );
5487 if ( !iGrps.isEmpty() )
5492 if ( !iGrp.isValid() ){
5493 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD GROUP" ) + "\n" + getErrorMsg() );
5497 //fill it and select it
5498 QModelIndex iEltBase;
5499 QListWidgetItem* item = NULL;
5500 bool eltAdded = false;
5501 getDocumentModel()->clearGroupElement(iGrp);
5502 int nbElts = eltBase_lw->count();
5503 for ( int r = 0; r < nbElts; ++r){
5504 item = eltBase_lw->item(r);
5505 iEltBase = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5506 if ( iEltBase.isValid() )
5507 eltAdded = getDocumentModel()->addGroupElement( iGrp, iEltBase );
5510 QString newName = name_le->text();
5511 if ( !newName.isEmpty() )
5512 getDocumentModel()->setName( iGrp, newName );
5514 HEXA_NS::Group* hGroup = getDocumentModel()->data(iGrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
5517 QString groupName = QString::fromStdString(hGroup->getNextName());
5518 name_le->setText(groupName);
5521 result = groupsModel->mapFromSource(iGrp);
5526 // ------------------------- LawDialog ----------------------------------
5527 // ============================================================== Constructeur
5529 LawDialog::LawDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5530 : HexaBaseDialog(parent, editmode, f),
5533 _helpFileName = "gui_discret_law.html#add-law";
5535 _initWidget(editmode);
5536 if ( editmode == NEW_MODE ){
5537 setWindowTitle( tr("Law Construction") );
5538 } else if ( editmode == UPDATE_MODE ){
5539 setWindowTitle( tr("Law Modification") );
5541 else if ( editmode == INFO_MODE){
5542 setWindowTitle( tr("Law Information") );
5546 // ============================================================== Destructeur
5547 LawDialog::~LawDialog()
5551 // ============================================================== _initInputWidget
5552 void LawDialog::_initInputWidget( Mode editmode )
5556 // setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5557 installEventFilter(this);
5559 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5560 name_le->installEventFilter(this);
5563 strKind[ HEXA_NS::Uniform ] = "Uniform";
5564 strKind[ HEXA_NS::Arithmetic ] = "Arithmetic";
5565 strKind[ HEXA_NS::Geometric ] = "Geometric";
5568 QMap<HEXA_NS::KindLaw, QString>::ConstIterator iKind, iEnd;
5569 for( iKind = strKind.constBegin(), iEnd = strKind.constEnd(); iKind != iEnd; ++iKind )
5570 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5572 if (editmode == INFO_MODE)
5574 name_le->setReadOnly(true);
5575 nb_nodes_spb->setReadOnly(true);
5576 coeff_spb->setReadOnly(true);
5577 kind_cb->setEnabled(false);
5581 // ============================================================== clear
5582 void LawDialog::clear()
5586 modelUnregister(this);
5589 // ============================================================== setValue
5590 void LawDialog::setValue(HEXA_NS::Law* l)
5593 name_le->setText( l->getName() );
5595 nb_nodes_spb->setValue( l->getNodes() );
5596 coeff_spb->setValue( l->getCoefficient() );
5598 HEXA_NS::KindLaw k = l->getKind();
5599 kind_cb->setCurrentIndex( kind_cb->findData(k) );
5604 // ============================================================== getValue
5605 HEXA_NS::Law* LawDialog::getValue()
5610 // ============================================================== apply
5611 bool LawDialog::apply(QModelIndex& result)
5613 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5616 if ( !getDocumentModel() ) return false;
5618 const MeshModel* meshModel = getMeshModel();
5619 if (meshModel == NULL) return false;
5621 QString lawName = name_le->text();
5622 int nbnodes = nb_nodes_spb->value();
5623 double coeff = coeff_spb->value();
5624 DocumentModel::KindLaw lawKind = static_cast<DocumentModel::KindLaw>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5627 if ( _value == NULL ){ // create Law
5628 iLaw = getDocumentModel()->addLaw( lawName, nbnodes );
5630 QModelIndexList iLaws = getDocumentModel()->match(
5631 getDocumentModel()->index(0, 0),
5633 QVariant::fromValue( _value ),
5635 Qt::MatchRecursive );
5636 if ( !iLaws.isEmpty() )
5640 if ( !iLaw.isValid() ){
5641 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5644 //fill it and select it
5645 bool setOk = getDocumentModel()->setLaw( iLaw, nbnodes, coeff, lawKind );
5647 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5651 QString newName = name_le->text();
5652 if ( !newName.isEmpty() )/*{*/
5653 getDocumentModel()->setName( iLaw, newName );
5655 HEXA_NS::Law* hLaw = getDocumentModel()->data(iLaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
5659 name_le->setText(hLaw->getNextName(buffer));
5663 result = meshModel->mapFromSource(iLaw);
5668 // ------------------------- PropagationDialog ----------------------------------
5669 // ============================================================== Constructeur
5670 PropagationDialog::PropagationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5671 : HexaBaseDialog(parent, editmode, f),
5674 _helpFileName = "gui_propag.html";
5676 _initWidget(editmode);
5678 if ( editmode == INFO_MODE ){
5679 setWindowTitle( tr("Propagation Information") );
5682 } else if ( editmode == UPDATE_MODE ){
5683 setWindowTitle( tr("Propagation Modification") );
5686 } else if ( editmode == NEW_MODE ){
5687 setWindowTitle( tr("Propagation(s) Setting") );
5691 // ============================================================== Destructeur
5692 PropagationDialog::~PropagationDialog()
5696 // ============================================================== _initInputWidget
5697 void PropagationDialog::_initInputWidget( Mode editmode )
5700 QValidator *validator = new QRegExpValidator(rx, this);
5702 installEventFilter(this);
5705 law_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5706 law_le->installEventFilter(this);
5707 law_le->setValidator( validator );
5709 propagations_lw->setProperty( "HexaWidgetType", QVariant::fromValue(PROPAGATION_TREE) );
5710 propagations_lw->installEventFilter(this);
5712 QShortcut* delPropagationShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), propagations_lw);
5713 delPropagationShortcut->setContext( Qt::WidgetShortcut );
5715 law_le->setReadOnly(true);
5717 if ( editmode == INFO_MODE)
5718 way_cb->setEnabled(false);
5720 connect( delPropagationShortcut, SIGNAL(activated()), this, SLOT(deletePropagationItem()) );
5721 connect( propagations_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
5724 // ============================================================== clear
5725 void PropagationDialog::clear()
5727 propagations_lw->clear();
5728 modelUnregister(propagations_lw);
5731 modelUnregister(law_le);
5733 modelUnregister(this);
5736 // ============================================================== deletePropagationItem
5737 void PropagationDialog::deletePropagationItem()
5739 delete propagations_lw->currentItem();
5742 // ============================================================== setValue
5743 void PropagationDialog::setValue(HEXA_NS::Propagation* p)
5745 if (getMeshSelectionModel() == NULL) return;
5746 HEXA_NS::Law* l = p->getLaw();
5747 bool way = p->getWay();
5750 QModelIndex ip = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
5751 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(ip) );
5753 // law on propagation
5755 law_le->setText( l->getName() );
5756 QModelIndex il = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(l) );
5757 law_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(il) );
5760 // way of propagation
5761 way_cb->setChecked(way);
5766 // ============================================================== selectElementOfModel
5768 /*Selects in the model (treeview) elements selected in a listwidget,
5769 * or an element in a line edit.*/
5771 void PropagationDialog::selectElementOfModel()
5773 if (!getMeshSelectionModel()) return;
5775 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5776 if ( !currentListWidget ) return;
5778 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5780 getMeshSelectionModel()->clearSelection();
5781 foreach ( QListWidgetItem *item, sel ){
5782 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
5783 index = getMeshSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5784 if ( index.isValid() )
5785 getMeshSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
5789 // ============================================================== getValue
5790 HEXA_NS::Propagation* PropagationDialog::getValue()
5795 // ============================================================== apply
5796 bool PropagationDialog::apply(QModelIndex& result)
5798 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5802 if ( !getDocumentModel() ) return false;
5803 const MeshModel* meshModel = getMeshModel();
5804 if (meshModel == NULL) return false;
5806 bool way = way_cb->isChecked();
5807 QListWidgetItem* item = NULL;
5809 QModelIndex iPropagation;
5810 QModelIndex iLaw = meshModel->mapToSource( law_le->property("QModelIndex").value<QModelIndex>() );
5811 if (!iLaw.isValid() ){
5812 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5816 int nbPropagations = propagations_lw->count();
5817 for (int r = 0; r < nbPropagations; ++r){
5818 item = propagations_lw->item(r);
5819 iPropagation = meshModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5820 if ( !iPropagation.isValid() ){
5821 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5825 //fill it and select it
5826 isOk = getDocumentModel()->setPropagation( iPropagation, iLaw, way );
5828 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) + "\n" + getErrorMsg() );
5832 result = meshModel->mapFromSource(iPropagation);
5838 // ------------------------- ComputeMeshDialog ----------------------------------
5839 // ============================================================== Constructeur
5840 ComputeMeshDialog::ComputeMeshDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5841 HexaBaseDialog(parent, editmode, f)
5843 _helpFileName = "gui_mesh.html";
5844 setWindowTitle( tr("Compute mesh") );
5846 _initWidget(editmode);
5849 // ============================================================== Destructeur
5850 ComputeMeshDialog::~ComputeMeshDialog()
5854 // ============================================================== _initInputWidget
5855 void ComputeMeshDialog::_initInputWidget( Mode editmode )
5859 // ============================================================== setDocumentModel
5860 void ComputeMeshDialog::setDocumentModel(DocumentModel* m)
5862 if (m == NULL) return;
5863 _name->setText(m->getName());
5866 // ============================================================== clear
5867 void ComputeMeshDialog::clear()
5869 modelUnregister(this);
5872 // ============================================================== apply
5873 bool ComputeMeshDialog::apply(QModelIndex& result)
5875 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5878 if (getDocumentModel() == NULL) return false;
5879 QString command = QString("import hexablock ; %1 = hexablock.mesh(\"%2\", \"%1\", %3, \"%4\")")
5880 .arg( _name->text() )
5881 .arg( getDocumentModel()->getName() )
5882 .arg( _dim->value() )
5883 .arg( _fact->text() );
5885 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
5886 PyConsole_Console* pyConsole = app->pythonConsole();
5889 pyConsole->exec( command );
5896 // ------------------------- ReplaceHexaDialog ----------------------------------
5897 // ============================================================== Constructeur
5898 ReplaceHexaDialog::ReplaceHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5899 HexaBaseDialog(parent, editmode, f)
5901 _helpFileName = "gui_replace_hexa.html";
5903 _initWidget(editmode);
5906 // ============================================================== Destructeur
5907 ReplaceHexaDialog::~ReplaceHexaDialog()
5911 // ============================================================== getAssocsVTK
5913 * Returns elements currently associated to vtk
5915 QModelIndexList ReplaceHexaDialog::getAssocsVTK()
5917 QModelIndexList assocs;
5919 QListWidgetItem* item = NULL;
5921 //ListWidget content
5922 int nbQuads = quads_lw->count();
5923 for ( int r = 0; r < nbQuads; ++r ){
5924 item = quads_lw->item(r);
5925 //iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
5926 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5927 if ( iQuad.isValid() )
5931 nbQuads = quads_lw_2->count();
5932 for( int i = 0; i < nbQuads; ++i)
5934 item = quads_lw_2->item(i);
5935 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5936 if (iQuad.isValid())
5943 // ============================================================== _initInputWidget
5944 void ReplaceHexaDialog::_initInputWidget( Mode editmode )
5948 installEventFilter(this);
5950 c1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5951 c2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5953 p1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5954 p2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5956 c1_le->installEventFilter(this);
5957 c2_le->installEventFilter(this);
5959 p1_le->installEventFilter(this);
5960 p2_le->installEventFilter(this);
5962 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5963 quads_lw->installEventFilter(this);
5965 quads_lw_2->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5966 quads_lw_2->installEventFilter(this);
5968 if ( editmode == NEW_MODE ){
5969 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5970 QShortcut* delQuadShortcut2 = new QShortcut( QKeySequence(Qt::Key_X), quads_lw_2 );
5971 delQuadShortcut->setContext( Qt::WidgetShortcut );
5972 delQuadShortcut2->setContext( Qt::WidgetShortcut );
5973 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()) );
5974 connect( quads_lw, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5975 connect( delQuadShortcut2, SIGNAL(activated()), this, SLOT(deleteQuadItem2()));
5976 connect( quads_lw_2, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5979 c1_le->setReadOnly(true);
5980 c2_le->setReadOnly(true);
5982 p1_le->setReadOnly(true);
5983 p2_le->setReadOnly(true);
5985 connect(quads_lw, SIGNAL(itemSelectionChanged()),
5986 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5988 connect(quads_lw_2, SIGNAL(itemSelectionChanged()),
5989 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5992 // ============================================================== clear
5993 void ReplaceHexaDialog::clear()
5996 modelUnregister(quads_lw);
5998 quads_lw_2->clear();
5999 modelUnregister(quads_lw_2);
6002 modelUnregister(p1_le);
6005 modelUnregister(p2_le);
6008 modelUnregister(c1_le);
6011 modelUnregister(c2_le);
6013 modelUnregister(this);
6016 // ============================================================== updateButtonBox
6017 void ReplaceHexaDialog::updateButtonBox()
6019 int nbQuad = quads_lw->count();
6022 _applyButton->setEnabled(true);
6024 _applyButton->setEnabled(false);
6028 // ============================================================== deleteQuadItem
6029 void ReplaceHexaDialog::deleteQuadItem()
6031 delete quads_lw->currentItem();
6035 // ============================================================== deleteQuadItem2
6036 void ReplaceHexaDialog::deleteQuadItem2()
6038 delete quads_lw_2->currentItem();
6042 // ============================================================== apply
6043 bool ReplaceHexaDialog::apply(QModelIndex& result)
6045 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6048 if ( !getDocumentModel() ) return false;
6049 const PatternDataModel* patternDataModel = getPatternDataModel();
6050 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6051 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
6053 QModelIndex ielts; //result
6055 QListWidgetItem* item = NULL;
6056 QModelIndexList iquads_source;
6058 int nbQuads = quads_lw->count();
6059 for ( int r = 0; r < nbQuads; ++r){
6060 item = quads_lw->item(r);
6061 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6062 if ( iquad.isValid() )
6063 iquads_source << iquad;
6066 QModelIndexList iquads_dest;
6067 nbQuads = quads_lw_2->count();
6068 for (int i = 0; i < nbQuads; ++i)
6070 item = quads_lw_2->item(i);
6071 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6072 if (iquad.isValid())
6073 iquads_dest << iquad;
6076 QModelIndex ip1_source = patternDataModel->mapToSource( _index[p1_le] );
6077 QModelIndex ip2_source = patternDataModel->mapToSource( _index[p2_le] );
6079 QModelIndex ic1_dest = patternDataModel->mapToSource( _index[c1_le] );
6080 QModelIndex ic2_dest = patternDataModel->mapToSource( _index[c2_le] );
6082 bool ipts_ok = ip1_source.isValid() && ip2_source.isValid() &&
6083 ic1_dest.isValid() && ic2_dest.isValid();
6087 ielts = getDocumentModel()->replace( iquads_source, iquads_dest,
6088 ip1_source, ic1_dest,
6089 ip2_source, ic2_dest );
6092 if ( !ielts.isValid() ){
6093 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REPLACE HEXA" ) + "\n" + getErrorMsg() );
6096 _value = ielts.model()->data(ielts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6097 // result = patternBuilderModel->mapFromSource(ielts);
6098 result = patternDataModel->mapFromSource(ielts);
6100 //update the list (indexes)
6101 for ( int r = 0; r < nbQuads; ++r ){
6102 item = quads_lw->item(r);
6103 iquad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
6104 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iquad) );
6105 item->setData(LW_DATA_ROLE, iquad.data(HEXA_DATA_ROLE));
6111 // ------------------------- QuadRevolutionDialog ----------------------------------
6112 // ============================================================== Constructeur
6114 QuadRevolutionDialog::QuadRevolutionDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
6115 HexaBaseDialog(parent, editmode, f)
6118 _helpFileName = "gui_quad_revolution.html#guiquadsrevolution";
6119 connect( revolutionUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6120 connect( revolution_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6121 _initWidget(editmode);
6122 revolutionUni_rb->click();
6125 // ============================================================== getAssocsVTK
6127 * Returns elements currently associated to vtk
6129 QModelIndexList QuadRevolutionDialog::getAssocsVTK()
6131 QModelIndexList assocs;
6133 QListWidgetItem* item = NULL;
6134 if (getPatternDataSelectionModel() == NULL) return assocs;
6136 //ListWidget content
6137 const PatternDataModel* patternDataModel = getPatternDataModel();
6138 if ( !patternDataModel ) return assocs;
6139 int nbQuads = quads_lw->count();
6140 for ( int r = 0; r < nbQuads; ++r ){
6141 item = quads_lw->item(r);
6142 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6143 if ( iQuad.isValid() )
6149 // ============================================================== Destructeur
6150 QuadRevolutionDialog::~QuadRevolutionDialog()
6154 // ============================================================== _initInputWidget
6155 void QuadRevolutionDialog::_initInputWidget( Mode editmode )
6157 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
6158 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6159 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6161 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
6162 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
6163 angle_spb->setProperty("Angle", QVariant::fromValue(true));
6164 angle_spb->installEventFilter(this);
6166 angles_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
6167 angles_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
6168 angles_lw->setProperty("Angle", QVariant::fromValue(true));
6169 angles_lw->installEventFilter(this);
6171 installEventFilter(this);
6172 revolutionUni_rb->installEventFilter(this);
6173 revolution_rb->installEventFilter(this);
6175 quads_lw->installEventFilter(this);
6176 center_le->installEventFilter(this);
6177 axis_le->installEventFilter(this);
6179 center_le->setReadOnly(true);
6180 axis_le->setReadOnly(true);
6182 angles_lw->setItemDelegate( new HexaAngleDoubleSpinBoxDelegate(angles_lw) );
6183 angles_lw->setEditTriggers( QAbstractItemView::DoubleClicked );
6185 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
6186 delQuadShortcut->setContext( Qt::WidgetShortcut );
6187 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(delQuadItem()) );
6188 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()));
6189 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()));
6191 connect(quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
6194 // ============================================================== updateHelpFileName
6195 void QuadRevolutionDialog::updateHelpFileName()
6197 if ( sender() == revolutionUni_rb ){
6198 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutionuniform";
6199 } else if ( sender() == revolution_rb ){
6200 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutioncustom";
6204 // ============================================================== clear
6205 void QuadRevolutionDialog::clear()
6208 modelUnregister(quads_lw);
6211 modelUnregister(center_le);
6214 modelUnregister(axis_le);
6216 modelUnregister(this);
6219 // ============================================================== addAngleItem
6220 void QuadRevolutionDialog::addAngleItem() //CS_TODO
6222 QListWidgetItem* previousItem = angles_lw->currentItem();
6223 QListWidgetItem* newItem = new QListWidgetItem();
6225 double defaultValue = 180.;
6227 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6229 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6230 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6231 angles_lw->addItem(newItem);
6236 // ============================================================== delAngleItem
6237 void QuadRevolutionDialog::delAngleItem()
6239 delete angles_lw->currentItem();
6243 // ============================================================== delQuadItem
6244 void QuadRevolutionDialog::delQuadItem()
6246 delete quads_lw->currentItem();
6250 // ============================================================== apply
6251 bool QuadRevolutionDialog::apply(QModelIndex& result)
6253 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6256 DocumentModel* docModel = getDocumentModel();
6257 PatternDataModel* patternDataModel = getPatternDataModel();
6258 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6260 QListWidgetItem* item = NULL;
6262 QModelIndexList istartquads;
6264 int nbQuads = quads_lw->count();
6265 for ( int r = 0; r < nbQuads; ++r){
6266 item = quads_lw->item(r);
6267 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6268 if ( iquad.isValid() )
6269 istartquads << iquad;
6272 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6273 QModelIndex iaxis = patternDataModel->mapToSource(_index[axis_le]);
6274 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
6275 int angle = angle_spb->value();
6276 int nbre = nbre_spb->value();
6278 vector<double> angles;
6279 int nbAngles = angles_lw->count();
6280 for ( int r = 0; r < nbAngles; ++r){
6281 item = angles_lw->item(r);
6282 angles.push_back(item->data(Qt::EditRole).toDouble());
6285 QModelIndex iElts; //result
6286 if (nbQuads == 1 && istartquads[0].isValid() && icenter.isValid() && iaxis.isValid())
6288 if (revolutionUni_rb->isChecked())
6289 iElts = docModel->revolutionQuadUni(istartquads[0], icenter, iaxis, angle, nbre);
6290 else if (revolution_rb->isChecked())
6291 iElts = docModel->revolutionQuad(istartquads[0], icenter, iaxis, angles);
6293 else if (nbQuads > 1 && icenter.isValid() && iaxis.isValid())
6295 if (revolutionUni_rb->isChecked())
6296 iElts = docModel->revolutionQuadsUni(istartquads, icenter, iaxis, angle, nbre);
6297 else if (revolution_rb->isChecked())
6298 iElts = docModel->revolutionQuads(istartquads, icenter, iaxis, angles);
6301 if ( !iElts.isValid() ){
6302 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD REVOLUTION" ) + "\n" + getErrorMsg() );
6305 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6306 result = patternDataModel->mapFromSource(iElts);
6307 // result = patternBuilderModel->mapFromSource(iElts);
6312 // ------------------------- MakeHemiSphereDialog ----------------------------------
6313 // ============================================================== Constructeur
6314 MakeHemiSphereDialog::MakeHemiSphereDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
6315 HexaBaseDialog(parent, editmode, f)
6317 _helpFileName = "gui_hemisphere.html";
6319 _initWidget(editmode);
6322 connect( sphereTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6323 connect( sphereUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6324 connect( sphere2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6325 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6326 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6328 connect( sphericalTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6329 connect( sphericalUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6330 connect( spherical2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6331 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6332 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6334 connect( rindTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6335 connect( rindUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6336 connect( rind2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6337 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6338 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6341 // ============================================================== Destructeur
6342 MakeHemiSphereDialog::~MakeHemiSphereDialog()
6346 // ============================================================== _initInputWidget
6347 void MakeHemiSphereDialog::_initInputWidget( Mode editmode )
6349 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6350 hole_axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6351 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6352 vplan_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6354 sphere_radext_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6355 sphere_radext_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6356 sphere_radext_spb->setProperty("Radius", QVariant::fromValue(true));
6358 sphere_radint_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6359 sphere_radint_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6360 sphere_radint_spb->setProperty("Radius", QVariant::fromValue(true));
6362 hole_rad_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6363 hole_rad_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6364 hole_rad_spb->setProperty("Radius", QVariant::fromValue(true));
6366 radial_angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6367 radial_angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6368 radial_angle_spb->setProperty("Angle", QVariant::fromValue(true));
6370 radius_lw_1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6371 radius_lw_1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6372 radius_lw_1->setProperty("Radius", QVariant::fromValue(true));
6374 radius_lw_2->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6375 radius_lw_2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6376 radius_lw_2->setProperty("Radius", QVariant::fromValue(true));
6378 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6379 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6380 height_lw->setProperty("Length", QVariant::fromValue(true));
6382 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6383 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6384 angle_lw->setProperty("Angle", QVariant::fromValue(true));
6386 installEventFilter(this);
6387 center_le->installEventFilter(this);
6388 hole_axis_le->installEventFilter(this);
6389 base_le->installEventFilter(this);
6390 vplan_le->installEventFilter(this);
6392 sphere_radext_spb->installEventFilter(this);
6393 sphere_radint_spb->installEventFilter(this);
6394 hole_rad_spb->installEventFilter(this);
6395 radial_angle_spb->installEventFilter(this);
6396 radius_lw_1->installEventFilter(this);
6397 radius_lw_2->installEventFilter(this);
6398 height_lw->installEventFilter(this);
6399 angle_lw->installEventFilter(this);
6401 sphere_rb->installEventFilter(this);
6402 sphereTop_rb->installEventFilter(this);
6403 sphereUni_rb->installEventFilter(this);
6404 sphere2_rb->installEventFilter(this);
6405 rind_rb->installEventFilter(this);
6406 rindTop_rb->installEventFilter(this);
6407 rindUni_rb->installEventFilter(this);
6408 rind2_rb->installEventFilter(this);
6409 spherical_rb->installEventFilter(this);
6410 sphericalTop_rb->installEventFilter(this);
6411 sphericalUni_rb->installEventFilter(this);
6412 spherical2_rb->installEventFilter(this);
6414 center_le->setReadOnly(true);
6415 hole_axis_le->setReadOnly(true);
6416 base_le->setReadOnly(true);
6417 vplan_le->setReadOnly(true);
6419 radius_lw_1->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_1));
6420 radius_lw_1->setEditTriggers(QAbstractItemView::DoubleClicked);
6422 radius_lw_2->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_2));
6423 radius_lw_2->setEditTriggers(QAbstractItemView::DoubleClicked);
6425 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
6426 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6428 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
6429 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6431 connect( add_radius_pb_1, SIGNAL(clicked()), this, SLOT(addRadiusItem1()) );
6432 connect( del_radius_pb_1, SIGNAL(clicked()), this, SLOT(delRadiusItem1()) );
6434 connect( add_radius_pb_2, SIGNAL(clicked()), this, SLOT(addRadiusItem2()) );
6435 connect( del_radius_pb_2, SIGNAL(clicked()), this, SLOT(delRadiusItem2()) );
6437 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
6438 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
6440 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
6441 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
6444 // ============================================================== updateHelpFileName
6445 void MakeHemiSphereDialog::updateHelpFileName()
6447 if ( sender() == sphereTop_rb || sender() == rindTop_rb ){
6448 _helpFileName = "gui_hemisphere.html#guisphereandrindsimple";
6449 } else if ( sender() == sphereUni_rb ){
6450 _helpFileName = "gui_hemisphere.html#guisphereuniform";
6451 } else if ( sender() == sphere2_rb ){
6452 _helpFileName = "gui_hemisphere.html#guispherecustom";
6453 } else if ( sender() == rindUni_rb ){
6454 _helpFileName = "gui_hemisphere.html#guirinduniform";
6455 } else if ( sender() == rind2_rb ){
6456 _helpFileName = "gui_hemisphere.html#guirindcustom";
6457 } else if ( sender() == sphericalTop_rb ){
6458 _helpFileName = "gui_hemisphere.html#guiconcentricsimple";
6459 } else if ( sender() == sphericalUni_rb ){
6460 _helpFileName = "gui_hemisphere.html#guiconcentricuniform";
6461 } else if ( sender() == spherical2_rb ){
6462 _helpFileName = "gui_hemisphere.html#guiconcentriccustom";
6466 // ============================================================== addRadiusItem
6467 void MakeHemiSphereDialog::addRadiusItem1()
6469 QListWidgetItem* previousItem = radius_lw_1->currentItem();
6470 QListWidgetItem* newItem = new QListWidgetItem();
6472 double defaultValue = 1.;
6474 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6476 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6477 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6478 radius_lw_1->addItem(newItem);
6481 // ============================================================== delRadiusItem
6482 void MakeHemiSphereDialog::delRadiusItem1()
6484 delete radius_lw_1->currentItem();
6487 // ============================================================== addRadiusItem
6488 void MakeHemiSphereDialog::addRadiusItem2()
6490 QListWidgetItem* previousItem = radius_lw_2->currentItem();
6491 QListWidgetItem* newItem = new QListWidgetItem();
6493 double defaultValue = 1.;
6495 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6497 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6498 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6499 radius_lw_2->addItem(newItem);
6502 // ============================================================== delRadiusItem
6503 void MakeHemiSphereDialog::delRadiusItem2()
6505 delete radius_lw_2->currentItem();
6508 // ============================================================== addAngleItem
6509 void MakeHemiSphereDialog::addAngleItem()
6511 QListWidgetItem* previousItem = angle_lw->currentItem();
6512 QListWidgetItem* newItem = new QListWidgetItem();
6514 double defaultValue = 180.;
6516 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6518 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6519 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6520 angle_lw->addItem(newItem);
6523 // ============================================================== delAngleItem
6524 void MakeHemiSphereDialog::delAngleItem()
6526 delete angle_lw->currentItem();
6529 // ============================================================== addHeightItem
6530 void MakeHemiSphereDialog::addHeightItem()
6532 QListWidgetItem* previousItem = height_lw->currentItem();
6533 QListWidgetItem* newItem = new QListWidgetItem();
6535 double defaultValue = 1.;
6537 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6539 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6540 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6541 height_lw->addItem(newItem);
6544 // ============================================================== delHeightItem
6545 void MakeHemiSphereDialog::delHeightItem()
6547 delete height_lw->currentItem();
6550 // ============================================================== clear
6551 void MakeHemiSphereDialog::clear()
6554 modelUnregister(center_le);
6556 hole_axis_le->clear();
6557 modelUnregister(hole_axis_le);
6560 modelUnregister(base_le);
6563 modelUnregister(vplan_le);
6565 modelUnregister(this);
6568 // ============================================================== apply
6569 bool MakeHemiSphereDialog::apply(QModelIndex& result)
6571 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6574 DocumentModel* docModel = getDocumentModel();
6575 PatternDataModel* patternDataModel = getPatternDataModel();
6576 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6579 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6580 QModelIndex ivplan = patternDataModel->mapToSource( _index[vplan_le] );
6581 QModelIndex ivecx = patternDataModel->mapToSource(_index[base_le]);
6582 QModelIndex ivecz = patternDataModel->mapToSource(_index[hole_axis_le]);
6583 // QModelIndex ivecx = patternBuilderModel->mapToSource( _index[base_le] );
6584 // QModelIndex ivecz = patternBuilderModel->mapToSource( _index[hole_axis_le] );
6586 double radhole = hole_rad_spb->value();
6587 double radext = sphere_radext_spb->value();
6588 double radint = sphere_radint_spb->value();
6589 double radang = radial_angle_spb->value();
6591 int crit = crit_spb->value();
6592 int nb = nbre_spb->value();
6593 int nrad = ngrid_rad_spb->value();
6594 int nang = ngrid_ang_spb->value();
6595 int nhaut = ngrid_height_spb->value();
6597 //radius, angles and heights collection
6598 QListWidgetItem* item = NULL;
6600 vector<double> radius1;
6601 vector<double> radius2;
6602 vector<double> angles;
6603 vector<double> heights;
6606 // double somme = 0.;
6607 int nbAngles = angle_lw->count();
6608 for ( int r = 0; r < nbAngles; ++r){
6609 item = angle_lw->item(r);
6610 double itemValue = item->data(Qt::EditRole).toDouble();
6611 angles.push_back(itemValue);
6612 // somme += itemValue;
6615 //radius1 collection
6616 int nbRadius = radius_lw_1->count();
6617 for ( int r = 0; r < nbRadius; ++r){
6618 item = radius_lw_1->item(r);
6619 radius1.push_back(item->data(Qt::EditRole).toDouble());
6622 //radius2 collection
6623 nbRadius = radius_lw_2->count();
6624 for ( int r = 0; r < nbRadius; ++r){
6625 item = radius_lw_2->item(r);
6626 radius2.push_back(item->data(Qt::EditRole).toDouble());
6629 //heights collection
6630 int nbHeight = height_lw->count();
6631 for ( int r = 0; r < nbHeight; ++r){
6632 item = height_lw->item(r);
6633 heights.push_back(item->data(Qt::EditRole).toDouble());
6636 if (sphere_rb->isChecked())
6638 if (sphereTop_rb->isChecked())
6639 iElts = docModel->makeSphereTop( nrad, nang, nhaut );
6640 else if (sphereUni_rb->isChecked())
6642 if (icenter.isValid() && ivplan.isValid() && ivecx.isValid() && ivecz.isValid())
6643 iElts = docModel->makeSphereUni(icenter, ivecx, ivecz, radhole, radext, radang,
6644 ivplan, nrad, nang, nhaut);
6646 else if (sphere2_rb->isChecked())
6648 // if (somme > 360.01)
6650 // SUIT_MessageBox::information( 0,
6652 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6655 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6656 iElts = docModel->makeSphere(icenter, ivecx, ivecz, radius2, angles, heights);
6659 else if (spherical_rb->isChecked())
6661 if (sphericalTop_rb->isChecked())
6662 iElts = docModel->makeSphericalTop(nb, crit);
6663 else if (sphericalUni_rb->isChecked())
6665 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6666 iElts = docModel->makeSphericalUni(icenter, ivecx, ivecz, radhole, nb, crit);
6668 else if (spherical2_rb->isChecked())
6670 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6671 iElts = docModel->makeSpherical(icenter, ivecx, ivecz, radius1, crit);
6674 else if (rind_rb->isChecked())
6676 if (rindTop_rb->isChecked())
6677 iElts = docModel->makeRindTop(nrad, nang, nhaut);
6678 else if (rindUni_rb->isChecked())
6680 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid() && ivplan.isValid())
6681 iElts = docModel->makeRindUni(icenter, ivecx, ivecz,
6682 radhole, radint, radext, radang,
6683 ivplan, nrad, nang, nhaut);
6685 else if (rind2_rb->isChecked())
6687 // if (somme > 360.01)
6689 // SUIT_MessageBox::information( 0,
6691 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6694 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6695 iElts = docModel->makeRind(icenter, ivecx, ivecz, radius2, angles, heights);
6699 if ( !iElts.isValid() ){
6700 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) + "\n" + getErrorMsg() );
6703 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6704 result = patternDataModel->mapFromSource(iElts);
6705 // result = patternBuilderModel->mapFromSource(iElts);
6710 // ------------------------- ModelInfoDialog ----------------------------------
6711 ModelInfoDialog::ModelInfoDialog(QWidget* parent, Qt::WindowFlags wf):
6712 HexaBaseDialog(parent, INFO_MODE, wf)
6715 setWindowTitle(HEXABLOCKGUI::tr("MODEL_INFO"));
6718 void ModelInfoDialog::updateInfo()
6720 DocumentModel* docModel = getDocumentModel();
6721 if (docModel == NULL) return;
6724 model_name_le->setText(docModel->getName());
6726 //Nb of elements in the model
6727 total_vertices_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_VERTEX)));
6728 total_edges_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_EDGE)));
6729 total_quads_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_QUAD)));
6730 total_hexas_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_HEXA)));
6732 ///Nb of used elements in the model
6733 used_vertices_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_VERTEX)));
6734 used_edges_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_EDGE)));
6735 used_quads_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_QUAD)));
6736 used_hexas_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_HEXA)));
6738 //Nb of unused elements in the model
6739 unused_vertices_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_VERTEX)));
6740 unused_edges_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_EDGE)));
6741 unused_quads_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_QUAD)));
6742 unused_hexas_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_HEXA)));
6745 void ModelInfoDialog::showEvent( QShowEvent * event )
6748 QDialog::showEvent ( event );
6751 // ============================================================== hideEvent
6752 void ModelInfoDialog::hideEvent ( QHideEvent * event )
6754 QDialog::hideEvent( event );
6757 // ------------------------- AddShapeDialog ----------------------------------
6758 AddShapeDialog::AddShapeDialog(QWidget* parent, Mode editmode, Qt::WindowFlags wf):
6759 HexaBaseDialog(parent, editmode, wf)
6761 _helpFileName = "gui_add_geometry.html#guiaddgeometry";
6763 _initWidget(editmode);
6764 setWindowTitle(HEXABLOCKGUI::tr("ADD_SHAPE"));
6767 // ============================================================== Destructeur
6768 AddShapeDialog::~AddShapeDialog()
6770 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
6771 this, SLOT(onCurrentSelectionChanged()) );
6774 // ============================================================== close
6775 void AddShapeDialog::close()
6777 HEXABLOCKGUI::assocInProgress = false;
6778 HexaBaseDialog::close();
6781 // ============================================================== _initInputWidget
6782 void AddShapeDialog::_initInputWidget( Mode editmode )
6784 shape_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMSHAPE_TREE) );
6785 shape_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_SHAPE) );
6786 shape_le->installEventFilter(this);
6787 shape_le->setReadOnly(true);
6790 void AddShapeDialog::clear()
6793 shape_le->setProperty("GeomObj", QVariant());
6795 modelUnregister(this);
6798 // ============================================================== onCurrentSelectionChanged
6799 void AddShapeDialog::onCurrentSelectionChanged()
6801 SALOME_ListIO selectedObjects;
6802 HEXABLOCKGUI::currentDocGView->getSelected(selectedObjects);
6803 if (selectedObjects.IsEmpty())
6806 // * extract the TopoDS_Shape of the selected object
6807 TopoDS_Shape selectedTopoShape = GEOMBase::GetTopoFromSelection( selectedObjects );
6808 if (selectedTopoShape.IsNull())
6810 shape_le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(selectedTopoShape));
6812 // * extract the name of the selected shape
6814 GEOMBase::GetNameOfSelectedIObjects( selectedObjects, name, true );
6815 shape_le->setText(name);
6818 // ============================================================== onWindowActivated
6819 void AddShapeDialog::onWindowActivated(SUIT_ViewManager* vm)
6821 QString vmType = vm->getType();
6822 if ( vmType == OCCViewer_Viewer::Type() )
6823 shape_le->setFocus();
6826 // ============================================================== apply
6827 bool AddShapeDialog::apply(QModelIndex& result)
6830 QString shapeName = shape_le->text();
6831 QVariant v = shape_le->property("TopoDS_Shape");
6832 if ( !v.isValid() || shapeName.isEmpty())
6836 TopoDS_Shape shape = v.value<TopoDS_Shape>();
6840 assocOk = getDocumentModel()->addShape(shape, shapeName);
6844 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), HEXABLOCKGUI::tr("ADD_SHAPE_FAILED") + "\n" + getErrorMsg() );