1 // Copyright (C) 2009-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <OCCViewer_ViewWindow.h>
21 #include "HEXABLOCKGUI_DocumentPanel.hxx"
22 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
23 #include "HEXABLOCKGUI_OccGraphicView.hxx"
24 #include "HEXABLOCKGUI_SalomeTools.hxx"
31 #include <SalomeApp_Application.h>
32 #include <SalomeApp_Study.h>
33 #include <PyConsole_Console.h>
34 #include <SalomeApp_Tools.h>
36 #include <Standard_GUID.hxx>
37 #include <TDF_Label.hxx>
39 #include <OCCViewer_ViewManager.h>
42 #include <TopExp_Explorer.hxx>
43 #include <TopoDS_Iterator.hxx>
44 #include <TopTools_MapOfShape.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <TColStd_IndexedMapOfInteger.hxx>
48 #include <SUIT_Session.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_OverrideCursor.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_Session.h>
53 #include "SVTK_Selection.h"
54 #include <SVTK_ViewModel.h>
55 #include <VTKViewer_ViewModel.h>
56 #include <SVTK_View.h>
58 #include <SUIT_ResourceMgr.h>
62 #define BUTTON_BOX_MIN_WIDTH 5
63 #define VERTEX_COORD_MIN -1000000
64 #define VERTEX_COORD_MAX 1000000
65 #define SPINBOX_ANGLE_MAX 360
66 #define SPINBOX_DOUBLE_MAX 1000000000
67 #define SPINBOX_POSITIVE_DOUBLE_MIN 0
72 using namespace HEXABLOCK::GUI;
75 Q_DECLARE_METATYPE(HEXABLOCK::GUI::HexaTreeRole);
76 Q_DECLARE_METATYPE(DocumentModel::GeomObj);
77 Q_DECLARE_METATYPE(TopAbs_ShapeEnum);
78 Q_DECLARE_METATYPE(TopoDS_Shape);
80 //General SpinBox Delegate
81 class HexaDoubleSpinBoxDelegate : public QStyledItemDelegate {
83 HexaDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
85 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
86 const QModelIndex &index) const{
87 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
88 sb->setDecimals(NB_DECIMALS);
93 //Angle SpinBox Delegate
94 class HexaAngleDoubleSpinBoxDelegate : public QStyledItemDelegate {
96 HexaAngleDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
98 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
99 const QModelIndex &index) const{
100 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
101 sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
102 sb->setMaximum(SPINBOX_ANGLE_MAX);
103 sb->setDecimals(NB_DECIMALS);
109 //Positive DoubleSpinBox Delegate (for heigth, radius, ...)
110 class HexaPositiveDoubleSpinBoxDelegate : public QStyledItemDelegate {
112 HexaPositiveDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
114 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
115 const QModelIndex &index) const{
116 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
117 sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
118 sb->setMaximum(SPINBOX_DOUBLE_MAX); //10e9
119 sb->setDecimals(NB_DECIMALS);
124 // ======================================================== Constructeur
125 HexaBaseDialog::HexaBaseDialog( QWidget * parent, Mode editmode, Qt::WindowFlags f ):
127 _editMode( editmode ),
130 debugEdgeAssoc(false),
131 autoFocusSwitch(true)
133 _strHexaWidgetType[VERTEX_TREE] = tr( "VERTEX" );
134 _strHexaWidgetType[EDGE_TREE] = tr( "EDGE" );
135 _strHexaWidgetType[QUAD_TREE] = tr( "QUAD" );
136 _strHexaWidgetType[HEXA_TREE] = tr( "HEXA" );
138 _strHexaWidgetType[VECTOR_TREE] = tr( "VECTOR" );
139 // _strHexaWidgetType[CYLINDER_TREE] = tr( "CYLINDER" );
140 // _strHexaWidgetType[PIPE_TREE] = tr( "PIPE" );
141 _strHexaWidgetType[ELEMENTS_TREE] = tr( "ELEMENTS" );
142 _strHexaWidgetType[CROSSELEMENTS_TREE]= tr( "CROSSELEMENTS" );
145 _strHexaWidgetType[GEOMSHAPE_TREE] = tr( "GEOMSHAPE" );
146 _strHexaWidgetType[GEOMPOINT_TREE] = tr( "GEOMPOINT" );
147 _strHexaWidgetType[GEOMEDGE_TREE] = tr( "GEOMEDGE" );
148 _strHexaWidgetType[GEOMFACE_TREE] = tr( "GEOMFACE" );
150 _strHexaWidgetType[GROUP_TREE] = tr( "GROUP" );
151 _strHexaWidgetType[LAW_TREE] = tr( "LAW" );
152 _strHexaWidgetType[PROPAGATION_TREE]= tr( "PROPAGATION" );
155 // ============================================================= getIndexList
156 QModelIndexList HexaBaseDialog::getIndexList(QListWidget* itemsList, bool mapToSource)
158 QModelIndexList iItems;
160 QListWidgetItem* item = NULL;
162 const PatternDataModel* patternDataModel = getPatternDataModel();
163 if (patternDataModel == NULL || itemsList == NULL) return iItems;
165 unsigned int nbItems = itemsList->count();
166 for ( int r = 0; r < nbItems; ++r){
167 item = itemsList->item(r);
169 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
171 iItem = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
178 // ================================================================ computeAndSetDimension
179 void HexaBaseDialog::computeAndSetDimension(const QModelIndex& elt)
181 // * Check if everything is OK for the computing
182 DocumentModel* docModel = getDocumentModel();
183 if (docModel == NULL || _currentObj == NULL)
186 int selectedType = elt.data(HEXA_TREE_ROLE).toInt();
187 if (selectedType != EDGE_TREE && selectedType != GEOMEDGE_TREE)
190 QListWidget* list = dynamic_cast<QListWidget*>(_currentObj);
191 QDoubleSpinBox* spb = dynamic_cast<QDoubleSpinBox*>(_currentObj);
193 if (list == NULL && spb == NULL)
196 // * Compute the value of the dimension
199 if (_currentObj->property("Radius").isValid())
200 value = docModel->getRadius(elt);
201 else if (_currentObj->property("Angle").isValid())
202 value = docModel->getAngle(elt);
203 else if (_currentObj->property("Length").isValid())
204 value = docModel->getLength(elt);
209 // * Set the value to the field (radius, length or height)
212 QListWidgetItem* item = list->currentItem();
217 item->setText(QString::number(value));
218 list->editItem(item);
222 else if (spb != NULL)
224 spb->setValue(value);
230 // ============================================================= resetSizeAndShow
231 void HexaBaseDialog::resetSizeAndShow(QDockWidget* parent)
236 //force the dialog to fit its contain
237 // setMinimumWidth(sizeHint().width());
239 //set the dialog in the dockwidget
240 if (parent->widget())
241 parent->widget()->close();
242 parent->setWidget(this);
243 parent->setWindowTitle(windowTitle());
246 // setMinimumWidth(MIN_WIDTH);
249 QString HexaBaseDialog::getErrorMsg()
251 DocumentModel* docModel = getDocumentModel();
252 Hex::Hex* hex = docModel->getHexaRoot();
253 int nbErrorMsg = hex->sizeofMessage();
254 QString msg, newLine = "\n";
255 for (int i = 1; i < nbErrorMsg; ++i)
256 msg += newLine + hex->getMessageLine(i);
261 //unlink the widget from the model
262 void HexaBaseDialog::modelUnregister(QWidget* widget)
264 if (widget == NULL) return;
266 if (widget->property("GeomWidgetType").isValid())
268 widget->setProperty("GeomObj", QVariant());
269 widget->setProperty("TopoDS_Shape", QVariant());
272 widget->setProperty("HexaData", QVariant());
273 widget->setProperty("QModelIndex", QVariant());
274 _index[widget] = QModelIndex();
276 HexaBaseDialog* diag = dynamic_cast<HexaBaseDialog*>(widget);
278 diag->clearWidgetsIndexes();
281 // ============================================================= connectDocumentGraphicView
282 void HexaBaseDialog::connectDocumentGraphicView(VtkDocumentGraphicView* docGView)
284 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
285 if (docGView == NULL) return;
287 disconnectDocumentGraphicView(docGView); //to avoid double connect
289 //Connect the graphic view and its model to the dialog box
290 connect( docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
291 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
292 // connect( docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
293 // this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
294 connect( docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
295 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
296 connect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
297 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
298 connect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
299 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
302 // ============================================================= disconnectDocumentGraphicView
303 void HexaBaseDialog::disconnectDocumentGraphicView(VtkDocumentGraphicView* docGView)
305 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
306 if (docGView == NULL) return;
309 //Disconnect graphic view signals form the dialog box
310 disconnect(docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
311 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
313 // disconnect(docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
314 // this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
316 disconnect(docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
317 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
319 disconnect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
320 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
322 disconnect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
323 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
326 // ============================================================= onCurrentSelectionChanged
327 void HexaBaseDialog::onCurrentSelectionChanged()
329 highlightSelectedAssocs();
332 // ============================================================= clearCurrentObjectFocus
333 void HexaBaseDialog::clearCurrentObjectFocus()
335 QWidget* currentWidget = dynamic_cast<QWidget*>(_currentObj);
336 if (currentWidget != NULL)
338 currentWidget->clearFocus();
343 // ============================================================= setFocusToNextField
344 //Sets focus to the next field of the current object
345 void HexaBaseDialog::setFocusToNextField()
349 if (!HEXABLOCKGUI::assocInProgress && autoFocusSwitch)
351 _highlightWidget(_currentObj, Qt::white);
356 // ============================================================== _initButtonBox
357 QGroupBox* HexaBaseDialog::_initButtonBox( Mode editmode )
359 if ( editmode == INFO_MODE )
362 QGroupBox* buttonBox = new QGroupBox();
363 buttonBox->setMinimumWidth(BUTTON_BOX_MIN_WIDTH);
364 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
365 QHBoxLayout* buttonsHLayout = new QHBoxLayout();
366 _applyButton = new QPushButton(tr("Apply"));
367 QPushButton* closeButton = new QPushButton(tr("Close"));
368 QPushButton* helpButton = new QPushButton(tr("Help"));
370 connect( _applyButton, SIGNAL(clicked()), this, SLOT(apply()), Qt::UniqueConnection );
371 connect( closeButton, SIGNAL(clicked()), this, SLOT(close()), Qt::UniqueConnection );
372 connect( helpButton, SIGNAL(clicked()), this, SLOT(onHelpRequested()), Qt::UniqueConnection );
374 buttonsHLayout->addWidget( _applyButton );
375 buttonsHLayout->addWidget( closeButton );
376 buttonsHLayout->addStretch(1);
377 buttonsHLayout->addWidget( helpButton );
378 buttonBox->setLayout(buttonsHLayout);
379 layout()->addWidget(buttonBox);
380 buttonBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
384 // ============================================================== _initWidget
385 void HexaBaseDialog::_initWidget( Mode editmode )
387 _initInputWidget( editmode );
388 _initButtonBox( editmode );
391 // ============================================================== apply
392 bool HexaBaseDialog::apply()
395 bool applied = apply(iNew);
398 _selectAndHighlight( iNew );
399 if (!HEXABLOCKGUI::assocInProgress)
400 getDocumentModel()->updateGeomTree();
405 void HexaBaseDialog::clearVTKSelection()
407 HEXABLOCKGUI::currentDocGView->clearSelection();
408 _highlightWidget(_currentObj, Qt::white);
411 void HexaBaseDialog::clearOCCSelection()
413 HEXABLOCKGUI::currentOccGView->clearSelection();
416 // ============================================================== close
417 void HexaBaseDialog::close()
419 //reset the data selection pattern (forget all selections of the current context)
420 getPatternDataSelectionModel()->reset();
421 // getPatternBuilderSelectionModel()->reset();
422 getPatternGeomSelectionModel()->reset();
424 //Clear vtk selection
427 //Clear occ selection
430 //Close the dialog box
432 parentWidget()->close();
434 getPatternDataSelectionModel()->setInfoMode(true);
437 // ============================================================== onHelpRequested
438 void HexaBaseDialog::onHelpRequested()
440 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
442 app->onHelpContextModule( "HEXABLOCK", _helpFileName );
446 platform = "winapplication";
448 platform = "application";
451 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
452 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
453 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( _helpFileName ),
454 QObject::tr( "BUT_OK" ) );
458 // ============================================================== highlightSelectedAssocs
459 void HexaBaseDialog::highlightSelectedAssocs()
461 QMultiMap<QString, int> geomAssocs = getAssocsGEOM();
462 QModelIndexList vtkAssocs = getAssocsVTK();
464 // HEXABLOCKGUI::selectionMgr()->clearSelected();
465 //highlight geom selected elts
466 if (geomAssocs.size() > 0)
467 HEXABLOCKGUI::currentOccGView->highlight(geomAssocs, false);
469 //highlight vtk selected elts
470 if (!vtkAssocs.isEmpty())
471 HEXABLOCKGUI::currentDocGView->highlight(vtkAssocs);
474 // ============================================================== refreshHighlight
475 void HexaBaseDialog::refreshHighlight()
477 HEXABLOCKGUI::selectionMgr()->clearSelected();
478 highlightSelectedAssocs();
481 bool HexaBaseDialog::isDimensionType(const QObject* obj)
486 return (obj->property("Radius").isValid()) ||
487 (obj->property("Angle").isValid()) ||
488 (obj->property("Length").isValid());
491 // ============================================================== getObjectViewType
492 HEXABLOCKGUI::ViewType HexaBaseDialog::getObjectViewType(QObject* obj)
495 return HEXABLOCKGUI::UNKNOWN;
497 QVariant v1 = obj->property("GeomWidgetType");
498 QVariant v2 = obj->property("HexaWidgetType");
500 if (v1.isValid() && v2.isValid() && isDimensionType(obj))
501 return HEXABLOCKGUI::VTK_OCC;
502 else if (v1.isValid())
503 return HEXABLOCKGUI::OCC;
504 else if (v2.isValid())
505 return HEXABLOCKGUI::VTK;
507 return HEXABLOCKGUI::UNKNOWN;
510 // ============================================================== _selectAndHighlight
511 void HexaBaseDialog::_selectAndHighlight( const QModelIndex& i )
513 if ( !i.isValid() ) return;
514 setProperty("QModelIndex", QVariant::fromValue(i));
518 // ============================================================== _allowSelection
519 void HexaBaseDialog::_allowSelection()
521 if ( getDocumentModel() )
522 getDocumentModel()->disallowEdition();
525 // ============================================================== _disallowSelection
526 void HexaBaseDialog::_disallowSelection()
528 if ( getDocumentModel() ){
529 getDocumentModel()->allowEdition();
531 HEXABLOCKGUI::currentDocGView->setAllSelection();
534 // ============================================================== _allowVTKSelection
535 bool HexaBaseDialog::_allowVTKSelection( QObject* obj )
539 QVariant v = obj->property("HexaWidgetType");
540 HexaWidgetType wType = v.value<HexaWidgetType>();
544 HEXABLOCKGUI::currentDocGView->setVertexSelection(); isOk = true;
547 HEXABLOCKGUI::currentDocGView->setEdgeSelection(); isOk = true;
550 HEXABLOCKGUI::currentDocGView->setQuadSelection(); isOk = true;
553 HEXABLOCKGUI::currentDocGView->setHexaSelection(); isOk = true;
555 default: HEXABLOCKGUI::currentDocGView->setAllSelection();
560 // ============================================================== _allowOCCSelection
561 bool HexaBaseDialog::_allowOCCSelection( QObject* obj )
563 QVariant v = obj->property("GeomWidgetType");
564 GeomWidgetType wType = v.value<GeomWidgetType>();
565 HEXABLOCKGUI::currentOccGView->setSelectionMode(wType);
570 // ============================================================== _getSelector
571 QItemSelectionModel* HexaBaseDialog::_getSelector( QObject* obj )
576 QItemSelectionModel* selector = NULL;
578 HexaWidgetType wtype;
579 QVariant v = obj->property("HexaWidgetType");
580 QVariant v2 = obj->property("GeomWidgetType");
581 if ( !v.isValid() || (v2.isValid() && isDimensionType(obj)) )
584 wtype = v.value<HexaWidgetType>();
591 case VECTOR_TREE: selector = getPatternDataSelectionModel(); break;
592 // case CYLINDER_TREE:
594 // case ELEMENTS_TREE:
595 // case CROSSELEMENTS_TREE: selector = getPatternBuilderSelectionModel(); break;
598 case GEOMFACE_TREE: selector = getPatternGeomSelectionModel(); break;
599 case GROUP_TREE: selector = getGroupsSelectionModel(); break;
601 case PROPAGATION_TREE: selector = getMeshSelectionModel(); break;
608 // ============================================================== getGeomObj
609 DocumentModel::GeomObj* HexaBaseDialog::getGeomObj(const QModelIndex& index)
611 HEXA_NS::NewShape* aSh = getDocumentModel()->getHexaPtr<HEXA_NS::NewShape*>(index);
612 DocumentModel::GeomObj* geomObj = NULL;
615 geomObj = new DocumentModel::GeomObj;
616 geomObj->shapeName = aSh->getName();
617 geomObj->subId = QString::number(-1);
621 HEXA_NS::EltBase* aSShElt = getDocumentModel()->getHexaPtr(index);
622 HEXA_NS::SubShape* aSSh = dynamic_cast<HEXA_NS::SubShape*>(aSShElt);
625 geomObj = new DocumentModel::GeomObj;
627 if (aSSh->getParentShape() != NULL)
628 shapeName = aSSh->getParentShape()->getName();
629 geomObj->shapeName = shapeName;
630 geomObj->subId = QString::number(aSSh->getIdent());
636 // ============================================================== _onSelectionChanged
638 * Puts elements selected in the model (treeview) in the corresponding
639 * line edit widget (the one that has the focus) of the current dialog box.
641 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QLineEdit* le )
643 QModelIndexList l = sel.indexes();
644 if ( l.count() == 0 ) return false;
646 // mono selection mode: we just get the first selected element
647 QModelIndex selected = l[0];
649 // we just return if the selection is not valid or the selection and the
650 // line content are the same
651 if ( !selected.isValid() || le->property("HexaData") == selected.data(HEXA_DATA_ROLE) )
655 int selType = selected.data(HEXA_TREE_ROLE).toInt();
658 QVariant v = le->property("HexaWidgetType");
659 if ( !v.isValid() ) return false;
660 HexaWidgetType wType = v.value<HexaWidgetType>();
662 // check selection compatibility between selection and widget
663 if ( selType != wType ){
664 SUIT_MessageBox::information( 0, tr("HEXA_INFO"),
665 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg(_strHexaWidgetType[wType]));
668 if (le->property("GeomWidgetType").isValid())
670 DocumentModel::GeomObj* geomObj = getGeomObj(selected);
673 le->setProperty("GeomObj", QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
675 DocumentModel* docModel = getDocumentModel();
676 QString objId = geomObj->shapeName + "," + geomObj->subId;
677 HEXA_NS::SubShape* ssh = docModel->getGeomPtr(objId);
680 TopoDS_Shape shape = ssh->getShape();
682 le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(shape));
684 setCurrentGeomObj(geomObj);
688 //fill the lineEdit if selection is OK
689 le->setText( selected.data().toString() );// name
690 le->setProperty("QModelIndex", QVariant::fromValue(selected));
691 le->setProperty("HexaData", selected.data(HEXA_DATA_ROLE));
692 _index[le] = selected;
694 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(_currentObj);
695 if (selected.isValid() && lineEdit != NULL)
696 setFocusToNextField();
701 // ============================================================== _onSelectionChanged
703 * Puts elements selected in the model (treeview) in the corresponding list widget
704 * of the current dialog box.
706 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QListWidget* lw )
708 QModelIndexList l = sel.indexes();
710 if ( l.count() == 0 ) return false;
713 QVariant v = lw->property("HexaWidgetType");
714 if ( !v.isValid() ) return false;
715 HexaWidgetType wType = v.value<HexaWidgetType>();
717 //fill the listWidget
718 QListWidgetItem* item = NULL;
722 foreach( const QModelIndex& isel, l ){
723 // if ( lw->count() == maxSize) break;
724 selType = isel.data(HEXA_TREE_ROLE).toInt();
725 if ( selType != wType ){ // check selection compatibility between selection and widget
726 SUIT_MessageBox::information( 0,
728 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg( _strHexaWidgetType[wType]) );
731 // add selection to listWidget if selection is OK
732 selName = isel.data().toString();
733 QList<QListWidgetItem *> twice = lw->findItems( selName, Qt::MatchExactly);
734 if ( twice.count() == 0 ){
735 item = new QListWidgetItem( selName );
736 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(isel) );
737 item->setData(LW_DATA_ROLE, isel.data(HEXA_DATA_ROLE));
738 if (lw->property("GeomWidgetType").isValid())
740 DocumentModel::GeomObj* geomObj = getGeomObj(isel);
742 item->setData(LW_ASSOC_ROLE, QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
751 // ============================================================== onSelectionChanged
753 * Puts elements selected in the model in the corresponding widget (list widget or line edit)
754 * of the current dialog box.
756 void HexaBaseDialog::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
758 QModelIndexList l = sel.indexes();
760 if ( l.count() == 0 )
762 QModelIndex selected = l[0];
764 // * no edition for Info Dialogs
765 if ( _editMode == INFO_MODE || _currentObj == NULL || !selected.isValid())
768 if (isDimensionType(_currentObj))
770 // ** set the dimension of the selected object in the editor **/
771 int selectedType = selected.data(HEXA_TREE_ROLE).toInt();
772 if (selectedType == EDGE_TREE || selectedType == GEOMEDGE_TREE)
773 computeAndSetDimension(selected);
777 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
778 QListWidget* aListWidget = dynamic_cast<QListWidget*>(_currentObj);
780 // * fill the lineedit with selection
783 _onSelectionChanged( sel, aLineEdit );
787 // * fill the listWidget with selection
789 _onSelectionChanged( sel, aListWidget );
792 // ============================================================== showEvent
793 void HexaBaseDialog::showEvent( QShowEvent * event )
795 if ( _editMode == INFO_MODE )
796 getDocumentModel()->allowEdition();
798 getDocumentModel()->disallowEdition();
800 //Connect to salome selection signals
801 if (HEXABLOCKGUI::selectionMgr() != NULL)
803 connect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
804 this, SLOT(onCurrentSelectionChanged()), Qt::UniqueConnection );
807 //connect model selection signals
808 connectDocumentGraphicView();
810 QDialog::showEvent ( event );
814 // ============================================================== hideEvent
815 void HexaBaseDialog::hideEvent ( QHideEvent * event )
817 //Disconnection salome selection signals
818 if (HEXABLOCKGUI::selectionMgr() != NULL)
819 disconnect( HEXABLOCKGUI::selectionMgr() , SIGNAL(currentSelectionChanged()),
820 this, SLOT(onCurrentSelectionChanged()) );
822 //Disconnect vtk window activation signals
823 // if (HEXABLOCKGUI::currentDocGView->getViewWindow() != NULL)
824 // disconnect( HEXABLOCKGUI::currentDocGView->getViewWindow()->getViewManager(),
825 // SIGNAL( activated(SUIT_ViewManager*) ),
826 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
828 //Disconnect occ window activation signals
829 // if (HEXABLOCKGUI::currentOccGView->getViewWindow() != NULL)
830 // disconnect( HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager(),
831 // SIGNAL( activated(SUIT_ViewManager*) ),
832 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
834 //Disconnect model selection signals
835 disconnectDocumentGraphicView();
836 getDocumentModel()->allowEdition();
838 QDialog::hideEvent( event );
841 // ============================================================== updateButtonBox
842 void HexaBaseDialog::updateButtonBox()
846 // ============================================================== updateName
847 void HexaBaseDialog::updateName()
849 const PatternDataModel* patternDataModel = getPatternDataModel();
851 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(sender());
852 if (!lineEdit) return;
853 QString newName = lineEdit->text();
854 if ( newName.isEmpty() ) return;
856 QVariant v = lineEdit->property("QModelIndex");
857 if ( !v.isValid() ) return;
859 QModelIndex index = v.value<QModelIndex>();
860 if ( index.isValid() )
861 getDocumentModel()->setName( patternDataModel->mapToSource(index), newName );
864 // ============================================================== updateDefaultName
865 void HexaBaseDialog::updateDefaultName(QLineEdit* name_field, HEXA_NS::EnumElt type)
867 if (name_field == NULL) return;
869 HEXA_NS::Document* doc = getDocumentModel()->getHexaDocument();
870 if (doc == NULL) return;
872 name_field->setText(doc->getNextName(type).c_str());
875 // ============================================================== selectElementOfModel
876 /*Selects in the model (treeview) elements selected in a listwidget,
877 * or an element in a line edit.*/
878 void HexaBaseDialog::selectElementOfModel()
880 if (getPatternDataSelectionModel() == NULL) return;
882 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
883 if ( !currentListWidget ) return;
885 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
887 getPatternDataSelectionModel()->clearSelection();
888 foreach ( QListWidgetItem *item, sel ){
889 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
890 index = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
891 if ( index.isValid() )
892 getPatternDataSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
896 // ============================================================== _isLineOrListWidget
898 * Return true is the widget is a line or a list
901 bool HexaBaseDialog::_isLineOrListWidget(QObject *widget)
903 if (widget == NULL) return false;
905 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(widget);
906 QListWidget *listWidget = dynamic_cast<QListWidget*>(widget);
907 return (lineEdit != NULL) || (listWidget != NULL);
909 }//_isLineOrListWidget
912 // ============================================================== _highlightWidget
914 * Highlight the given widget with the given color.
916 void HexaBaseDialog::_highlightWidget(QObject *obj, Qt::GlobalColor clr)
918 QDoubleSpinBox* spb = dynamic_cast<QDoubleSpinBox*>(obj);
919 if (!_isLineOrListWidget(obj) && spb == NULL)
922 QWidget *widget = dynamic_cast<QWidget*>(obj);
923 QPalette palette1 = widget->palette();
924 palette1.setColor(QPalette::Active, widget->backgroundRole(), clr);
925 widget->setPalette(palette1);
929 // ============================================================== _updateCurrentObject
930 void HexaBaseDialog::_updateCurrentObject(QObject* obj)
932 _highlightWidget(_currentObj, Qt::white);
934 _highlightWidget(obj, Qt::yellow);
937 // ============================================================== eventFilter
939 * Handles events from the treeview and the dialog boxes.
941 bool HexaBaseDialog::eventFilter(QObject *obj, QEvent *event)
943 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(obj);
944 QListWidget *listWidget = dynamic_cast<QListWidget*>(obj);
946 // * Enter key press ------
947 if ( event->type() == QEvent::KeyPress &&
948 ((QKeyEvent*)event)->key() == Qt::Key_Return)
950 setFocusToNextField();
954 // * Focus out from a list widget ------
955 if ( event->type() == QEvent::FocusOut && listWidget != NULL)
957 QItemSelectionModel * selectionModel = listWidget->selectionModel();
958 selectionModel->clearSelection();
961 if ( event->type() != QEvent::FocusIn )
965 HEXABLOCKGUI::ViewType vtype = getObjectViewType(obj);
966 if (vtype == HEXABLOCKGUI::VTK_OCC)
968 _allowVTKSelection(obj);
969 _allowOCCSelection(obj);
971 else if (vtype == HEXABLOCKGUI::VTK)
972 _allowVTKSelection( obj );
973 else if (vtype == HEXABLOCKGUI::OCC)
974 _allowOCCSelection( obj );
976 //Depending on the focused widget type, get the right selector for it
979 QItemSelectionModel* selector = _getSelector( obj );
980 if ( selector == NULL )
982 _updateCurrentObject(obj);
986 if ( _currentObj != obj && (lineEdit == NULL || listWidget == NULL) )
987 selector->clearSelection();
989 _updateCurrentObject(obj);
991 //If the widget contains an element, select it in model/view
992 if ( lineEdit != NULL ){ //element can be from lineEdit
993 v = lineEdit->property("HexaData");
995 return QObject::eventFilter(obj, event);
996 index = ((SelectionModel*)selector)->indexBy( HEXA_DATA_ROLE, v);
998 selector->select( index, QItemSelectionModel::SelectCurrent );
1001 return QObject::eventFilter(obj, event);
1004 // ------------------------- VERTEX ----------------------------------
1005 // ============================================================== Constructeur
1006 VertexDialog::VertexDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1007 HexaBaseDialog(parent, editmode, f),
1010 _helpFileName = "gui_vertex.html";
1012 _initWidget(editmode);
1014 if ( editmode == NEW_MODE ){
1015 setWindowTitle( tr("Vertex Construction") );
1016 } else if ( editmode == UPDATE_MODE ){
1017 setWindowTitle( tr("Vertex Modification") );
1019 else if ( editmode == INFO_MODE){
1020 setWindowTitle( tr("Vertex Information") );
1024 // ============================================================== Destructeur
1025 VertexDialog::~VertexDialog()
1029 // ============================================================== _initInputWidget
1030 void VertexDialog::_initInputWidget( Mode editmode )
1032 // x_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1033 // y_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1034 // z_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1035 QDoubleValidator *doubleValidator = new QDoubleValidator(widget_2);
1036 x_spb->setValidator(doubleValidator);
1037 y_spb->setValidator(doubleValidator);
1038 z_spb->setValidator(doubleValidator);
1040 // setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1041 installEventFilter(this);
1042 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1043 name_le->installEventFilter(this);
1045 if (editmode == INFO_MODE)
1047 name_le->setReadOnly(true);
1048 x_spb->setReadOnly(true);
1049 y_spb->setReadOnly(true);
1050 z_spb->setReadOnly(true);
1053 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
1056 // ============================================================== clear
1057 void VertexDialog::clear()
1061 modelUnregister(this);
1064 // ============================================================== setValue
1065 void VertexDialog::setValue(HEXA_NS::Vertex* v)
1068 name_le->setText( v->getName() );
1071 // x_spb->setValue( v->getX() );
1072 // y_spb->setValue( v->getY() );
1073 // z_spb->setValue( v->getZ() );
1074 x_spb->setText( QString::number(v->getX()) );
1075 y_spb->setText( QString::number(v->getY()) );
1076 z_spb->setText( QString::number(v->getZ()) );
1078 if ( getPatternDataSelectionModel() != NULL ){
1079 QModelIndex iv = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1081 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1082 name_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1087 // ============================================================== getValue
1088 HEXA_NS::Vertex* VertexDialog::getValue()
1094 // ============================================================== apply
1095 bool VertexDialog::apply(QModelIndex& result)
1097 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1100 if ( !getDocumentModel() ) return false;
1101 if ( !getPatternDataSelectionModel() ) return false;
1102 const PatternDataModel* patternDataModel = getPatternDataModel();
1103 if ( !patternDataModel ) return false;
1105 QModelIndex iVertex;
1107 QString xStr = x_spb->text();
1108 QString yStr = y_spb->text();
1109 QString zStr = z_spb->text();
1110 bool isOk = false, validArgs = !xStr.isEmpty() && !yStr.isEmpty() && !zStr.isEmpty();
1112 double newX, newY, newZ;
1115 newX = xStr.toDouble();
1116 newY = yStr.toDouble();
1117 newZ = zStr.toDouble();
1120 if ( _editMode == UPDATE_MODE && validArgs){
1121 QVariant v = property("QModelIndex");
1123 iVertex = patternDataModel->mapToSource( v.value<QModelIndex>() );
1124 if ( iVertex.isValid() )
1125 isOk = getDocumentModel()->updateVertex( iVertex, newX, newY, newZ );
1127 } else if ( _editMode == NEW_MODE && validArgs){
1128 iVertex = getDocumentModel()->addVertex( newX, newY, newZ );
1129 if ( iVertex.isValid() )
1133 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "VERTEX UPDATE/CONSTRUCTION" ) + "\n" + getErrorMsg() );
1137 QString newName = name_le->text();
1138 if ( !newName.isEmpty() )
1139 getDocumentModel()->setName( iVertex, newName );
1141 //the default name in the dialog box
1142 HEXA_NS::Vertex* v = getDocumentModel()->getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1144 updateDefaultName(name_le, v->getType());
1146 // to select/highlight result
1147 result = patternDataModel->mapFromSource(iVertex);
1152 // ------------------------- EDGE ----------------------------------
1154 // ============================================================== Constructeur
1155 EdgeDialog::EdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1156 HexaBaseDialog(parent, editmode, f),
1159 _helpFileName = "gui_edge.html";
1161 _initWidget(editmode);
1163 if ( editmode == INFO_MODE ){
1164 setWindowTitle( tr("Edge Information") );
1167 else if ( editmode == UPDATE_MODE ){
1168 setWindowTitle( tr("Edge Modification") );
1174 // ============================================================== Destructeur
1175 EdgeDialog::~EdgeDialog()
1180 // ============================================================== _initInputWidget
1181 void EdgeDialog::_initInputWidget( Mode editmode )
1184 QValidator *validator = new QRegExpValidator(rx, this);
1186 // setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1187 installEventFilter(this);
1189 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1190 name_le->installEventFilter(this);
1192 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1193 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1194 v0_le_rb0->setValidator( validator );
1195 v1_le_rb0->setValidator( validator );
1196 v0_le_rb0->installEventFilter(this);
1197 v1_le_rb0->installEventFilter(this);
1199 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1200 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1201 vex_le_rb1->setValidator( validator );
1202 vec_le_rb1->setValidator( validator );
1203 vex_le_rb1->installEventFilter(this);
1204 vec_le_rb1->installEventFilter(this);
1206 v0_le_rb0->setReadOnly(true);
1207 v1_le_rb0->setReadOnly(true);
1208 vex_le_rb1->setReadOnly(true);
1209 vec_le_rb1->setReadOnly(true);
1211 if (editmode == INFO_MODE)
1212 name_le->setReadOnly(true);
1216 // ============================================================== Clear
1217 void EdgeDialog::clear()
1222 modelUnregister(v0_le_rb0);
1225 modelUnregister(v1_le_rb0);
1227 vex_le_rb1->clear();
1228 modelUnregister(vex_le_rb1);
1230 vec_le_rb1->clear();
1231 modelUnregister(vec_le_rb1);
1233 modelUnregister(this);
1236 // ============================================================== setValue
1237 void EdgeDialog::setValue(HEXA_NS::Edge* e)
1239 HEXA_NS::Vertex* v0 = e->getVertex(0);
1240 HEXA_NS::Vertex* v1 = e->getVertex(1);
1242 name_le->setText( e->getName() );
1243 v0_le_rb0->setText( v0->getName() );
1244 v1_le_rb0->setText( v1->getName() );
1246 if ( getPatternDataSelectionModel() ){
1247 QModelIndex ie = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e) );
1248 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1249 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1251 name_le->setProperty( "QModelIndex", QVariant::fromValue(ie) );
1252 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1253 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1258 // ============================================================== getValue
1259 HEXA_NS::Edge* EdgeDialog::getValue()
1264 // ============================================================== apply
1265 bool EdgeDialog::apply(QModelIndex& result)
1267 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1270 if ( !getDocumentModel() ) return false;
1271 const PatternDataModel* patternDataModel = getPatternDataModel();
1272 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1273 if ( !patternDataModel /*|| !patternBuilderModel*/ ) return false;
1277 if ( rb0->isChecked() ){
1278 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1279 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1280 if ( iv0.isValid()&& iv1.isValid() ){
1281 iEdge = getDocumentModel()->addEdgeVertices( iv0, iv1 );
1283 } else if ( rb1->isChecked() ){
1284 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
1285 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb1] );
1286 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
1287 if ( ivex.isValid() && ivec.isValid() ){
1288 iEdge = getDocumentModel()->addEdgeVector( ivex, ivec );
1292 if ( !iEdge.isValid() ){
1293 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD EDGE" ) + "\n" + getErrorMsg() );
1296 _value = iEdge.model()->data(iEdge, HEXA_DATA_ROLE).value<HEXA_NS::Edge*>();
1298 QString newName = name_le->text();
1299 if ( !newName.isEmpty() )/*{*/
1300 getDocumentModel()->setName( iEdge, newName );
1302 //update the default name in the dialog box
1304 updateDefaultName(name_le, _value->getType());
1306 result = patternDataModel->mapFromSource(iEdge);
1311 // ------------------------- QUAD ----------------------------------
1313 // ============================================================== Constructeur
1314 QuadDialog::QuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1315 HexaBaseDialog(parent, editmode, f),
1318 _helpFileName = "gui_quadrangle.html";
1320 _initWidget(editmode);
1323 if ( editmode == INFO_MODE ){
1324 setWindowTitle( tr("Quad Information") );
1328 // ============================================================== Destructeur
1329 QuadDialog::~QuadDialog()
1333 // ============================================================== _initInputWidget
1334 void QuadDialog::_initInputWidget( Mode editmode )
1337 QValidator *validator = new QRegExpValidator(rx, this);
1339 installEventFilter(this);
1340 name_le->installEventFilter(this);
1342 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1343 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1344 v2_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1345 v3_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1347 v0_le_rb0->setValidator( validator );
1348 v1_le_rb0->setValidator( validator );
1349 v2_le_rb0->setValidator( validator );
1350 v3_le_rb0->setValidator( validator );
1351 v0_le_rb0->installEventFilter(this);
1352 v1_le_rb0->installEventFilter(this);
1353 v2_le_rb0->installEventFilter(this);
1354 v3_le_rb0->installEventFilter(this);
1356 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1357 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1358 e2_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1359 e3_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1361 e0_le_rb1->setValidator( validator );
1362 e1_le_rb1->setValidator( validator );
1363 e2_le_rb1->setValidator( validator );
1364 e3_le_rb1->setValidator( validator );
1366 e0_le_rb1->installEventFilter(this);
1367 e1_le_rb1->installEventFilter(this);
1368 e2_le_rb1->installEventFilter(this);
1369 e3_le_rb1->installEventFilter(this);
1371 v0_le_rb0->setReadOnly(true);
1372 v1_le_rb0->setReadOnly(true);
1373 v2_le_rb0->setReadOnly(true);
1374 v3_le_rb0->setReadOnly(true);
1376 e0_le_rb1->setReadOnly(true);
1377 e1_le_rb1->setReadOnly(true);
1378 e2_le_rb1->setReadOnly(true);
1379 e3_le_rb1->setReadOnly(true);
1381 if (editmode == INFO_MODE)
1382 name_le->setReadOnly(true);
1385 // ============================================================== clear
1386 void QuadDialog::clear()
1388 //Clear the dialog and unregister it from the model
1389 QModelIndex invalidIndex;
1394 modelUnregister(v0_le_rb0);
1397 modelUnregister(v1_le_rb0);
1400 modelUnregister(v2_le_rb0);
1403 modelUnregister(v3_le_rb0);
1406 modelUnregister(e0_le_rb1);
1409 modelUnregister(e1_le_rb1);
1412 modelUnregister(e2_le_rb1);
1415 modelUnregister(e3_le_rb1);
1417 modelUnregister(this);
1421 // ============================================================== setValue
1422 void QuadDialog::setValue(HEXA_NS::Quad* q)
1424 Q_ASSERT( q->countEdge() == 4 );
1425 Q_ASSERT( q->countVertex() == 4 );
1428 name_le->setText( q->getName() );
1431 HEXA_NS::Vertex* v0 = q->getVertex(0);
1432 HEXA_NS::Vertex* v1 = q->getVertex(1);
1433 HEXA_NS::Vertex* v2 = q->getVertex(2);
1434 HEXA_NS::Vertex* v3 = q->getVertex(3);
1436 v0_le_rb0->setText( v0->getName() );
1437 v1_le_rb0->setText( v1->getName() );
1438 v2_le_rb0->setText( v2->getName() );
1439 v3_le_rb0->setText( v3->getName() );
1443 HEXA_NS::Edge* e0 = q->getEdge(0);
1444 HEXA_NS::Edge* e1 = q->getEdge(1);
1445 HEXA_NS::Edge* e2 = q->getEdge(2);
1446 HEXA_NS::Edge* e3 = q->getEdge(3);
1448 e0_le_rb1->setText( e0->getName() );
1449 e1_le_rb1->setText( e1->getName() );
1450 e2_le_rb1->setText( e2->getName() );
1451 e3_le_rb1->setText( e3->getName() );
1453 if ( getPatternDataSelectionModel() ){
1454 QModelIndex iq = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(q) );
1456 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1457 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1458 QModelIndex iv2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v2) );
1459 QModelIndex iv3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v3) );
1461 QModelIndex ie0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e0) );
1462 QModelIndex ie1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e1) );
1463 QModelIndex ie2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e2) );
1464 QModelIndex ie3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e3) );
1466 name_le->setProperty( "QModelIndex", QVariant::fromValue(iq) );
1468 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1469 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1470 v2_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv2) );
1471 v3_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv3) );
1473 e0_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie0) );
1474 e1_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie1) );
1475 e2_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie2) );
1476 e3_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie3) );
1482 // ============================================================== getValue
1483 HEXA_NS::Quad* QuadDialog::getValue()
1489 // ============================================================== apply
1490 bool QuadDialog::apply(QModelIndex& result)
1492 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1495 if ( !getDocumentModel() ) return false;
1496 const PatternDataModel* patternDataModel = getPatternDataModel();
1497 if ( !patternDataModel ) return false;
1501 if ( rb0->isChecked() ){ //vertices
1502 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1503 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1504 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb0] );
1505 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb0] );
1511 iQuad = getDocumentModel()->addQuadVertices( iv0, iv1, iv2, iv3 );
1513 } else if ( rb1->isChecked() ){ //edges
1514 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
1515 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
1516 QModelIndex ie2 = patternDataModel->mapToSource( _index[e2_le_rb1] );
1517 QModelIndex ie3 = patternDataModel->mapToSource( _index[e3_le_rb1] );
1523 iQuad = getDocumentModel()->addQuadEdges( ie0, ie1, ie2, ie3 );
1527 if ( !iQuad.isValid() ){
1528 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD QUAD" ) + "\n" + getErrorMsg());
1531 _value = iQuad.model()->data(iQuad, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1533 QString newName = name_le->text();
1534 if ( !newName.isEmpty() )/*{*/
1535 getDocumentModel()->setName( iQuad, newName );
1537 //the default name in the dialog box
1539 updateDefaultName(name_le, _value->getType());
1541 // to select/highlight result
1542 result = patternDataModel->mapFromSource(iQuad);
1548 // ------------------------- HEXA ----------------------------------
1550 // ============================================================== HexaDialog
1552 HexaDialog::HexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1553 HexaBaseDialog(parent, editmode, f),
1556 _helpFileName = "gui_hexahedron.html";
1558 _initWidget(editmode);
1561 if ( editmode == INFO_MODE ){
1562 setWindowTitle( tr("Hexahedron Information") );
1563 quads_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
1564 vertices_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
1568 // ============================================================== Destructeur
1569 HexaDialog::~HexaDialog()
1573 // ============================================================== _initInputWidget
1574 void HexaDialog::_initInputWidget( Mode editmode )
1578 installEventFilter(this);
1579 name_le->installEventFilter(this);
1581 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
1582 quads_lw->installEventFilter(this);
1584 vertices_lw->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1585 vertices_lw->installEventFilter(this);
1587 if ( editmode != INFO_MODE ) {
1588 // delete item from listwidget
1589 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
1590 QShortcut* delVertexShortcut = new QShortcut( QKeySequence(Qt::Key_X), vertices_lw );
1591 delQuadShortcut->setContext( Qt::WidgetShortcut );
1592 delVertexShortcut->setContext( Qt::WidgetShortcut );
1593 connect(delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()));
1594 connect(delVertexShortcut, SIGNAL(activated()), this, SLOT(deleteVertexItem()));
1596 // highlight item on model view (VTK) from listwidget
1597 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1598 connect( vertices_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1600 if ( editmode != INFO_MODE)
1602 connect( vertices_rb, SIGNAL(clicked()), vertices_lw, SLOT(setFocus()));
1603 connect( quads_rb, SIGNAL(clicked()), quads_lw, SLOT(setFocus()));
1606 connect( vertices_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1607 connect( quads_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1609 if (editmode == INFO_MODE)
1610 name_le->setReadOnly(true);
1613 // ============================================================== clear
1614 void HexaDialog::clear()
1619 modelUnregister(quads_lw);
1621 vertices_lw->clear();
1622 modelUnregister(vertices_lw);
1624 modelUnregister(this);
1627 // ============================================================== getAssocsVTK
1629 * Returns elements currently associated to vtk
1631 QModelIndexList HexaDialog::getAssocsVTK()
1633 QModelIndexList assocs;
1634 QModelIndex iQuad, iVertex;
1635 QListWidgetItem* item = NULL;
1637 const PatternDataModel* patternDataModel = getPatternDataModel();
1638 if (patternDataModel == NULL) return assocs;
1639 if (quads_rb->isChecked())
1641 //ListWidget content
1642 int nbQuads = quads_lw->count();
1643 for ( int r = 0; r < nbQuads; ++r ){
1644 item = quads_lw->item(r);
1645 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1646 if ( iQuad.isValid() )
1651 else if (vertices_rb->isChecked())
1653 //ListWidget content
1654 int nbVertices = vertices_lw->count();
1655 for ( int r = 0; r < nbVertices; ++r ){
1656 item = vertices_lw->item(r);
1657 iVertex = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1658 if ( iVertex.isValid() )
1667 // ============================================================== updateButtonBox
1668 void HexaDialog::updateButtonBox()
1670 if ( _editMode == INFO_MODE )
1673 if ( quads_rb->isChecked() ){ // build from quads count() must be between [2,6]
1674 int nbQuads = quads_lw->count();
1675 if ( nbQuads >= 2 && nbQuads <= 6 ){
1676 _applyButton->setEnabled(true);
1678 _applyButton->setEnabled(false);
1680 } else if ( vertices_rb->isChecked() ){ // build from vertices count() must be equals to 8
1681 int nbVertices = vertices_lw->count();
1682 if ( nbVertices == 8 ){
1683 _applyButton->setEnabled(true);
1685 _applyButton->setEnabled(false);
1690 // ============================================================== deleteQuadItem
1691 void HexaDialog::deleteQuadItem()
1693 delete quads_lw->currentItem();
1697 // ============================================================== deleteVertexItem
1698 void HexaDialog::deleteVertexItem()
1700 delete vertices_lw->currentItem();
1704 // ============================================================== _setValueQuads
1705 void HexaDialog::_setValueQuads( HEXA_NS::Hexa* h )
1707 QListWidgetItem *qItem = NULL;
1708 HEXA_NS::Quad *q = NULL;
1710 if (getPatternDataSelectionModel() == NULL) return;
1712 for( int i = 0; i <= 5; ++i ){
1714 qIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(q)) );
1715 qItem = new QListWidgetItem( q->getName() );
1716 qItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(qIndex) );
1717 qItem->setData(LW_DATA_ROLE, qIndex.data(HEXA_DATA_ROLE));
1718 quads_lw->addItem( qItem );
1722 // ============================================================== _setValueVertices
1723 void HexaDialog::_setValueVertices( HEXA_NS::Hexa* h )
1725 QListWidgetItem *vItem = NULL;
1726 HEXA_NS::Vertex* v = NULL;
1728 if (getPatternDataSelectionModel() == NULL) return;
1729 vertices_lw->clear();
1730 for( int i = 0; i <= 7; ++i ){
1731 v = h->getVertex(i);
1732 vIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(v)) );
1733 vItem = new QListWidgetItem( v->getName() );
1734 vItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(vIndex) );
1735 vItem->setData(LW_DATA_ROLE, vIndex.data(HEXA_DATA_ROLE));
1736 vertices_lw->addItem( vItem );
1740 // ============================================================== setValue
1741 void HexaDialog::setValue(HEXA_NS::Hexa* h)
1744 name_le->setText( h->getName() );
1746 if ( getPatternDataSelectionModel()){
1747 QModelIndex hIndex = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(h) );
1748 _setValueVertices(h);
1750 name_le->setProperty( "QModelIndex", QVariant::fromValue(hIndex) );
1755 // ============================================================== getValue
1756 HEXA_NS::Hexa* HexaDialog::getValue()
1761 // ============================================================== apply
1762 bool HexaDialog::apply(QModelIndex& result)
1764 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1767 if ( !getDocumentModel() ) return false;
1768 const PatternDataModel* patternDataModel = getPatternDataModel();
1769 if ( !patternDataModel ) return false;
1773 QListWidget* currentLw = NULL;
1774 QListWidgetItem* item = NULL;
1776 if ( quads_rb->isChecked() )
1777 currentLw = dynamic_cast<QListWidget*>( quads_lw );
1778 else if ( vertices_rb->isChecked() )
1779 currentLw = dynamic_cast<QListWidget*>( vertices_lw );
1782 QModelIndexList iElts;
1783 int nbItems = currentLw->count();
1784 for ( int r = 0; r < nbItems; ++r){
1785 item = currentLw->item(r);
1786 iElt = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1787 if ( iElt.isValid() )
1791 nbItems = iElts.count();
1792 if ( quads_rb->isChecked() && (nbItems>=2 && nbItems<=6) ){ // build from quads iElts.count() should be between [2,6]
1793 iHexa = getDocumentModel()->addHexaQuads( iElts );
1794 } else if ( vertices_rb->isChecked() && nbItems== 8 ){ // build from vertices
1795 iHexa = getDocumentModel()->addHexaVertices( iElts[0], iElts[1], iElts[2], iElts[3],
1796 iElts[4], iElts[5], iElts[6], iElts[7] );
1799 if ( !iHexa.isValid() ){
1800 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD HEXA" ) + "\n" + getErrorMsg() );
1803 _value = iHexa.model()->data(iHexa, HEXA_DATA_ROLE).value<HEXA_NS::Hexa*>();
1805 QString newName = name_le->text();
1806 if ( !newName.isEmpty() )/*{*/
1807 getDocumentModel()->setName( iHexa, newName );
1809 //update the default name in the dialog box
1811 updateDefaultName(name_le, _value->getType());
1813 // to select/highlight result
1814 result = patternDataModel->mapFromSource(iHexa);
1820 // ------------------------- VECTOR ----------------------------------
1822 // ============================================================== Constructeur
1824 VectorDialog::VectorDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1825 HexaBaseDialog(parent, editmode, f),
1828 _helpFileName = "gui_vector.html";
1830 _initWidget(editmode);
1834 if ( editmode == INFO_MODE ){
1835 setWindowTitle( tr("Vector Information") );
1840 // ============================================================== Destructeur
1841 VectorDialog::~VectorDialog()
1845 // ============================================================== _initInputWidget
1846 void VectorDialog::_initInputWidget( Mode editmode )
1849 QValidator *validator = new QRegExpValidator(rx, this);
1851 installEventFilter(this);
1852 name_le->installEventFilter(this);
1854 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1855 v0_le_rb1->setValidator( validator );
1856 v0_le_rb1->installEventFilter(this);
1858 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1859 v1_le_rb1->setValidator( validator );
1860 v1_le_rb1->installEventFilter(this);
1862 if ( editmode == INFO_MODE ){
1863 name_le->setReadOnly(true);
1864 dx_spb_rb0->setReadOnly(true);
1865 dy_spb_rb0->setReadOnly(true);
1866 dz_spb_rb0->setReadOnly(true);
1869 v0_le_rb1->setReadOnly(true);
1870 v1_le_rb1->setReadOnly(true);
1873 // ============================================================== clear
1874 void VectorDialog::clear()
1878 modelUnregister(v0_le_rb1);
1881 modelUnregister(v1_le_rb1);
1883 modelUnregister(this);
1886 // ============================================================== setValue
1887 void VectorDialog::setValue(HEXA_NS::Vector* v)
1889 name_le->setText( v->getName() );
1890 dx_spb_rb0->setValue( v->getDx() );
1891 dy_spb_rb0->setValue( v->getDy() );
1892 dz_spb_rb0->setValue( v->getDz() );
1894 if ( getPatternDataSelectionModel() ){
1895 QModelIndex ivec = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1896 name_le->setProperty( "QModelIndex", QVariant::fromValue(ivec) );
1901 // ============================================================== getValue
1902 HEXA_NS::Vector* VectorDialog::getValue()
1907 // ============================================================== apply
1908 bool VectorDialog::apply(QModelIndex& result)
1910 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1913 if ( !getDocumentModel() ) return false;
1914 const PatternDataModel* patternDataModel = getPatternDataModel();
1915 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1916 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
1918 QModelIndex iVector;
1920 if ( rb0->isChecked() ){ //scalar
1921 double dx = dx_spb_rb0->value();
1922 double dy = dy_spb_rb0->value();
1923 double dz = dz_spb_rb0->value();
1925 iVector = getDocumentModel()->addVector( dx, dy, dz );
1926 } else if ( rb1->isChecked() ){ //vertices
1927 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
1928 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
1932 iVector = getDocumentModel()->addVectorVertices( iv0, iv1 );
1936 if ( !iVector.isValid() ){
1937 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD VECTOR" ) + "\n" + getErrorMsg());
1941 _value = iVector.model()->data(iVector, HEXA_DATA_ROLE).value<HEXA_NS::Vector *>();
1943 QString newName = name_le->text();
1944 if ( !newName.isEmpty() )/*{*/
1945 getDocumentModel()->setName( iVector, newName );
1947 //update the default name in the dialog box
1949 updateDefaultName(name_le, _value->getType());
1951 // to select/highlight result
1952 result = patternDataModel->mapFromSource(iVector);
1953 // result = patternBuilderModel->mapFromSource(iVector);
1958 // ------------------------- MakeGridDialog ----------------------------------
1959 // ============================================================== Constructeur
1961 MakeGridDialog::MakeGridDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
1962 : HexaBaseDialog(parent, editmode, f)
1965 _initWidget(editmode);
1968 _helpFileName = "creategrids.html#guicartgridsimple";
1969 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1970 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1971 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1973 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1974 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1975 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1977 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1978 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1979 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1982 // ============================================================== Destructeur
1983 MakeGridDialog::~MakeGridDialog()
1987 // ============================================================== _initInputWidget
1988 void MakeGridDialog::_initInputWidget( Mode editmode )
1990 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1991 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1992 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1993 vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1995 center_le->setReadOnly(true);
1996 axis_le->setReadOnly(true);
1997 base_le->setReadOnly(true);
1998 vec_le->setReadOnly(true);
2000 installEventFilter(this);
2001 center_le->installEventFilter(this);
2002 axis_le->installEventFilter(this);
2003 base_le->installEventFilter(this);
2004 vec_le->installEventFilter(this);
2006 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2007 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2009 angle_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(angle_lw));
2010 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2012 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2013 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2015 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2016 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2018 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2019 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2021 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2022 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2025 // ============================================================== clear
2026 void MakeGridDialog::clear()
2029 modelUnregister(center_le);
2032 modelUnregister(axis_le);
2035 modelUnregister(base_le);
2038 modelUnregister(vec_le);
2040 modelUnregister(this);
2043 // ============================================================== updateHelpFileName
2044 void MakeGridDialog::updateHelpFileName()
2046 if ( sender() == rb0 ){
2047 _helpFileName = "creategrids.html#guicartgridsimple";
2048 } else if ( sender() == rb1 ){
2049 _helpFileName = "creategrids.html#guicartgriduniform";
2050 } else if ( sender() == rb2 ){
2051 _helpFileName = "creategrids.html#guicartgridcustom";
2055 // ============================================================== addRadiusItem
2056 void MakeGridDialog::addRadiusItem()
2058 QListWidgetItem* previousItem = radius_lw->currentItem();
2059 QListWidgetItem* newItem = new QListWidgetItem();
2061 double defaultValue = 1.;
2063 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2065 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2066 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2067 radius_lw->addItem(newItem);
2070 // ============================================================== delRadiusItem
2071 void MakeGridDialog::delRadiusItem()
2073 delete radius_lw->currentItem();
2076 // ============================================================== addAngleItem
2077 void MakeGridDialog::addAngleItem()
2079 QListWidgetItem* previousItem = angle_lw->currentItem();
2080 QListWidgetItem* newItem = new QListWidgetItem();
2082 double defaultValue = 1.;
2084 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2086 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2087 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2088 angle_lw->addItem(newItem);
2091 // ============================================================== delAngleItem
2092 void MakeGridDialog::delAngleItem()
2094 delete angle_lw->currentItem();
2097 // ============================================================== addHeightItem
2098 void MakeGridDialog::addHeightItem()
2100 QListWidgetItem* previousItem = height_lw->currentItem();
2101 QListWidgetItem* newItem = new QListWidgetItem();
2103 double defaultValue = 1.;
2105 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2107 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2108 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2109 height_lw->addItem(newItem);
2112 // ============================================================== delHeightItem
2113 void MakeGridDialog::delHeightItem()
2115 delete height_lw->currentItem();
2118 // ============================================================== apply
2119 bool MakeGridDialog::apply(QModelIndex& result)
2121 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2124 DocumentModel* docModel = getDocumentModel();
2125 PatternDataModel* patternDataModel = getPatternDataModel();
2126 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2128 QModelIndex iNewElts;
2129 if ( rb0->isChecked() )
2131 long nx = nx_spb->value();
2132 long ny = ny_spb->value();
2133 long nz = nz_spb->value();
2134 iNewElts = docModel->makeCartesianTop(nx, ny, nz);
2136 else if ( rb1->isChecked() )
2138 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2139 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2140 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2141 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le] );
2142 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2143 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2144 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2146 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2148 double lx = lx_spb->value();
2149 double ly = ly_spb->value();
2150 double lz = lz_spb->value();
2151 double nx = nx_spb->value();
2152 double ny = ny_spb->value();
2153 double nz = nz_spb->value();
2155 iNewElts = docModel->makeCartesianUni( icenter, ibase, ivec, iaxis,
2156 lx, ly, lz, nx, ny, nz);
2159 } else if ( rb2->isChecked() )
2161 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2162 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2163 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2164 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le] );
2165 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2166 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2167 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2169 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2171 QListWidgetItem* item = NULL;
2173 vector<double> radius;
2174 vector<double> angles;
2175 vector<double> heights;
2177 // double somme = 0.;
2178 int nbAngles = angle_lw->count();
2179 for ( int r = 0; r < nbAngles; ++r){
2180 item = angle_lw->item(r);
2181 double itemValue = item->data(Qt::EditRole).toDouble();
2182 angles.push_back(itemValue);
2183 // somme += itemValue;
2185 // if (somme > 360.01)
2187 // SUIT_MessageBox::information( 0,
2189 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2193 int nbRadius = radius_lw->count();
2194 for ( int r = 0; r < nbRadius; ++r){
2195 item = radius_lw->item(r);
2196 radius.push_back(item->data(Qt::EditRole).toDouble());
2199 int nbHeight = height_lw->count();
2200 for ( int r = 0; r < nbHeight; ++r){
2201 item = height_lw->item(r);
2202 heights.push_back(item->data(Qt::EditRole).toDouble());
2205 iNewElts = docModel->makeCartesian( icenter, ibase, ivec, iaxis,
2206 radius, angles, heights);
2210 if ( !iNewElts.isValid() )
2212 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE GRID" ) + "\n" + getErrorMsg() );
2216 result = patternDataModel->mapFromSource(iNewElts);
2217 // result = patternBuilderModel->mapFromSource( iNewElts );
2222 // ============================================================== Constructeur
2224 MakeCylinderDialog::MakeCylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2225 : HexaBaseDialog(parent, editmode, f)
2228 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinder";
2229 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2230 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2231 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2232 _initWidget(editmode);
2237 // ============================================================== Destructeur
2238 MakeCylinderDialog::~MakeCylinderDialog()
2242 void MakeCylinderDialog::_initInputWidget( Mode editmode )
2244 installEventFilter(this);
2246 rb0->installEventFilter(this);
2247 rb1->installEventFilter(this);
2248 rb2->installEventFilter(this);
2250 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
2251 origin_le->installEventFilter(this);
2252 origin_le->setReadOnly(true);
2254 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2255 axis_le->installEventFilter(this);
2256 axis_le->setReadOnly(true);
2258 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE));
2259 base_le->installEventFilter(this);
2260 base_le->setReadOnly(true);
2262 ext_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2263 ext_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2264 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2265 ext_radius_spb->installEventFilter(this);
2267 int_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2268 int_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2269 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2270 int_radius_spb->installEventFilter(this);
2272 angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2273 angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2274 angle_spb->setProperty("Angle", QVariant::fromValue(true));
2275 angle_spb->installEventFilter(this);
2277 height_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2278 height_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2279 height_spb->setProperty("Length", QVariant::fromValue(true));
2280 height_spb->installEventFilter(this);
2282 radius_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2283 radius_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2284 radius_lw->setProperty("Radius", QVariant::fromValue(true));
2285 radius_lw->installEventFilter(this);
2288 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2289 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2290 angle_lw->setProperty("Angle", QVariant::fromValue(true));
2291 angle_lw->installEventFilter(this);
2293 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2294 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2295 height_lw->setProperty("Length", QVariant::fromValue(true));
2296 height_lw->installEventFilter(this);
2298 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2299 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2301 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2302 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2304 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2305 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2307 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2308 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2310 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2311 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2313 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2314 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2317 // ============================================================== updateHelpFileName
2318 void MakeCylinderDialog::updateHelpFileName()
2320 if ( sender() == rb0 ){
2321 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindersimple";
2322 } else if ( sender() == rb1 ){
2323 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinderuniform";
2324 } else if ( sender() == rb2 ){
2325 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindercustom";
2329 // ============================================================== addRadiusItem
2330 void MakeCylinderDialog::addRadiusItem()
2332 QListWidgetItem* previousItem = radius_lw->currentItem();
2333 QListWidgetItem* newItem = new QListWidgetItem();
2335 double defaultValue = 1.;
2337 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2339 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2340 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2341 radius_lw->addItem(newItem);
2344 // ============================================================== delRadiusItem
2345 void MakeCylinderDialog::delRadiusItem()
2347 delete radius_lw->currentItem();
2350 // ============================================================== addAngleItem
2351 void MakeCylinderDialog::addAngleItem()
2353 QListWidgetItem* previousItem = angle_lw->currentItem();
2354 QListWidgetItem* newItem = new QListWidgetItem();
2356 double defaultValue = 180.;
2358 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2360 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2361 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2362 angle_lw->addItem(newItem);
2365 // ============================================================== delAngleItem
2366 void MakeCylinderDialog::delAngleItem()
2368 delete angle_lw->currentItem();
2371 // ============================================================== addHeightItem
2372 void MakeCylinderDialog::addHeightItem()
2374 QListWidgetItem* previousItem = height_lw->currentItem();
2375 QListWidgetItem* newItem = new QListWidgetItem();
2377 double defaultValue = 1.;
2379 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2381 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2382 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2383 height_lw->addItem(newItem);
2386 // ============================================================== delHeightItem
2387 void MakeCylinderDialog::delHeightItem()
2389 delete height_lw->currentItem();
2392 // ============================================================== clear
2393 void MakeCylinderDialog::clear()
2396 modelUnregister(origin_le);
2399 modelUnregister(axis_le);
2402 modelUnregister(base_le);
2404 modelUnregister(this);
2407 // ============================================================== apply
2408 bool MakeCylinderDialog::apply(QModelIndex& result)
2410 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2413 DocumentModel* docModel = getDocumentModel();
2414 PatternDataModel* patternDataModel = getPatternDataModel();
2415 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2417 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2418 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2419 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2420 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2421 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2422 double rext = ext_radius_spb->value();
2423 double rint = int_radius_spb->value();
2424 double angle = angle_spb->value();
2425 double height = height_spb->value();
2426 double nr = nr_spb->value();
2427 double na = na_spb->value();
2428 double nh = nh_spb->value();
2431 if (rb0->isChecked())
2432 iElts = docModel->makeCylinderTop(nr, na, nh);
2433 else if (rb1->isChecked())
2435 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2436 iElts = docModel->makeCylinderUni(iorigin, ibase, iaxis, rint,
2437 rext, angle, height, nr, na, nh);
2439 else if (rb2->isChecked())
2441 QListWidgetItem* item = NULL;
2443 vector<double> radius;
2444 vector<double> angles;
2445 vector<double> heights;
2447 // double somme = 0.;
2448 int nbAngles = angle_lw->count();
2449 for ( int r = 0; r < nbAngles; ++r){
2450 item = angle_lw->item(r);
2451 double itemValue = item->data(Qt::EditRole).toDouble();
2452 angles.push_back(itemValue);
2453 // somme += itemValue;
2455 // if (somme > 360.01)
2457 // SUIT_MessageBox::information( 0,
2459 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2463 int nbRadius = radius_lw->count();
2464 for ( int r = 0; r < nbRadius; ++r){
2465 item = radius_lw->item(r);
2466 radius.push_back(item->data(Qt::EditRole).toDouble());
2469 int nbHeight = height_lw->count();
2470 for ( int r = 0; r < nbHeight; ++r){
2471 item = height_lw->item(r);
2472 heights.push_back(item->data(Qt::EditRole).toDouble());
2475 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2476 iElts = docModel->makeCylinder( iorigin, ibase, iaxis, radius, angles, heights);
2480 if ( !iElts.isValid() ){
2481 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDER" ) + "\n" + getErrorMsg() );
2485 result = patternDataModel->mapFromSource(iElts);
2486 // result = patternBuilderModel->mapFromSource(iElts);
2491 //---------------------------------- MakePipeDialog -----------------------------
2492 // ============================================================== Constructeur
2494 MakePipeDialog::MakePipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2495 : HexaBaseDialog(parent, editmode, f)
2498 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipe";
2499 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2500 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2501 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2502 _initWidget(editmode);
2506 // ============================================================== Destructeur
2507 MakePipeDialog::~MakePipeDialog()
2511 // ============================================================== _initInputWidget
2512 void MakePipeDialog::_initInputWidget( Mode editmode )
2514 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2515 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2516 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2518 installEventFilter(this);
2519 origin_le->installEventFilter(this);
2520 axis_le->installEventFilter(this);
2521 base_le->installEventFilter(this);
2523 rb0->installEventFilter(this);
2524 rb1->installEventFilter(this);
2525 rb2->installEventFilter(this);
2527 origin_le->setReadOnly(true);
2528 axis_le->setReadOnly(true);
2529 base_le->setReadOnly(true);
2531 ext_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2532 ext_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2533 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2534 ext_radius_spb->installEventFilter(this);
2536 int_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2537 int_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2538 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2539 int_radius_spb->installEventFilter(this);
2541 angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2542 angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2543 angle_spb->setProperty("Angle", QVariant::fromValue(true));
2544 angle_spb->installEventFilter(this);
2546 height_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2547 height_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2548 height_spb->setProperty("Length", QVariant::fromValue(true));
2549 height_spb->installEventFilter(this);
2551 radius_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2552 radius_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2553 radius_lw->setProperty("Radius", QVariant::fromValue(true));
2554 radius_lw->installEventFilter(this);
2556 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2557 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2558 angle_lw->setProperty("Angle", QVariant::fromValue(true));
2559 angle_lw->installEventFilter(this);
2561 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2562 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2563 height_lw->setProperty("Length", QVariant::fromValue(true));
2564 height_lw->installEventFilter(this);
2566 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2567 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2569 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2570 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2572 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2573 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2575 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2576 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2578 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2579 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2581 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2582 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2586 // ============================================================== updateHelpFileName
2587 void MakePipeDialog::updateHelpFileName()
2589 if ( sender() == rb0 ){
2590 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipesimple";
2591 } else if ( sender() == rb1 ){
2592 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipeuniform";
2593 } else if ( sender() == rb2 ){
2594 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipecustom";
2598 // ============================================================== addRadiusItem
2599 void MakePipeDialog::addRadiusItem()
2601 QListWidgetItem* previousItem = radius_lw->currentItem();
2602 QListWidgetItem* newItem = new QListWidgetItem();
2604 double defaultValue = 1.;
2606 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2608 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2609 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2610 radius_lw->addItem(newItem);
2613 // ============================================================== delRadiusItem
2614 void MakePipeDialog::delRadiusItem()
2616 delete radius_lw->currentItem();
2619 // ============================================================== addAngleItem
2620 void MakePipeDialog::addAngleItem()
2622 QListWidgetItem* previousItem = angle_lw->currentItem();
2623 QListWidgetItem* newItem = new QListWidgetItem();
2625 double defaultValue = 180.;
2627 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2629 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2630 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2631 angle_lw->addItem(newItem);
2634 // ============================================================== delAngleItem
2635 void MakePipeDialog::delAngleItem()
2637 delete angle_lw->currentItem();
2640 // ============================================================== addHeightItem
2641 void MakePipeDialog::addHeightItem()
2643 QListWidgetItem* previousItem = height_lw->currentItem();
2644 QListWidgetItem* newItem = new QListWidgetItem();
2646 double defaultValue = 1.;
2648 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2650 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2651 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2652 height_lw->addItem(newItem);
2655 // ============================================================== delHeightItem
2656 void MakePipeDialog::delHeightItem()
2658 delete height_lw->currentItem();
2661 // ============================================================== clear
2662 void MakePipeDialog::clear()
2665 modelUnregister(origin_le);
2668 modelUnregister(axis_le);
2671 modelUnregister(base_le);
2673 modelUnregister(this);
2676 // ============================================================== apply
2677 bool MakePipeDialog::apply(QModelIndex& result)
2679 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2682 DocumentModel* docModel = getDocumentModel();
2683 PatternDataModel* patternDataModel = getPatternDataModel();
2684 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2686 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2687 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2688 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2689 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2690 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2691 double rext = ext_radius_spb->value();
2692 double rint = int_radius_spb->value();
2693 double angle = angle_spb->value();
2694 double height = height_spb->value();
2695 int nr = nr_spb->value();
2696 int na = na_spb->value();
2697 int nh = nh_spb->value();
2701 if (rb0->isChecked())
2702 iElts = docModel->makePipeTop(nr, na, nh);
2703 else if (rb1->isChecked())
2705 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2706 iElts = docModel->makePipeUni(iorigin, ibase, iaxis, rint, rext, angle, height,
2709 else if (rb2->isChecked())
2711 QListWidgetItem* item = NULL;
2713 vector<double> radius;
2714 vector<double> angles;
2715 vector<double> heights;
2717 // double somme = 0.;
2718 int nbAngles = angle_lw->count();
2719 for ( int r = 0; r < nbAngles; ++r){
2720 item = angle_lw->item(r);
2721 double itemValue = item->data(Qt::EditRole).toDouble();
2722 angles.push_back(itemValue);
2723 // somme += itemValue;
2725 // if (somme > 360.01)
2727 // SUIT_MessageBox::information( 0,
2729 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2733 int nbRadius = radius_lw->count();
2734 for ( int r = 0; r < nbRadius; ++r){
2735 item = radius_lw->item(r);
2736 radius.push_back(item->data(Qt::EditRole).toDouble());
2739 int nbHeight = height_lw->count();
2740 for ( int r = 0; r < nbHeight; ++r){
2741 item = height_lw->item(r);
2742 heights.push_back(item->data(Qt::EditRole).toDouble());
2744 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2745 iElts = docModel->makePipe( iorigin, ibase, iaxis, radius, angles, heights );
2748 if ( !iElts.isValid() ){
2749 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPE" ) + "\n" + getErrorMsg() );
2753 // to select/highlight result
2754 result = patternDataModel->mapFromSource(iElts);
2755 // result = patternBuilderModel->mapFromSource(iElts);
2760 //---------------------------------- MakeCylindersDialog -----------------------------
2761 // ============================================================== Constructeur
2763 MakeCylindersDialog::MakeCylindersDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2764 : HexaBaseDialog(parent, editmode, f)
2766 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinders";
2768 _initWidget(editmode);
2771 // ============================================================== Destructeur
2772 MakeCylindersDialog::~MakeCylindersDialog()
2776 void MakeCylindersDialog::_initInputWidget( Mode editmode )
2778 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2779 center2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2780 direction_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2781 direction2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2783 radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2784 radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2785 radius_spb->setProperty("Radius", QVariant::fromValue(true));
2786 radius_spb->installEventFilter(this);
2788 height_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2789 height_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2790 height_spb->setProperty("Length", QVariant::fromValue(true));
2791 height_spb->installEventFilter(this);
2793 radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2794 radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2795 radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2796 radius2_spb->installEventFilter(this);
2798 height2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2799 height2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2800 height2_spb->setProperty("Length", QVariant::fromValue(true));
2801 height2_spb->installEventFilter(this);
2803 installEventFilter(this);
2804 center_le->installEventFilter(this);
2805 center2_le->installEventFilter(this);
2806 direction_le->installEventFilter(this);
2807 direction2_le->installEventFilter(this);
2809 center_le->setReadOnly(true);
2810 center2_le->setReadOnly(true);
2811 direction_le->setReadOnly(true);
2812 direction2_le->setReadOnly(true);
2815 // ============================================================== clear
2816 void MakeCylindersDialog::clear()
2819 modelUnregister(center_le);
2821 center2_le->clear();
2822 modelUnregister(center2_le);
2824 direction_le->clear();
2825 modelUnregister(direction_le);
2827 direction2_le->clear();
2828 modelUnregister(direction2_le);
2830 modelUnregister(this);
2833 // ============================================================== apply
2834 bool MakeCylindersDialog::apply(QModelIndex& result)
2836 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2839 DocumentModel* docModel = getDocumentModel();
2840 PatternDataModel* patternDataModel = getPatternDataModel();
2841 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2844 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2845 QModelIndex icenter2 = patternDataModel->mapToSource( _index[center2_le] );
2846 QModelIndex idir = patternDataModel->mapToSource( _index[direction_le] );
2847 QModelIndex idir2 = patternDataModel->mapToSource( _index[direction2_le] );
2848 // QModelIndex idir = patternBuilderModel->mapToSource( _index[direction_le] );
2849 // QModelIndex idir2 = patternBuilderModel->mapToSource( _index[direction2_le] );
2851 if ( icenter.isValid() && icenter2.isValid() && idir.isValid() && idir2.isValid()){
2852 double r1 = radius_spb->value();
2853 double h1 = height_spb->value();
2854 double r2 = radius2_spb->value();
2855 double h2 = height2_spb->value();
2856 iElts = docModel->makeCylinders( icenter, idir, r1, h1, icenter2, idir2, r2, h2 );
2859 if ( !iElts.isValid() ){
2860 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDERS" ) + "\n" + getErrorMsg() );
2864 result = patternDataModel->mapFromSource(iElts);
2865 // result = patternBuilderModel->mapFromSource(iElts);
2870 //---------------------------------- MakePipesDialog -----------------------------
2871 // ============================================================== Constructeur
2873 MakePipesDialog::MakePipesDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2874 : HexaBaseDialog(parent, editmode, f)
2876 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipes";
2878 _initWidget(editmode);
2881 // ============================================================== Destructeur
2882 MakePipesDialog::~MakePipesDialog()
2886 // ============================================================== _initInputWidget
2887 void MakePipesDialog::_initInputWidget( Mode editmode )
2889 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2890 origin2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2891 dir_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2892 dir2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2894 ext_radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2895 ext_radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2896 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2897 ext_radius_spb->installEventFilter(this);
2899 int_radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2900 int_radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2901 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2902 int_radius_spb->installEventFilter(this);
2904 height_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2905 height_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2906 height_spb->setProperty("Length", QVariant::fromValue(true));
2907 height_spb->installEventFilter(this);
2909 ext_radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2910 ext_radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2911 ext_radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2912 ext_radius2_spb->installEventFilter(this);
2914 int_radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2915 int_radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2916 int_radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2917 int_radius2_spb->installEventFilter(this);
2919 height2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2920 height2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2921 height2_spb->setProperty("Length", QVariant::fromValue(true));
2922 height2_spb->installEventFilter(this);
2924 origin_le->installEventFilter(this);
2925 origin2_le->installEventFilter(this);
2926 dir_le->installEventFilter(this);
2927 dir2_le->installEventFilter(this);
2929 origin_le->setReadOnly(true);
2930 origin2_le->setReadOnly(true);
2931 dir_le->setReadOnly(true);
2932 dir2_le->setReadOnly(true);
2935 // ============================================================== clear
2936 void MakePipesDialog::clear()
2939 modelUnregister(origin_le);
2941 origin2_le->clear();
2942 modelUnregister(origin2_le);
2945 modelUnregister(dir_le);
2948 modelUnregister(dir2_le);
2950 modelUnregister(this);
2953 // ============================================================== apply
2954 bool MakePipesDialog::apply(QModelIndex& result)
2956 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2959 DocumentModel* docModel = getDocumentModel();
2960 PatternDataModel* patternDataModel = getPatternDataModel();
2961 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2963 QModelIndex iorigin1 = patternDataModel->mapToSource( _index[origin_le] );
2964 QModelIndex iorigin2 = patternDataModel->mapToSource( _index[origin2_le] );
2965 QModelIndex idir1 = patternDataModel->mapToSource( _index[dir_le] );
2966 QModelIndex idir2 = patternDataModel->mapToSource( _index[dir2_le] );
2967 // QModelIndex idir1 = patternBuilderModel->mapToSource( _index[dir_le] );
2968 // QModelIndex idir2 = patternBuilderModel->mapToSource( _index[dir2_le] );
2969 double rint1 = int_radius_spb->value();
2970 double rext1 = ext_radius_spb->value();
2971 double height1 = height_spb->value();
2972 double rint2 = int_radius2_spb->value();
2973 double rext2 = ext_radius2_spb->value();
2974 double height2 = height_spb->value();
2978 if ( iorigin1.isValid() && iorigin2.isValid() && idir1.isValid() && idir2.isValid())
2979 iElts = docModel->makePipes( iorigin1, idir1, rint1, rext1, height1,
2980 iorigin2, idir2, rint2, rext2, height2);
2982 if ( !iElts.isValid() ){
2983 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPES" ) + "\n" + getErrorMsg() );
2987 result = patternDataModel->mapFromSource(iElts);
2988 // result = patternBuilderModel->mapFromSource(iElts);
2993 //---------------------------------- RemoveHexaDialog -----------------------------
2994 // ============================================================== Constructeur
2996 RemoveHexaDialog::RemoveHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2997 : HexaBaseDialog(parent, editmode, f)
2999 _helpFileName = "gui_remove.html";
3001 _initWidget(editmode);
3004 // ============================================================== Destructeur
3005 RemoveHexaDialog::~RemoveHexaDialog()
3009 // ============================================================== _initInputWidget
3010 void RemoveHexaDialog::_initInputWidget( Mode editmode )
3013 QValidator *validator = new QRegExpValidator(rx, this);
3015 hexa_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3016 hexa_le->setValidator( validator );
3017 hexa_le->installEventFilter(this);
3018 hexa_le->setReadOnly(true);
3019 autoFocusSwitch = false;
3022 // ============================================================== clear
3023 void RemoveHexaDialog::clear()
3026 modelUnregister(hexa_le);
3028 modelUnregister(this);
3031 // ============================================================== apply
3032 bool RemoveHexaDialog::apply(QModelIndex& result)
3034 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3037 if ( !getDocumentModel() ) return false;
3038 const PatternDataModel* patternDataModel = getPatternDataModel();
3039 if ( !patternDataModel ) return false;
3041 QModelIndex ihexa = patternDataModel->mapToSource( _index[hexa_le] );
3043 bool removed = false;
3044 if ( ihexa.isValid() ){
3045 if ( connected_cb->isChecked() ){
3046 removed = getDocumentModel()->removeConnectedHexa( ihexa );
3048 removed = getDocumentModel()->removeHexa( ihexa );
3052 if ( removed == false ){
3053 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE HEXA" ) + "\n" + getErrorMsg() );
3062 //---------------------------------- PrismQuadDialog -----------------------------
3063 // ============================================================== Constructeur
3065 PrismQuadDialog::PrismQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3066 : HexaBaseDialog(parent, editmode, f)
3069 _helpFileName = "gui_prism_join_quad.html#guiextrudequads";
3070 connect( extrudeTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3071 connect( extrudeUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3072 connect( extrude_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3073 _initWidget(editmode);
3074 extrudeTop_rb->click();
3077 // ============================================================== Destructeur
3078 PrismQuadDialog::~PrismQuadDialog()
3082 // ============================================================== getAssocsVTK
3084 * Returns elements currently associated to vtk
3086 QModelIndexList PrismQuadDialog::getAssocsVTK()
3088 QModelIndexList assocs;
3090 QListWidgetItem* item = NULL;
3092 //ListWidget content
3093 const PatternDataModel* patternDataModel = getPatternDataModel();
3094 if ( !patternDataModel ) return assocs;
3095 int nbQuads = quads_lw->count();
3096 for ( int r = 0; r < nbQuads; ++r ){
3097 item = quads_lw->item(r);
3098 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3099 if ( iQuad.isValid() )
3105 // ============================================================== _initInputWidget
3106 void PrismQuadDialog::_initInputWidget( Mode editmode )
3108 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3109 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3111 length_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3112 length_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3113 length_spb->setProperty("Length", QVariant::fromValue(true));
3114 length_spb->installEventFilter(this);
3117 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3118 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3119 height_lw->setProperty("Length", QVariant::fromValue(true));
3120 height_lw->installEventFilter(this);
3122 installEventFilter(this);
3123 quads_lw->installEventFilter(this);
3124 axis_le->installEventFilter(this);
3126 extrudeTop_rb->installEventFilter(this);
3127 extrudeUni_rb->installEventFilter(this);
3128 extrude_rb->installEventFilter(this);
3130 axis_le->setReadOnly(true);
3132 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3133 delQuadShortcut->setContext( Qt::WidgetShortcut );
3134 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3135 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3137 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3138 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3139 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3140 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3143 // ============================================================== updateHelpFileName
3144 void PrismQuadDialog::updateHelpFileName()
3146 if ( sender() == extrudeTop_rb ){
3147 _helpFileName = "gui_prism_join_quad.html#guiextrudequadssimple";
3148 } else if ( sender() == extrudeUni_rb ){
3149 _helpFileName = "gui_prism_join_quad.html#guiextrudequadsuniform";
3150 } else if ( sender() == extrude_rb ){
3151 _helpFileName = "gui_prism_join_quad.html#guiextrudequadscustom";
3155 // ============================================================== clear
3156 void PrismQuadDialog::clear()
3159 modelUnregister(quads_lw);
3162 modelUnregister(axis_le);
3164 modelUnregister(this);
3167 // ============================================================== removeQuad
3168 void PrismQuadDialog::removeQuad()
3170 QListWidgetItem *item = quads_lw->currentItem();
3173 int r = quads_lw->row(item);
3174 quads_lw->takeItem(r);
3179 // ============================================================== addHeightItem
3180 void PrismQuadDialog::addHeightItem()
3182 QListWidgetItem* previousItem = height_lw->currentItem();
3183 QListWidgetItem* newItem = new QListWidgetItem();
3185 double defaultValue = 1.;
3187 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3189 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3190 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3191 height_lw->addItem(newItem);
3194 // ============================================================== delHeightItem
3195 void PrismQuadDialog::delHeightItem()
3197 delete height_lw->currentItem();
3200 // ============================================================== apply
3201 bool PrismQuadDialog::apply(QModelIndex& result)
3203 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3206 DocumentModel* docModel = getDocumentModel();
3207 PatternDataModel* patternDataModel = getPatternDataModel();
3208 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3210 QModelIndexList iquads = getIndexList(quads_lw);
3211 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
3212 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
3213 double length = length_spb->value();
3214 int nb = nb_spb->value();
3216 vector<double> heights;
3217 QListWidgetItem* item = NULL;
3218 int nbItems = height_lw->count();
3220 for ( int r = 0; r < nbItems; ++r){
3221 item = height_lw->item(r);
3222 heights.push_back( item->data(Qt::EditRole).toDouble() );
3226 int nbQuads = iquads.count();
3228 if (nbQuads == 1 && iquads[0].isValid())
3230 if (extrudeTop_rb->isChecked())
3231 iElts = docModel->extrudeQuadTop(iquads[0], nb);
3232 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3233 iElts = docModel->extrudeQuadUni(iquads[0], iaxis, length, nb);
3234 else if (extrude_rb->isChecked() && iaxis.isValid())
3235 iElts = docModel->extrudeQuad(iquads[0], iaxis, heights);
3237 else if (nbQuads > 1)
3239 if (extrudeTop_rb->isChecked())
3240 iElts = docModel->extrudeQuadsTop(iquads, nb);
3241 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3242 iElts = docModel->extrudeQuadsUni(iquads, iaxis, length, nb);
3243 else if (extrude_rb->isChecked() && iaxis.isValid())
3244 iElts = docModel->extrudeQuads(iquads, iaxis, heights);
3247 if ( !iElts.isValid() ){
3248 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PRISM QUAD(S)" ) + "\n" + getErrorMsg() );
3252 result = patternDataModel->mapFromSource(iElts);
3253 // result = patternBuilderModel->mapFromSource(iElts);
3258 //---------------------------------- JoinQuadDialog -----------------------------
3259 // ============================================================== Constructeur
3261 JoinQuadDialog::JoinQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3262 : HexaBaseDialog(parent, editmode, f)
3265 _helpFileName = "gui_prism_join_quad.html#guijoinquads";
3266 connect( joinUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3267 connect( join_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3268 _initWidget(editmode);
3269 joinUni_rb->click();
3272 // ============================================================== Destructeur
3273 JoinQuadDialog::~JoinQuadDialog()
3277 // ============================================================== getAssocsVTK
3279 * Returns elements currently associated to vtk
3281 QModelIndexList JoinQuadDialog::getAssocsVTK()
3283 QModelIndexList assocs;
3285 QListWidgetItem* item = NULL;
3287 if (getPatternDataSelectionModel() == NULL) return assocs;
3289 //ListWidget content
3290 const PatternDataModel* patternDataModel = getPatternDataModel();
3291 if ( !patternDataModel ) return assocs;
3292 int nbQuads = quads_lw->count();
3293 for ( int r = 0; r < nbQuads; ++r ){
3294 item = quads_lw->item(r);
3295 // iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
3296 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
3297 if ( iQuad.isValid() ) assocs << iQuad;
3302 // ============================================================== _initInputWidget
3303 void JoinQuadDialog::_initInputWidget( Mode editmode )
3305 quad_dest_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3306 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3307 vex0_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3308 vex1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3309 vex2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3310 vex3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3312 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3313 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3314 height_lw->setProperty("Length", QVariant::fromValue(true));
3315 height_lw->installEventFilter(this);
3317 installEventFilter(this);
3318 quad_dest_le->installEventFilter(this);
3319 quads_lw->installEventFilter(this);
3320 vex0_le->installEventFilter(this);
3321 vex1_le->installEventFilter(this);
3322 vex2_le->installEventFilter(this);
3323 vex3_le->installEventFilter(this);
3325 joinUni_rb->installEventFilter(this);
3326 join_rb->installEventFilter(this);
3328 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3329 delQuadShortcut->setContext( Qt::WidgetShortcut );
3330 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3332 quad_dest_le->setReadOnly(true);
3333 vex0_le->setReadOnly(true);
3334 vex1_le->setReadOnly(true);
3335 vex2_le->setReadOnly(true);
3336 vex3_le->setReadOnly(true);
3338 _currentObj = quads_lw;
3339 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3340 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3342 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3344 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3345 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3348 // ============================================================== updateHelpFileName
3349 void JoinQuadDialog::updateHelpFileName()
3351 if ( sender() == joinUni_rb ){
3352 _helpFileName = "gui_prism_join_quad.html#guijoinquadsuniform";
3353 } else if ( sender() == join_rb ){
3354 _helpFileName = "gui_prism_join_quad.html#guijoinquadscustom";
3358 // ============================================================== addHeightItem
3359 void JoinQuadDialog::addHeightItem()
3361 QListWidgetItem* previousItem = height_lw->currentItem();
3362 QListWidgetItem* newItem = new QListWidgetItem();
3364 double defaultValue = 1.;
3366 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3368 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3369 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3370 height_lw->addItem(newItem);
3373 // ============================================================== delHeightItem
3374 void JoinQuadDialog::delHeightItem()
3376 delete height_lw->currentItem();
3379 // ============================================================== clear
3380 void JoinQuadDialog::clear()
3382 quad_dest_le->clear();
3383 modelUnregister(quad_dest_le);
3386 modelUnregister(quads_lw);
3389 modelUnregister(vex0_le);
3392 modelUnregister(vex1_le);
3395 modelUnregister(vex2_le);
3398 modelUnregister(vex3_le);
3400 modelUnregister(this);
3403 // ============================================================== removeQuad
3404 void JoinQuadDialog::removeQuad()
3406 QListWidgetItem *item = quads_lw->currentItem();
3409 int r = quads_lw->row(item);
3410 quads_lw->takeItem(r);
3415 // ============================================================== apply
3416 bool JoinQuadDialog::apply(QModelIndex& result)
3418 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3421 DocumentModel* docModel = getDocumentModel();
3422 PatternDataModel* patternDataModel = getPatternDataModel();
3423 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3425 QModelIndexList iquads;
3427 QListWidgetItem* item = NULL;
3428 int nbQuads = quads_lw->count();
3429 for ( int r = 0; r < nbQuads; ++r){
3430 item = quads_lw->item(r);
3431 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3432 if ( iquad.isValid() )
3435 QModelIndex iquaddest = patternDataModel->mapToSource( _index[quad_dest_le] );
3436 QModelIndex ivex0 = patternDataModel->mapToSource( _index[vex0_le] );
3437 QModelIndex ivex1 = patternDataModel->mapToSource( _index[vex1_le] );
3438 QModelIndex ivex2 = patternDataModel->mapToSource( _index[vex2_le] );
3439 QModelIndex ivex3 = patternDataModel->mapToSource( _index[vex3_le] );
3440 double nb = nb_spb->value();
3442 vector<double> heights;
3443 int nbHeight = height_lw->count();
3444 for ( int r = 0; r < nbHeight; ++r){
3445 item = height_lw->item(r);
3446 heights.push_back(item->data(Qt::EditRole).toDouble());
3450 if (nbQuads == 1 && iquads[0].isValid() && iquaddest.isValid() && ivex0.isValid() &&
3451 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3453 if (joinUni_rb->isChecked())
3454 iElts = docModel->joinQuadUni(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3455 else if (join_rb->isChecked())
3456 iElts = docModel->joinQuad(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3458 else if (nbQuads > 1 && iquaddest.isValid() && ivex0.isValid() &&
3459 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3461 if (joinUni_rb->isChecked())
3462 iElts = docModel->joinQuadsUni(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3463 else if (join_rb->isChecked())
3464 iElts = docModel->joinQuads(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3467 if ( !iElts.isValid() ){
3468 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT JOIN QUAD(S)" ) + "\n" + getErrorMsg() );
3471 result = patternDataModel->mapFromSource(iElts);
3472 // result = patternBuilderModel->mapFromSource(iElts);
3477 // ------------------------- MergeDialog ----------------------------------
3478 // ============================================================== Constructeur
3480 MergeDialog::MergeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3481 : HexaBaseDialog(parent, editmode, f)
3484 _initWidget(editmode);
3487 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3488 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3489 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3490 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3492 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3493 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3494 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3496 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3497 connect( rb2, SIGNAL(cliked()), this, SLOT(clearVTKSelection()) );
3498 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3501 // ============================================================== Destructeur
3502 MergeDialog::~MergeDialog()
3506 // ============================================================== _initInputWidget
3507 void MergeDialog::_initInputWidget( Mode editmode )
3510 QValidator *validator = new QRegExpValidator(rx, this);
3512 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3513 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3514 v0_le_rb0->setValidator( validator );
3515 v1_le_rb0->setValidator( validator );
3516 v0_le_rb0->installEventFilter(this);
3517 v1_le_rb0->installEventFilter(this);
3519 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3520 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3521 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3522 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3524 v0_le_rb1->setValidator( validator );
3525 v1_le_rb1->setValidator( validator );
3526 e0_le_rb1->setValidator( validator );
3527 e1_le_rb1->setValidator( validator );
3529 v0_le_rb1->installEventFilter(this);
3530 v1_le_rb1->installEventFilter(this);
3531 e0_le_rb1->installEventFilter(this);
3532 e1_le_rb1->installEventFilter(this);
3534 v0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3535 v1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3536 v2_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3537 v3_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3538 q0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3539 q1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3541 v0_le_rb2->setValidator( validator );
3542 v1_le_rb2->setValidator( validator );
3543 v2_le_rb2->setValidator( validator );
3544 v3_le_rb2->setValidator( validator );
3545 q0_le_rb2->setValidator( validator );
3546 q1_le_rb2->setValidator( validator );
3548 v0_le_rb2->installEventFilter(this);
3549 v1_le_rb2->installEventFilter(this);
3550 v2_le_rb2->installEventFilter(this);
3551 v3_le_rb2->installEventFilter(this);
3552 q0_le_rb2->installEventFilter(this);
3553 q1_le_rb2->installEventFilter(this);
3555 v0_le_rb0->setReadOnly(true);
3556 v1_le_rb0->setReadOnly(true);
3558 v0_le_rb1->setReadOnly(true);
3559 v1_le_rb1->setReadOnly(true);
3560 e0_le_rb1->setReadOnly(true);
3561 e1_le_rb1->setReadOnly(true);
3563 v0_le_rb2->setReadOnly(true);
3564 v1_le_rb2->setReadOnly(true);
3565 v2_le_rb2->setReadOnly(true);
3566 v3_le_rb2->setReadOnly(true);
3567 q0_le_rb2->setReadOnly(true);
3568 q1_le_rb2->setReadOnly(true);
3571 // ============================================================== clear
3572 void MergeDialog::clear()
3575 modelUnregister(v0_le_rb0);
3578 modelUnregister(v1_le_rb0);
3581 modelUnregister(e0_le_rb1);
3584 modelUnregister(e1_le_rb1);
3587 modelUnregister(v0_le_rb1);
3590 modelUnregister(v1_le_rb1);
3593 modelUnregister(q0_le_rb2);
3596 modelUnregister(q1_le_rb2);
3599 modelUnregister(v0_le_rb2);
3602 modelUnregister(v1_le_rb2);
3605 modelUnregister(v2_le_rb2);
3608 modelUnregister(v3_le_rb2);
3610 modelUnregister(this);
3613 // ============================================================== updateHelpFileName
3614 void MergeDialog::updateHelpFileName()
3616 if ( sender() == rb0 ){
3617 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3618 } else if ( sender() == rb1 ){
3619 _helpFileName = "gui_merge_elmts.html#merge-two-edges";
3620 } else if ( sender() == rb2 ){
3621 _helpFileName = "gui_merge_elmts.html#merge-two-quadrangles";
3625 // ============================================================== apply
3626 bool MergeDialog::apply(QModelIndex& result)
3628 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3631 if (getDocumentModel() == NULL) return false;
3632 const PatternDataModel* patternDataModel = getPatternDataModel();
3633 if ( !patternDataModel ) return false;
3635 bool merged = false;
3637 if ( rb0->isChecked() ){
3638 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
3639 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
3643 merged = getDocumentModel()->mergeVertices( iv0, iv1 );
3645 } else if ( rb1->isChecked() ){
3646 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
3647 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
3648 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
3649 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
3655 merged = getDocumentModel()->mergeEdges( ie0, ie1, iv0, iv1);
3657 } else if ( rb2->isChecked() ){
3659 QModelIndex iq0 = patternDataModel->mapToSource( _index[q0_le_rb2] );
3660 QModelIndex iq1 = patternDataModel->mapToSource( _index[q1_le_rb2] );
3661 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb2] );
3662 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb2] );
3663 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb2] );
3664 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb2] );
3672 merged = getDocumentModel()->mergeQuads( iq0, iq1,
3673 iv0, iv1, iv2, iv3 );
3677 if ( merged == false ){
3678 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MERGE" ) + "\n" + getErrorMsg() );
3685 // ------------------------- DisconnectDialog ----------------------------------
3686 // ============================================================== Constructeur
3688 DisconnectDialog::DisconnectDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3689 : HexaBaseDialog(parent, editmode, f)
3692 _initWidget(editmode);
3695 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3697 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3698 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3699 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3701 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3702 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3703 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3705 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3706 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3707 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3709 connect( rb3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3710 connect( rb3, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3711 connect( rb3, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3715 // ============================================================== Destructeur
3716 DisconnectDialog::~DisconnectDialog()
3720 // ============================================================== _initInputWidget
3721 void DisconnectDialog::_initInputWidget( Mode editmode )
3724 QValidator *validator = new QRegExpValidator(rx, this);
3726 installEventFilter(this);
3729 v_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3730 h_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3731 v_le_rb0->setValidator( validator );
3732 h_le_rb0->setValidator( validator );
3733 v_le_rb0->installEventFilter(this);
3734 h_le_rb0->installEventFilter(this);
3737 e_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3738 h_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3739 e_le_rb1->setValidator( validator );
3740 h_le_rb1->setValidator( validator );
3741 e_le_rb1->installEventFilter(this);
3742 h_le_rb1->installEventFilter(this);
3745 q_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3746 h_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3747 q_le_rb2->setValidator( validator );
3748 h_le_rb2->setValidator( validator );
3749 q_le_rb2->installEventFilter(this);
3750 h_le_rb2->installEventFilter(this);
3753 d_edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3754 hexas_lw->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3755 d_edges_lw->installEventFilter(this);
3756 hexas_lw->installEventFilter(this);
3758 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), d_edges_lw);
3759 QShortcut* delHexaShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), hexas_lw);
3760 delEdgeShortcut->setContext( Qt::WidgetShortcut );
3761 delHexaShortcut->setContext( Qt::WidgetShortcut );
3763 v_le_rb0->setReadOnly(true);
3764 h_le_rb0->setReadOnly(true);
3766 e_le_rb1->setReadOnly(true);
3767 h_le_rb1->setReadOnly(true);
3769 q_le_rb2->setReadOnly(true);
3770 h_le_rb2->setReadOnly(true);
3772 connect( d_edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3773 connect( hexas_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3774 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
3775 connect( delHexaShortcut, SIGNAL(activated()), this, SLOT(deleteHexaItem()) );
3776 autoFocusSwitch = false;
3780 // =============================================== getAssocsVTK
3782 * Returns elements in the list
3784 QModelIndexList DisconnectDialog::getAssocsVTK()
3786 QModelIndexList iElts;
3788 QListWidgetItem* item = NULL;
3790 const PatternDataModel* patternDataModel = getPatternDataModel();
3791 if (patternDataModel == NULL || !rb3->isChecked())
3793 //ListWidget content
3794 if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == EDGE_TREE)
3796 int nbEdges = d_edges_lw->count();
3797 for ( int r = 0; r < nbEdges; ++r )
3799 item = d_edges_lw->item(r);
3800 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3801 if ( index.isValid() )
3805 else if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == HEXA_TREE)
3807 int nbHexas = hexas_lw->count();
3808 for ( int r = 0; r < nbHexas; ++r )
3810 item = hexas_lw->item(r);
3811 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3812 if ( index.isValid() )
3819 // ============================================================== clear
3820 void DisconnectDialog::clear()
3823 modelUnregister(v_le_rb0);
3826 modelUnregister(h_le_rb0);
3829 modelUnregister(e_le_rb1);
3832 modelUnregister(h_le_rb1);
3834 d_edges_lw->clear();
3835 modelUnregister(d_edges_lw);
3838 modelUnregister(hexas_lw);
3841 modelUnregister(q_le_rb2);
3844 modelUnregister(h_le_rb2);
3846 modelUnregister(this);
3849 // ============================================================== deleteEdgeItem
3850 void DisconnectDialog::deleteEdgeItem()
3852 delete d_edges_lw->currentItem();
3855 // ============================================================== deleteHexaItem
3856 void DisconnectDialog::deleteHexaItem()
3858 delete hexas_lw->currentItem();
3861 // ============================================================== updateHelpFileName
3862 void DisconnectDialog::updateHelpFileName()
3864 if ( sender() == rb0 ){
3865 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3866 } else if ( sender() == rb1 ){
3867 _helpFileName = "gui_disc_elmts.html#disconnect-an-edge";
3868 } else if ( sender() == rb2 ){
3869 _helpFileName = "gui_disc_elmts.html#disconnect-a-quadrangle";
3870 } else if (sender() == rb3 ){
3871 _helpFileName = "gui_disc_elmts.html#disconnect-edges";
3875 // ============================================================== apply
3876 bool DisconnectDialog::apply(QModelIndex& result)
3878 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3880 if (getDocumentModel() == NULL) return false;
3881 const PatternDataModel* patternDataModel = getPatternDataModel();
3882 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3883 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
3887 if ( rb0->isChecked() ){
3888 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb0] );
3889 QModelIndex ivex = patternDataModel->mapToSource( _index[v_le_rb0] );
3891 if ( ihexa.isValid()
3892 && ivex.isValid() ){
3893 iElts = getDocumentModel()->disconnectVertex( ihexa, ivex );
3895 } else if ( rb1->isChecked() ){
3896 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb1] );
3897 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le_rb1] );
3899 if ( ihexa.isValid()
3900 && iedge.isValid() ){
3901 iElts = getDocumentModel()->disconnectEdge( ihexa, iedge );
3903 } else if ( rb2->isChecked() ){
3904 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb2] );
3905 QModelIndex iquad = patternDataModel->mapToSource( _index[q_le_rb2] );
3907 if ( ihexa.isValid()
3908 && iquad.isValid() ){
3909 iElts = getDocumentModel()->disconnectQuad( ihexa, iquad );
3911 } else if ( rb3->isChecked() ){ //
3913 QModelIndex iedge, ihexa;
3914 QModelIndexList iedges, ihexas;
3915 QListWidgetItem* item = NULL;
3918 int nbEdges = d_edges_lw->count();
3919 for (int r = 0; r < nbEdges; ++r){
3920 item = d_edges_lw->item(r);
3921 iedge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3922 if ( iedge.isValid() )
3927 int nbHexas = hexas_lw->count();
3928 for (int r = 0; r < nbHexas; ++r){
3929 item = hexas_lw->item(r);
3930 ihexa = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3931 if ( ihexa.isValid() )
3935 iElts = getDocumentModel()->disconnectEdges( ihexas, iedges );
3938 if ( !iElts.isValid() ){
3939 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT DISCONNECT" ) + "\n" + getErrorMsg() );
3943 result = patternDataModel->mapFromSource(iElts);
3944 // result = patternBuilderModel->mapFromSource(iElts);
3950 // ------------------------- CutEdgeDialog ----------------------------------
3951 // ============================================================== Constructeur
3953 CutEdgeDialog::CutEdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3954 HexaBaseDialog(parent, editmode, f)
3957 _helpFileName = "gui_cut_hexa.html";
3958 connect( cutUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3959 connect( cut_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3960 _initWidget(editmode);
3965 // ============================================================== Destructeur
3966 CutEdgeDialog::~CutEdgeDialog()
3970 // ============================================================== _initInputWidget
3971 void CutEdgeDialog::_initInputWidget( Mode editmode )
3973 installEventFilter(this);
3975 e_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3976 e_le->installEventFilter(this);
3978 cutUni_rb->installEventFilter(this);
3979 cut_rb->installEventFilter(this);
3981 e_le->setReadOnly(true);
3983 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3984 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3985 height_lw->setProperty("Length", QVariant::fromValue(true));
3986 height_lw->installEventFilter(this);
3988 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3989 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3991 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3992 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3995 // ============================================================== updateHelpFileName
3996 void CutEdgeDialog::updateHelpFileName()
3998 if ( sender() == cutUni_rb ){
3999 _helpFileName = "gui_cut_hexa.html#guicuthexauniform";
4000 } else if ( sender() == cut_rb ){
4001 _helpFileName = "gui_cut_hexa.html#guicuthexacustom";
4005 // ============================================================== clear
4006 void CutEdgeDialog::clear()
4009 modelUnregister(e_le);
4011 modelUnregister(this);
4014 // ============================================================== addHeightItem
4015 void CutEdgeDialog::addHeightItem()
4017 QListWidgetItem* previousItem = height_lw->currentItem();
4018 QListWidgetItem* newItem = new QListWidgetItem();
4020 double defaultValue = 1.;
4022 defaultValue = previousItem->data(Qt::EditRole).toDouble();
4024 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
4025 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
4026 height_lw->addItem(newItem);
4029 // ============================================================== delHeightItem
4030 void CutEdgeDialog::delHeightItem()
4032 delete height_lw->currentItem();
4035 // ============================================================== apply
4036 bool CutEdgeDialog::apply(QModelIndex& result)
4038 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4041 DocumentModel* docModel = getDocumentModel();
4042 PatternDataModel* patternDataModel = getPatternDataModel();
4043 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4046 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le] );
4048 if (cutUni_rb->isChecked() && iedge.isValid())
4050 int nbCut = nb_cut_spb->value();
4051 iElts = docModel->cutUni(iedge, nbCut);
4053 else if (cut_rb->isChecked() && iedge.isValid())
4055 vector<double> heights;
4056 QListWidgetItem* item = NULL;
4057 int nbItems = height_lw->count();
4059 for ( int r = 0; r < nbItems; ++r){
4060 item = height_lw->item(r);
4061 heights.push_back( item->data(Qt::EditRole).toDouble() );
4064 iElts = docModel->cut(iedge, heights);
4067 if ( !iElts.isValid() ){
4068 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT CUT EDGE" ) + "\n" + getErrorMsg() );
4072 result = patternDataModel->mapFromSource(iElts);
4073 // result = patternBuilderModel->mapFromSource(iElts);
4075 //Update the line edit
4077 e_le->setProperty("QModelIndex", invalid );
4079 QModelIndex invalidIndex;
4080 _index[e_le] = invalidIndex;
4087 // // ------------------------- MakeTransformationDialog ----------------------------------
4088 // ============================================================== Constructeur
4090 MakeTransformationDialog::MakeTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4091 : HexaBaseDialog(parent, editmode, f)
4094 _initWidget(editmode);
4097 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
4098 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4099 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4100 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4103 // ============================================================== Destructeur
4104 MakeTransformationDialog::~MakeTransformationDialog()
4108 // ============================================================== _initInputWidget
4109 void MakeTransformationDialog::_initInputWidget( Mode editmode )
4112 QValidator *validator = new QRegExpValidator(rx, this);
4114 installEventFilter(this);
4115 rb0->installEventFilter(this);
4116 rb1->installEventFilter(this);
4117 rb2->installEventFilter(this);
4119 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4120 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4122 vec_le_rb0->setValidator( validator );
4123 elts_le_rb0->setValidator( validator );
4124 vec_le_rb0->installEventFilter(this);
4125 elts_le_rb0->installEventFilter(this);
4127 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4128 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4129 vex_le_rb1->setValidator( validator );
4130 elts_le_rb1->setValidator( validator );
4131 vex_le_rb1->installEventFilter(this);
4132 elts_le_rb1->installEventFilter(this);
4134 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4135 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4136 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4137 vex_le_rb2->setValidator( validator );
4138 vec_le_rb2->setValidator( validator );
4139 elts_le_rb2->setValidator( validator );
4140 vex_le_rb2->installEventFilter(this);
4141 vec_le_rb2->installEventFilter(this);
4142 elts_le_rb2->installEventFilter(this);
4144 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
4145 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
4146 angle_spb->setProperty("Angle", QVariant::fromValue(true));
4147 angle_spb->installEventFilter(this);
4149 vec_le_rb0->setReadOnly(true);
4150 elts_le_rb0->setReadOnly(true);
4152 vex_le_rb1->setReadOnly(true);
4153 elts_le_rb1->setReadOnly(true);
4155 vex_le_rb2->setReadOnly(true);
4156 vec_le_rb2->setReadOnly(true);
4157 elts_le_rb2->setReadOnly(true);
4161 // ============================================================== clear
4162 void MakeTransformationDialog::clear()
4164 elts_le_rb0->clear();
4165 modelUnregister(elts_le_rb0);
4167 vec_le_rb0->clear();
4168 modelUnregister(vec_le_rb0);
4170 elts_le_rb1->clear();
4171 modelUnregister(elts_le_rb1);
4173 vex_le_rb1->clear();
4174 modelUnregister(vex_le_rb1);
4176 elts_le_rb2->clear();
4177 modelUnregister(elts_le_rb2);
4179 vex_le_rb2->clear();
4180 modelUnregister(vex_le_rb2);
4182 vec_le_rb2->clear();
4183 modelUnregister(vec_le_rb2);
4185 modelUnregister(this);
4188 // ============================================================== updateHelpFileName
4189 void MakeTransformationDialog::updateHelpFileName()
4191 if ( sender() == rb0 ){
4192 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
4193 } else if ( sender() == rb1 ){
4194 _helpFileName = "gui_make_elmts.html#make-elements-by-scaling";
4195 } else if ( sender() == rb2 ){
4196 _helpFileName = "gui_make_elmts.html#make-elements-by-rotation";
4200 // ============================================================== apply
4201 bool MakeTransformationDialog::apply(QModelIndex& result)
4203 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4206 if (getDocumentModel() == NULL) return false;
4207 const PatternDataModel* patternDataModel = getPatternDataModel();
4208 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4209 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4211 QModelIndex iNewElts;
4213 if ( rb0->isChecked() ){
4214 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb0] );
4215 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb0] );
4216 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4217 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4219 if ( ielts.isValid()
4221 iNewElts = getDocumentModel()->makeTranslation( ielts, ivec );
4223 } else if ( rb1->isChecked() ){
4224 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4225 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb1] );
4226 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4227 double k = k_spb->value();
4229 if ( ielts.isValid()
4231 iNewElts = getDocumentModel()->makeScale( ielts, ivex, k );
4233 } else if ( rb2->isChecked() ){
4234 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4235 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb2] );
4236 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4237 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4238 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb2] );
4239 double angle = angle_spb->value();
4241 if ( ielts.isValid()
4244 iNewElts = getDocumentModel()->makeRotation( ielts, ivex, ivec, angle );
4247 if ( !iNewElts.isValid() ){
4248 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4252 result = patternDataModel->mapFromSource(iNewElts);
4253 if (result.isValid())
4255 MESSAGE("======> Result is valid!");
4256 HEXA_NS::Elements* elts = getDocumentModel()->getHexaPtr<HEXA_NS::Elements*>(result);
4257 MESSAGE("======> " << elts->getName());
4261 MESSAGE("======> Result is not valid!");
4263 // result = patternBuilderModel->mapFromSource(iNewElts);
4268 // // ------------------------- MakeSymmetryDialog ----------------------------------
4269 // ============================================================== Constructeur
4271 MakeSymmetryDialog::MakeSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4272 HexaBaseDialog(parent, editmode, f)
4275 _initWidget(editmode);
4278 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4279 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4280 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4281 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4284 // ============================================================== Destructeur
4285 MakeSymmetryDialog::~MakeSymmetryDialog()
4289 // ============================================================== _initInputWidget
4290 void MakeSymmetryDialog::_initInputWidget( Mode editmode )
4293 QValidator *validator = new QRegExpValidator(rx, this);
4295 installEventFilter(this);
4297 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4298 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4299 vex_le_rb0->setValidator( validator );
4300 elts_le_rb0->setValidator( validator );
4301 vex_le_rb0->installEventFilter(this);
4302 elts_le_rb0->installEventFilter(this);
4304 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4305 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4306 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4307 vex_le_rb1->setValidator( validator );
4308 vec_le_rb1->setValidator( validator );
4309 elts_le_rb1->setValidator( validator );
4310 vex_le_rb1->installEventFilter(this);
4311 vec_le_rb1->installEventFilter(this);
4312 elts_le_rb1->installEventFilter(this);
4314 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4315 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4316 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4317 vex_le_rb2->setValidator( validator );
4318 vec_le_rb2->setValidator( validator );
4319 elts_le_rb2->setValidator( validator );
4320 vex_le_rb2->installEventFilter(this);
4321 vec_le_rb2->installEventFilter(this);
4322 elts_le_rb2->installEventFilter(this);
4324 vex_le_rb0->setReadOnly(true);
4325 elts_le_rb0->setReadOnly(true);
4326 vex_le_rb1->setReadOnly(true);
4327 vec_le_rb1->setReadOnly(true);
4328 elts_le_rb1->setReadOnly(true);
4329 vex_le_rb2->setReadOnly(true);
4330 vec_le_rb2->setReadOnly(true);
4331 elts_le_rb2->setReadOnly(true);
4334 // ============================================================== clear
4335 void MakeSymmetryDialog::clear()
4337 elts_le_rb0->clear();
4338 modelUnregister(elts_le_rb0);
4340 vex_le_rb0->clear();
4341 modelUnregister(vex_le_rb0);
4343 elts_le_rb1->clear();
4344 modelUnregister(elts_le_rb1);
4346 vex_le_rb1->clear();
4347 modelUnregister(vex_le_rb1);
4349 vec_le_rb1->clear();
4350 modelUnregister(vec_le_rb1);
4352 elts_le_rb2->clear();
4353 modelUnregister(elts_le_rb2);
4355 vex_le_rb2->clear();
4356 modelUnregister(vex_le_rb2);
4358 vec_le_rb2->clear();
4359 modelUnregister(vec_le_rb2);
4361 modelUnregister(this);
4364 // ============================================================== updateHelpFileName
4365 void MakeSymmetryDialog::updateHelpFileName()
4367 if ( sender() == rb0 ){
4368 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4369 } else if ( sender() == rb1 ){
4370 _helpFileName = "gui_make_symmetry.html#make-elements-by-line-symmetry";
4371 } else if ( sender() == rb2 ){
4372 _helpFileName = "gui_make_symmetry.html#make-elements-by-plane-symmetry";
4376 // ============================================================== apply
4377 bool MakeSymmetryDialog::apply(QModelIndex& result)
4379 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4381 if (getDocumentModel() == NULL) return false;
4382 const PatternDataModel* patternDataModel = getPatternDataModel();
4383 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4384 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4386 QModelIndex iNewElts;
4388 if ( rb0->isChecked() ){
4389 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4390 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb0] );
4391 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4393 if ( ielts.isValid()
4395 iNewElts = getDocumentModel()->makeSymmetryPoint( ielts, ivex );
4398 } else if ( rb1->isChecked() ){
4399 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4400 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb1] );
4401 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4402 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4403 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb1] );
4405 if ( ielts.isValid()
4408 iNewElts = getDocumentModel()->makeSymmetryLine( ielts, ivex, ivec );
4410 } else if ( rb2->isChecked() ){
4411 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4412 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4413 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4414 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4415 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4417 if ( ielts.isValid()
4420 iNewElts = getDocumentModel()->makeSymmetryPlane( ielts, ivex, ivec );
4423 if ( !iNewElts.isValid() ){
4424 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4428 // result = patternBuilderModel->mapFromSource(iNewElts);
4429 result = patternDataModel->mapFromSource(iNewElts);
4434 // // ------------------------- PerformTransformationDialog ----------------------------------
4435 // ============================================================== Constructeur
4436 PerformTransformationDialog::PerformTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4437 HexaBaseDialog(parent, editmode, f)
4440 _initWidget(editmode);
4443 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4444 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4445 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4446 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4449 // ============================================================== Destructeur
4450 PerformTransformationDialog::~PerformTransformationDialog()
4454 // ============================================================== _initInputWidget
4455 void PerformTransformationDialog::_initInputWidget( Mode editmode )
4458 QValidator *validator = new QRegExpValidator(rx, this);
4460 installEventFilter(this);
4461 rb0->installEventFilter(this);
4462 rb1->installEventFilter(this);
4463 rb2->installEventFilter(this);
4465 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4466 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4467 vec_le_rb0->setValidator( validator );
4468 elts_le_rb0->setValidator( validator );
4469 vec_le_rb0->installEventFilter(this);
4470 elts_le_rb0->installEventFilter(this);
4472 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4473 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4474 vex_le_rb1->setValidator( validator );
4475 elts_le_rb1->setValidator( validator );
4476 vex_le_rb1->installEventFilter(this);
4477 elts_le_rb1->installEventFilter(this);
4480 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4481 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4482 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4483 vex_le_rb2->setValidator( validator );
4484 vec_le_rb2->setValidator( validator );
4485 elts_le_rb2->setValidator( validator );
4486 vex_le_rb2->installEventFilter(this);
4487 vec_le_rb2->installEventFilter(this);
4488 elts_le_rb2->installEventFilter(this);
4490 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
4491 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
4492 angle_spb->setProperty("Angle", QVariant::fromValue(true));
4493 angle_spb->installEventFilter(this);
4495 vec_le_rb0->setReadOnly(true);
4496 elts_le_rb0->setReadOnly(true);
4497 vex_le_rb1->setReadOnly(true);
4498 elts_le_rb1->setReadOnly(true);
4499 vex_le_rb2->setReadOnly(true);
4500 vec_le_rb2->setReadOnly(true);
4501 elts_le_rb2->setReadOnly(true);
4505 // ============================================================== clear
4506 void PerformTransformationDialog::clear()
4508 vec_le_rb0->clear();
4509 modelUnregister(vec_le_rb0);
4511 elts_le_rb0->clear();
4512 modelUnregister(elts_le_rb0);
4514 vex_le_rb1->clear();
4515 modelUnregister(vex_le_rb1);
4517 elts_le_rb1->clear();
4518 modelUnregister(elts_le_rb1);
4520 vex_le_rb2->clear();
4521 modelUnregister(vex_le_rb2);
4523 vec_le_rb2->clear();
4524 modelUnregister(vec_le_rb2);
4526 elts_le_rb2->clear();
4527 modelUnregister(elts_le_rb2);
4529 modelUnregister(this);
4532 // ============================================================== updateHelpFileName
4533 void PerformTransformationDialog::updateHelpFileName()
4535 if ( sender() == rb0 ){
4536 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4537 } else if ( sender() == rb1 ){
4538 _helpFileName = "gui_modify_elmts.html#modify-elements-by-scaling";
4539 } else if ( sender() == rb2 ){
4540 _helpFileName = "gui_modify_elmts.html#modify-elements-by-rotation";
4544 // ============================================================== apply
4545 bool PerformTransformationDialog::apply(QModelIndex& result)
4547 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4550 if (getDocumentModel() == NULL) return false;
4551 const PatternDataModel* patternDataModel = getPatternDataModel();
4552 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4553 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4555 bool performed = false;
4557 if ( rb0->isChecked() ){
4558 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4559 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb0]);
4560 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4561 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb0]);
4563 if ( ielts.isValid()
4565 performed = getDocumentModel()->performTranslation( ielts, ivec );
4567 } else if ( rb1->isChecked() ){
4568 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4569 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb1]);
4570 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4571 double k = k_spb->value();
4573 if ( ielts.isValid()
4575 performed = getDocumentModel()->performScale( ielts, ivex, k );
4577 } else if ( rb2->isChecked() ){
4578 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4579 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4580 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4581 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4582 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4583 double angle = angle_spb->value();
4585 if ( ielts.isValid()
4588 performed = getDocumentModel()->performRotation( ielts, ivex, ivec, angle );
4591 if ( performed == false){
4592 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM TRANSFORMATION" ) + "\n" + getErrorMsg() );
4599 // // ------------------------- PerformSymmetryDialog ----------------------------------
4600 // ============================================================== Constructeur
4601 PerformSymmetryDialog::PerformSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4602 : HexaBaseDialog(parent, editmode, f)
4605 _initWidget( editmode );
4608 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4609 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4610 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4611 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4614 // ============================================================== Destructeur
4615 PerformSymmetryDialog::~PerformSymmetryDialog()
4619 // ============================================================== _initInputWidget
4620 void PerformSymmetryDialog::_initInputWidget( Mode editmode )
4623 QValidator *validator = new QRegExpValidator(rx, this);
4625 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4626 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4627 vex_le_rb0->setValidator( validator );
4628 elts_le_rb0->setValidator( validator );
4629 vex_le_rb0->installEventFilter(this);
4630 elts_le_rb0->installEventFilter(this);
4632 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4633 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4634 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4635 vex_le_rb1->setValidator( validator );
4636 vec_le_rb1->setValidator( validator );
4637 elts_le_rb1->setValidator( validator );
4638 vex_le_rb1->installEventFilter(this);
4639 vec_le_rb1->installEventFilter(this);
4640 elts_le_rb1->installEventFilter(this);
4642 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4643 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4644 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4645 vex_le_rb2->setValidator( validator );
4646 vec_le_rb2->setValidator( validator );
4647 elts_le_rb2->setValidator( validator );
4648 vex_le_rb2->installEventFilter(this);
4649 vec_le_rb2->installEventFilter(this);
4650 elts_le_rb2->installEventFilter(this);
4652 vex_le_rb0->setReadOnly(true);
4653 elts_le_rb0->setReadOnly(true);
4654 vex_le_rb1->setReadOnly(true);
4655 vec_le_rb1->setReadOnly(true);
4656 elts_le_rb1->setReadOnly(true);
4657 vex_le_rb2->setReadOnly(true);
4658 vec_le_rb2->setReadOnly(true);
4659 elts_le_rb2->setReadOnly(true);
4663 // ============================================================== clear
4664 void PerformSymmetryDialog::clear()
4666 vex_le_rb0->clear();
4667 modelUnregister(vex_le_rb0);
4669 elts_le_rb0->clear();
4670 modelUnregister(elts_le_rb0);
4672 elts_le_rb1->clear();
4673 modelUnregister(elts_le_rb1);
4675 vex_le_rb1->clear();
4676 modelUnregister(vex_le_rb1);
4678 vec_le_rb1->clear();
4679 modelUnregister(vec_le_rb1);
4681 elts_le_rb2->clear();
4682 modelUnregister(elts_le_rb2);
4684 vex_le_rb2->clear();
4685 modelUnregister(vex_le_rb2);
4687 vec_le_rb2->clear();
4688 modelUnregister(vec_le_rb2);
4690 modelUnregister(this);
4693 // ============================================================== updateHelpFileName
4694 void PerformSymmetryDialog::updateHelpFileName()
4696 if ( sender() == rb0 ){
4697 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4698 } else if ( sender() == rb1 ){
4699 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-line-symmetry";
4700 } else if ( sender() == rb2 ){
4701 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-plane-symmetry";
4705 // ============================================================== apply
4706 bool PerformSymmetryDialog::apply(QModelIndex& result)
4708 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4711 if (getDocumentModel() == NULL) return false;
4712 const PatternDataModel* patternDataModel = getPatternDataModel();
4713 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4714 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4716 bool performed = false;
4718 if ( rb0->isChecked() ){
4719 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4720 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb0]);
4721 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4723 if ( ielts.isValid()
4725 performed = getDocumentModel()->performSymmetryPoint( ielts, ivex );
4727 } else if ( rb1->isChecked() ){
4728 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4729 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb1]);
4730 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4731 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4732 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb1]);
4734 if ( ielts.isValid()
4737 performed = getDocumentModel()->performSymmetryLine( ielts, ivex, ivec );
4739 } else if ( rb2->isChecked() ){
4740 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4741 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4742 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4743 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4744 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4746 if ( ielts.isValid()
4749 performed = getDocumentModel()->performSymmetryPlane( ielts, ivex, ivec );
4752 if ( performed == false ){
4753 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM SYMMETRY" ) + "\n" + getErrorMsg() );
4760 // // ------------------------- EdgeAssocDialog ----------------------------------
4761 // ============================================================== Constructeur
4762 EdgeAssocDialog::EdgeAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4763 HexaBaseDialog( parent, editmode, f )
4765 _helpFileName ="gui_asso_quad_to_geom.html#one-edge";
4767 _initWidget(editmode);
4772 // ============================================================== Destructeur
4773 EdgeAssocDialog::~EdgeAssocDialog()
4777 // ============================================================== close
4778 void EdgeAssocDialog::close()
4780 HEXABLOCKGUI::assocInProgress = false;
4781 HexaBaseDialog::close();
4784 // ============================================================== _initInputWidget
4785 void EdgeAssocDialog::_initInputWidget( Mode editmode )
4788 QValidator *validator = new QRegExpValidator(rx, this);
4791 first_vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4792 first_vex_le->installEventFilter(this);
4793 first_vex_le->setValidator( validator );
4795 single_edge_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4796 single_edge_le->installEventFilter(this);
4798 edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4799 edges_lw->installEventFilter(this);
4803 lines_lw->setProperty("HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4804 lines_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4805 lines_lw->installEventFilter(this);
4807 single_line_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4808 single_line_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4809 single_line_le->installEventFilter(this);
4812 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), edges_lw);
4813 QShortcut* delLineShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), lines_lw);
4814 delLineShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4815 delEdgeShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4817 pend_spb->setValue(1.);
4819 first_vex_le->setReadOnly(true);
4820 single_edge_le->setReadOnly(true);
4821 single_line_le->setReadOnly(true);
4823 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
4824 connect( delLineShortcut, SIGNAL(activated()), this, SLOT(deleteLineItem()) );
4825 connect( edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
4826 connect( lines_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4827 connect( single_rb, SIGNAL(clicked()), this, SLOT( refreshHighlight()), Qt::UniqueConnection );
4828 connect( multiple_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection );
4829 connect( single_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4830 connect( multiple_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4833 // ============================================================== updateHelpFileName
4834 void EdgeAssocDialog::updateHelpFileName()
4836 if ( sender() == single_rb ){
4837 _helpFileName = "gui_asso_quad_to_geom.html#one-edge";
4838 } else if ( sender() == multiple_rb ){
4839 _helpFileName = "gui_asso_quad_to_geom.html#line";
4843 // ============================================================== getAssocsVTK
4845 * Returns elements currently being associated in vtk side
4847 QModelIndexList EdgeAssocDialog::getAssocsVTK()
4849 QModelIndexList assocs;
4851 QListWidgetItem* item = NULL;
4853 if (getPatternDataSelectionModel() == NULL) return assocs;
4854 if (single_rb->isChecked())
4857 QVariant v = single_edge_le->property("QModelIndex");
4858 if ( !v.isValid() ) return assocs;
4859 assocs << v.value<QModelIndex>();
4862 else if (multiple_rb->isChecked())
4864 //ListWidget content
4865 const PatternDataModel* patternDataModel = getPatternDataModel();
4866 if ( !patternDataModel ) return assocs;
4867 int nbEdges = edges_lw->count();
4868 for ( int r = 0; r < nbEdges; ++r){
4869 item = edges_lw->item(r);
4870 iEdge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4871 if ( iEdge.isValid() ) assocs << iEdge;
4878 // ============================================================== getAssocsGEOM
4880 * Returns elements currently being associated in geom side
4882 QMultiMap<QString, int> EdgeAssocDialog::getAssocsGEOM()
4884 QMultiMap<QString, int> assocs;
4885 QListWidgetItem* item = NULL;
4886 DocumentModel::GeomObj geomObj;
4888 if (single_rb->isChecked())
4891 QVariant v = single_line_le->property("GeomObj");
4892 if ( !v.isValid() ) return assocs;
4893 geomObj = v.value<DocumentModel::GeomObj>();
4894 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4897 else if (multiple_rb->isChecked())
4899 //ListWidget content
4900 unsigned int nbEdges = lines_lw->count();
4901 for ( int r = 0; r < nbEdges; ++r){
4902 item = lines_lw->item(r);
4903 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4904 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4911 // ============================================================== selectElementOfGeom
4912 /*Highlight in the OCC view selected elements in a listwidget,
4913 * or an element in a line edit.*/
4914 void EdgeAssocDialog::selectElementOfGeom()
4916 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4917 if ( !currentListWidget )
4921 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4922 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4923 pgsm->clearSelection();
4924 if (sel.count() == 0)
4927 QListWidgetItem *item = sel[0];
4928 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
4929 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4930 if ( index.isValid() )
4931 pgsm->select( index, QItemSelectionModel::SelectCurrent );
4934 // ============================================================== clear
4935 void EdgeAssocDialog::clear()
4937 first_vex_le->clear();
4938 modelUnregister(first_vex_le);
4941 modelUnregister(edges_lw);
4945 single_edge_le->clear();
4946 modelUnregister(single_edge_le);
4948 single_line_le->clear();
4949 modelUnregister(single_line_le);
4951 modelUnregister(this);
4954 // ============================================================== onWindowActivated
4955 void EdgeAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4957 QString vmType = vm->getType();
4958 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4960 if (single_rb->isChecked())
4961 single_edge_le->setFocus();
4962 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le )
4963 edges_lw->setFocus();
4965 else if ( vmType == OCCViewer_Viewer::Type() ){
4966 if (single_rb->isChecked())
4967 single_line_le->setFocus();
4968 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le)
4969 lines_lw->setFocus();
4973 // ============================================================== apply
4974 bool EdgeAssocDialog::apply(QModelIndex& result)
4976 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4979 bool assocOk = false;
4981 PatternDataModel* patternDataModel = getPatternDataModel();
4982 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4983 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4985 QModelIndex iEdge, iGeomEdge;
4986 QModelIndexList iEdges;
4987 QListWidgetItem* item = NULL;
4988 QList<DocumentModel::GeomObj> assocs;
4989 DocumentModel::GeomObj aLine;
4990 HEXA_NS::SubShape* ssh;
4991 HEXA_NS::EdgeShape* sh;
4992 HEXA_NS::NewShapes shapes;
4993 HEXA_NS::IntVector subIds;
4995 QModelIndexList edges, lines;
4997 if (single_rb->isChecked()){ //Single edge and/or line association
4999 iEdge = patternDataModel->mapToSource( _index[single_edge_le] );
5000 if ( !iEdge.isValid() || myLine == NULL)
5002 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5005 id = myLine->shapeName+","+myLine->subId;
5006 ssh = getDocumentModel()->getGeomPtr(id);
5007 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
5008 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5009 if (!iGeomEdge.isValid())
5011 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5014 assocOk = getDocumentModel()->addEdgeAssociation(iEdge, iGeomEdge, pstart_spb->value(), pend_spb->value());
5015 edges << _index[single_edge_le];
5018 else { //Multiple edge and/or line association
5021 iEdges = getIndexList(edges_lw, true);
5022 int nbLines = lines_lw->count();
5023 if (iEdges.count() == 0 || nbLines == 0)
5025 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5028 edges = getIndexList(edges_lw, false);
5030 for (int r = 0; r < nbLines; ++r){
5031 item = lines_lw->item(r);
5032 aLine = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5033 id = aLine.shapeName+","+aLine.subId;
5034 ssh = getDocumentModel()->getGeomPtr(id);
5035 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
5038 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5041 shapes.push_back(sh->getParentShape());
5042 subIds.push_back(sh->getIdent());
5043 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5044 if (iGeomEdge.isValid())
5048 if ( close_cb->isChecked() ){ //closed line
5049 QModelIndex iFirstVertex = patternDataModel->mapToSource( _index[first_vex_le] );
5050 if ( !iFirstVertex.isValid() )
5052 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5055 bool inv = inverse_cb->isChecked();
5056 assocOk = getDocumentModel()->associateClosedLine( iFirstVertex, iEdges, shapes, subIds, pstart_spb->value(), inv );
5060 assocOk = getDocumentModel()->associateOpenedLine( iEdges, shapes, subIds, pstart_spb->value(), pend_spb->value() );
5064 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) + "\n" + getErrorMsg() );
5068 // highlight associated items in the trees
5069 pdsm->unhighlightTreeItems();
5070 pgsm->unhighlightTreeItems();
5071 pdsm->highlightTreeItems(edges);
5072 pgsm->highlightTreeItems(lines);
5074 // highlight associated items in the views
5075 highlightSelectedAssocs();
5080 // ------------------------- QuadAssocDialog ----------------------------------
5081 // ============================================================== Constructeur
5082 QuadAssocDialog::QuadAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5083 HexaBaseDialog(parent, editmode, f)
5085 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-face-or-a-shell-of-the-geometry";
5087 _initWidget(editmode);
5090 // ============================================================== Destructeur
5091 QuadAssocDialog::~QuadAssocDialog()
5093 disconnect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
5094 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(addFace()) );
5095 delete _delFaceShortcut;
5098 // ============================================================== close
5099 void QuadAssocDialog::close()
5101 HEXABLOCKGUI::assocInProgress = false;
5102 HexaBaseDialog::close();
5105 // ============================================================== _initInputWidget
5106 void QuadAssocDialog::_initInputWidget( Mode editmode )
5109 QValidator *validator = new QRegExpValidator(rx, this);
5111 quad_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5112 quad_le->installEventFilter(this);
5113 quad_le->setValidator( validator );
5115 faces_lw->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
5116 faces_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
5117 faces_lw->installEventFilter(this);
5118 _delFaceShortcut = new QShortcut( QKeySequence(Qt::Key_X/*Qt::Key_Delete*/), faces_lw );
5119 _delFaceShortcut->setContext( Qt::WidgetShortcut );
5121 quad_le->setReadOnly(true);
5123 connect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
5124 connect( faces_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
5127 // ============================================================== getAssocsVTK
5129 * Returns elements currently being associated in vtk side
5131 QModelIndexList QuadAssocDialog::getAssocsVTK()
5133 QModelIndexList assocs;
5137 QVariant v = quad_le->property("QModelIndex");
5140 assocs << v.value<QModelIndex>();
5144 // ============================================================== getAssocsGEOM
5146 * Returns elements currently being associated in geom side
5148 QMultiMap<QString, int> QuadAssocDialog::getAssocsGEOM()
5150 QMultiMap<QString, int> assocs;
5151 QListWidgetItem* item = NULL;
5152 DocumentModel::GeomObj geomObj;
5154 //ListWidget content
5155 unsigned int nbFaces = faces_lw->count();
5156 for ( int r = 0; r < nbFaces; ++r){
5157 item = faces_lw->item(r);
5158 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5159 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
5164 // ============================================================== selectElementOfGeom
5165 /*Highlight in the OCC view selected elements in a listwidget,
5166 * or an element in a line edit.*/
5168 void QuadAssocDialog::selectElementOfGeom()
5170 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5171 if ( !currentListWidget )
5175 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5176 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
5177 pgsm->clearSelection();
5178 if (sel.count() == 0)
5180 QListWidgetItem *item = sel[0];
5181 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
5182 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5183 if ( index.isValid() )
5184 pgsm->select( index, QItemSelectionModel::SelectCurrent );
5187 void QuadAssocDialog::clear()
5190 modelUnregister(quad_le);
5194 modelUnregister(this);
5197 // ============================================================== onWindowActivated
5198 void QuadAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
5200 QString vmType = vm->getType();
5201 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
5202 quad_le->setFocus();
5203 else if ( vmType == OCCViewer_Viewer::Type() ){
5204 faces_lw->setFocus();
5208 // ============================================================== deleteFaceItem
5209 void QuadAssocDialog::deleteFaceItem()
5211 delete faces_lw->currentItem();
5214 // ============================================================== apply
5215 bool QuadAssocDialog::apply(QModelIndex& result)
5217 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5220 PatternDataModel* patternDataModel = getPatternDataModel();
5221 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
5222 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
5225 QModelIndex iQuad, iGeomFace;
5226 HEXA_NS::SubShape* ssh;
5227 HEXA_NS::FaceShape* sh;
5231 iQuad = patternDataModel->mapToSource( _index[quad_le] );
5234 QListWidgetItem* item = NULL;
5235 DocumentModel::GeomObj aFace;
5236 QModelIndexList quads, faces;
5237 int nbFaces = faces_lw->count();
5238 for ( int r = 0; r < nbFaces; ++r ){
5239 item = faces_lw->item(r);
5240 aFace = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5241 id = aFace.shapeName+","+aFace.subId;
5242 ssh = getDocumentModel()->getGeomPtr(id);
5243 sh = dynamic_cast<HEXA_NS::FaceShape*>(ssh);
5246 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) );
5249 iGeomFace = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5250 if (!getDocumentModel()->addQuadAssociation(iQuad, iGeomFace))
5252 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) + "\n" + getErrorMsg() );
5255 else if (iGeomFace.isValid())
5260 if (iQuad.isValid())
5261 quads << _index[quad_le];
5263 // highlight associated items in the trees
5264 pdsm->highlightTreeItems(quads);
5265 pgsm->highlightTreeItems(faces);
5267 // highlight associated items in the views
5268 highlightSelectedAssocs();
5273 // ------------------------- GroupDialog ----------------------------------
5274 // ============================================================== Constructeur
5275 GroupDialog::GroupDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5276 HexaBaseDialog(parent, editmode, f),
5279 _helpFileName = "gui_groups.html#add-group";
5281 _initWidget(editmode);
5282 // setFocusProxy( name_le/*eltBase_lw */);
5284 if ( editmode == NEW_MODE ){
5285 setWindowTitle( tr("Group Construction") );
5286 } else if ( editmode == UPDATE_MODE ){
5287 setWindowTitle( tr("Group Modification") );
5288 } else if ( editmode == INFO_MODE ){
5289 setWindowTitle( tr("Group Information") );
5293 // ============================================================== Destructeur
5294 GroupDialog::~GroupDialog()
5298 // ============================================================== getAssocsVTK
5300 * Returns elements currently being associated in vtk side
5302 QModelIndexList GroupDialog::getAssocsVTK()
5304 QModelIndexList assocs;
5306 QListWidgetItem* item = NULL;
5307 if (getPatternDataSelectionModel() == NULL) return assocs;
5308 //ListWidget content
5309 const PatternDataModel* patternDataModel = getPatternDataModel();
5310 if ( !patternDataModel ) return assocs;
5311 int nbElts = eltBase_lw->count();
5312 for ( int r = 0; r < nbElts; ++r){
5313 item = eltBase_lw->item(r);
5314 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5315 if ( iItem.isValid() ) assocs << iItem;
5320 // ============================================================== _initInputWidget
5321 void GroupDialog::_initInputWidget( Mode editmode )
5323 installEventFilter(this);
5324 name_le->installEventFilter(this);
5327 strKind[ HEXA_NS::HexaCell ] = "HexaCell";
5328 strKind[ HEXA_NS::QuadCell ] = "QuadCell";
5329 strKind[ HEXA_NS::EdgeCell ] = "EdgeCell";
5330 strKind[ HEXA_NS::HexaNode ] = "HexaNode";
5331 strKind[ HEXA_NS::QuadNode ] = "QuadNode";
5332 strKind[ HEXA_NS::EdgeNode ] = "EdgeNode";
5333 strKind[ HEXA_NS::VertexNode ] = "VertexNode";
5335 QMap<HEXA_NS::EnumGroup, QString>::ConstIterator iKind;
5336 for( iKind = strKind.constBegin(); iKind != strKind.constEnd(); ++iKind )
5337 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5339 onKindChanged( kind_cb->currentIndex() );
5340 eltBase_lw->installEventFilter(this);
5342 if ( editmode != INFO_MODE ){
5343 QShortcut* delEltShortcut = new QShortcut( QKeySequence(Qt::Key_X), eltBase_lw );
5344 delEltShortcut->setContext( Qt::WidgetShortcut );
5345 connect(delEltShortcut, SIGNAL(activated()), this, SLOT(removeEltBase()));
5346 connect(kind_cb, SIGNAL(activated(int)), this, SLOT(onKindChanged(int)) );
5349 if ( editmode == INFO_MODE)
5351 name_le->setReadOnly(true);
5352 kind_cb->setEnabled(false);
5353 eltBase_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
5356 connect(eltBase_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5359 // ============================================================== clear
5360 void GroupDialog::clear()
5364 eltBase_lw->clear();
5365 modelUnregister(eltBase_lw);
5367 modelUnregister(this);
5370 // ============================================================== onKindChanged
5371 void GroupDialog::onKindChanged(int index)
5374 switch ( kind_cb->itemData(index).toInt() ){
5375 case HEXA_NS::HexaCell:
5376 case HEXA_NS::HexaNode:
5377 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(HEXA_TREE));
5380 case HEXA_NS::QuadCell:
5381 case HEXA_NS::QuadNode:
5382 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5385 case HEXA_NS::EdgeCell:
5386 case HEXA_NS::EdgeNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
5389 case HEXA_NS::VertexNode:
5390 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
5393 default:Q_ASSERT(false);
5395 eltBase_lw->clear();
5396 eltBase_lw->setFocus();
5399 // ============================================================== setValue
5400 void GroupDialog::setValue(HEXA_NS::Group* g)
5403 name_le->setText( g->getName() );
5407 kind_cb->addItem ( strKind[g->getKind()], QVariant( g->getKind() ) );
5410 HEXA_NS::EltBase* eltBase = NULL;
5411 QListWidgetItem* item = NULL;
5412 QModelIndex iEltBase;
5413 QList<QStandardItem *> eltBaseItems;
5416 if ( !getPatternDataSelectionModel() ) return;
5417 if ( !getGroupsSelectionModel() ) return;
5419 QModelIndex iGroup = getGroupsSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(g) );
5420 name_le->setProperty( "QModelIndex", QVariant::fromValue(iGroup) );
5423 int nbElts = g->countElement();
5424 for ( int nr = 0; nr < nbElts; ++nr ){
5425 eltBase = g->getElement( nr );
5426 switch ( g->getKind() ){
5427 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: v = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
5428 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: v = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
5429 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: v = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
5430 case HEXA_NS::VertexNode: v = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
5432 iEltBase = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, v);
5433 if ( iEltBase.isValid() ){
5434 item = new QListWidgetItem( eltBase->getName() );
5435 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iEltBase) );
5436 item->setData(LW_DATA_ROLE, iEltBase.data(HEXA_DATA_ROLE));
5437 eltBase_lw->addItem( item );
5443 // ============================================================== getValue
5444 HEXA_NS::Group* GroupDialog::getValue()
5449 // ============================================================== removeEltBase
5450 void GroupDialog::removeEltBase()
5452 QListWidgetItem *item = eltBase_lw->currentItem();
5455 int r = eltBase_lw->row(item);
5456 eltBase_lw->takeItem(r);
5462 // ============================================================== apply
5463 bool GroupDialog::apply(QModelIndex& result)
5465 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5468 if ( !getDocumentModel() ) return false;
5469 const PatternDataModel* patternDataModel = getPatternDataModel();
5470 const GroupsModel* groupsModel = getGroupsModel();
5471 if (patternDataModel == NULL || groupsModel == NULL) return false;
5473 QString grpName = name_le->text();
5474 DocumentModel::Group grpKind = static_cast<DocumentModel::Group>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5476 if ( _value == NULL ){ // create group
5477 iGrp = getDocumentModel()->addGroup( grpName, grpKind );
5479 QModelIndexList iGrps = getDocumentModel()->match(
5480 getDocumentModel()->index(0, 0),
5482 QVariant::fromValue( _value ),
5484 Qt::MatchRecursive );
5485 if ( !iGrps.isEmpty() )
5490 if ( !iGrp.isValid() ){
5491 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD GROUP" ) + "\n" + getErrorMsg() );
5495 //fill it and select it
5496 QModelIndex iEltBase;
5497 QListWidgetItem* item = NULL;
5498 bool eltAdded = false;
5499 getDocumentModel()->clearGroupElement(iGrp);
5500 int nbElts = eltBase_lw->count();
5501 for ( int r = 0; r < nbElts; ++r){
5502 item = eltBase_lw->item(r);
5503 iEltBase = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5504 if ( iEltBase.isValid() )
5505 eltAdded = getDocumentModel()->addGroupElement( iGrp, iEltBase );
5508 QString newName = name_le->text();
5509 if ( !newName.isEmpty() )
5510 getDocumentModel()->setName( iGrp, newName );
5512 HEXA_NS::Group* hGroup = getDocumentModel()->data(iGrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
5515 QString groupName = QString::fromStdString(hGroup->getNextName());
5516 name_le->setText(groupName);
5519 result = groupsModel->mapFromSource(iGrp);
5524 // ------------------------- LawDialog ----------------------------------
5525 // ============================================================== Constructeur
5527 LawDialog::LawDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5528 : HexaBaseDialog(parent, editmode, f),
5531 _helpFileName = "gui_discret_law.html#add-law";
5533 _initWidget(editmode);
5534 if ( editmode == NEW_MODE ){
5535 setWindowTitle( tr("Law Construction") );
5536 } else if ( editmode == UPDATE_MODE ){
5537 setWindowTitle( tr("Law Modification") );
5539 else if ( editmode == INFO_MODE){
5540 setWindowTitle( tr("Law Information") );
5544 // ============================================================== Destructeur
5545 LawDialog::~LawDialog()
5549 // ============================================================== _initInputWidget
5550 void LawDialog::_initInputWidget( Mode editmode )
5554 // setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5555 installEventFilter(this);
5557 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5558 name_le->installEventFilter(this);
5561 strKind[ HEXA_NS::Uniform ] = "Uniform";
5562 strKind[ HEXA_NS::Arithmetic ] = "Arithmetic";
5563 strKind[ HEXA_NS::Geometric ] = "Geometric";
5566 QMap<HEXA_NS::KindLaw, QString>::ConstIterator iKind, iEnd;
5567 for( iKind = strKind.constBegin(), iEnd = strKind.constEnd(); iKind != iEnd; ++iKind )
5568 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5570 if (editmode == INFO_MODE)
5572 name_le->setReadOnly(true);
5573 nb_nodes_spb->setReadOnly(true);
5574 coeff_spb->setReadOnly(true);
5575 kind_cb->setEnabled(false);
5579 // ============================================================== clear
5580 void LawDialog::clear()
5584 modelUnregister(this);
5587 // ============================================================== setValue
5588 void LawDialog::setValue(HEXA_NS::Law* l)
5591 name_le->setText( l->getName() );
5593 nb_nodes_spb->setValue( l->getNodes() );
5594 coeff_spb->setValue( l->getCoefficient() );
5596 HEXA_NS::KindLaw k = l->getKind();
5597 kind_cb->setCurrentIndex( kind_cb->findData(k) );
5602 // ============================================================== getValue
5603 HEXA_NS::Law* LawDialog::getValue()
5608 // ============================================================== apply
5609 bool LawDialog::apply(QModelIndex& result)
5611 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5614 if ( !getDocumentModel() ) return false;
5616 const MeshModel* meshModel = getMeshModel();
5617 if (meshModel == NULL) return false;
5619 QString lawName = name_le->text();
5620 int nbnodes = nb_nodes_spb->value();
5621 double coeff = coeff_spb->value();
5622 DocumentModel::KindLaw lawKind = static_cast<DocumentModel::KindLaw>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5625 if ( _value == NULL ){ // create Law
5626 iLaw = getDocumentModel()->addLaw( lawName, nbnodes );
5628 QModelIndexList iLaws = getDocumentModel()->match(
5629 getDocumentModel()->index(0, 0),
5631 QVariant::fromValue( _value ),
5633 Qt::MatchRecursive );
5634 if ( !iLaws.isEmpty() )
5638 if ( !iLaw.isValid() ){
5639 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5642 //fill it and select it
5643 bool setOk = getDocumentModel()->setLaw( iLaw, nbnodes, coeff, lawKind );
5645 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5649 QString newName = name_le->text();
5650 if ( !newName.isEmpty() )/*{*/
5651 getDocumentModel()->setName( iLaw, newName );
5653 HEXA_NS::Law* hLaw = getDocumentModel()->data(iLaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
5657 name_le->setText(hLaw->getNextName(buffer));
5661 result = meshModel->mapFromSource(iLaw);
5666 // ------------------------- PropagationDialog ----------------------------------
5667 // ============================================================== Constructeur
5668 PropagationDialog::PropagationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5669 : HexaBaseDialog(parent, editmode, f),
5672 _helpFileName = "gui_propag.html";
5674 _initWidget(editmode);
5676 if ( editmode == INFO_MODE ){
5677 setWindowTitle( tr("Propagation Information") );
5680 } else if ( editmode == UPDATE_MODE ){
5681 setWindowTitle( tr("Propagation Modification") );
5684 } else if ( editmode == NEW_MODE ){
5685 setWindowTitle( tr("Propagation(s) Setting") );
5689 // ============================================================== Destructeur
5690 PropagationDialog::~PropagationDialog()
5694 // ============================================================== _initInputWidget
5695 void PropagationDialog::_initInputWidget( Mode editmode )
5698 QValidator *validator = new QRegExpValidator(rx, this);
5700 installEventFilter(this);
5703 law_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5704 law_le->installEventFilter(this);
5705 law_le->setValidator( validator );
5707 propagations_lw->setProperty( "HexaWidgetType", QVariant::fromValue(PROPAGATION_TREE) );
5708 propagations_lw->installEventFilter(this);
5710 QShortcut* delPropagationShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), propagations_lw);
5711 delPropagationShortcut->setContext( Qt::WidgetShortcut );
5713 law_le->setReadOnly(true);
5715 if ( editmode == INFO_MODE)
5716 way_cb->setEnabled(false);
5718 connect( delPropagationShortcut, SIGNAL(activated()), this, SLOT(deletePropagationItem()) );
5719 connect( propagations_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
5722 // ============================================================== clear
5723 void PropagationDialog::clear()
5725 propagations_lw->clear();
5726 modelUnregister(propagations_lw);
5729 modelUnregister(law_le);
5731 modelUnregister(this);
5734 // ============================================================== deletePropagationItem
5735 void PropagationDialog::deletePropagationItem()
5737 delete propagations_lw->currentItem();
5740 // ============================================================== setValue
5741 void PropagationDialog::setValue(HEXA_NS::Propagation* p)
5743 if (getMeshSelectionModel() == NULL) return;
5744 HEXA_NS::Law* l = p->getLaw();
5745 bool way = p->getWay();
5748 QModelIndex ip = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
5749 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(ip) );
5751 // law on propagation
5753 law_le->setText( l->getName() );
5754 QModelIndex il = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(l) );
5755 law_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(il) );
5758 // way of propagation
5759 way_cb->setChecked(way);
5764 // ============================================================== selectElementOfModel
5766 /*Selects in the model (treeview) elements selected in a listwidget,
5767 * or an element in a line edit.*/
5769 void PropagationDialog::selectElementOfModel()
5771 if (!getMeshSelectionModel()) return;
5773 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5774 if ( !currentListWidget ) return;
5776 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5778 getMeshSelectionModel()->clearSelection();
5779 foreach ( QListWidgetItem *item, sel ){
5780 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
5781 index = getMeshSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5782 if ( index.isValid() )
5783 getMeshSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
5787 // ============================================================== getValue
5788 HEXA_NS::Propagation* PropagationDialog::getValue()
5793 // ============================================================== apply
5794 bool PropagationDialog::apply(QModelIndex& result)
5796 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5800 if ( !getDocumentModel() ) return false;
5801 const MeshModel* meshModel = getMeshModel();
5802 if (meshModel == NULL) return false;
5804 bool way = way_cb->isChecked();
5805 QListWidgetItem* item = NULL;
5807 QModelIndex iPropagation;
5808 QModelIndex iLaw = meshModel->mapToSource( law_le->property("QModelIndex").value<QModelIndex>() );
5809 if (!iLaw.isValid() ){
5810 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5814 int nbPropagations = propagations_lw->count();
5815 for (int r = 0; r < nbPropagations; ++r){
5816 item = propagations_lw->item(r);
5817 iPropagation = meshModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5818 if ( !iPropagation.isValid() ){
5819 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5823 //fill it and select it
5824 isOk = getDocumentModel()->setPropagation( iPropagation, iLaw, way );
5826 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) + "\n" + getErrorMsg() );
5830 result = meshModel->mapFromSource(iPropagation);
5836 // ------------------------- ComputeMeshDialog ----------------------------------
5837 // ============================================================== Constructeur
5838 ComputeMeshDialog::ComputeMeshDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5839 HexaBaseDialog(parent, editmode, f)
5841 _helpFileName = "gui_mesh.html";
5842 setWindowTitle( tr("Compute mesh") );
5844 _initWidget(editmode);
5847 // ============================================================== Destructeur
5848 ComputeMeshDialog::~ComputeMeshDialog()
5852 // ============================================================== _initInputWidget
5853 void ComputeMeshDialog::_initInputWidget( Mode editmode )
5857 // ============================================================== setDocumentModel
5858 void ComputeMeshDialog::setDocumentModel(DocumentModel* m)
5860 if (m == NULL) return;
5861 _name->setText(m->getName());
5864 // ============================================================== clear
5865 void ComputeMeshDialog::clear()
5867 modelUnregister(this);
5870 // ============================================================== apply
5871 bool ComputeMeshDialog::apply(QModelIndex& result)
5873 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5876 if (getDocumentModel() == NULL) return false;
5877 QString command = QString("import hexablock ; %1 = hexablock.mesh(\"%2\", \"%1\", %3, \"%4\")")
5878 .arg( _name->text() )
5879 .arg( getDocumentModel()->getName() )
5880 .arg( _dim->value() )
5881 .arg( _fact->text() );
5883 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
5884 PyConsole_Console* pyConsole = app->pythonConsole();
5887 pyConsole->exec( command );
5894 // ------------------------- ReplaceHexaDialog ----------------------------------
5895 // ============================================================== Constructeur
5896 ReplaceHexaDialog::ReplaceHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5897 HexaBaseDialog(parent, editmode, f)
5899 _helpFileName = "gui_replace_hexa.html";
5901 _initWidget(editmode);
5904 // ============================================================== Destructeur
5905 ReplaceHexaDialog::~ReplaceHexaDialog()
5909 // ============================================================== getAssocsVTK
5911 * Returns elements currently associated to vtk
5913 QModelIndexList ReplaceHexaDialog::getAssocsVTK()
5915 QModelIndexList assocs;
5917 QListWidgetItem* item = NULL;
5919 //ListWidget content
5920 int nbQuads = quads_lw->count();
5921 for ( int r = 0; r < nbQuads; ++r ){
5922 item = quads_lw->item(r);
5923 //iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
5924 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5925 if ( iQuad.isValid() )
5929 nbQuads = quads_lw_2->count();
5930 for( int i = 0; i < nbQuads; ++i)
5932 item = quads_lw_2->item(i);
5933 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5934 if (iQuad.isValid())
5941 // ============================================================== _initInputWidget
5942 void ReplaceHexaDialog::_initInputWidget( Mode editmode )
5946 installEventFilter(this);
5948 c1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5949 c2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5951 p1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5952 p2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5954 c1_le->installEventFilter(this);
5955 c2_le->installEventFilter(this);
5957 p1_le->installEventFilter(this);
5958 p2_le->installEventFilter(this);
5960 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5961 quads_lw->installEventFilter(this);
5963 quads_lw_2->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5964 quads_lw_2->installEventFilter(this);
5966 if ( editmode == NEW_MODE ){
5967 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5968 QShortcut* delQuadShortcut2 = new QShortcut( QKeySequence(Qt::Key_X), quads_lw_2 );
5969 delQuadShortcut->setContext( Qt::WidgetShortcut );
5970 delQuadShortcut2->setContext( Qt::WidgetShortcut );
5971 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()) );
5972 connect( quads_lw, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5973 connect( delQuadShortcut2, SIGNAL(activated()), this, SLOT(deleteQuadItem2()));
5974 connect( quads_lw_2, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5977 c1_le->setReadOnly(true);
5978 c2_le->setReadOnly(true);
5980 p1_le->setReadOnly(true);
5981 p2_le->setReadOnly(true);
5983 connect(quads_lw, SIGNAL(itemSelectionChanged()),
5984 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5986 connect(quads_lw_2, SIGNAL(itemSelectionChanged()),
5987 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5990 // ============================================================== clear
5991 void ReplaceHexaDialog::clear()
5994 modelUnregister(quads_lw);
5996 quads_lw_2->clear();
5997 modelUnregister(quads_lw_2);
6000 modelUnregister(p1_le);
6003 modelUnregister(p2_le);
6006 modelUnregister(c1_le);
6009 modelUnregister(c2_le);
6011 modelUnregister(this);
6014 // ============================================================== updateButtonBox
6015 void ReplaceHexaDialog::updateButtonBox()
6017 int nbQuad = quads_lw->count();
6020 _applyButton->setEnabled(true);
6022 _applyButton->setEnabled(false);
6026 // ============================================================== deleteQuadItem
6027 void ReplaceHexaDialog::deleteQuadItem()
6029 delete quads_lw->currentItem();
6033 // ============================================================== deleteQuadItem2
6034 void ReplaceHexaDialog::deleteQuadItem2()
6036 delete quads_lw_2->currentItem();
6040 // ============================================================== apply
6041 bool ReplaceHexaDialog::apply(QModelIndex& result)
6043 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6046 if ( !getDocumentModel() ) return false;
6047 const PatternDataModel* patternDataModel = getPatternDataModel();
6048 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6049 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
6051 QModelIndex ielts; //result
6053 QListWidgetItem* item = NULL;
6054 QModelIndexList iquads_source;
6056 int nbQuads = quads_lw->count();
6057 for ( int r = 0; r < nbQuads; ++r){
6058 item = quads_lw->item(r);
6059 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6060 if ( iquad.isValid() )
6061 iquads_source << iquad;
6064 QModelIndexList iquads_dest;
6065 nbQuads = quads_lw_2->count();
6066 for (int i = 0; i < nbQuads; ++i)
6068 item = quads_lw_2->item(i);
6069 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6070 if (iquad.isValid())
6071 iquads_dest << iquad;
6074 QModelIndex ip1_source = patternDataModel->mapToSource( _index[p1_le] );
6075 QModelIndex ip2_source = patternDataModel->mapToSource( _index[p2_le] );
6077 QModelIndex ic1_dest = patternDataModel->mapToSource( _index[c1_le] );
6078 QModelIndex ic2_dest = patternDataModel->mapToSource( _index[c2_le] );
6080 bool ipts_ok = ip1_source.isValid() && ip2_source.isValid() &&
6081 ic1_dest.isValid() && ic2_dest.isValid();
6085 ielts = getDocumentModel()->replace( iquads_source, iquads_dest,
6086 ip1_source, ic1_dest,
6087 ip2_source, ic2_dest );
6090 if ( !ielts.isValid() ){
6091 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REPLACE HEXA" ) + "\n" + getErrorMsg() );
6094 _value = ielts.model()->data(ielts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6095 // result = patternBuilderModel->mapFromSource(ielts);
6096 result = patternDataModel->mapFromSource(ielts);
6098 //update the list (indexes)
6099 for ( int r = 0; r < nbQuads; ++r ){
6100 item = quads_lw->item(r);
6101 iquad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
6102 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iquad) );
6103 item->setData(LW_DATA_ROLE, iquad.data(HEXA_DATA_ROLE));
6109 // ------------------------- QuadRevolutionDialog ----------------------------------
6110 // ============================================================== Constructeur
6112 QuadRevolutionDialog::QuadRevolutionDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
6113 HexaBaseDialog(parent, editmode, f)
6116 _helpFileName = "gui_quad_revolution.html#guiquadsrevolution";
6117 connect( revolutionUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6118 connect( revolution_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6119 _initWidget(editmode);
6120 revolutionUni_rb->click();
6123 // ============================================================== getAssocsVTK
6125 * Returns elements currently associated to vtk
6127 QModelIndexList QuadRevolutionDialog::getAssocsVTK()
6129 QModelIndexList assocs;
6131 QListWidgetItem* item = NULL;
6132 if (getPatternDataSelectionModel() == NULL) return assocs;
6134 //ListWidget content
6135 const PatternDataModel* patternDataModel = getPatternDataModel();
6136 if ( !patternDataModel ) return assocs;
6137 int nbQuads = quads_lw->count();
6138 for ( int r = 0; r < nbQuads; ++r ){
6139 item = quads_lw->item(r);
6140 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6141 if ( iQuad.isValid() )
6147 // ============================================================== Destructeur
6148 QuadRevolutionDialog::~QuadRevolutionDialog()
6152 // ============================================================== _initInputWidget
6153 void QuadRevolutionDialog::_initInputWidget( Mode editmode )
6155 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
6156 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6157 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6159 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
6160 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
6161 angle_spb->setProperty("Angle", QVariant::fromValue(true));
6162 angle_spb->installEventFilter(this);
6164 angles_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
6165 angles_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
6166 angles_lw->setProperty("Angle", QVariant::fromValue(true));
6167 angles_lw->installEventFilter(this);
6169 installEventFilter(this);
6170 revolutionUni_rb->installEventFilter(this);
6171 revolution_rb->installEventFilter(this);
6173 quads_lw->installEventFilter(this);
6174 center_le->installEventFilter(this);
6175 axis_le->installEventFilter(this);
6177 center_le->setReadOnly(true);
6178 axis_le->setReadOnly(true);
6180 angles_lw->setItemDelegate( new HexaAngleDoubleSpinBoxDelegate(angles_lw) );
6181 angles_lw->setEditTriggers( QAbstractItemView::DoubleClicked );
6183 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
6184 delQuadShortcut->setContext( Qt::WidgetShortcut );
6185 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(delQuadItem()) );
6186 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()));
6187 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()));
6189 connect(quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
6192 // ============================================================== updateHelpFileName
6193 void QuadRevolutionDialog::updateHelpFileName()
6195 if ( sender() == revolutionUni_rb ){
6196 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutionuniform";
6197 } else if ( sender() == revolution_rb ){
6198 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutioncustom";
6202 // ============================================================== clear
6203 void QuadRevolutionDialog::clear()
6206 modelUnregister(quads_lw);
6209 modelUnregister(center_le);
6212 modelUnregister(axis_le);
6214 modelUnregister(this);
6217 // ============================================================== addAngleItem
6218 void QuadRevolutionDialog::addAngleItem() //CS_TODO
6220 QListWidgetItem* previousItem = angles_lw->currentItem();
6221 QListWidgetItem* newItem = new QListWidgetItem();
6223 double defaultValue = 180.;
6225 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6227 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6228 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6229 angles_lw->addItem(newItem);
6234 // ============================================================== delAngleItem
6235 void QuadRevolutionDialog::delAngleItem()
6237 delete angles_lw->currentItem();
6241 // ============================================================== delQuadItem
6242 void QuadRevolutionDialog::delQuadItem()
6244 delete quads_lw->currentItem();
6248 // ============================================================== apply
6249 bool QuadRevolutionDialog::apply(QModelIndex& result)
6251 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6254 DocumentModel* docModel = getDocumentModel();
6255 PatternDataModel* patternDataModel = getPatternDataModel();
6256 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6258 QListWidgetItem* item = NULL;
6260 QModelIndexList istartquads;
6262 int nbQuads = quads_lw->count();
6263 for ( int r = 0; r < nbQuads; ++r){
6264 item = quads_lw->item(r);
6265 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6266 if ( iquad.isValid() )
6267 istartquads << iquad;
6270 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6271 QModelIndex iaxis = patternDataModel->mapToSource(_index[axis_le]);
6272 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
6273 int angle = angle_spb->value();
6274 int nbre = nbre_spb->value();
6276 vector<double> angles;
6277 int nbAngles = angles_lw->count();
6278 for ( int r = 0; r < nbAngles; ++r){
6279 item = angles_lw->item(r);
6280 angles.push_back(item->data(Qt::EditRole).toDouble());
6283 QModelIndex iElts; //result
6284 if (nbQuads == 1 && istartquads[0].isValid() && icenter.isValid() && iaxis.isValid())
6286 if (revolutionUni_rb->isChecked())
6287 iElts = docModel->revolutionQuadUni(istartquads[0], icenter, iaxis, angle, nbre);
6288 else if (revolution_rb->isChecked())
6289 iElts = docModel->revolutionQuad(istartquads[0], icenter, iaxis, angles);
6291 else if (nbQuads > 1 && icenter.isValid() && iaxis.isValid())
6293 if (revolutionUni_rb->isChecked())
6294 iElts = docModel->revolutionQuadsUni(istartquads, icenter, iaxis, angle, nbre);
6295 else if (revolution_rb->isChecked())
6296 iElts = docModel->revolutionQuads(istartquads, icenter, iaxis, angles);
6299 if ( !iElts.isValid() ){
6300 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD REVOLUTION" ) + "\n" + getErrorMsg() );
6303 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6304 result = patternDataModel->mapFromSource(iElts);
6305 // result = patternBuilderModel->mapFromSource(iElts);
6310 // ------------------------- MakeHemiSphereDialog ----------------------------------
6311 // ============================================================== Constructeur
6312 MakeHemiSphereDialog::MakeHemiSphereDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
6313 HexaBaseDialog(parent, editmode, f)
6315 _helpFileName = "gui_hemisphere.html";
6317 _initWidget(editmode);
6320 connect( sphereTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6321 connect( sphereUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6322 connect( sphere2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6323 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6324 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6326 connect( sphericalTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6327 connect( sphericalUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6328 connect( spherical2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6329 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6330 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6332 connect( rindTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6333 connect( rindUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6334 connect( rind2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6335 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6336 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6339 // ============================================================== Destructeur
6340 MakeHemiSphereDialog::~MakeHemiSphereDialog()
6344 // ============================================================== _initInputWidget
6345 void MakeHemiSphereDialog::_initInputWidget( Mode editmode )
6347 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6348 hole_axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6349 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6350 vplan_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6352 sphere_radext_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6353 sphere_radext_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6354 sphere_radext_spb->setProperty("Radius", QVariant::fromValue(true));
6356 sphere_radint_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6357 sphere_radint_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6358 sphere_radint_spb->setProperty("Radius", QVariant::fromValue(true));
6360 hole_rad_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6361 hole_rad_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6362 hole_rad_spb->setProperty("Radius", QVariant::fromValue(true));
6364 radial_angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6365 radial_angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6366 radial_angle_spb->setProperty("Angle", QVariant::fromValue(true));
6368 radius_lw_1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6369 radius_lw_1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6370 radius_lw_1->setProperty("Radius", QVariant::fromValue(true));
6372 radius_lw_2->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6373 radius_lw_2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6374 radius_lw_2->setProperty("Radius", QVariant::fromValue(true));
6376 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6377 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6378 height_lw->setProperty("Length", QVariant::fromValue(true));
6380 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6381 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6382 angle_lw->setProperty("Angle", QVariant::fromValue(true));
6384 installEventFilter(this);
6385 center_le->installEventFilter(this);
6386 hole_axis_le->installEventFilter(this);
6387 base_le->installEventFilter(this);
6388 vplan_le->installEventFilter(this);
6390 sphere_radext_spb->installEventFilter(this);
6391 sphere_radint_spb->installEventFilter(this);
6392 hole_rad_spb->installEventFilter(this);
6393 radial_angle_spb->installEventFilter(this);
6394 radius_lw_1->installEventFilter(this);
6395 radius_lw_2->installEventFilter(this);
6396 height_lw->installEventFilter(this);
6397 angle_lw->installEventFilter(this);
6399 sphere_rb->installEventFilter(this);
6400 sphereTop_rb->installEventFilter(this);
6401 sphereUni_rb->installEventFilter(this);
6402 sphere2_rb->installEventFilter(this);
6403 rind_rb->installEventFilter(this);
6404 rindTop_rb->installEventFilter(this);
6405 rindUni_rb->installEventFilter(this);
6406 rind2_rb->installEventFilter(this);
6407 spherical_rb->installEventFilter(this);
6408 sphericalTop_rb->installEventFilter(this);
6409 sphericalUni_rb->installEventFilter(this);
6410 spherical2_rb->installEventFilter(this);
6412 center_le->setReadOnly(true);
6413 hole_axis_le->setReadOnly(true);
6414 base_le->setReadOnly(true);
6415 vplan_le->setReadOnly(true);
6417 radius_lw_1->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_1));
6418 radius_lw_1->setEditTriggers(QAbstractItemView::DoubleClicked);
6420 radius_lw_2->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_2));
6421 radius_lw_2->setEditTriggers(QAbstractItemView::DoubleClicked);
6423 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
6424 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6426 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
6427 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6429 connect( add_radius_pb_1, SIGNAL(clicked()), this, SLOT(addRadiusItem1()) );
6430 connect( del_radius_pb_1, SIGNAL(clicked()), this, SLOT(delRadiusItem1()) );
6432 connect( add_radius_pb_2, SIGNAL(clicked()), this, SLOT(addRadiusItem2()) );
6433 connect( del_radius_pb_2, SIGNAL(clicked()), this, SLOT(delRadiusItem2()) );
6435 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
6436 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
6438 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
6439 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
6442 // ============================================================== updateHelpFileName
6443 void MakeHemiSphereDialog::updateHelpFileName()
6445 if ( sender() == sphereTop_rb || sender() == rindTop_rb ){
6446 _helpFileName = "gui_hemisphere.html#guisphereandrindsimple";
6447 } else if ( sender() == sphereUni_rb ){
6448 _helpFileName = "gui_hemisphere.html#guisphereuniform";
6449 } else if ( sender() == sphere2_rb ){
6450 _helpFileName = "gui_hemisphere.html#guispherecustom";
6451 } else if ( sender() == rindUni_rb ){
6452 _helpFileName = "gui_hemisphere.html#guirinduniform";
6453 } else if ( sender() == rind2_rb ){
6454 _helpFileName = "gui_hemisphere.html#guirindcustom";
6455 } else if ( sender() == sphericalTop_rb ){
6456 _helpFileName = "gui_hemisphere.html#guiconcentricsimple";
6457 } else if ( sender() == sphericalUni_rb ){
6458 _helpFileName = "gui_hemisphere.html#guiconcentricuniform";
6459 } else if ( sender() == spherical2_rb ){
6460 _helpFileName = "gui_hemisphere.html#guiconcentriccustom";
6464 // ============================================================== addRadiusItem
6465 void MakeHemiSphereDialog::addRadiusItem1()
6467 QListWidgetItem* previousItem = radius_lw_1->currentItem();
6468 QListWidgetItem* newItem = new QListWidgetItem();
6470 double defaultValue = 1.;
6472 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6474 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6475 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6476 radius_lw_1->addItem(newItem);
6479 // ============================================================== delRadiusItem
6480 void MakeHemiSphereDialog::delRadiusItem1()
6482 delete radius_lw_1->currentItem();
6485 // ============================================================== addRadiusItem
6486 void MakeHemiSphereDialog::addRadiusItem2()
6488 QListWidgetItem* previousItem = radius_lw_2->currentItem();
6489 QListWidgetItem* newItem = new QListWidgetItem();
6491 double defaultValue = 1.;
6493 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6495 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6496 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6497 radius_lw_2->addItem(newItem);
6500 // ============================================================== delRadiusItem
6501 void MakeHemiSphereDialog::delRadiusItem2()
6503 delete radius_lw_2->currentItem();
6506 // ============================================================== addAngleItem
6507 void MakeHemiSphereDialog::addAngleItem()
6509 QListWidgetItem* previousItem = angle_lw->currentItem();
6510 QListWidgetItem* newItem = new QListWidgetItem();
6512 double defaultValue = 180.;
6514 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6516 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6517 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6518 angle_lw->addItem(newItem);
6521 // ============================================================== delAngleItem
6522 void MakeHemiSphereDialog::delAngleItem()
6524 delete angle_lw->currentItem();
6527 // ============================================================== addHeightItem
6528 void MakeHemiSphereDialog::addHeightItem()
6530 QListWidgetItem* previousItem = height_lw->currentItem();
6531 QListWidgetItem* newItem = new QListWidgetItem();
6533 double defaultValue = 1.;
6535 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6537 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6538 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6539 height_lw->addItem(newItem);
6542 // ============================================================== delHeightItem
6543 void MakeHemiSphereDialog::delHeightItem()
6545 delete height_lw->currentItem();
6548 // ============================================================== clear
6549 void MakeHemiSphereDialog::clear()
6552 modelUnregister(center_le);
6554 hole_axis_le->clear();
6555 modelUnregister(hole_axis_le);
6558 modelUnregister(base_le);
6561 modelUnregister(vplan_le);
6563 modelUnregister(this);
6566 // ============================================================== apply
6567 bool MakeHemiSphereDialog::apply(QModelIndex& result)
6569 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6572 DocumentModel* docModel = getDocumentModel();
6573 PatternDataModel* patternDataModel = getPatternDataModel();
6574 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6577 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6578 QModelIndex ivplan = patternDataModel->mapToSource( _index[vplan_le] );
6579 QModelIndex ivecx = patternDataModel->mapToSource(_index[base_le]);
6580 QModelIndex ivecz = patternDataModel->mapToSource(_index[hole_axis_le]);
6581 // QModelIndex ivecx = patternBuilderModel->mapToSource( _index[base_le] );
6582 // QModelIndex ivecz = patternBuilderModel->mapToSource( _index[hole_axis_le] );
6584 double radhole = hole_rad_spb->value();
6585 double radext = sphere_radext_spb->value();
6586 double radint = sphere_radint_spb->value();
6587 double radang = radial_angle_spb->value();
6589 int crit = crit_spb->value();
6590 int nb = nbre_spb->value();
6591 int nrad = ngrid_rad_spb->value();
6592 int nang = ngrid_ang_spb->value();
6593 int nhaut = ngrid_height_spb->value();
6595 //radius, angles and heights collection
6596 QListWidgetItem* item = NULL;
6598 vector<double> radius1;
6599 vector<double> radius2;
6600 vector<double> angles;
6601 vector<double> heights;
6604 // double somme = 0.;
6605 int nbAngles = angle_lw->count();
6606 for ( int r = 0; r < nbAngles; ++r){
6607 item = angle_lw->item(r);
6608 double itemValue = item->data(Qt::EditRole).toDouble();
6609 angles.push_back(itemValue);
6610 // somme += itemValue;
6613 //radius1 collection
6614 int nbRadius = radius_lw_1->count();
6615 for ( int r = 0; r < nbRadius; ++r){
6616 item = radius_lw_1->item(r);
6617 radius1.push_back(item->data(Qt::EditRole).toDouble());
6620 //radius2 collection
6621 nbRadius = radius_lw_2->count();
6622 for ( int r = 0; r < nbRadius; ++r){
6623 item = radius_lw_2->item(r);
6624 radius2.push_back(item->data(Qt::EditRole).toDouble());
6627 //heights collection
6628 int nbHeight = height_lw->count();
6629 for ( int r = 0; r < nbHeight; ++r){
6630 item = height_lw->item(r);
6631 heights.push_back(item->data(Qt::EditRole).toDouble());
6634 if (sphere_rb->isChecked())
6636 if (sphereTop_rb->isChecked())
6637 iElts = docModel->makeSphereTop( nrad, nang, nhaut );
6638 else if (sphereUni_rb->isChecked())
6640 if (icenter.isValid() && ivplan.isValid() && ivecx.isValid() && ivecz.isValid())
6641 iElts = docModel->makeSphereUni(icenter, ivecx, ivecz, radhole, radext, radang,
6642 ivplan, nrad, nang, nhaut);
6644 else if (sphere2_rb->isChecked())
6646 // if (somme > 360.01)
6648 // SUIT_MessageBox::information( 0,
6650 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6653 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6654 iElts = docModel->makeSphere(icenter, ivecx, ivecz, radius2, angles, heights);
6657 else if (spherical_rb->isChecked())
6659 if (sphericalTop_rb->isChecked())
6660 iElts = docModel->makeSphericalTop(nb, crit);
6661 else if (sphericalUni_rb->isChecked())
6663 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6664 iElts = docModel->makeSphericalUni(icenter, ivecx, ivecz, radhole, nb, crit);
6666 else if (spherical2_rb->isChecked())
6668 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6669 iElts = docModel->makeSpherical(icenter, ivecx, ivecz, radius1, crit);
6672 else if (rind_rb->isChecked())
6674 if (rindTop_rb->isChecked())
6675 iElts = docModel->makeRindTop(nrad, nang, nhaut);
6676 else if (rindUni_rb->isChecked())
6678 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid() && ivplan.isValid())
6679 iElts = docModel->makeRindUni(icenter, ivecx, ivecz,
6680 radhole, radint, radext, radang,
6681 ivplan, nrad, nang, nhaut);
6683 else if (rind2_rb->isChecked())
6685 // if (somme > 360.01)
6687 // SUIT_MessageBox::information( 0,
6689 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6692 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6693 iElts = docModel->makeRind(icenter, ivecx, ivecz, radius2, angles, heights);
6697 if ( !iElts.isValid() ){
6698 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) + "\n" + getErrorMsg() );
6701 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6702 result = patternDataModel->mapFromSource(iElts);
6703 // result = patternBuilderModel->mapFromSource(iElts);
6708 // ------------------------- ModelInfoDialog ----------------------------------
6709 ModelInfoDialog::ModelInfoDialog(QWidget* parent, Qt::WindowFlags wf):
6710 HexaBaseDialog(parent, INFO_MODE, wf)
6713 setWindowTitle(HEXABLOCKGUI::tr("MODEL_INFO"));
6716 void ModelInfoDialog::updateInfo()
6718 DocumentModel* docModel = getDocumentModel();
6719 if (docModel == NULL) return;
6722 model_name_le->setText(docModel->getName());
6724 //Nb of elements in the model
6725 total_vertices_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_VERTEX)));
6726 total_edges_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_EDGE)));
6727 total_quads_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_QUAD)));
6728 total_hexas_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_HEXA)));
6730 ///Nb of used elements in the model
6731 used_vertices_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_VERTEX)));
6732 used_edges_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_EDGE)));
6733 used_quads_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_QUAD)));
6734 used_hexas_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_HEXA)));
6736 //Nb of unused elements in the model
6737 unused_vertices_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_VERTEX)));
6738 unused_edges_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_EDGE)));
6739 unused_quads_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_QUAD)));
6740 unused_hexas_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_HEXA)));
6743 void ModelInfoDialog::showEvent( QShowEvent * event )
6746 QDialog::showEvent ( event );
6749 // ============================================================== hideEvent
6750 void ModelInfoDialog::hideEvent ( QHideEvent * event )
6752 QDialog::hideEvent( event );
6755 // ------------------------- AddShapeDialog ----------------------------------
6756 AddShapeDialog::AddShapeDialog(QWidget* parent, Mode editmode, Qt::WindowFlags wf):
6757 HexaBaseDialog(parent, editmode, wf)
6759 _helpFileName = "gui_add_geometry.html#guiaddgeometry";
6761 _initWidget(editmode);
6762 setWindowTitle(HEXABLOCKGUI::tr("ADD_SHAPE"));
6765 // ============================================================== Destructeur
6766 AddShapeDialog::~AddShapeDialog()
6768 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
6769 this, SLOT(onCurrentSelectionChanged()) );
6772 // ============================================================== close
6773 void AddShapeDialog::close()
6775 HEXABLOCKGUI::assocInProgress = false;
6776 HexaBaseDialog::close();
6779 // ============================================================== _initInputWidget
6780 void AddShapeDialog::_initInputWidget( Mode editmode )
6782 shape_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMSHAPE_TREE) );
6783 shape_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_SHAPE) );
6784 shape_le->installEventFilter(this);
6785 shape_le->setReadOnly(true);
6788 void AddShapeDialog::clear()
6791 shape_le->setProperty("GeomObj", QVariant());
6793 modelUnregister(this);
6796 // ============================================================== onCurrentSelectionChanged
6797 void AddShapeDialog::onCurrentSelectionChanged()
6799 SALOME_ListIO selectedObjects;
6800 HEXABLOCKGUI::currentDocGView->getSelected(selectedObjects);
6801 if (selectedObjects.IsEmpty())
6804 // * extract the TopoDS_Shape of the selected object
6805 TopoDS_Shape selectedTopoShape = GEOMBase::GetTopoFromSelection( selectedObjects );
6806 if (selectedTopoShape.IsNull())
6808 shape_le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(selectedTopoShape));
6810 // * extract the name of the selected shape
6812 GEOMBase::GetNameOfSelectedIObjects( selectedObjects, name, true );
6813 shape_le->setText(name);
6816 // ============================================================== onWindowActivated
6817 void AddShapeDialog::onWindowActivated(SUIT_ViewManager* vm)
6819 QString vmType = vm->getType();
6820 if ( vmType == OCCViewer_Viewer::Type() )
6821 shape_le->setFocus();
6824 // ============================================================== apply
6825 bool AddShapeDialog::apply(QModelIndex& result)
6828 QString shapeName = shape_le->text();
6829 QVariant v = shape_le->property("TopoDS_Shape");
6830 if ( !v.isValid() || shapeName.isEmpty())
6834 TopoDS_Shape shape = v.value<TopoDS_Shape>();
6838 assocOk = getDocumentModel()->addShape(shape, shapeName);
6842 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), HEXABLOCKGUI::tr("ADD_SHAPE_FAILED") + "\n" + getErrorMsg() );