1 // Copyright (C) 2009-2015 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <OCCViewer_ViewWindow.h>
21 #include "HEXABLOCKGUI_DocumentPanel.hxx"
22 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
23 #include "HEXABLOCKGUI_OccGraphicView.hxx"
24 #include "HEXABLOCKGUI_SalomeTools.hxx"
31 #include <SalomeApp_Application.h>
32 #include <SalomeApp_Study.h>
33 #ifndef DISABLE_PYCONSOLE
34 #include <PyConsole_Console.h>
36 #include <SalomeApp_Tools.h>
38 #include <Standard_GUID.hxx>
39 #include <TDF_Label.hxx>
41 #include <OCCViewer_ViewManager.h>
44 #include <TopExp_Explorer.hxx>
45 #include <TopoDS_Iterator.hxx>
46 #include <TopTools_MapOfShape.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <TColStd_IndexedMapOfInteger.hxx>
50 #include <SUIT_Session.h>
51 #include <SUIT_Desktop.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_MessageBox.h>
54 #include <SUIT_Session.h>
55 #include "SVTK_Selection.h"
56 #include <SVTK_ViewModel.h>
57 #include <VTKViewer_ViewModel.h>
58 #include <SVTK_View.h>
60 #include <SUIT_ResourceMgr.h>
64 #include <utilities.h>
66 #define BUTTON_BOX_MIN_WIDTH 5
67 #define VERTEX_COORD_MIN -1000000
68 #define VERTEX_COORD_MAX 1000000
69 #define SPINBOX_ANGLE_MAX 360
70 #define SPINBOX_DOUBLE_MAX 1000000000
71 #define SPINBOX_POSITIVE_DOUBLE_MIN 0
76 using namespace HEXABLOCK::GUI;
79 Q_DECLARE_METATYPE(HEXABLOCK::GUI::HexaTreeRole);
80 Q_DECLARE_METATYPE(DocumentModel::GeomObj);
81 Q_DECLARE_METATYPE(TopAbs_ShapeEnum);
82 Q_DECLARE_METATYPE(TopoDS_Shape);
84 //General SpinBox Delegate
85 class HexaDoubleSpinBoxDelegate : public QStyledItemDelegate {
87 HexaDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
89 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
90 const QModelIndex &index) const{
91 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
92 sb->setDecimals(NB_DECIMALS);
97 //Angle SpinBox Delegate
98 class HexaAngleDoubleSpinBoxDelegate : public QStyledItemDelegate {
100 HexaAngleDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
102 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
103 const QModelIndex &index) const{
104 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
105 sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
106 sb->setMaximum(SPINBOX_ANGLE_MAX);
107 sb->setDecimals(NB_DECIMALS);
113 //Positive DoubleSpinBox Delegate (for heigth, radius, ...)
114 class HexaPositiveDoubleSpinBoxDelegate : public QStyledItemDelegate {
116 HexaPositiveDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
118 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
119 const QModelIndex &index) const{
120 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
121 sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
122 sb->setMaximum(SPINBOX_DOUBLE_MAX); //10e9
123 sb->setDecimals(NB_DECIMALS);
128 // ======================================================== Constructeur
129 HexaBaseDialog::HexaBaseDialog( QWidget * parent, Mode editmode, Qt::WindowFlags f ):
131 _editMode( editmode ),
134 debugEdgeAssoc(false),
135 autoFocusSwitch(true)
137 _strHexaWidgetType[VERTEX_TREE] = tr( "VERTEX" );
138 _strHexaWidgetType[EDGE_TREE] = tr( "EDGE" );
139 _strHexaWidgetType[QUAD_TREE] = tr( "QUAD" );
140 _strHexaWidgetType[HEXA_TREE] = tr( "HEXA" );
142 _strHexaWidgetType[VECTOR_TREE] = tr( "VECTOR" );
143 // _strHexaWidgetType[CYLINDER_TREE] = tr( "CYLINDER" );
144 // _strHexaWidgetType[PIPE_TREE] = tr( "PIPE" );
145 _strHexaWidgetType[ELEMENTS_TREE] = tr( "ELEMENTS" );
146 _strHexaWidgetType[CROSSELEMENTS_TREE]= tr( "CROSSELEMENTS" );
149 _strHexaWidgetType[GEOMSHAPE_TREE] = tr( "GEOMSHAPE" );
150 _strHexaWidgetType[GEOMPOINT_TREE] = tr( "GEOMPOINT" );
151 _strHexaWidgetType[GEOMEDGE_TREE] = tr( "GEOMEDGE" );
152 _strHexaWidgetType[GEOMFACE_TREE] = tr( "GEOMFACE" );
154 _strHexaWidgetType[GROUP_TREE] = tr( "GROUP" );
155 _strHexaWidgetType[LAW_TREE] = tr( "LAW" );
156 _strHexaWidgetType[PROPAGATION_TREE]= tr( "PROPAGATION" );
159 // ============================================================= getIndexList
160 QModelIndexList HexaBaseDialog::getIndexList(QListWidget* itemsList, bool mapToSource)
162 QModelIndexList iItems;
164 QListWidgetItem* item = NULL;
166 const PatternDataModel* patternDataModel = getPatternDataModel();
167 if (patternDataModel == NULL || itemsList == NULL) return iItems;
169 unsigned int nbItems = itemsList->count();
170 for ( int r = 0; r < nbItems; ++r){
171 item = itemsList->item(r);
173 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
175 iItem = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
182 // ================================================================ computeAndSetDimension
183 void HexaBaseDialog::computeAndSetDimension(const QModelIndex& elt)
185 // * Check if everything is OK for the computing
186 DocumentModel* docModel = getDocumentModel();
187 if (docModel == NULL || _currentObj == NULL)
190 int selectedType = elt.data(HEXA_TREE_ROLE).toInt();
191 if (selectedType != EDGE_TREE && selectedType != GEOMEDGE_TREE)
194 QListWidget* list = dynamic_cast<QListWidget*>(_currentObj);
195 QDoubleSpinBox* spb = dynamic_cast<QDoubleSpinBox*>(_currentObj);
197 if (list == NULL && spb == NULL)
200 // * Compute the value of the dimension
203 if (_currentObj->property("Radius").isValid())
204 value = docModel->getRadius(elt);
205 else if (_currentObj->property("Angle").isValid())
206 value = docModel->getAngle(elt);
207 else if (_currentObj->property("Length").isValid())
208 value = docModel->getLength(elt);
213 // * Set the value to the field (radius, length or height)
216 QListWidgetItem* item = list->currentItem();
221 item->setText(QString::number(value));
222 list->editItem(item);
226 else if (spb != NULL)
228 spb->setValue(value);
234 // ============================================================= resetSizeAndShow
235 void HexaBaseDialog::resetSizeAndShow(QDockWidget* parent)
240 //force the dialog to fit its contain
241 // setMinimumWidth(sizeHint().width());
243 //set the dialog in the dockwidget
244 if (parent->widget())
245 parent->widget()->close();
246 parent->setWidget(this);
247 parent->setWindowTitle(windowTitle());
250 // setMinimumWidth(MIN_WIDTH);
253 QString HexaBaseDialog::getErrorMsg()
255 DocumentModel* docModel = getDocumentModel();
256 Hex::Hex* hex = docModel->getHexaRoot();
257 int nbErrorMsg = hex->sizeofMessage();
258 QString msg, newLine = "\n";
259 for (int i = 1; i < nbErrorMsg; ++i)
260 msg += newLine + hex->getMessageLine(i);
265 //unlink the widget from the model
266 void HexaBaseDialog::modelUnregister(QWidget* widget)
268 if (widget == NULL) return;
270 if (widget->property("GeomWidgetType").isValid())
272 widget->setProperty("GeomObj", QVariant());
273 widget->setProperty("TopoDS_Shape", QVariant());
276 widget->setProperty("HexaData", QVariant());
277 widget->setProperty("QModelIndex", QVariant());
278 _index[widget] = QModelIndex();
280 HexaBaseDialog* diag = dynamic_cast<HexaBaseDialog*>(widget);
282 diag->clearWidgetsIndexes();
285 // ============================================================= connectDocumentGraphicView
286 void HexaBaseDialog::connectDocumentGraphicView(VtkDocumentGraphicView* docGView)
288 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
289 if (docGView == NULL) return;
291 disconnectDocumentGraphicView(docGView); //to avoid double connect
293 //Connect the graphic view and its model to the dialog box
294 connect( docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
295 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
296 // connect( docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
297 // this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
298 connect( docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
299 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
300 connect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
301 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
302 connect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
303 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
306 // ============================================================= disconnectDocumentGraphicView
307 void HexaBaseDialog::disconnectDocumentGraphicView(VtkDocumentGraphicView* docGView)
309 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
310 if (docGView == NULL) return;
313 //Disconnect graphic view signals form the dialog box
314 disconnect(docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
315 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
317 // disconnect(docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
318 // this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
320 disconnect(docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
321 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
323 disconnect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
324 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
326 disconnect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
327 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
330 // ============================================================= onCurrentSelectionChanged
331 void HexaBaseDialog::onCurrentSelectionChanged()
333 highlightSelectedAssocs();
336 // ============================================================= clearCurrentObjectFocus
337 void HexaBaseDialog::clearCurrentObjectFocus()
339 QWidget* currentWidget = dynamic_cast<QWidget*>(_currentObj);
340 if (currentWidget != NULL)
342 currentWidget->clearFocus();
347 // ============================================================= setFocusToNextField
348 //Sets focus to the next field of the current object
349 void HexaBaseDialog::setFocusToNextField()
353 if (!HEXABLOCKGUI::assocInProgress && autoFocusSwitch)
355 _highlightWidget(_currentObj, Qt::white);
360 // ============================================================== _initButtonBox
361 QGroupBox* HexaBaseDialog::_initButtonBox( Mode editmode )
363 if ( editmode == INFO_MODE )
366 QGroupBox* buttonBox = new QGroupBox();
367 buttonBox->setMinimumWidth(BUTTON_BOX_MIN_WIDTH);
368 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
369 QHBoxLayout* buttonsHLayout = new QHBoxLayout();
370 _applyButton = new QPushButton(tr("Apply"));
371 QPushButton* closeButton = new QPushButton(tr("Close"));
372 QPushButton* helpButton = new QPushButton(tr("Help"));
374 connect( _applyButton, SIGNAL(clicked()), this, SLOT(apply()), Qt::UniqueConnection );
375 connect( closeButton, SIGNAL(clicked()), this, SLOT(close()), Qt::UniqueConnection );
376 connect( helpButton, SIGNAL(clicked()), this, SLOT(onHelpRequested()), Qt::UniqueConnection );
378 buttonsHLayout->addWidget( _applyButton );
379 buttonsHLayout->addWidget( closeButton );
380 buttonsHLayout->addStretch(1);
381 buttonsHLayout->addWidget( helpButton );
382 buttonBox->setLayout(buttonsHLayout);
383 layout()->addWidget(buttonBox);
384 buttonBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
388 // ============================================================== _initWidget
389 void HexaBaseDialog::_initWidget( Mode editmode )
391 _initInputWidget( editmode );
392 _initButtonBox( editmode );
395 // ============================================================== apply
396 bool HexaBaseDialog::apply()
399 bool applied = apply(iNew);
402 _selectAndHighlight( iNew );
403 if (!HEXABLOCKGUI::assocInProgress)
404 getDocumentModel()->updateGeomTree();
409 void HexaBaseDialog::clearVTKSelection()
411 HEXABLOCKGUI::currentDocGView->clearSelection();
412 _highlightWidget(_currentObj, Qt::white);
415 void HexaBaseDialog::clearOCCSelection()
417 HEXABLOCKGUI::currentOccGView->clearSelection();
420 // ============================================================== close
421 void HexaBaseDialog::close()
423 //reset the data selection pattern (forget all selections of the current context)
424 getPatternDataSelectionModel()->reset();
425 // getPatternBuilderSelectionModel()->reset();
426 getPatternGeomSelectionModel()->reset();
428 //Clear vtk selection
431 //Clear occ selection
434 //Close the dialog box
436 parentWidget()->close();
438 getPatternDataSelectionModel()->setInfoMode(true);
441 // ============================================================== onHelpRequested
442 void HexaBaseDialog::onHelpRequested()
444 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
446 app->onHelpContextModule( "HEXABLOCK", _helpFileName );
450 platform = "winapplication";
452 platform = "application";
455 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
456 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
457 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( _helpFileName ),
458 QObject::tr( "BUT_OK" ) );
462 // ============================================================== highlightSelectedAssocs
463 void HexaBaseDialog::highlightSelectedAssocs()
465 QMultiMap<QString, int> geomAssocs = getAssocsGEOM();
466 QModelIndexList vtkAssocs = getAssocsVTK();
468 // HEXABLOCKGUI::selectionMgr()->clearSelected();
469 //highlight geom selected elts
470 if (geomAssocs.size() > 0)
471 HEXABLOCKGUI::currentOccGView->highlight(geomAssocs, false);
473 //highlight vtk selected elts
474 if (!vtkAssocs.isEmpty())
475 HEXABLOCKGUI::currentDocGView->highlight(vtkAssocs);
478 // ============================================================== refreshHighlight
479 void HexaBaseDialog::refreshHighlight()
481 HEXABLOCKGUI::selectionMgr()->clearSelected();
482 highlightSelectedAssocs();
485 bool HexaBaseDialog::isDimensionType(const QObject* obj)
490 return (obj->property("Radius").isValid()) ||
491 (obj->property("Angle").isValid()) ||
492 (obj->property("Length").isValid());
495 // ============================================================== getObjectViewType
496 HEXABLOCKGUI::ViewType HexaBaseDialog::getObjectViewType(QObject* obj)
499 return HEXABLOCKGUI::UNKNOWN;
501 QVariant v1 = obj->property("GeomWidgetType");
502 QVariant v2 = obj->property("HexaWidgetType");
504 if (v1.isValid() && v2.isValid() && isDimensionType(obj))
505 return HEXABLOCKGUI::VTK_OCC;
506 else if (v1.isValid())
507 return HEXABLOCKGUI::OCC;
508 else if (v2.isValid())
509 return HEXABLOCKGUI::VTK;
511 return HEXABLOCKGUI::UNKNOWN;
514 // ============================================================== _selectAndHighlight
515 void HexaBaseDialog::_selectAndHighlight( const QModelIndex& i )
517 if ( !i.isValid() ) return;
518 setProperty("QModelIndex", QVariant::fromValue(i));
522 // ============================================================== _allowSelection
523 void HexaBaseDialog::_allowSelection()
525 if ( getDocumentModel() )
526 getDocumentModel()->disallowEdition();
529 // ============================================================== _disallowSelection
530 void HexaBaseDialog::_disallowSelection()
532 if ( getDocumentModel() ){
533 getDocumentModel()->allowEdition();
535 HEXABLOCKGUI::currentDocGView->setAllSelection();
538 // ============================================================== _allowVTKSelection
539 bool HexaBaseDialog::_allowVTKSelection( QObject* obj )
543 QVariant v = obj->property("HexaWidgetType");
544 HexaWidgetType wType = v.value<HexaWidgetType>();
548 HEXABLOCKGUI::currentDocGView->setVertexSelection(); isOk = true;
551 HEXABLOCKGUI::currentDocGView->setEdgeSelection(); isOk = true;
554 HEXABLOCKGUI::currentDocGView->setQuadSelection(); isOk = true;
557 HEXABLOCKGUI::currentDocGView->setHexaSelection(); isOk = true;
559 default: HEXABLOCKGUI::currentDocGView->setAllSelection();
564 // ============================================================== _allowOCCSelection
565 bool HexaBaseDialog::_allowOCCSelection( QObject* obj )
567 QVariant v = obj->property("GeomWidgetType");
568 GeomWidgetType wType = v.value<GeomWidgetType>();
569 HEXABLOCKGUI::currentOccGView->setSelectionMode(wType);
574 // ============================================================== _getSelector
575 QItemSelectionModel* HexaBaseDialog::_getSelector( QObject* obj )
580 QItemSelectionModel* selector = NULL;
582 HexaWidgetType wtype;
583 QVariant v = obj->property("HexaWidgetType");
584 QVariant v2 = obj->property("GeomWidgetType");
585 if ( !v.isValid() || (v2.isValid() && isDimensionType(obj)) )
588 wtype = v.value<HexaWidgetType>();
595 case VECTOR_TREE: selector = getPatternDataSelectionModel(); break;
596 // case CYLINDER_TREE:
598 // case ELEMENTS_TREE:
599 // case CROSSELEMENTS_TREE: selector = getPatternBuilderSelectionModel(); break;
602 case GEOMFACE_TREE: selector = getPatternGeomSelectionModel(); break;
603 case GROUP_TREE: selector = getGroupsSelectionModel(); break;
605 case PROPAGATION_TREE: selector = getMeshSelectionModel(); break;
612 // ============================================================== getGeomObj
613 DocumentModel::GeomObj* HexaBaseDialog::getGeomObj(const QModelIndex& index)
615 HEXA_NS::NewShape* aSh = getDocumentModel()->getHexaPtr<HEXA_NS::NewShape*>(index);
616 DocumentModel::GeomObj* geomObj = NULL;
619 geomObj = new DocumentModel::GeomObj;
620 geomObj->shapeName = aSh->getName();
621 geomObj->subId = QString::number(-1);
625 HEXA_NS::EltBase* aSShElt = getDocumentModel()->getHexaPtr(index);
626 HEXA_NS::SubShape* aSSh = dynamic_cast<HEXA_NS::SubShape*>(aSShElt);
629 geomObj = new DocumentModel::GeomObj;
631 if (aSSh->getParentShape() != NULL)
632 shapeName = aSSh->getParentShape()->getName();
633 geomObj->shapeName = shapeName;
634 geomObj->subId = QString::number(aSSh->getIdent());
640 // ============================================================== _onSelectionChanged
642 * Puts elements selected in the model (treeview) in the corresponding
643 * line edit widget (the one that has the focus) of the current dialog box.
645 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QLineEdit* le )
647 QModelIndexList l = sel.indexes();
648 if ( l.count() == 0 ) return false;
650 // mono selection mode: we just get the first selected element
651 QModelIndex selected = l[0];
653 // we just return if the selection is not valid or the selection and the
654 // line content are the same
655 if ( !selected.isValid() || le->property("HexaData") == selected.data(HEXA_DATA_ROLE) )
659 int selType = selected.data(HEXA_TREE_ROLE).toInt();
662 QVariant v = le->property("HexaWidgetType");
663 if ( !v.isValid() ) return false;
664 HexaWidgetType wType = v.value<HexaWidgetType>();
666 // check selection compatibility between selection and widget
667 if ( selType != wType ){
668 SUIT_MessageBox::information( 0, tr("HEXA_INFO"),
669 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg(_strHexaWidgetType[wType]));
672 if (le->property("GeomWidgetType").isValid())
674 DocumentModel::GeomObj* geomObj = getGeomObj(selected);
677 le->setProperty("GeomObj", QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
679 DocumentModel* docModel = getDocumentModel();
680 QString objId = geomObj->shapeName + "," + geomObj->subId;
681 HEXA_NS::SubShape* ssh = docModel->getGeomPtr(objId);
684 TopoDS_Shape shape = ssh->getShape();
686 le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(shape));
688 setCurrentGeomObj(geomObj);
692 //fill the lineEdit if selection is OK
693 le->setText( selected.data().toString() );// name
694 le->setProperty("QModelIndex", QVariant::fromValue(selected));
695 le->setProperty("HexaData", selected.data(HEXA_DATA_ROLE));
696 _index[le] = selected;
698 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(_currentObj);
699 if (selected.isValid() && lineEdit != NULL)
700 setFocusToNextField();
705 // ============================================================== _onSelectionChanged
707 * Puts elements selected in the model (treeview) in the corresponding list widget
708 * of the current dialog box.
710 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QListWidget* lw )
712 QModelIndexList l = sel.indexes();
714 if ( l.count() == 0 ) return false;
717 QVariant v = lw->property("HexaWidgetType");
718 if ( !v.isValid() ) return false;
719 HexaWidgetType wType = v.value<HexaWidgetType>();
721 //fill the listWidget
722 QListWidgetItem* item = NULL;
726 foreach( const QModelIndex& isel, l ){
727 // if ( lw->count() == maxSize) break;
728 selType = isel.data(HEXA_TREE_ROLE).toInt();
729 if ( selType != wType ){ // check selection compatibility between selection and widget
730 SUIT_MessageBox::information( 0,
732 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg( _strHexaWidgetType[wType]) );
735 // add selection to listWidget if selection is OK
736 selName = isel.data().toString();
737 QList<QListWidgetItem *> twice = lw->findItems( selName, Qt::MatchExactly);
738 if ( twice.count() == 0 ){
739 item = new QListWidgetItem( selName );
740 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(isel) );
741 item->setData(LW_DATA_ROLE, isel.data(HEXA_DATA_ROLE));
742 if (lw->property("GeomWidgetType").isValid())
744 DocumentModel::GeomObj* geomObj = getGeomObj(isel);
746 item->setData(LW_ASSOC_ROLE, QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
755 // ============================================================== onSelectionChanged
757 * Puts elements selected in the model in the corresponding widget (list widget or line edit)
758 * of the current dialog box.
760 void HexaBaseDialog::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
762 QModelIndexList l = sel.indexes();
764 if ( l.count() == 0 )
766 QModelIndex selected = l[0];
768 // * no edition for Info Dialogs
769 if ( _editMode == INFO_MODE || _currentObj == NULL || !selected.isValid())
772 if (isDimensionType(_currentObj))
774 // ** set the dimension of the selected object in the editor **/
775 int selectedType = selected.data(HEXA_TREE_ROLE).toInt();
776 if (selectedType == EDGE_TREE || selectedType == GEOMEDGE_TREE)
777 computeAndSetDimension(selected);
781 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
782 QListWidget* aListWidget = dynamic_cast<QListWidget*>(_currentObj);
784 // * fill the lineedit with selection
787 _onSelectionChanged( sel, aLineEdit );
791 // * fill the listWidget with selection
793 _onSelectionChanged( sel, aListWidget );
796 // ============================================================== showEvent
797 void HexaBaseDialog::showEvent( QShowEvent * event )
799 if ( _editMode == INFO_MODE )
800 getDocumentModel()->allowEdition();
802 getDocumentModel()->disallowEdition();
804 //Connect to salome selection signals
805 if (HEXABLOCKGUI::selectionMgr() != NULL)
807 connect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
808 this, SLOT(onCurrentSelectionChanged()), Qt::UniqueConnection );
811 //connect model selection signals
812 connectDocumentGraphicView();
814 QDialog::showEvent ( event );
818 // ============================================================== hideEvent
819 void HexaBaseDialog::hideEvent ( QHideEvent * event )
821 //Disconnection salome selection signals
822 if (HEXABLOCKGUI::selectionMgr() != NULL)
823 disconnect( HEXABLOCKGUI::selectionMgr() , SIGNAL(currentSelectionChanged()),
824 this, SLOT(onCurrentSelectionChanged()) );
826 //Disconnect vtk window activation signals
827 // if (HEXABLOCKGUI::currentDocGView->getViewWindow() != NULL)
828 // disconnect( HEXABLOCKGUI::currentDocGView->getViewWindow()->getViewManager(),
829 // SIGNAL( activated(SUIT_ViewManager*) ),
830 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
832 //Disconnect occ window activation signals
833 // if (HEXABLOCKGUI::currentOccGView->getViewWindow() != NULL)
834 // disconnect( HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager(),
835 // SIGNAL( activated(SUIT_ViewManager*) ),
836 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
838 //Disconnect model selection signals
839 disconnectDocumentGraphicView();
840 getDocumentModel()->allowEdition();
842 QDialog::hideEvent( event );
845 // ============================================================== updateButtonBox
846 void HexaBaseDialog::updateButtonBox()
850 // ============================================================== updateName
851 void HexaBaseDialog::updateName()
853 const PatternDataModel* patternDataModel = getPatternDataModel();
855 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(sender());
856 if (!lineEdit) return;
857 QString newName = lineEdit->text();
858 if ( newName.isEmpty() ) return;
860 QVariant v = lineEdit->property("QModelIndex");
861 if ( !v.isValid() ) return;
863 QModelIndex index = v.value<QModelIndex>();
864 if ( index.isValid() )
865 getDocumentModel()->setName( patternDataModel->mapToSource(index), newName );
868 // ============================================================== updateDefaultName
869 void HexaBaseDialog::updateDefaultName(QLineEdit* name_field, HEXA_NS::EnumElt type)
871 if (name_field == NULL) return;
873 HEXA_NS::Document* doc = getDocumentModel()->getHexaDocument();
874 if (doc == NULL) return;
876 name_field->setText(doc->getNextName(type).c_str());
879 // ============================================================== selectElementOfModel
880 /*Selects in the model (treeview) elements selected in a listwidget,
881 * or an element in a line edit.*/
882 void HexaBaseDialog::selectElementOfModel()
884 if (getPatternDataSelectionModel() == NULL) return;
886 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
887 if ( !currentListWidget ) return;
889 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
891 getPatternDataSelectionModel()->clearSelection();
892 foreach ( QListWidgetItem *item, sel ){
893 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
894 index = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
895 if ( index.isValid() )
896 getPatternDataSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
900 // ============================================================== _isLineOrListWidget
902 * Return true is the widget is a line or a list
905 bool HexaBaseDialog::_isLineOrListWidget(QObject *widget)
907 if (widget == NULL) return false;
909 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(widget);
910 QListWidget *listWidget = dynamic_cast<QListWidget*>(widget);
911 return (lineEdit != NULL) || (listWidget != NULL);
913 }//_isLineOrListWidget
916 // ============================================================== _highlightWidget
918 * Highlight the given widget with the given color.
920 void HexaBaseDialog::_highlightWidget(QObject *obj, Qt::GlobalColor clr)
922 QDoubleSpinBox* spb = dynamic_cast<QDoubleSpinBox*>(obj);
923 if (!_isLineOrListWidget(obj) && spb == NULL)
926 QWidget *widget = dynamic_cast<QWidget*>(obj);
927 QPalette palette1 = widget->palette();
928 palette1.setColor(QPalette::Active, widget->backgroundRole(), clr);
929 widget->setPalette(palette1);
933 // ============================================================== _updateCurrentObject
934 void HexaBaseDialog::_updateCurrentObject(QObject* obj)
936 _highlightWidget(_currentObj, Qt::white);
938 _highlightWidget(obj, Qt::yellow);
941 // ============================================================== eventFilter
943 * Handles events from the treeview and the dialog boxes.
945 bool HexaBaseDialog::eventFilter(QObject *obj, QEvent *event)
947 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(obj);
948 QListWidget *listWidget = dynamic_cast<QListWidget*>(obj);
950 // * Enter key press ------
951 if ( event->type() == QEvent::KeyPress &&
952 ((QKeyEvent*)event)->key() == Qt::Key_Return)
954 setFocusToNextField();
958 // * Focus out from a list widget ------
959 if ( event->type() == QEvent::FocusOut && listWidget != NULL)
961 QItemSelectionModel * selectionModel = listWidget->selectionModel();
962 selectionModel->clearSelection();
965 if ( event->type() != QEvent::FocusIn )
969 HEXABLOCKGUI::ViewType vtype = getObjectViewType(obj);
970 if (vtype == HEXABLOCKGUI::VTK_OCC)
972 _allowVTKSelection(obj);
973 _allowOCCSelection(obj);
975 else if (vtype == HEXABLOCKGUI::VTK)
976 _allowVTKSelection( obj );
977 else if (vtype == HEXABLOCKGUI::OCC)
978 _allowOCCSelection( obj );
980 //Depending on the focused widget type, get the right selector for it
983 QItemSelectionModel* selector = _getSelector( obj );
984 if ( selector == NULL )
986 _updateCurrentObject(obj);
990 if ( _currentObj != obj && (lineEdit == NULL || listWidget == NULL) )
991 selector->clearSelection();
993 _updateCurrentObject(obj);
995 //If the widget contains an element, select it in model/view
996 if ( lineEdit != NULL ){ //element can be from lineEdit
997 v = lineEdit->property("HexaData");
999 return QObject::eventFilter(obj, event);
1000 index = ((SelectionModel*)selector)->indexBy( HEXA_DATA_ROLE, v);
1001 if (index.isValid())
1002 selector->select( index, QItemSelectionModel::SelectCurrent );
1005 return QObject::eventFilter(obj, event);
1008 // ------------------------- VERTEX ----------------------------------
1009 // ============================================================== Constructeur
1010 VertexDialog::VertexDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1011 HexaBaseDialog(parent, editmode, f),
1014 _helpFileName = "gui_vertex.html";
1016 _initWidget(editmode);
1018 if ( editmode == NEW_MODE ){
1019 setWindowTitle( tr("Vertex Construction") );
1020 } else if ( editmode == UPDATE_MODE ){
1021 setWindowTitle( tr("Vertex Modification") );
1023 else if ( editmode == INFO_MODE){
1024 setWindowTitle( tr("Vertex Information") );
1028 // ============================================================== Destructeur
1029 VertexDialog::~VertexDialog()
1033 // ============================================================== _initInputWidget
1034 void VertexDialog::_initInputWidget( Mode editmode )
1036 // x_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1037 // y_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1038 // z_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
1039 QDoubleValidator *doubleValidator = new QDoubleValidator(widget_2);
1040 x_spb->setValidator(doubleValidator);
1041 y_spb->setValidator(doubleValidator);
1042 z_spb->setValidator(doubleValidator);
1044 // setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1045 installEventFilter(this);
1046 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1047 name_le->installEventFilter(this);
1049 if (editmode == INFO_MODE)
1051 name_le->setReadOnly(true);
1052 x_spb->setReadOnly(true);
1053 y_spb->setReadOnly(true);
1054 z_spb->setReadOnly(true);
1057 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
1060 // ============================================================== clear
1061 void VertexDialog::clear()
1065 modelUnregister(this);
1068 // ============================================================== setValue
1069 void VertexDialog::setValue(HEXA_NS::Vertex* v)
1072 name_le->setText( v->getName() );
1075 // x_spb->setValue( v->getX() );
1076 // y_spb->setValue( v->getY() );
1077 // z_spb->setValue( v->getZ() );
1078 x_spb->setText( QString::number(v->getX()) );
1079 y_spb->setText( QString::number(v->getY()) );
1080 z_spb->setText( QString::number(v->getZ()) );
1082 if ( getPatternDataSelectionModel() != NULL ){
1083 QModelIndex iv = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1085 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1086 name_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1091 // ============================================================== getValue
1092 HEXA_NS::Vertex* VertexDialog::getValue()
1098 // ============================================================== apply
1099 bool VertexDialog::apply(QModelIndex& result)
1101 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1104 if ( !getDocumentModel() ) return false;
1105 if ( !getPatternDataSelectionModel() ) return false;
1106 const PatternDataModel* patternDataModel = getPatternDataModel();
1107 if ( !patternDataModel ) return false;
1109 QModelIndex iVertex;
1111 QString xStr = x_spb->text();
1112 QString yStr = y_spb->text();
1113 QString zStr = z_spb->text();
1114 bool isOk = false, validArgs = !xStr.isEmpty() && !yStr.isEmpty() && !zStr.isEmpty();
1116 double newX, newY, newZ;
1119 newX = xStr.toDouble();
1120 newY = yStr.toDouble();
1121 newZ = zStr.toDouble();
1124 if ( _editMode == UPDATE_MODE && validArgs){
1125 QVariant v = property("QModelIndex");
1127 iVertex = patternDataModel->mapToSource( v.value<QModelIndex>() );
1128 if ( iVertex.isValid() )
1129 isOk = getDocumentModel()->updateVertex( iVertex, newX, newY, newZ );
1131 } else if ( _editMode == NEW_MODE && validArgs){
1132 iVertex = getDocumentModel()->addVertex( newX, newY, newZ );
1133 if ( iVertex.isValid() )
1137 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "VERTEX UPDATE/CONSTRUCTION" ) + "\n" + getErrorMsg() );
1141 QString newName = name_le->text();
1142 if ( !newName.isEmpty() )
1143 getDocumentModel()->setName( iVertex, newName );
1145 //the default name in the dialog box
1146 HEXA_NS::Vertex* v = getDocumentModel()->getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1148 updateDefaultName(name_le, v->getType());
1150 // to select/highlight result
1151 result = patternDataModel->mapFromSource(iVertex);
1156 // ------------------------- EDGE ----------------------------------
1158 // ============================================================== Constructeur
1159 EdgeDialog::EdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1160 HexaBaseDialog(parent, editmode, f),
1163 _helpFileName = "gui_edge.html";
1165 _initWidget(editmode);
1167 if ( editmode == INFO_MODE ){
1168 setWindowTitle( tr("Edge Information") );
1171 else if ( editmode == UPDATE_MODE ){
1172 setWindowTitle( tr("Edge Modification") );
1178 // ============================================================== Destructeur
1179 EdgeDialog::~EdgeDialog()
1184 // ============================================================== _initInputWidget
1185 void EdgeDialog::_initInputWidget( Mode editmode )
1188 QValidator *validator = new QRegExpValidator(rx, this);
1190 // setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1191 installEventFilter(this);
1193 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1194 name_le->installEventFilter(this);
1196 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1197 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1198 v0_le_rb0->setValidator( validator );
1199 v1_le_rb0->setValidator( validator );
1200 v0_le_rb0->installEventFilter(this);
1201 v1_le_rb0->installEventFilter(this);
1203 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1204 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1205 vex_le_rb1->setValidator( validator );
1206 vec_le_rb1->setValidator( validator );
1207 vex_le_rb1->installEventFilter(this);
1208 vec_le_rb1->installEventFilter(this);
1210 v0_le_rb0->setReadOnly(true);
1211 v1_le_rb0->setReadOnly(true);
1212 vex_le_rb1->setReadOnly(true);
1213 vec_le_rb1->setReadOnly(true);
1215 if (editmode == INFO_MODE)
1216 name_le->setReadOnly(true);
1220 // ============================================================== Clear
1221 void EdgeDialog::clear()
1226 modelUnregister(v0_le_rb0);
1229 modelUnregister(v1_le_rb0);
1231 vex_le_rb1->clear();
1232 modelUnregister(vex_le_rb1);
1234 vec_le_rb1->clear();
1235 modelUnregister(vec_le_rb1);
1237 modelUnregister(this);
1240 // ============================================================== setValue
1241 void EdgeDialog::setValue(HEXA_NS::Edge* e)
1243 HEXA_NS::Vertex* v0 = e->getVertex(0);
1244 HEXA_NS::Vertex* v1 = e->getVertex(1);
1246 name_le->setText( e->getName() );
1247 v0_le_rb0->setText( v0->getName() );
1248 v1_le_rb0->setText( v1->getName() );
1250 if ( getPatternDataSelectionModel() ){
1251 QModelIndex ie = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e) );
1252 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1253 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1255 name_le->setProperty( "QModelIndex", QVariant::fromValue(ie) );
1256 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1257 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1262 // ============================================================== getValue
1263 HEXA_NS::Edge* EdgeDialog::getValue()
1268 // ============================================================== apply
1269 bool EdgeDialog::apply(QModelIndex& result)
1271 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1274 if ( !getDocumentModel() ) return false;
1275 const PatternDataModel* patternDataModel = getPatternDataModel();
1276 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1277 if ( !patternDataModel /*|| !patternBuilderModel*/ ) return false;
1281 if ( rb0->isChecked() ){
1282 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1283 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1284 if ( iv0.isValid()&& iv1.isValid() ){
1285 iEdge = getDocumentModel()->addEdgeVertices( iv0, iv1 );
1287 } else if ( rb1->isChecked() ){
1288 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
1289 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb1] );
1290 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
1291 if ( ivex.isValid() && ivec.isValid() ){
1292 iEdge = getDocumentModel()->addEdgeVector( ivex, ivec );
1296 if ( !iEdge.isValid() ){
1297 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD EDGE" ) + "\n" + getErrorMsg() );
1300 _value = iEdge.model()->data(iEdge, HEXA_DATA_ROLE).value<HEXA_NS::Edge*>();
1302 QString newName = name_le->text();
1303 if ( !newName.isEmpty() )/*{*/
1304 getDocumentModel()->setName( iEdge, newName );
1306 //update the default name in the dialog box
1308 updateDefaultName(name_le, _value->getType());
1310 result = patternDataModel->mapFromSource(iEdge);
1315 // ------------------------- QUAD ----------------------------------
1317 // ============================================================== Constructeur
1318 QuadDialog::QuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1319 HexaBaseDialog(parent, editmode, f),
1322 _helpFileName = "gui_quadrangle.html";
1324 _initWidget(editmode);
1327 if ( editmode == INFO_MODE ){
1328 setWindowTitle( tr("Quad Information") );
1332 // ============================================================== Destructeur
1333 QuadDialog::~QuadDialog()
1337 // ============================================================== _initInputWidget
1338 void QuadDialog::_initInputWidget( Mode editmode )
1341 QValidator *validator = new QRegExpValidator(rx, this);
1343 installEventFilter(this);
1344 name_le->installEventFilter(this);
1346 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1347 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1348 v2_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1349 v3_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1351 v0_le_rb0->setValidator( validator );
1352 v1_le_rb0->setValidator( validator );
1353 v2_le_rb0->setValidator( validator );
1354 v3_le_rb0->setValidator( validator );
1355 v0_le_rb0->installEventFilter(this);
1356 v1_le_rb0->installEventFilter(this);
1357 v2_le_rb0->installEventFilter(this);
1358 v3_le_rb0->installEventFilter(this);
1360 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1361 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1362 e2_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1363 e3_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1365 e0_le_rb1->setValidator( validator );
1366 e1_le_rb1->setValidator( validator );
1367 e2_le_rb1->setValidator( validator );
1368 e3_le_rb1->setValidator( validator );
1370 e0_le_rb1->installEventFilter(this);
1371 e1_le_rb1->installEventFilter(this);
1372 e2_le_rb1->installEventFilter(this);
1373 e3_le_rb1->installEventFilter(this);
1375 v0_le_rb0->setReadOnly(true);
1376 v1_le_rb0->setReadOnly(true);
1377 v2_le_rb0->setReadOnly(true);
1378 v3_le_rb0->setReadOnly(true);
1380 e0_le_rb1->setReadOnly(true);
1381 e1_le_rb1->setReadOnly(true);
1382 e2_le_rb1->setReadOnly(true);
1383 e3_le_rb1->setReadOnly(true);
1385 if (editmode == INFO_MODE)
1386 name_le->setReadOnly(true);
1389 // ============================================================== clear
1390 void QuadDialog::clear()
1392 //Clear the dialog and unregister it from the model
1393 QModelIndex invalidIndex;
1398 modelUnregister(v0_le_rb0);
1401 modelUnregister(v1_le_rb0);
1404 modelUnregister(v2_le_rb0);
1407 modelUnregister(v3_le_rb0);
1410 modelUnregister(e0_le_rb1);
1413 modelUnregister(e1_le_rb1);
1416 modelUnregister(e2_le_rb1);
1419 modelUnregister(e3_le_rb1);
1421 modelUnregister(this);
1425 // ============================================================== setValue
1426 void QuadDialog::setValue(HEXA_NS::Quad* q)
1428 Q_ASSERT( q->countEdge() == 4 );
1429 Q_ASSERT( q->countVertex() == 4 );
1432 name_le->setText( q->getName() );
1435 HEXA_NS::Vertex* v0 = q->getVertex(0);
1436 HEXA_NS::Vertex* v1 = q->getVertex(1);
1437 HEXA_NS::Vertex* v2 = q->getVertex(2);
1438 HEXA_NS::Vertex* v3 = q->getVertex(3);
1440 v0_le_rb0->setText( v0->getName() );
1441 v1_le_rb0->setText( v1->getName() );
1442 v2_le_rb0->setText( v2->getName() );
1443 v3_le_rb0->setText( v3->getName() );
1447 HEXA_NS::Edge* e0 = q->getEdge(0);
1448 HEXA_NS::Edge* e1 = q->getEdge(1);
1449 HEXA_NS::Edge* e2 = q->getEdge(2);
1450 HEXA_NS::Edge* e3 = q->getEdge(3);
1452 e0_le_rb1->setText( e0->getName() );
1453 e1_le_rb1->setText( e1->getName() );
1454 e2_le_rb1->setText( e2->getName() );
1455 e3_le_rb1->setText( e3->getName() );
1457 if ( getPatternDataSelectionModel() ){
1458 QModelIndex iq = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(q) );
1460 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1461 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1462 QModelIndex iv2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v2) );
1463 QModelIndex iv3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v3) );
1465 QModelIndex ie0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e0) );
1466 QModelIndex ie1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e1) );
1467 QModelIndex ie2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e2) );
1468 QModelIndex ie3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e3) );
1470 name_le->setProperty( "QModelIndex", QVariant::fromValue(iq) );
1472 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1473 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1474 v2_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv2) );
1475 v3_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv3) );
1477 e0_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie0) );
1478 e1_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie1) );
1479 e2_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie2) );
1480 e3_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie3) );
1486 // ============================================================== getValue
1487 HEXA_NS::Quad* QuadDialog::getValue()
1493 // ============================================================== apply
1494 bool QuadDialog::apply(QModelIndex& result)
1496 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1499 if ( !getDocumentModel() ) return false;
1500 const PatternDataModel* patternDataModel = getPatternDataModel();
1501 if ( !patternDataModel ) return false;
1505 if ( rb0->isChecked() ){ //vertices
1506 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1507 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1508 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb0] );
1509 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb0] );
1515 iQuad = getDocumentModel()->addQuadVertices( iv0, iv1, iv2, iv3 );
1517 } else if ( rb1->isChecked() ){ //edges
1518 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
1519 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
1520 QModelIndex ie2 = patternDataModel->mapToSource( _index[e2_le_rb1] );
1521 QModelIndex ie3 = patternDataModel->mapToSource( _index[e3_le_rb1] );
1527 iQuad = getDocumentModel()->addQuadEdges( ie0, ie1, ie2, ie3 );
1531 if ( !iQuad.isValid() ){
1532 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD QUAD" ) + "\n" + getErrorMsg());
1535 _value = iQuad.model()->data(iQuad, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1537 QString newName = name_le->text();
1538 if ( !newName.isEmpty() )/*{*/
1539 getDocumentModel()->setName( iQuad, newName );
1541 //the default name in the dialog box
1543 updateDefaultName(name_le, _value->getType());
1545 // to select/highlight result
1546 result = patternDataModel->mapFromSource(iQuad);
1552 // ------------------------- HEXA ----------------------------------
1554 // ============================================================== HexaDialog
1556 HexaDialog::HexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1557 HexaBaseDialog(parent, editmode, f),
1560 _helpFileName = "gui_hexahedron.html";
1562 _initWidget(editmode);
1565 if ( editmode == INFO_MODE ){
1566 setWindowTitle( tr("Hexahedron Information") );
1567 quads_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
1568 vertices_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
1572 // ============================================================== Destructeur
1573 HexaDialog::~HexaDialog()
1577 // ============================================================== _initInputWidget
1578 void HexaDialog::_initInputWidget( Mode editmode )
1582 installEventFilter(this);
1583 name_le->installEventFilter(this);
1585 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
1586 quads_lw->installEventFilter(this);
1588 vertices_lw->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1589 vertices_lw->installEventFilter(this);
1591 if ( editmode != INFO_MODE ) {
1592 // delete item from listwidget
1593 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
1594 QShortcut* delVertexShortcut = new QShortcut( QKeySequence(Qt::Key_X), vertices_lw );
1595 delQuadShortcut->setContext( Qt::WidgetShortcut );
1596 delVertexShortcut->setContext( Qt::WidgetShortcut );
1597 connect(delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()));
1598 connect(delVertexShortcut, SIGNAL(activated()), this, SLOT(deleteVertexItem()));
1600 // highlight item on model view (VTK) from listwidget
1601 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1602 connect( vertices_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1604 if ( editmode != INFO_MODE)
1606 connect( vertices_rb, SIGNAL(clicked()), vertices_lw, SLOT(setFocus()));
1607 connect( quads_rb, SIGNAL(clicked()), quads_lw, SLOT(setFocus()));
1610 connect( vertices_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1611 connect( quads_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1613 if (editmode == INFO_MODE)
1614 name_le->setReadOnly(true);
1617 // ============================================================== clear
1618 void HexaDialog::clear()
1623 modelUnregister(quads_lw);
1625 vertices_lw->clear();
1626 modelUnregister(vertices_lw);
1628 modelUnregister(this);
1631 // ============================================================== getAssocsVTK
1633 * Returns elements currently associated to vtk
1635 QModelIndexList HexaDialog::getAssocsVTK()
1637 QModelIndexList assocs;
1638 QModelIndex iQuad, iVertex;
1639 QListWidgetItem* item = NULL;
1641 const PatternDataModel* patternDataModel = getPatternDataModel();
1642 if (patternDataModel == NULL) return assocs;
1643 if (quads_rb->isChecked())
1645 //ListWidget content
1646 int nbQuads = quads_lw->count();
1647 for ( int r = 0; r < nbQuads; ++r ){
1648 item = quads_lw->item(r);
1649 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1650 if ( iQuad.isValid() )
1655 else if (vertices_rb->isChecked())
1657 //ListWidget content
1658 int nbVertices = vertices_lw->count();
1659 for ( int r = 0; r < nbVertices; ++r ){
1660 item = vertices_lw->item(r);
1661 iVertex = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1662 if ( iVertex.isValid() )
1671 // ============================================================== updateButtonBox
1672 void HexaDialog::updateButtonBox()
1674 if ( _editMode == INFO_MODE )
1677 if ( quads_rb->isChecked() ){ // build from quads count() must be between [2,6]
1678 int nbQuads = quads_lw->count();
1679 if ( nbQuads >= 2 && nbQuads <= 6 ){
1680 _applyButton->setEnabled(true);
1682 _applyButton->setEnabled(false);
1684 } else if ( vertices_rb->isChecked() ){ // build from vertices count() must be equals to 8
1685 int nbVertices = vertices_lw->count();
1686 if ( nbVertices == 8 ){
1687 _applyButton->setEnabled(true);
1689 _applyButton->setEnabled(false);
1694 // ============================================================== deleteQuadItem
1695 void HexaDialog::deleteQuadItem()
1697 delete quads_lw->currentItem();
1701 // ============================================================== deleteVertexItem
1702 void HexaDialog::deleteVertexItem()
1704 delete vertices_lw->currentItem();
1708 // ============================================================== _setValueQuads
1709 void HexaDialog::_setValueQuads( HEXA_NS::Hexa* h )
1711 QListWidgetItem *qItem = NULL;
1712 HEXA_NS::Quad *q = NULL;
1714 if (getPatternDataSelectionModel() == NULL) return;
1716 for( int i = 0; i <= 5; ++i ){
1718 qIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(q)) );
1719 qItem = new QListWidgetItem( q->getName() );
1720 qItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(qIndex) );
1721 qItem->setData(LW_DATA_ROLE, qIndex.data(HEXA_DATA_ROLE));
1722 quads_lw->addItem( qItem );
1726 // ============================================================== _setValueVertices
1727 void HexaDialog::_setValueVertices( HEXA_NS::Hexa* h )
1729 QListWidgetItem *vItem = NULL;
1730 HEXA_NS::Vertex* v = NULL;
1732 if (getPatternDataSelectionModel() == NULL) return;
1733 vertices_lw->clear();
1734 for( int i = 0; i <= 7; ++i ){
1735 v = h->getVertex(i);
1736 vIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(v)) );
1737 vItem = new QListWidgetItem( v->getName() );
1738 vItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(vIndex) );
1739 vItem->setData(LW_DATA_ROLE, vIndex.data(HEXA_DATA_ROLE));
1740 vertices_lw->addItem( vItem );
1744 // ============================================================== setValue
1745 void HexaDialog::setValue(HEXA_NS::Hexa* h)
1748 name_le->setText( h->getName() );
1750 if ( getPatternDataSelectionModel()){
1751 QModelIndex hIndex = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(h) );
1752 _setValueVertices(h);
1754 name_le->setProperty( "QModelIndex", QVariant::fromValue(hIndex) );
1759 // ============================================================== getValue
1760 HEXA_NS::Hexa* HexaDialog::getValue()
1765 // ============================================================== apply
1766 bool HexaDialog::apply(QModelIndex& result)
1768 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1771 if ( !getDocumentModel() ) return false;
1772 const PatternDataModel* patternDataModel = getPatternDataModel();
1773 if ( !patternDataModel ) return false;
1777 QListWidget* currentLw = NULL;
1778 QListWidgetItem* item = NULL;
1780 if ( quads_rb->isChecked() )
1781 currentLw = dynamic_cast<QListWidget*>( quads_lw );
1782 else if ( vertices_rb->isChecked() )
1783 currentLw = dynamic_cast<QListWidget*>( vertices_lw );
1786 QModelIndexList iElts;
1787 int nbItems = currentLw->count();
1788 for ( int r = 0; r < nbItems; ++r){
1789 item = currentLw->item(r);
1790 iElt = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1791 if ( iElt.isValid() )
1795 nbItems = iElts.count();
1796 if ( quads_rb->isChecked() && (nbItems>=2 && nbItems<=6) ){ // build from quads iElts.count() should be between [2,6]
1797 iHexa = getDocumentModel()->addHexaQuads( iElts );
1798 } else if ( vertices_rb->isChecked() && nbItems== 8 ){ // build from vertices
1799 iHexa = getDocumentModel()->addHexaVertices( iElts[0], iElts[1], iElts[2], iElts[3],
1800 iElts[4], iElts[5], iElts[6], iElts[7] );
1803 if ( !iHexa.isValid() ){
1804 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD HEXA" ) + "\n" + getErrorMsg() );
1807 _value = iHexa.model()->data(iHexa, HEXA_DATA_ROLE).value<HEXA_NS::Hexa*>();
1809 QString newName = name_le->text();
1810 if ( !newName.isEmpty() )/*{*/
1811 getDocumentModel()->setName( iHexa, newName );
1813 //update the default name in the dialog box
1815 updateDefaultName(name_le, _value->getType());
1817 // to select/highlight result
1818 result = patternDataModel->mapFromSource(iHexa);
1824 // ------------------------- VECTOR ----------------------------------
1826 // ============================================================== Constructeur
1828 VectorDialog::VectorDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1829 HexaBaseDialog(parent, editmode, f),
1832 _helpFileName = "gui_vector.html";
1834 _initWidget(editmode);
1838 if ( editmode == INFO_MODE ){
1839 setWindowTitle( tr("Vector Information") );
1844 // ============================================================== Destructeur
1845 VectorDialog::~VectorDialog()
1849 // ============================================================== _initInputWidget
1850 void VectorDialog::_initInputWidget( Mode editmode )
1853 QValidator *validator = new QRegExpValidator(rx, this);
1855 installEventFilter(this);
1856 name_le->installEventFilter(this);
1858 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1859 v0_le_rb1->setValidator( validator );
1860 v0_le_rb1->installEventFilter(this);
1862 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1863 v1_le_rb1->setValidator( validator );
1864 v1_le_rb1->installEventFilter(this);
1866 if ( editmode == INFO_MODE ){
1867 name_le->setReadOnly(true);
1868 dx_spb_rb0->setReadOnly(true);
1869 dy_spb_rb0->setReadOnly(true);
1870 dz_spb_rb0->setReadOnly(true);
1873 v0_le_rb1->setReadOnly(true);
1874 v1_le_rb1->setReadOnly(true);
1877 // ============================================================== clear
1878 void VectorDialog::clear()
1882 modelUnregister(v0_le_rb1);
1885 modelUnregister(v1_le_rb1);
1887 modelUnregister(this);
1890 // ============================================================== setValue
1891 void VectorDialog::setValue(HEXA_NS::Vector* v)
1893 name_le->setText( v->getName() );
1894 dx_spb_rb0->setValue( v->getDx() );
1895 dy_spb_rb0->setValue( v->getDy() );
1896 dz_spb_rb0->setValue( v->getDz() );
1898 if ( getPatternDataSelectionModel() ){
1899 QModelIndex ivec = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1900 name_le->setProperty( "QModelIndex", QVariant::fromValue(ivec) );
1905 // ============================================================== getValue
1906 HEXA_NS::Vector* VectorDialog::getValue()
1911 // ============================================================== apply
1912 bool VectorDialog::apply(QModelIndex& result)
1914 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1917 if ( !getDocumentModel() ) return false;
1918 const PatternDataModel* patternDataModel = getPatternDataModel();
1919 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1920 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
1922 QModelIndex iVector;
1924 if ( rb0->isChecked() ){ //scalar
1925 double dx = dx_spb_rb0->value();
1926 double dy = dy_spb_rb0->value();
1927 double dz = dz_spb_rb0->value();
1929 iVector = getDocumentModel()->addVector( dx, dy, dz );
1930 } else if ( rb1->isChecked() ){ //vertices
1931 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
1932 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
1936 iVector = getDocumentModel()->addVectorVertices( iv0, iv1 );
1940 if ( !iVector.isValid() ){
1941 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD VECTOR" ) + "\n" + getErrorMsg());
1945 _value = iVector.model()->data(iVector, HEXA_DATA_ROLE).value<HEXA_NS::Vector *>();
1947 QString newName = name_le->text();
1948 if ( !newName.isEmpty() )/*{*/
1949 getDocumentModel()->setName( iVector, newName );
1951 //update the default name in the dialog box
1953 updateDefaultName(name_le, _value->getType());
1955 // to select/highlight result
1956 result = patternDataModel->mapFromSource(iVector);
1957 // result = patternBuilderModel->mapFromSource(iVector);
1962 // ------------------------- MakeGridDialog ----------------------------------
1963 // ============================================================== Constructeur
1965 MakeGridDialog::MakeGridDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
1966 : HexaBaseDialog(parent, editmode, f)
1969 _initWidget(editmode);
1972 _helpFileName = "creategrids.html#guicartgridsimple";
1973 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1974 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1975 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1977 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1978 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1979 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1981 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1982 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1983 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1986 // ============================================================== Destructeur
1987 MakeGridDialog::~MakeGridDialog()
1991 // ============================================================== _initInputWidget
1992 void MakeGridDialog::_initInputWidget( Mode editmode )
1994 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1995 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1996 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1997 vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1999 center_le->setReadOnly(true);
2000 axis_le->setReadOnly(true);
2001 base_le->setReadOnly(true);
2002 vec_le->setReadOnly(true);
2004 installEventFilter(this);
2005 center_le->installEventFilter(this);
2006 axis_le->installEventFilter(this);
2007 base_le->installEventFilter(this);
2008 vec_le->installEventFilter(this);
2010 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2011 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2013 angle_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(angle_lw));
2014 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2016 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2017 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2019 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2020 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2022 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2023 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2025 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2026 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2029 // ============================================================== clear
2030 void MakeGridDialog::clear()
2033 modelUnregister(center_le);
2036 modelUnregister(axis_le);
2039 modelUnregister(base_le);
2042 modelUnregister(vec_le);
2044 modelUnregister(this);
2047 // ============================================================== updateHelpFileName
2048 void MakeGridDialog::updateHelpFileName()
2050 if ( sender() == rb0 ){
2051 _helpFileName = "creategrids.html#guicartgridsimple";
2052 } else if ( sender() == rb1 ){
2053 _helpFileName = "creategrids.html#guicartgriduniform";
2054 } else if ( sender() == rb2 ){
2055 _helpFileName = "creategrids.html#guicartgridcustom";
2059 // ============================================================== addRadiusItem
2060 void MakeGridDialog::addRadiusItem()
2062 QListWidgetItem* previousItem = radius_lw->currentItem();
2063 QListWidgetItem* newItem = new QListWidgetItem();
2065 double defaultValue = 1.;
2067 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2069 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2070 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2071 radius_lw->addItem(newItem);
2074 // ============================================================== delRadiusItem
2075 void MakeGridDialog::delRadiusItem()
2077 delete radius_lw->currentItem();
2080 // ============================================================== addAngleItem
2081 void MakeGridDialog::addAngleItem()
2083 QListWidgetItem* previousItem = angle_lw->currentItem();
2084 QListWidgetItem* newItem = new QListWidgetItem();
2086 double defaultValue = 1.;
2088 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2090 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2091 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2092 angle_lw->addItem(newItem);
2095 // ============================================================== delAngleItem
2096 void MakeGridDialog::delAngleItem()
2098 delete angle_lw->currentItem();
2101 // ============================================================== addHeightItem
2102 void MakeGridDialog::addHeightItem()
2104 QListWidgetItem* previousItem = height_lw->currentItem();
2105 QListWidgetItem* newItem = new QListWidgetItem();
2107 double defaultValue = 1.;
2109 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2111 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2112 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2113 height_lw->addItem(newItem);
2116 // ============================================================== delHeightItem
2117 void MakeGridDialog::delHeightItem()
2119 delete height_lw->currentItem();
2122 // ============================================================== apply
2123 bool MakeGridDialog::apply(QModelIndex& result)
2125 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2128 DocumentModel* docModel = getDocumentModel();
2129 PatternDataModel* patternDataModel = getPatternDataModel();
2130 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2132 QModelIndex iNewElts;
2133 if ( rb0->isChecked() )
2135 long nx = nx_spb->value();
2136 long ny = ny_spb->value();
2137 long nz = nz_spb->value();
2138 iNewElts = docModel->makeCartesianTop(nx, ny, nz);
2140 else if ( rb1->isChecked() )
2142 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2143 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2144 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2145 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le] );
2146 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2147 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2148 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2150 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2152 double lx = lx_spb->value();
2153 double ly = ly_spb->value();
2154 double lz = lz_spb->value();
2155 double nx = nx_spb->value();
2156 double ny = ny_spb->value();
2157 double nz = nz_spb->value();
2159 iNewElts = docModel->makeCartesianUni( icenter, ibase, ivec, iaxis,
2160 lx, ly, lz, nx, ny, nz);
2163 } else if ( rb2->isChecked() )
2165 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2166 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2167 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2168 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le] );
2169 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2170 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2171 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2173 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2175 QListWidgetItem* item = NULL;
2177 vector<double> radius;
2178 vector<double> angles;
2179 vector<double> heights;
2181 // double somme = 0.;
2182 int nbAngles = angle_lw->count();
2183 for ( int r = 0; r < nbAngles; ++r){
2184 item = angle_lw->item(r);
2185 double itemValue = item->data(Qt::EditRole).toDouble();
2186 angles.push_back(itemValue);
2187 // somme += itemValue;
2189 // if (somme > 360.01)
2191 // SUIT_MessageBox::information( 0,
2193 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2197 int nbRadius = radius_lw->count();
2198 for ( int r = 0; r < nbRadius; ++r){
2199 item = radius_lw->item(r);
2200 radius.push_back(item->data(Qt::EditRole).toDouble());
2203 int nbHeight = height_lw->count();
2204 for ( int r = 0; r < nbHeight; ++r){
2205 item = height_lw->item(r);
2206 heights.push_back(item->data(Qt::EditRole).toDouble());
2209 iNewElts = docModel->makeCartesian( icenter, ibase, ivec, iaxis,
2210 radius, angles, heights);
2214 if ( !iNewElts.isValid() )
2216 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE GRID" ) + "\n" + getErrorMsg() );
2220 result = patternDataModel->mapFromSource(iNewElts);
2221 // result = patternBuilderModel->mapFromSource( iNewElts );
2226 // ============================================================== Constructeur
2228 MakeCylinderDialog::MakeCylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2229 : HexaBaseDialog(parent, editmode, f)
2232 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinder";
2233 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2234 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2235 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2236 _initWidget(editmode);
2241 // ============================================================== Destructeur
2242 MakeCylinderDialog::~MakeCylinderDialog()
2246 void MakeCylinderDialog::_initInputWidget( Mode editmode )
2248 installEventFilter(this);
2250 rb0->installEventFilter(this);
2251 rb1->installEventFilter(this);
2252 rb2->installEventFilter(this);
2254 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
2255 origin_le->installEventFilter(this);
2256 origin_le->setReadOnly(true);
2258 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2259 axis_le->installEventFilter(this);
2260 axis_le->setReadOnly(true);
2262 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE));
2263 base_le->installEventFilter(this);
2264 base_le->setReadOnly(true);
2266 ext_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2267 ext_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2268 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2269 ext_radius_spb->installEventFilter(this);
2271 int_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2272 int_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2273 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2274 int_radius_spb->installEventFilter(this);
2276 angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2277 angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2278 angle_spb->setProperty("Angle", QVariant::fromValue(true));
2279 angle_spb->installEventFilter(this);
2281 height_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2282 height_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2283 height_spb->setProperty("Length", QVariant::fromValue(true));
2284 height_spb->installEventFilter(this);
2286 radius_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2287 radius_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2288 radius_lw->setProperty("Radius", QVariant::fromValue(true));
2289 radius_lw->installEventFilter(this);
2292 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2293 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2294 angle_lw->setProperty("Angle", QVariant::fromValue(true));
2295 angle_lw->installEventFilter(this);
2297 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2298 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2299 height_lw->setProperty("Length", QVariant::fromValue(true));
2300 height_lw->installEventFilter(this);
2302 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2303 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2305 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2306 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2308 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2309 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2311 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2312 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2314 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2315 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2317 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2318 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2321 // ============================================================== updateHelpFileName
2322 void MakeCylinderDialog::updateHelpFileName()
2324 if ( sender() == rb0 ){
2325 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindersimple";
2326 } else if ( sender() == rb1 ){
2327 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinderuniform";
2328 } else if ( sender() == rb2 ){
2329 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindercustom";
2333 // ============================================================== addRadiusItem
2334 void MakeCylinderDialog::addRadiusItem()
2336 QListWidgetItem* previousItem = radius_lw->currentItem();
2337 QListWidgetItem* newItem = new QListWidgetItem();
2339 double defaultValue = 1.;
2341 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2343 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2344 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2345 radius_lw->addItem(newItem);
2348 // ============================================================== delRadiusItem
2349 void MakeCylinderDialog::delRadiusItem()
2351 delete radius_lw->currentItem();
2354 // ============================================================== addAngleItem
2355 void MakeCylinderDialog::addAngleItem()
2357 QListWidgetItem* previousItem = angle_lw->currentItem();
2358 QListWidgetItem* newItem = new QListWidgetItem();
2360 double defaultValue = 180.;
2362 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2364 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2365 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2366 angle_lw->addItem(newItem);
2369 // ============================================================== delAngleItem
2370 void MakeCylinderDialog::delAngleItem()
2372 delete angle_lw->currentItem();
2375 // ============================================================== addHeightItem
2376 void MakeCylinderDialog::addHeightItem()
2378 QListWidgetItem* previousItem = height_lw->currentItem();
2379 QListWidgetItem* newItem = new QListWidgetItem();
2381 double defaultValue = 1.;
2383 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2385 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2386 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2387 height_lw->addItem(newItem);
2390 // ============================================================== delHeightItem
2391 void MakeCylinderDialog::delHeightItem()
2393 delete height_lw->currentItem();
2396 // ============================================================== clear
2397 void MakeCylinderDialog::clear()
2400 modelUnregister(origin_le);
2403 modelUnregister(axis_le);
2406 modelUnregister(base_le);
2408 modelUnregister(this);
2411 // ============================================================== apply
2412 bool MakeCylinderDialog::apply(QModelIndex& result)
2414 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2417 DocumentModel* docModel = getDocumentModel();
2418 PatternDataModel* patternDataModel = getPatternDataModel();
2419 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2421 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2422 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2423 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2424 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2425 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2426 double rext = ext_radius_spb->value();
2427 double rint = int_radius_spb->value();
2428 double angle = angle_spb->value();
2429 double height = height_spb->value();
2430 double nr = nr_spb->value();
2431 double na = na_spb->value();
2432 double nh = nh_spb->value();
2435 if (rb0->isChecked())
2436 iElts = docModel->makeCylinderTop(nr, na, nh);
2437 else if (rb1->isChecked())
2439 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2440 iElts = docModel->makeCylinderUni(iorigin, ibase, iaxis, rint,
2441 rext, angle, height, nr, na, nh);
2443 else if (rb2->isChecked())
2445 QListWidgetItem* item = NULL;
2447 vector<double> radius;
2448 vector<double> angles;
2449 vector<double> heights;
2451 // double somme = 0.;
2452 int nbAngles = angle_lw->count();
2453 for ( int r = 0; r < nbAngles; ++r){
2454 item = angle_lw->item(r);
2455 double itemValue = item->data(Qt::EditRole).toDouble();
2456 angles.push_back(itemValue);
2457 // somme += itemValue;
2459 // if (somme > 360.01)
2461 // SUIT_MessageBox::information( 0,
2463 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2467 int nbRadius = radius_lw->count();
2468 for ( int r = 0; r < nbRadius; ++r){
2469 item = radius_lw->item(r);
2470 radius.push_back(item->data(Qt::EditRole).toDouble());
2473 int nbHeight = height_lw->count();
2474 for ( int r = 0; r < nbHeight; ++r){
2475 item = height_lw->item(r);
2476 heights.push_back(item->data(Qt::EditRole).toDouble());
2479 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2480 iElts = docModel->makeCylinder( iorigin, ibase, iaxis, radius, angles, heights);
2484 if ( !iElts.isValid() ){
2485 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDER" ) + "\n" + getErrorMsg() );
2489 result = patternDataModel->mapFromSource(iElts);
2490 // result = patternBuilderModel->mapFromSource(iElts);
2495 //---------------------------------- MakePipeDialog -----------------------------
2496 // ============================================================== Constructeur
2498 MakePipeDialog::MakePipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2499 : HexaBaseDialog(parent, editmode, f)
2502 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipe";
2503 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2504 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2505 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2506 _initWidget(editmode);
2510 // ============================================================== Destructeur
2511 MakePipeDialog::~MakePipeDialog()
2515 // ============================================================== _initInputWidget
2516 void MakePipeDialog::_initInputWidget( Mode editmode )
2518 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2519 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2520 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2522 installEventFilter(this);
2523 origin_le->installEventFilter(this);
2524 axis_le->installEventFilter(this);
2525 base_le->installEventFilter(this);
2527 rb0->installEventFilter(this);
2528 rb1->installEventFilter(this);
2529 rb2->installEventFilter(this);
2531 origin_le->setReadOnly(true);
2532 axis_le->setReadOnly(true);
2533 base_le->setReadOnly(true);
2535 ext_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2536 ext_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2537 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2538 ext_radius_spb->installEventFilter(this);
2540 int_radius_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2541 int_radius_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2542 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2543 int_radius_spb->installEventFilter(this);
2545 angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2546 angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2547 angle_spb->setProperty("Angle", QVariant::fromValue(true));
2548 angle_spb->installEventFilter(this);
2550 height_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2551 height_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2552 height_spb->setProperty("Length", QVariant::fromValue(true));
2553 height_spb->installEventFilter(this);
2555 radius_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2556 radius_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2557 radius_lw->setProperty("Radius", QVariant::fromValue(true));
2558 radius_lw->installEventFilter(this);
2560 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2561 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2562 angle_lw->setProperty("Angle", QVariant::fromValue(true));
2563 angle_lw->installEventFilter(this);
2565 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2566 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2567 height_lw->setProperty("Length", QVariant::fromValue(true));
2568 height_lw->installEventFilter(this);
2570 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2571 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2573 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2574 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2576 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2577 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2579 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2580 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2582 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2583 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2585 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2586 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2590 // ============================================================== updateHelpFileName
2591 void MakePipeDialog::updateHelpFileName()
2593 if ( sender() == rb0 ){
2594 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipesimple";
2595 } else if ( sender() == rb1 ){
2596 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipeuniform";
2597 } else if ( sender() == rb2 ){
2598 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipecustom";
2602 // ============================================================== addRadiusItem
2603 void MakePipeDialog::addRadiusItem()
2605 QListWidgetItem* previousItem = radius_lw->currentItem();
2606 QListWidgetItem* newItem = new QListWidgetItem();
2608 double defaultValue = 1.;
2610 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2612 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2613 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2614 radius_lw->addItem(newItem);
2617 // ============================================================== delRadiusItem
2618 void MakePipeDialog::delRadiusItem()
2620 delete radius_lw->currentItem();
2623 // ============================================================== addAngleItem
2624 void MakePipeDialog::addAngleItem()
2626 QListWidgetItem* previousItem = angle_lw->currentItem();
2627 QListWidgetItem* newItem = new QListWidgetItem();
2629 double defaultValue = 180.;
2631 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2633 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2634 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2635 angle_lw->addItem(newItem);
2638 // ============================================================== delAngleItem
2639 void MakePipeDialog::delAngleItem()
2641 delete angle_lw->currentItem();
2644 // ============================================================== addHeightItem
2645 void MakePipeDialog::addHeightItem()
2647 QListWidgetItem* previousItem = height_lw->currentItem();
2648 QListWidgetItem* newItem = new QListWidgetItem();
2650 double defaultValue = 1.;
2652 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2654 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2655 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2656 height_lw->addItem(newItem);
2659 // ============================================================== delHeightItem
2660 void MakePipeDialog::delHeightItem()
2662 delete height_lw->currentItem();
2665 // ============================================================== clear
2666 void MakePipeDialog::clear()
2669 modelUnregister(origin_le);
2672 modelUnregister(axis_le);
2675 modelUnregister(base_le);
2677 modelUnregister(this);
2680 // ============================================================== apply
2681 bool MakePipeDialog::apply(QModelIndex& result)
2683 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2686 DocumentModel* docModel = getDocumentModel();
2687 PatternDataModel* patternDataModel = getPatternDataModel();
2688 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2690 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2691 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
2692 QModelIndex ibase = patternDataModel->mapToSource( _index[base_le] );
2693 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2694 // QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2695 double rext = ext_radius_spb->value();
2696 double rint = int_radius_spb->value();
2697 double angle = angle_spb->value();
2698 double height = height_spb->value();
2699 int nr = nr_spb->value();
2700 int na = na_spb->value();
2701 int nh = nh_spb->value();
2705 if (rb0->isChecked())
2706 iElts = docModel->makePipeTop(nr, na, nh);
2707 else if (rb1->isChecked())
2709 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2710 iElts = docModel->makePipeUni(iorigin, ibase, iaxis, rint, rext, angle, height,
2713 else if (rb2->isChecked())
2715 QListWidgetItem* item = NULL;
2717 vector<double> radius;
2718 vector<double> angles;
2719 vector<double> heights;
2721 // double somme = 0.;
2722 int nbAngles = angle_lw->count();
2723 for ( int r = 0; r < nbAngles; ++r){
2724 item = angle_lw->item(r);
2725 double itemValue = item->data(Qt::EditRole).toDouble();
2726 angles.push_back(itemValue);
2727 // somme += itemValue;
2729 // if (somme > 360.01)
2731 // SUIT_MessageBox::information( 0,
2733 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2737 int nbRadius = radius_lw->count();
2738 for ( int r = 0; r < nbRadius; ++r){
2739 item = radius_lw->item(r);
2740 radius.push_back(item->data(Qt::EditRole).toDouble());
2743 int nbHeight = height_lw->count();
2744 for ( int r = 0; r < nbHeight; ++r){
2745 item = height_lw->item(r);
2746 heights.push_back(item->data(Qt::EditRole).toDouble());
2748 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2749 iElts = docModel->makePipe( iorigin, ibase, iaxis, radius, angles, heights );
2752 if ( !iElts.isValid() ){
2753 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPE" ) + "\n" + getErrorMsg() );
2757 // to select/highlight result
2758 result = patternDataModel->mapFromSource(iElts);
2759 // result = patternBuilderModel->mapFromSource(iElts);
2764 //---------------------------------- MakeCylindersDialog -----------------------------
2765 // ============================================================== Constructeur
2767 MakeCylindersDialog::MakeCylindersDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2768 : HexaBaseDialog(parent, editmode, f)
2770 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinders";
2772 _initWidget(editmode);
2775 // ============================================================== Destructeur
2776 MakeCylindersDialog::~MakeCylindersDialog()
2780 void MakeCylindersDialog::_initInputWidget( Mode editmode )
2782 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2783 center2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2784 direction_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2785 direction2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2787 radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2788 radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2789 radius_spb->setProperty("Radius", QVariant::fromValue(true));
2790 radius_spb->installEventFilter(this);
2792 height_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2793 height_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2794 height_spb->setProperty("Length", QVariant::fromValue(true));
2795 height_spb->installEventFilter(this);
2797 radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2798 radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2799 radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2800 radius2_spb->installEventFilter(this);
2802 height2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2803 height2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2804 height2_spb->setProperty("Length", QVariant::fromValue(true));
2805 height2_spb->installEventFilter(this);
2807 installEventFilter(this);
2808 center_le->installEventFilter(this);
2809 center2_le->installEventFilter(this);
2810 direction_le->installEventFilter(this);
2811 direction2_le->installEventFilter(this);
2813 center_le->setReadOnly(true);
2814 center2_le->setReadOnly(true);
2815 direction_le->setReadOnly(true);
2816 direction2_le->setReadOnly(true);
2819 // ============================================================== clear
2820 void MakeCylindersDialog::clear()
2823 modelUnregister(center_le);
2825 center2_le->clear();
2826 modelUnregister(center2_le);
2828 direction_le->clear();
2829 modelUnregister(direction_le);
2831 direction2_le->clear();
2832 modelUnregister(direction2_le);
2834 modelUnregister(this);
2837 // ============================================================== apply
2838 bool MakeCylindersDialog::apply(QModelIndex& result)
2840 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2843 DocumentModel* docModel = getDocumentModel();
2844 PatternDataModel* patternDataModel = getPatternDataModel();
2845 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2848 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2849 QModelIndex icenter2 = patternDataModel->mapToSource( _index[center2_le] );
2850 QModelIndex idir = patternDataModel->mapToSource( _index[direction_le] );
2851 QModelIndex idir2 = patternDataModel->mapToSource( _index[direction2_le] );
2852 // QModelIndex idir = patternBuilderModel->mapToSource( _index[direction_le] );
2853 // QModelIndex idir2 = patternBuilderModel->mapToSource( _index[direction2_le] );
2855 if ( icenter.isValid() && icenter2.isValid() && idir.isValid() && idir2.isValid()){
2856 double r1 = radius_spb->value();
2857 double h1 = height_spb->value();
2858 double r2 = radius2_spb->value();
2859 double h2 = height2_spb->value();
2860 iElts = docModel->makeCylinders( icenter, idir, r1, h1, icenter2, idir2, r2, h2 );
2863 if ( !iElts.isValid() ){
2864 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDERS" ) + "\n" + getErrorMsg() );
2868 result = patternDataModel->mapFromSource(iElts);
2869 // result = patternBuilderModel->mapFromSource(iElts);
2874 //---------------------------------- MakePipesDialog -----------------------------
2875 // ============================================================== Constructeur
2877 MakePipesDialog::MakePipesDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2878 : HexaBaseDialog(parent, editmode, f)
2880 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipes";
2882 _initWidget(editmode);
2885 // ============================================================== Destructeur
2886 MakePipesDialog::~MakePipesDialog()
2890 // ============================================================== _initInputWidget
2891 void MakePipesDialog::_initInputWidget( Mode editmode )
2893 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2894 origin2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2895 dir_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2896 dir2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2898 ext_radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2899 ext_radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2900 ext_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2901 ext_radius_spb->installEventFilter(this);
2903 int_radius_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2904 int_radius_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2905 int_radius_spb->setProperty("Radius", QVariant::fromValue(true));
2906 int_radius_spb->installEventFilter(this);
2908 height_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2909 height_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2910 height_spb->setProperty("Length", QVariant::fromValue(true));
2911 height_spb->installEventFilter(this);
2913 ext_radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2914 ext_radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2915 ext_radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2916 ext_radius2_spb->installEventFilter(this);
2918 int_radius2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2919 int_radius2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2920 int_radius2_spb->setProperty("Radius", QVariant::fromValue(true));
2921 int_radius2_spb->installEventFilter(this);
2923 height2_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
2924 height2_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
2925 height2_spb->setProperty("Length", QVariant::fromValue(true));
2926 height2_spb->installEventFilter(this);
2928 origin_le->installEventFilter(this);
2929 origin2_le->installEventFilter(this);
2930 dir_le->installEventFilter(this);
2931 dir2_le->installEventFilter(this);
2933 origin_le->setReadOnly(true);
2934 origin2_le->setReadOnly(true);
2935 dir_le->setReadOnly(true);
2936 dir2_le->setReadOnly(true);
2939 // ============================================================== clear
2940 void MakePipesDialog::clear()
2943 modelUnregister(origin_le);
2945 origin2_le->clear();
2946 modelUnregister(origin2_le);
2949 modelUnregister(dir_le);
2952 modelUnregister(dir2_le);
2954 modelUnregister(this);
2957 // ============================================================== apply
2958 bool MakePipesDialog::apply(QModelIndex& result)
2960 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2963 DocumentModel* docModel = getDocumentModel();
2964 PatternDataModel* patternDataModel = getPatternDataModel();
2965 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2967 QModelIndex iorigin1 = patternDataModel->mapToSource( _index[origin_le] );
2968 QModelIndex iorigin2 = patternDataModel->mapToSource( _index[origin2_le] );
2969 QModelIndex idir1 = patternDataModel->mapToSource( _index[dir_le] );
2970 QModelIndex idir2 = patternDataModel->mapToSource( _index[dir2_le] );
2971 // QModelIndex idir1 = patternBuilderModel->mapToSource( _index[dir_le] );
2972 // QModelIndex idir2 = patternBuilderModel->mapToSource( _index[dir2_le] );
2973 double rint1 = int_radius_spb->value();
2974 double rext1 = ext_radius_spb->value();
2975 double height1 = height_spb->value();
2976 double rint2 = int_radius2_spb->value();
2977 double rext2 = ext_radius2_spb->value();
2978 double height2 = height_spb->value();
2982 if ( iorigin1.isValid() && iorigin2.isValid() && idir1.isValid() && idir2.isValid())
2983 iElts = docModel->makePipes( iorigin1, idir1, rint1, rext1, height1,
2984 iorigin2, idir2, rint2, rext2, height2);
2986 if ( !iElts.isValid() ){
2987 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPES" ) + "\n" + getErrorMsg() );
2991 result = patternDataModel->mapFromSource(iElts);
2992 // result = patternBuilderModel->mapFromSource(iElts);
2997 //---------------------------------- RemoveHexaDialog -----------------------------
2998 // ============================================================== Constructeur
3000 RemoveHexaDialog::RemoveHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3001 : HexaBaseDialog(parent, editmode, f)
3003 _helpFileName = "gui_remove.html";
3005 _initWidget(editmode);
3008 // ============================================================== Destructeur
3009 RemoveHexaDialog::~RemoveHexaDialog()
3013 // ============================================================== _initInputWidget
3014 void RemoveHexaDialog::_initInputWidget( Mode editmode )
3017 QValidator *validator = new QRegExpValidator(rx, this);
3019 hexa_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3020 hexa_le->setValidator( validator );
3021 hexa_le->installEventFilter(this);
3022 hexa_le->setReadOnly(true);
3023 autoFocusSwitch = false;
3026 // ============================================================== clear
3027 void RemoveHexaDialog::clear()
3030 modelUnregister(hexa_le);
3032 modelUnregister(this);
3035 // ============================================================== apply
3036 bool RemoveHexaDialog::apply(QModelIndex& result)
3038 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3041 if ( !getDocumentModel() ) return false;
3042 const PatternDataModel* patternDataModel = getPatternDataModel();
3043 if ( !patternDataModel ) return false;
3045 QModelIndex ihexa = patternDataModel->mapToSource( _index[hexa_le] );
3047 bool removed = false;
3048 if ( ihexa.isValid() ){
3049 if ( connected_cb->isChecked() ){
3050 removed = getDocumentModel()->removeConnectedHexa( ihexa );
3052 removed = getDocumentModel()->removeHexa( ihexa );
3056 if ( removed == false ){
3057 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE HEXA" ) + "\n" + getErrorMsg() );
3066 //---------------------------------- PrismQuadDialog -----------------------------
3067 // ============================================================== Constructeur
3069 PrismQuadDialog::PrismQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3070 : HexaBaseDialog(parent, editmode, f)
3073 _helpFileName = "gui_prism_join_quad.html#guiextrudequads";
3074 connect( extrudeTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3075 connect( extrudeUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3076 connect( extrude_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3077 _initWidget(editmode);
3078 extrudeTop_rb->click();
3081 // ============================================================== Destructeur
3082 PrismQuadDialog::~PrismQuadDialog()
3086 // ============================================================== getAssocsVTK
3088 * Returns elements currently associated to vtk
3090 QModelIndexList PrismQuadDialog::getAssocsVTK()
3092 QModelIndexList assocs;
3094 QListWidgetItem* item = NULL;
3096 //ListWidget content
3097 const PatternDataModel* patternDataModel = getPatternDataModel();
3098 if ( !patternDataModel ) return assocs;
3099 int nbQuads = quads_lw->count();
3100 for ( int r = 0; r < nbQuads; ++r ){
3101 item = quads_lw->item(r);
3102 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3103 if ( iQuad.isValid() )
3109 // ============================================================== _initInputWidget
3110 void PrismQuadDialog::_initInputWidget( Mode editmode )
3112 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3113 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3115 length_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3116 length_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3117 length_spb->setProperty("Length", QVariant::fromValue(true));
3118 length_spb->installEventFilter(this);
3121 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3122 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3123 height_lw->setProperty("Length", QVariant::fromValue(true));
3124 height_lw->installEventFilter(this);
3126 installEventFilter(this);
3127 quads_lw->installEventFilter(this);
3128 axis_le->installEventFilter(this);
3130 extrudeTop_rb->installEventFilter(this);
3131 extrudeUni_rb->installEventFilter(this);
3132 extrude_rb->installEventFilter(this);
3134 axis_le->setReadOnly(true);
3136 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3137 delQuadShortcut->setContext( Qt::WidgetShortcut );
3138 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3139 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3141 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3142 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3143 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3144 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3147 // ============================================================== updateHelpFileName
3148 void PrismQuadDialog::updateHelpFileName()
3150 if ( sender() == extrudeTop_rb ){
3151 _helpFileName = "gui_prism_join_quad.html#guiextrudequadssimple";
3152 } else if ( sender() == extrudeUni_rb ){
3153 _helpFileName = "gui_prism_join_quad.html#guiextrudequadsuniform";
3154 } else if ( sender() == extrude_rb ){
3155 _helpFileName = "gui_prism_join_quad.html#guiextrudequadscustom";
3159 // ============================================================== clear
3160 void PrismQuadDialog::clear()
3163 modelUnregister(quads_lw);
3166 modelUnregister(axis_le);
3168 modelUnregister(this);
3171 // ============================================================== removeQuad
3172 void PrismQuadDialog::removeQuad()
3174 QListWidgetItem *item = quads_lw->currentItem();
3177 int r = quads_lw->row(item);
3178 quads_lw->takeItem(r);
3183 // ============================================================== addHeightItem
3184 void PrismQuadDialog::addHeightItem()
3186 QListWidgetItem* previousItem = height_lw->currentItem();
3187 QListWidgetItem* newItem = new QListWidgetItem();
3189 double defaultValue = 1.;
3191 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3193 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3194 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3195 height_lw->addItem(newItem);
3198 // ============================================================== delHeightItem
3199 void PrismQuadDialog::delHeightItem()
3201 delete height_lw->currentItem();
3204 // ============================================================== apply
3205 bool PrismQuadDialog::apply(QModelIndex& result)
3207 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3210 DocumentModel* docModel = getDocumentModel();
3211 PatternDataModel* patternDataModel = getPatternDataModel();
3212 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3214 QModelIndexList iquads = getIndexList(quads_lw);
3215 QModelIndex iaxis = patternDataModel->mapToSource( _index[axis_le] );
3216 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
3217 double length = length_spb->value();
3218 int nb = nb_spb->value();
3220 vector<double> heights;
3221 QListWidgetItem* item = NULL;
3222 int nbItems = height_lw->count();
3224 for ( int r = 0; r < nbItems; ++r){
3225 item = height_lw->item(r);
3226 heights.push_back( item->data(Qt::EditRole).toDouble() );
3230 int nbQuads = iquads.count();
3232 if (nbQuads == 1 && iquads[0].isValid())
3234 if (extrudeTop_rb->isChecked())
3235 iElts = docModel->extrudeQuadTop(iquads[0], nb);
3236 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3237 iElts = docModel->extrudeQuadUni(iquads[0], iaxis, length, nb);
3238 else if (extrude_rb->isChecked() && iaxis.isValid())
3239 iElts = docModel->extrudeQuad(iquads[0], iaxis, heights);
3241 else if (nbQuads > 1)
3243 if (extrudeTop_rb->isChecked())
3244 iElts = docModel->extrudeQuadsTop(iquads, nb);
3245 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3246 iElts = docModel->extrudeQuadsUni(iquads, iaxis, length, nb);
3247 else if (extrude_rb->isChecked() && iaxis.isValid())
3248 iElts = docModel->extrudeQuads(iquads, iaxis, heights);
3251 if ( !iElts.isValid() ){
3252 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PRISM QUAD(S)" ) + "\n" + getErrorMsg() );
3256 result = patternDataModel->mapFromSource(iElts);
3257 // result = patternBuilderModel->mapFromSource(iElts);
3262 //---------------------------------- JoinQuadDialog -----------------------------
3263 // ============================================================== Constructeur
3265 JoinQuadDialog::JoinQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3266 : HexaBaseDialog(parent, editmode, f)
3269 _helpFileName = "gui_prism_join_quad.html#guijoinquads";
3270 connect( joinUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3271 connect( join_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3272 _initWidget(editmode);
3273 joinUni_rb->click();
3276 // ============================================================== Destructeur
3277 JoinQuadDialog::~JoinQuadDialog()
3281 // ============================================================== getAssocsVTK
3283 * Returns elements currently associated to vtk
3285 QModelIndexList JoinQuadDialog::getAssocsVTK()
3287 QModelIndexList assocs;
3289 QListWidgetItem* item = NULL;
3291 if (getPatternDataSelectionModel() == NULL) return assocs;
3293 //ListWidget content
3294 const PatternDataModel* patternDataModel = getPatternDataModel();
3295 if ( !patternDataModel ) return assocs;
3296 int nbQuads = quads_lw->count();
3297 for ( int r = 0; r < nbQuads; ++r ){
3298 item = quads_lw->item(r);
3299 // iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
3300 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
3301 if ( iQuad.isValid() ) assocs << iQuad;
3306 // ============================================================== _initInputWidget
3307 void JoinQuadDialog::_initInputWidget( Mode editmode )
3309 quad_dest_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3310 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3311 vex0_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3312 vex1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3313 vex2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3314 vex3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3316 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3317 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3318 height_lw->setProperty("Length", QVariant::fromValue(true));
3319 height_lw->installEventFilter(this);
3321 installEventFilter(this);
3322 quad_dest_le->installEventFilter(this);
3323 quads_lw->installEventFilter(this);
3324 vex0_le->installEventFilter(this);
3325 vex1_le->installEventFilter(this);
3326 vex2_le->installEventFilter(this);
3327 vex3_le->installEventFilter(this);
3329 joinUni_rb->installEventFilter(this);
3330 join_rb->installEventFilter(this);
3332 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3333 delQuadShortcut->setContext( Qt::WidgetShortcut );
3334 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3336 quad_dest_le->setReadOnly(true);
3337 vex0_le->setReadOnly(true);
3338 vex1_le->setReadOnly(true);
3339 vex2_le->setReadOnly(true);
3340 vex3_le->setReadOnly(true);
3342 _currentObj = quads_lw;
3343 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3344 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3346 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3348 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3349 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3352 // ============================================================== updateHelpFileName
3353 void JoinQuadDialog::updateHelpFileName()
3355 if ( sender() == joinUni_rb ){
3356 _helpFileName = "gui_prism_join_quad.html#guijoinquadsuniform";
3357 } else if ( sender() == join_rb ){
3358 _helpFileName = "gui_prism_join_quad.html#guijoinquadscustom";
3362 // ============================================================== addHeightItem
3363 void JoinQuadDialog::addHeightItem()
3365 QListWidgetItem* previousItem = height_lw->currentItem();
3366 QListWidgetItem* newItem = new QListWidgetItem();
3368 double defaultValue = 1.;
3370 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3372 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3373 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3374 height_lw->addItem(newItem);
3377 // ============================================================== delHeightItem
3378 void JoinQuadDialog::delHeightItem()
3380 delete height_lw->currentItem();
3383 // ============================================================== clear
3384 void JoinQuadDialog::clear()
3386 quad_dest_le->clear();
3387 modelUnregister(quad_dest_le);
3390 modelUnregister(quads_lw);
3393 modelUnregister(vex0_le);
3396 modelUnregister(vex1_le);
3399 modelUnregister(vex2_le);
3402 modelUnregister(vex3_le);
3404 modelUnregister(this);
3407 // ============================================================== removeQuad
3408 void JoinQuadDialog::removeQuad()
3410 QListWidgetItem *item = quads_lw->currentItem();
3413 int r = quads_lw->row(item);
3414 quads_lw->takeItem(r);
3419 // ============================================================== apply
3420 bool JoinQuadDialog::apply(QModelIndex& result)
3422 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3425 DocumentModel* docModel = getDocumentModel();
3426 PatternDataModel* patternDataModel = getPatternDataModel();
3427 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3429 QModelIndexList iquads;
3431 QListWidgetItem* item = NULL;
3432 int nbQuads = quads_lw->count();
3433 for ( int r = 0; r < nbQuads; ++r){
3434 item = quads_lw->item(r);
3435 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3436 if ( iquad.isValid() )
3439 QModelIndex iquaddest = patternDataModel->mapToSource( _index[quad_dest_le] );
3440 QModelIndex ivex0 = patternDataModel->mapToSource( _index[vex0_le] );
3441 QModelIndex ivex1 = patternDataModel->mapToSource( _index[vex1_le] );
3442 QModelIndex ivex2 = patternDataModel->mapToSource( _index[vex2_le] );
3443 QModelIndex ivex3 = patternDataModel->mapToSource( _index[vex3_le] );
3444 double nb = nb_spb->value();
3446 vector<double> heights;
3447 int nbHeight = height_lw->count();
3448 for ( int r = 0; r < nbHeight; ++r){
3449 item = height_lw->item(r);
3450 heights.push_back(item->data(Qt::EditRole).toDouble());
3454 if (nbQuads == 1 && iquads[0].isValid() && iquaddest.isValid() && ivex0.isValid() &&
3455 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3457 if (joinUni_rb->isChecked())
3458 iElts = docModel->joinQuadUni(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3459 else if (join_rb->isChecked())
3460 iElts = docModel->joinQuad(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3462 else if (nbQuads > 1 && iquaddest.isValid() && ivex0.isValid() &&
3463 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3465 if (joinUni_rb->isChecked())
3466 iElts = docModel->joinQuadsUni(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3467 else if (join_rb->isChecked())
3468 iElts = docModel->joinQuads(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3471 if ( !iElts.isValid() ){
3472 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT JOIN QUAD(S)" ) + "\n" + getErrorMsg() );
3475 result = patternDataModel->mapFromSource(iElts);
3476 // result = patternBuilderModel->mapFromSource(iElts);
3481 // ------------------------- MergeDialog ----------------------------------
3482 // ============================================================== Constructeur
3484 MergeDialog::MergeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3485 : HexaBaseDialog(parent, editmode, f)
3488 _initWidget(editmode);
3491 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3492 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3493 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3494 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3496 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3497 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3498 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3500 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3501 connect( rb2, SIGNAL(cliked()), this, SLOT(clearVTKSelection()) );
3502 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3505 // ============================================================== Destructeur
3506 MergeDialog::~MergeDialog()
3510 // ============================================================== _initInputWidget
3511 void MergeDialog::_initInputWidget( Mode editmode )
3514 QValidator *validator = new QRegExpValidator(rx, this);
3516 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3517 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3518 v0_le_rb0->setValidator( validator );
3519 v1_le_rb0->setValidator( validator );
3520 v0_le_rb0->installEventFilter(this);
3521 v1_le_rb0->installEventFilter(this);
3523 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3524 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3525 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3526 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3528 v0_le_rb1->setValidator( validator );
3529 v1_le_rb1->setValidator( validator );
3530 e0_le_rb1->setValidator( validator );
3531 e1_le_rb1->setValidator( validator );
3533 v0_le_rb1->installEventFilter(this);
3534 v1_le_rb1->installEventFilter(this);
3535 e0_le_rb1->installEventFilter(this);
3536 e1_le_rb1->installEventFilter(this);
3538 v0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3539 v1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3540 v2_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3541 v3_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3542 q0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3543 q1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3545 v0_le_rb2->setValidator( validator );
3546 v1_le_rb2->setValidator( validator );
3547 v2_le_rb2->setValidator( validator );
3548 v3_le_rb2->setValidator( validator );
3549 q0_le_rb2->setValidator( validator );
3550 q1_le_rb2->setValidator( validator );
3552 v0_le_rb2->installEventFilter(this);
3553 v1_le_rb2->installEventFilter(this);
3554 v2_le_rb2->installEventFilter(this);
3555 v3_le_rb2->installEventFilter(this);
3556 q0_le_rb2->installEventFilter(this);
3557 q1_le_rb2->installEventFilter(this);
3559 v0_le_rb0->setReadOnly(true);
3560 v1_le_rb0->setReadOnly(true);
3562 v0_le_rb1->setReadOnly(true);
3563 v1_le_rb1->setReadOnly(true);
3564 e0_le_rb1->setReadOnly(true);
3565 e1_le_rb1->setReadOnly(true);
3567 v0_le_rb2->setReadOnly(true);
3568 v1_le_rb2->setReadOnly(true);
3569 v2_le_rb2->setReadOnly(true);
3570 v3_le_rb2->setReadOnly(true);
3571 q0_le_rb2->setReadOnly(true);
3572 q1_le_rb2->setReadOnly(true);
3575 // ============================================================== clear
3576 void MergeDialog::clear()
3579 modelUnregister(v0_le_rb0);
3582 modelUnregister(v1_le_rb0);
3585 modelUnregister(e0_le_rb1);
3588 modelUnregister(e1_le_rb1);
3591 modelUnregister(v0_le_rb1);
3594 modelUnregister(v1_le_rb1);
3597 modelUnregister(q0_le_rb2);
3600 modelUnregister(q1_le_rb2);
3603 modelUnregister(v0_le_rb2);
3606 modelUnregister(v1_le_rb2);
3609 modelUnregister(v2_le_rb2);
3612 modelUnregister(v3_le_rb2);
3614 modelUnregister(this);
3617 // ============================================================== updateHelpFileName
3618 void MergeDialog::updateHelpFileName()
3620 if ( sender() == rb0 ){
3621 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3622 } else if ( sender() == rb1 ){
3623 _helpFileName = "gui_merge_elmts.html#merge-two-edges";
3624 } else if ( sender() == rb2 ){
3625 _helpFileName = "gui_merge_elmts.html#merge-two-quadrangles";
3629 // ============================================================== apply
3630 bool MergeDialog::apply(QModelIndex& result)
3632 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3635 if (getDocumentModel() == NULL) return false;
3636 const PatternDataModel* patternDataModel = getPatternDataModel();
3637 if ( !patternDataModel ) return false;
3639 bool merged = false;
3641 if ( rb0->isChecked() ){
3642 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
3643 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
3647 merged = getDocumentModel()->mergeVertices( iv0, iv1 );
3649 } else if ( rb1->isChecked() ){
3650 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
3651 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
3652 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
3653 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
3659 merged = getDocumentModel()->mergeEdges( ie0, ie1, iv0, iv1);
3661 } else if ( rb2->isChecked() ){
3663 QModelIndex iq0 = patternDataModel->mapToSource( _index[q0_le_rb2] );
3664 QModelIndex iq1 = patternDataModel->mapToSource( _index[q1_le_rb2] );
3665 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb2] );
3666 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb2] );
3667 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb2] );
3668 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb2] );
3676 merged = getDocumentModel()->mergeQuads( iq0, iq1,
3677 iv0, iv1, iv2, iv3 );
3681 if ( merged == false ){
3682 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MERGE" ) + "\n" + getErrorMsg() );
3689 // ------------------------- DisconnectDialog ----------------------------------
3690 // ============================================================== Constructeur
3692 DisconnectDialog::DisconnectDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3693 : HexaBaseDialog(parent, editmode, f)
3696 _initWidget(editmode);
3699 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3701 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3702 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3703 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3705 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3706 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3707 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3709 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3710 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3711 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3713 connect( rb3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3714 connect( rb3, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3715 connect( rb3, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3719 // ============================================================== Destructeur
3720 DisconnectDialog::~DisconnectDialog()
3724 // ============================================================== _initInputWidget
3725 void DisconnectDialog::_initInputWidget( Mode editmode )
3728 QValidator *validator = new QRegExpValidator(rx, this);
3730 installEventFilter(this);
3733 v_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3734 h_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3735 v_le_rb0->setValidator( validator );
3736 h_le_rb0->setValidator( validator );
3737 v_le_rb0->installEventFilter(this);
3738 h_le_rb0->installEventFilter(this);
3741 e_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3742 h_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3743 e_le_rb1->setValidator( validator );
3744 h_le_rb1->setValidator( validator );
3745 e_le_rb1->installEventFilter(this);
3746 h_le_rb1->installEventFilter(this);
3749 q_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3750 h_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3751 q_le_rb2->setValidator( validator );
3752 h_le_rb2->setValidator( validator );
3753 q_le_rb2->installEventFilter(this);
3754 h_le_rb2->installEventFilter(this);
3757 d_edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3758 hexas_lw->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3759 d_edges_lw->installEventFilter(this);
3760 hexas_lw->installEventFilter(this);
3762 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), d_edges_lw);
3763 QShortcut* delHexaShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), hexas_lw);
3764 delEdgeShortcut->setContext( Qt::WidgetShortcut );
3765 delHexaShortcut->setContext( Qt::WidgetShortcut );
3767 v_le_rb0->setReadOnly(true);
3768 h_le_rb0->setReadOnly(true);
3770 e_le_rb1->setReadOnly(true);
3771 h_le_rb1->setReadOnly(true);
3773 q_le_rb2->setReadOnly(true);
3774 h_le_rb2->setReadOnly(true);
3776 connect( d_edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3777 connect( hexas_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3778 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
3779 connect( delHexaShortcut, SIGNAL(activated()), this, SLOT(deleteHexaItem()) );
3780 autoFocusSwitch = false;
3784 // =============================================== getAssocsVTK
3786 * Returns elements in the list
3788 QModelIndexList DisconnectDialog::getAssocsVTK()
3790 QModelIndexList iElts;
3792 QListWidgetItem* item = NULL;
3794 const PatternDataModel* patternDataModel = getPatternDataModel();
3795 if (patternDataModel == NULL || !rb3->isChecked())
3797 //ListWidget content
3798 if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == EDGE_TREE)
3800 int nbEdges = d_edges_lw->count();
3801 for ( int r = 0; r < nbEdges; ++r )
3803 item = d_edges_lw->item(r);
3804 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3805 if ( index.isValid() )
3809 else if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == HEXA_TREE)
3811 int nbHexas = hexas_lw->count();
3812 for ( int r = 0; r < nbHexas; ++r )
3814 item = hexas_lw->item(r);
3815 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3816 if ( index.isValid() )
3823 // ============================================================== clear
3824 void DisconnectDialog::clear()
3827 modelUnregister(v_le_rb0);
3830 modelUnregister(h_le_rb0);
3833 modelUnregister(e_le_rb1);
3836 modelUnregister(h_le_rb1);
3838 d_edges_lw->clear();
3839 modelUnregister(d_edges_lw);
3842 modelUnregister(hexas_lw);
3845 modelUnregister(q_le_rb2);
3848 modelUnregister(h_le_rb2);
3850 modelUnregister(this);
3853 // ============================================================== deleteEdgeItem
3854 void DisconnectDialog::deleteEdgeItem()
3856 delete d_edges_lw->currentItem();
3859 // ============================================================== deleteHexaItem
3860 void DisconnectDialog::deleteHexaItem()
3862 delete hexas_lw->currentItem();
3865 // ============================================================== updateHelpFileName
3866 void DisconnectDialog::updateHelpFileName()
3868 if ( sender() == rb0 ){
3869 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3870 } else if ( sender() == rb1 ){
3871 _helpFileName = "gui_disc_elmts.html#disconnect-an-edge";
3872 } else if ( sender() == rb2 ){
3873 _helpFileName = "gui_disc_elmts.html#disconnect-a-quadrangle";
3874 } else if (sender() == rb3 ){
3875 _helpFileName = "gui_disc_elmts.html#disconnect-edges";
3879 // ============================================================== apply
3880 bool DisconnectDialog::apply(QModelIndex& result)
3882 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3884 if (getDocumentModel() == NULL) return false;
3885 const PatternDataModel* patternDataModel = getPatternDataModel();
3886 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3887 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
3891 if ( rb0->isChecked() ){
3892 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb0] );
3893 QModelIndex ivex = patternDataModel->mapToSource( _index[v_le_rb0] );
3895 if ( ihexa.isValid()
3896 && ivex.isValid() ){
3897 iElts = getDocumentModel()->disconnectVertex( ihexa, ivex );
3899 } else if ( rb1->isChecked() ){
3900 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb1] );
3901 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le_rb1] );
3903 if ( ihexa.isValid()
3904 && iedge.isValid() ){
3905 iElts = getDocumentModel()->disconnectEdge( ihexa, iedge );
3907 } else if ( rb2->isChecked() ){
3908 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb2] );
3909 QModelIndex iquad = patternDataModel->mapToSource( _index[q_le_rb2] );
3911 if ( ihexa.isValid()
3912 && iquad.isValid() ){
3913 iElts = getDocumentModel()->disconnectQuad( ihexa, iquad );
3915 } else if ( rb3->isChecked() ){ //
3917 QModelIndex iedge, ihexa;
3918 QModelIndexList iedges, ihexas;
3919 QListWidgetItem* item = NULL;
3922 int nbEdges = d_edges_lw->count();
3923 for (int r = 0; r < nbEdges; ++r){
3924 item = d_edges_lw->item(r);
3925 iedge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3926 if ( iedge.isValid() )
3931 int nbHexas = hexas_lw->count();
3932 for (int r = 0; r < nbHexas; ++r){
3933 item = hexas_lw->item(r);
3934 ihexa = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3935 if ( ihexa.isValid() )
3939 iElts = getDocumentModel()->disconnectEdges( ihexas, iedges );
3942 if ( !iElts.isValid() ){
3943 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT DISCONNECT" ) + "\n" + getErrorMsg() );
3947 result = patternDataModel->mapFromSource(iElts);
3948 // result = patternBuilderModel->mapFromSource(iElts);
3954 // ------------------------- CutEdgeDialog ----------------------------------
3955 // ============================================================== Constructeur
3957 CutEdgeDialog::CutEdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3958 HexaBaseDialog(parent, editmode, f)
3961 _helpFileName = "gui_cut_hexa.html";
3962 connect( cutUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3963 connect( cut_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3964 _initWidget(editmode);
3969 // ============================================================== Destructeur
3970 CutEdgeDialog::~CutEdgeDialog()
3974 // ============================================================== _initInputWidget
3975 void CutEdgeDialog::_initInputWidget( Mode editmode )
3977 installEventFilter(this);
3979 e_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3980 e_le->installEventFilter(this);
3982 cutUni_rb->installEventFilter(this);
3983 cut_rb->installEventFilter(this);
3985 e_le->setReadOnly(true);
3987 height_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
3988 height_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
3989 height_lw->setProperty("Length", QVariant::fromValue(true));
3990 height_lw->installEventFilter(this);
3992 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3993 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3995 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3996 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3999 // ============================================================== updateHelpFileName
4000 void CutEdgeDialog::updateHelpFileName()
4002 if ( sender() == cutUni_rb ){
4003 _helpFileName = "gui_cut_hexa.html#guicuthexauniform";
4004 } else if ( sender() == cut_rb ){
4005 _helpFileName = "gui_cut_hexa.html#guicuthexacustom";
4009 // ============================================================== clear
4010 void CutEdgeDialog::clear()
4013 modelUnregister(e_le);
4015 modelUnregister(this);
4018 // ============================================================== addHeightItem
4019 void CutEdgeDialog::addHeightItem()
4021 QListWidgetItem* previousItem = height_lw->currentItem();
4022 QListWidgetItem* newItem = new QListWidgetItem();
4024 double defaultValue = 1.;
4026 defaultValue = previousItem->data(Qt::EditRole).toDouble();
4028 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
4029 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
4030 height_lw->addItem(newItem);
4033 // ============================================================== delHeightItem
4034 void CutEdgeDialog::delHeightItem()
4036 delete height_lw->currentItem();
4039 // ============================================================== apply
4040 bool CutEdgeDialog::apply(QModelIndex& result)
4042 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4045 DocumentModel* docModel = getDocumentModel();
4046 PatternDataModel* patternDataModel = getPatternDataModel();
4047 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4050 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le] );
4052 if (cutUni_rb->isChecked() && iedge.isValid())
4054 int nbCut = nb_cut_spb->value();
4055 iElts = docModel->cutUni(iedge, nbCut);
4057 else if (cut_rb->isChecked() && iedge.isValid())
4059 vector<double> heights;
4060 QListWidgetItem* item = NULL;
4061 int nbItems = height_lw->count();
4063 for ( int r = 0; r < nbItems; ++r){
4064 item = height_lw->item(r);
4065 heights.push_back( item->data(Qt::EditRole).toDouble() );
4068 iElts = docModel->cut(iedge, heights);
4071 if ( !iElts.isValid() ){
4072 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT CUT EDGE" ) + "\n" + getErrorMsg() );
4076 result = patternDataModel->mapFromSource(iElts);
4077 // result = patternBuilderModel->mapFromSource(iElts);
4079 //Update the line edit
4081 e_le->setProperty("QModelIndex", invalid );
4083 QModelIndex invalidIndex;
4084 _index[e_le] = invalidIndex;
4091 // // ------------------------- MakeTransformationDialog ----------------------------------
4092 // ============================================================== Constructeur
4094 MakeTransformationDialog::MakeTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4095 : HexaBaseDialog(parent, editmode, f)
4098 _initWidget(editmode);
4101 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
4102 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4103 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4104 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4107 // ============================================================== Destructeur
4108 MakeTransformationDialog::~MakeTransformationDialog()
4112 // ============================================================== _initInputWidget
4113 void MakeTransformationDialog::_initInputWidget( Mode editmode )
4116 QValidator *validator = new QRegExpValidator(rx, this);
4118 installEventFilter(this);
4119 rb0->installEventFilter(this);
4120 rb1->installEventFilter(this);
4121 rb2->installEventFilter(this);
4123 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4124 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4126 vec_le_rb0->setValidator( validator );
4127 elts_le_rb0->setValidator( validator );
4128 vec_le_rb0->installEventFilter(this);
4129 elts_le_rb0->installEventFilter(this);
4131 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4132 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4133 vex_le_rb1->setValidator( validator );
4134 elts_le_rb1->setValidator( validator );
4135 vex_le_rb1->installEventFilter(this);
4136 elts_le_rb1->installEventFilter(this);
4138 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4139 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4140 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4141 vex_le_rb2->setValidator( validator );
4142 vec_le_rb2->setValidator( validator );
4143 elts_le_rb2->setValidator( validator );
4144 vex_le_rb2->installEventFilter(this);
4145 vec_le_rb2->installEventFilter(this);
4146 elts_le_rb2->installEventFilter(this);
4148 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
4149 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
4150 angle_spb->setProperty("Angle", QVariant::fromValue(true));
4151 angle_spb->installEventFilter(this);
4153 vec_le_rb0->setReadOnly(true);
4154 elts_le_rb0->setReadOnly(true);
4156 vex_le_rb1->setReadOnly(true);
4157 elts_le_rb1->setReadOnly(true);
4159 vex_le_rb2->setReadOnly(true);
4160 vec_le_rb2->setReadOnly(true);
4161 elts_le_rb2->setReadOnly(true);
4165 // ============================================================== clear
4166 void MakeTransformationDialog::clear()
4168 elts_le_rb0->clear();
4169 modelUnregister(elts_le_rb0);
4171 vec_le_rb0->clear();
4172 modelUnregister(vec_le_rb0);
4174 elts_le_rb1->clear();
4175 modelUnregister(elts_le_rb1);
4177 vex_le_rb1->clear();
4178 modelUnregister(vex_le_rb1);
4180 elts_le_rb2->clear();
4181 modelUnregister(elts_le_rb2);
4183 vex_le_rb2->clear();
4184 modelUnregister(vex_le_rb2);
4186 vec_le_rb2->clear();
4187 modelUnregister(vec_le_rb2);
4189 modelUnregister(this);
4192 // ============================================================== updateHelpFileName
4193 void MakeTransformationDialog::updateHelpFileName()
4195 if ( sender() == rb0 ){
4196 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
4197 } else if ( sender() == rb1 ){
4198 _helpFileName = "gui_make_elmts.html#make-elements-by-scaling";
4199 } else if ( sender() == rb2 ){
4200 _helpFileName = "gui_make_elmts.html#make-elements-by-rotation";
4204 // ============================================================== apply
4205 bool MakeTransformationDialog::apply(QModelIndex& result)
4207 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4210 if (getDocumentModel() == NULL) return false;
4211 const PatternDataModel* patternDataModel = getPatternDataModel();
4212 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4213 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4215 QModelIndex iNewElts;
4217 if ( rb0->isChecked() ){
4218 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb0] );
4219 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb0] );
4220 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4221 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4223 if ( ielts.isValid()
4225 iNewElts = getDocumentModel()->makeTranslation( ielts, ivec );
4227 } else if ( rb1->isChecked() ){
4228 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4229 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb1] );
4230 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4231 double k = k_spb->value();
4233 if ( ielts.isValid()
4235 iNewElts = getDocumentModel()->makeScale( ielts, ivex, k );
4237 } else if ( rb2->isChecked() ){
4238 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4239 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb2] );
4240 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4241 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4242 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb2] );
4243 double angle = angle_spb->value();
4245 if ( ielts.isValid()
4248 iNewElts = getDocumentModel()->makeRotation( ielts, ivex, ivec, angle );
4251 if ( !iNewElts.isValid() ){
4252 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4256 result = patternDataModel->mapFromSource(iNewElts);
4257 if (result.isValid())
4259 MESSAGE("======> Result is valid!");
4260 HEXA_NS::Elements* elts = getDocumentModel()->getHexaPtr<HEXA_NS::Elements*>(result);
4261 MESSAGE("======> " << elts->getName());
4265 MESSAGE("======> Result is not valid!");
4267 // result = patternBuilderModel->mapFromSource(iNewElts);
4272 // // ------------------------- MakeSymmetryDialog ----------------------------------
4273 // ============================================================== Constructeur
4275 MakeSymmetryDialog::MakeSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4276 HexaBaseDialog(parent, editmode, f)
4279 _initWidget(editmode);
4282 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4283 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4284 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4285 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4288 // ============================================================== Destructeur
4289 MakeSymmetryDialog::~MakeSymmetryDialog()
4293 // ============================================================== _initInputWidget
4294 void MakeSymmetryDialog::_initInputWidget( Mode editmode )
4297 QValidator *validator = new QRegExpValidator(rx, this);
4299 installEventFilter(this);
4301 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4302 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4303 vex_le_rb0->setValidator( validator );
4304 elts_le_rb0->setValidator( validator );
4305 vex_le_rb0->installEventFilter(this);
4306 elts_le_rb0->installEventFilter(this);
4308 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4309 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4310 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4311 vex_le_rb1->setValidator( validator );
4312 vec_le_rb1->setValidator( validator );
4313 elts_le_rb1->setValidator( validator );
4314 vex_le_rb1->installEventFilter(this);
4315 vec_le_rb1->installEventFilter(this);
4316 elts_le_rb1->installEventFilter(this);
4318 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4319 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4320 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4321 vex_le_rb2->setValidator( validator );
4322 vec_le_rb2->setValidator( validator );
4323 elts_le_rb2->setValidator( validator );
4324 vex_le_rb2->installEventFilter(this);
4325 vec_le_rb2->installEventFilter(this);
4326 elts_le_rb2->installEventFilter(this);
4328 vex_le_rb0->setReadOnly(true);
4329 elts_le_rb0->setReadOnly(true);
4330 vex_le_rb1->setReadOnly(true);
4331 vec_le_rb1->setReadOnly(true);
4332 elts_le_rb1->setReadOnly(true);
4333 vex_le_rb2->setReadOnly(true);
4334 vec_le_rb2->setReadOnly(true);
4335 elts_le_rb2->setReadOnly(true);
4338 // ============================================================== clear
4339 void MakeSymmetryDialog::clear()
4341 elts_le_rb0->clear();
4342 modelUnregister(elts_le_rb0);
4344 vex_le_rb0->clear();
4345 modelUnregister(vex_le_rb0);
4347 elts_le_rb1->clear();
4348 modelUnregister(elts_le_rb1);
4350 vex_le_rb1->clear();
4351 modelUnregister(vex_le_rb1);
4353 vec_le_rb1->clear();
4354 modelUnregister(vec_le_rb1);
4356 elts_le_rb2->clear();
4357 modelUnregister(elts_le_rb2);
4359 vex_le_rb2->clear();
4360 modelUnregister(vex_le_rb2);
4362 vec_le_rb2->clear();
4363 modelUnregister(vec_le_rb2);
4365 modelUnregister(this);
4368 // ============================================================== updateHelpFileName
4369 void MakeSymmetryDialog::updateHelpFileName()
4371 if ( sender() == rb0 ){
4372 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4373 } else if ( sender() == rb1 ){
4374 _helpFileName = "gui_make_symmetry.html#make-elements-by-line-symmetry";
4375 } else if ( sender() == rb2 ){
4376 _helpFileName = "gui_make_symmetry.html#make-elements-by-plane-symmetry";
4380 // ============================================================== apply
4381 bool MakeSymmetryDialog::apply(QModelIndex& result)
4383 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4385 if (getDocumentModel() == NULL) return false;
4386 const PatternDataModel* patternDataModel = getPatternDataModel();
4387 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4388 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4390 QModelIndex iNewElts;
4392 if ( rb0->isChecked() ){
4393 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4394 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb0] );
4395 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4397 if ( ielts.isValid()
4399 iNewElts = getDocumentModel()->makeSymmetryPoint( ielts, ivex );
4402 } else if ( rb1->isChecked() ){
4403 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4404 QModelIndex ielts = patternDataModel->mapToSource( _index[elts_le_rb1] );
4405 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4406 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4407 QModelIndex ivec = patternDataModel->mapToSource( _index[vec_le_rb1] );
4409 if ( ielts.isValid()
4412 iNewElts = getDocumentModel()->makeSymmetryLine( ielts, ivex, ivec );
4414 } else if ( rb2->isChecked() ){
4415 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4416 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4417 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4418 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4419 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4421 if ( ielts.isValid()
4424 iNewElts = getDocumentModel()->makeSymmetryPlane( ielts, ivex, ivec );
4427 if ( !iNewElts.isValid() ){
4428 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4432 // result = patternBuilderModel->mapFromSource(iNewElts);
4433 result = patternDataModel->mapFromSource(iNewElts);
4438 // // ------------------------- PerformTransformationDialog ----------------------------------
4439 // ============================================================== Constructeur
4440 PerformTransformationDialog::PerformTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4441 HexaBaseDialog(parent, editmode, f)
4444 _initWidget(editmode);
4447 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4448 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4449 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4450 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4453 // ============================================================== Destructeur
4454 PerformTransformationDialog::~PerformTransformationDialog()
4458 // ============================================================== _initInputWidget
4459 void PerformTransformationDialog::_initInputWidget( Mode editmode )
4462 QValidator *validator = new QRegExpValidator(rx, this);
4464 installEventFilter(this);
4465 rb0->installEventFilter(this);
4466 rb1->installEventFilter(this);
4467 rb2->installEventFilter(this);
4469 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4470 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4471 vec_le_rb0->setValidator( validator );
4472 elts_le_rb0->setValidator( validator );
4473 vec_le_rb0->installEventFilter(this);
4474 elts_le_rb0->installEventFilter(this);
4476 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4477 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4478 vex_le_rb1->setValidator( validator );
4479 elts_le_rb1->setValidator( validator );
4480 vex_le_rb1->installEventFilter(this);
4481 elts_le_rb1->installEventFilter(this);
4484 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4485 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4486 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4487 vex_le_rb2->setValidator( validator );
4488 vec_le_rb2->setValidator( validator );
4489 elts_le_rb2->setValidator( validator );
4490 vex_le_rb2->installEventFilter(this);
4491 vec_le_rb2->installEventFilter(this);
4492 elts_le_rb2->installEventFilter(this);
4494 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
4495 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
4496 angle_spb->setProperty("Angle", QVariant::fromValue(true));
4497 angle_spb->installEventFilter(this);
4499 vec_le_rb0->setReadOnly(true);
4500 elts_le_rb0->setReadOnly(true);
4501 vex_le_rb1->setReadOnly(true);
4502 elts_le_rb1->setReadOnly(true);
4503 vex_le_rb2->setReadOnly(true);
4504 vec_le_rb2->setReadOnly(true);
4505 elts_le_rb2->setReadOnly(true);
4509 // ============================================================== clear
4510 void PerformTransformationDialog::clear()
4512 vec_le_rb0->clear();
4513 modelUnregister(vec_le_rb0);
4515 elts_le_rb0->clear();
4516 modelUnregister(elts_le_rb0);
4518 vex_le_rb1->clear();
4519 modelUnregister(vex_le_rb1);
4521 elts_le_rb1->clear();
4522 modelUnregister(elts_le_rb1);
4524 vex_le_rb2->clear();
4525 modelUnregister(vex_le_rb2);
4527 vec_le_rb2->clear();
4528 modelUnregister(vec_le_rb2);
4530 elts_le_rb2->clear();
4531 modelUnregister(elts_le_rb2);
4533 modelUnregister(this);
4536 // ============================================================== updateHelpFileName
4537 void PerformTransformationDialog::updateHelpFileName()
4539 if ( sender() == rb0 ){
4540 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4541 } else if ( sender() == rb1 ){
4542 _helpFileName = "gui_modify_elmts.html#modify-elements-by-scaling";
4543 } else if ( sender() == rb2 ){
4544 _helpFileName = "gui_modify_elmts.html#modify-elements-by-rotation";
4548 // ============================================================== apply
4549 bool PerformTransformationDialog::apply(QModelIndex& result)
4551 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4554 if (getDocumentModel() == NULL) return false;
4555 const PatternDataModel* patternDataModel = getPatternDataModel();
4556 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4557 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4559 bool performed = false;
4561 if ( rb0->isChecked() ){
4562 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4563 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb0]);
4564 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4565 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb0]);
4567 if ( ielts.isValid()
4569 performed = getDocumentModel()->performTranslation( ielts, ivec );
4571 } else if ( rb1->isChecked() ){
4572 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4573 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb1]);
4574 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4575 double k = k_spb->value();
4577 if ( ielts.isValid()
4579 performed = getDocumentModel()->performScale( ielts, ivex, k );
4581 } else if ( rb2->isChecked() ){
4582 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4583 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4584 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4585 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4586 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4587 double angle = angle_spb->value();
4589 if ( ielts.isValid()
4592 performed = getDocumentModel()->performRotation( ielts, ivex, ivec, angle );
4595 if ( performed == false){
4596 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM TRANSFORMATION" ) + "\n" + getErrorMsg() );
4603 // // ------------------------- PerformSymmetryDialog ----------------------------------
4604 // ============================================================== Constructeur
4605 PerformSymmetryDialog::PerformSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4606 : HexaBaseDialog(parent, editmode, f)
4609 _initWidget( editmode );
4612 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4613 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4614 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4615 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4618 // ============================================================== Destructeur
4619 PerformSymmetryDialog::~PerformSymmetryDialog()
4623 // ============================================================== _initInputWidget
4624 void PerformSymmetryDialog::_initInputWidget( Mode editmode )
4627 QValidator *validator = new QRegExpValidator(rx, this);
4629 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4630 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4631 vex_le_rb0->setValidator( validator );
4632 elts_le_rb0->setValidator( validator );
4633 vex_le_rb0->installEventFilter(this);
4634 elts_le_rb0->installEventFilter(this);
4636 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4637 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4638 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4639 vex_le_rb1->setValidator( validator );
4640 vec_le_rb1->setValidator( validator );
4641 elts_le_rb1->setValidator( validator );
4642 vex_le_rb1->installEventFilter(this);
4643 vec_le_rb1->installEventFilter(this);
4644 elts_le_rb1->installEventFilter(this);
4646 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4647 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4648 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4649 vex_le_rb2->setValidator( validator );
4650 vec_le_rb2->setValidator( validator );
4651 elts_le_rb2->setValidator( validator );
4652 vex_le_rb2->installEventFilter(this);
4653 vec_le_rb2->installEventFilter(this);
4654 elts_le_rb2->installEventFilter(this);
4656 vex_le_rb0->setReadOnly(true);
4657 elts_le_rb0->setReadOnly(true);
4658 vex_le_rb1->setReadOnly(true);
4659 vec_le_rb1->setReadOnly(true);
4660 elts_le_rb1->setReadOnly(true);
4661 vex_le_rb2->setReadOnly(true);
4662 vec_le_rb2->setReadOnly(true);
4663 elts_le_rb2->setReadOnly(true);
4667 // ============================================================== clear
4668 void PerformSymmetryDialog::clear()
4670 vex_le_rb0->clear();
4671 modelUnregister(vex_le_rb0);
4673 elts_le_rb0->clear();
4674 modelUnregister(elts_le_rb0);
4676 elts_le_rb1->clear();
4677 modelUnregister(elts_le_rb1);
4679 vex_le_rb1->clear();
4680 modelUnregister(vex_le_rb1);
4682 vec_le_rb1->clear();
4683 modelUnregister(vec_le_rb1);
4685 elts_le_rb2->clear();
4686 modelUnregister(elts_le_rb2);
4688 vex_le_rb2->clear();
4689 modelUnregister(vex_le_rb2);
4691 vec_le_rb2->clear();
4692 modelUnregister(vec_le_rb2);
4694 modelUnregister(this);
4697 // ============================================================== updateHelpFileName
4698 void PerformSymmetryDialog::updateHelpFileName()
4700 if ( sender() == rb0 ){
4701 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4702 } else if ( sender() == rb1 ){
4703 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-line-symmetry";
4704 } else if ( sender() == rb2 ){
4705 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-plane-symmetry";
4709 // ============================================================== apply
4710 bool PerformSymmetryDialog::apply(QModelIndex& result)
4712 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4715 if (getDocumentModel() == NULL) return false;
4716 const PatternDataModel* patternDataModel = getPatternDataModel();
4717 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4718 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
4720 bool performed = false;
4722 if ( rb0->isChecked() ){
4723 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4724 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb0]);
4725 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4727 if ( ielts.isValid()
4729 performed = getDocumentModel()->performSymmetryPoint( ielts, ivex );
4731 } else if ( rb1->isChecked() ){
4732 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4733 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb1]);
4734 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4735 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4736 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb1]);
4738 if ( ielts.isValid()
4741 performed = getDocumentModel()->performSymmetryLine( ielts, ivex, ivec );
4743 } else if ( rb2->isChecked() ){
4744 // QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4745 QModelIndex ielts = patternDataModel->mapToSource(_index[elts_le_rb2]);
4746 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4747 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4748 QModelIndex ivec = patternDataModel->mapToSource(_index[vec_le_rb2]);
4750 if ( ielts.isValid()
4753 performed = getDocumentModel()->performSymmetryPlane( ielts, ivex, ivec );
4756 if ( performed == false ){
4757 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM SYMMETRY" ) + "\n" + getErrorMsg() );
4764 // // ------------------------- EdgeAssocDialog ----------------------------------
4765 // ============================================================== Constructeur
4766 EdgeAssocDialog::EdgeAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4767 HexaBaseDialog( parent, editmode, f )
4769 _helpFileName ="gui_asso_quad_to_geom.html#one-edge";
4771 _initWidget(editmode);
4776 // ============================================================== Destructeur
4777 EdgeAssocDialog::~EdgeAssocDialog()
4781 // ============================================================== close
4782 void EdgeAssocDialog::close()
4784 HEXABLOCKGUI::assocInProgress = false;
4785 HexaBaseDialog::close();
4788 // ============================================================== _initInputWidget
4789 void EdgeAssocDialog::_initInputWidget( Mode editmode )
4792 QValidator *validator = new QRegExpValidator(rx, this);
4795 first_vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4796 first_vex_le->installEventFilter(this);
4797 first_vex_le->setValidator( validator );
4799 single_edge_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4800 single_edge_le->installEventFilter(this);
4802 edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4803 edges_lw->installEventFilter(this);
4807 lines_lw->setProperty("HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4808 lines_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4809 lines_lw->installEventFilter(this);
4811 single_line_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4812 single_line_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4813 single_line_le->installEventFilter(this);
4816 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), edges_lw);
4817 QShortcut* delLineShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), lines_lw);
4818 delLineShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4819 delEdgeShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4821 pend_spb->setValue(1.);
4823 first_vex_le->setReadOnly(true);
4824 single_edge_le->setReadOnly(true);
4825 single_line_le->setReadOnly(true);
4827 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
4828 connect( delLineShortcut, SIGNAL(activated()), this, SLOT(deleteLineItem()) );
4829 connect( edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
4830 connect( lines_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4831 connect( single_rb, SIGNAL(clicked()), this, SLOT( refreshHighlight()), Qt::UniqueConnection );
4832 connect( multiple_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection );
4833 connect( single_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4834 connect( multiple_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4837 // ============================================================== updateHelpFileName
4838 void EdgeAssocDialog::updateHelpFileName()
4840 if ( sender() == single_rb ){
4841 _helpFileName = "gui_asso_quad_to_geom.html#one-edge";
4842 } else if ( sender() == multiple_rb ){
4843 _helpFileName = "gui_asso_quad_to_geom.html#line";
4847 // ============================================================== getAssocsVTK
4849 * Returns elements currently being associated in vtk side
4851 QModelIndexList EdgeAssocDialog::getAssocsVTK()
4853 QModelIndexList assocs;
4855 QListWidgetItem* item = NULL;
4857 if (getPatternDataSelectionModel() == NULL) return assocs;
4858 if (single_rb->isChecked())
4861 QVariant v = single_edge_le->property("QModelIndex");
4862 if ( !v.isValid() ) return assocs;
4863 assocs << v.value<QModelIndex>();
4866 else if (multiple_rb->isChecked())
4868 //ListWidget content
4869 const PatternDataModel* patternDataModel = getPatternDataModel();
4870 if ( !patternDataModel ) return assocs;
4871 int nbEdges = edges_lw->count();
4872 for ( int r = 0; r < nbEdges; ++r){
4873 item = edges_lw->item(r);
4874 iEdge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4875 if ( iEdge.isValid() ) assocs << iEdge;
4882 // ============================================================== getAssocsGEOM
4884 * Returns elements currently being associated in geom side
4886 QMultiMap<QString, int> EdgeAssocDialog::getAssocsGEOM()
4888 QMultiMap<QString, int> assocs;
4889 QListWidgetItem* item = NULL;
4890 DocumentModel::GeomObj geomObj;
4892 if (single_rb->isChecked())
4895 QVariant v = single_line_le->property("GeomObj");
4896 if ( !v.isValid() ) return assocs;
4897 geomObj = v.value<DocumentModel::GeomObj>();
4898 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4901 else if (multiple_rb->isChecked())
4903 //ListWidget content
4904 unsigned int nbEdges = lines_lw->count();
4905 for ( int r = 0; r < nbEdges; ++r){
4906 item = lines_lw->item(r);
4907 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4908 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4915 // ============================================================== selectElementOfGeom
4916 /*Highlight in the OCC view selected elements in a listwidget,
4917 * or an element in a line edit.*/
4918 void EdgeAssocDialog::selectElementOfGeom()
4920 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4921 if ( !currentListWidget )
4925 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4926 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4927 pgsm->clearSelection();
4928 if (sel.count() == 0)
4931 QListWidgetItem *item = sel[0];
4932 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
4933 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4934 if ( index.isValid() )
4935 pgsm->select( index, QItemSelectionModel::SelectCurrent );
4938 // ============================================================== clear
4939 void EdgeAssocDialog::clear()
4941 first_vex_le->clear();
4942 modelUnregister(first_vex_le);
4945 modelUnregister(edges_lw);
4949 single_edge_le->clear();
4950 modelUnregister(single_edge_le);
4952 single_line_le->clear();
4953 modelUnregister(single_line_le);
4955 modelUnregister(this);
4958 // ============================================================== onWindowActivated
4959 void EdgeAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4961 QString vmType = vm->getType();
4962 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4964 if (single_rb->isChecked())
4965 single_edge_le->setFocus();
4966 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le )
4967 edges_lw->setFocus();
4969 else if ( vmType == OCCViewer_Viewer::Type() ){
4970 if (single_rb->isChecked())
4971 single_line_le->setFocus();
4972 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le)
4973 lines_lw->setFocus();
4977 // ============================================================== apply
4978 bool EdgeAssocDialog::apply(QModelIndex& result)
4980 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4983 bool assocOk = false;
4985 PatternDataModel* patternDataModel = getPatternDataModel();
4986 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4987 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4989 QModelIndex iEdge, iGeomEdge;
4990 QModelIndexList iEdges;
4991 QListWidgetItem* item = NULL;
4992 QList<DocumentModel::GeomObj> assocs;
4993 DocumentModel::GeomObj aLine;
4994 HEXA_NS::SubShape* ssh;
4995 HEXA_NS::EdgeShape* sh;
4996 HEXA_NS::NewShapes shapes;
4997 HEXA_NS::IntVector subIds;
4999 QModelIndexList edges, lines;
5001 if (single_rb->isChecked()){ //Single edge and/or line association
5003 iEdge = patternDataModel->mapToSource( _index[single_edge_le] );
5004 if ( !iEdge.isValid() || myLine == NULL)
5006 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5009 id = myLine->shapeName+","+myLine->subId;
5010 ssh = getDocumentModel()->getGeomPtr(id);
5011 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
5012 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5013 if (!iGeomEdge.isValid())
5015 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5018 assocOk = getDocumentModel()->addEdgeAssociation(iEdge, iGeomEdge, pstart_spb->value(), pend_spb->value());
5019 edges << _index[single_edge_le];
5022 else { //Multiple edge and/or line association
5025 iEdges = getIndexList(edges_lw, true);
5026 int nbLines = lines_lw->count();
5027 if (iEdges.count() == 0 || nbLines == 0)
5029 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5032 edges = getIndexList(edges_lw, false);
5034 for (int r = 0; r < nbLines; ++r){
5035 item = lines_lw->item(r);
5036 aLine = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5037 id = aLine.shapeName+","+aLine.subId;
5038 ssh = getDocumentModel()->getGeomPtr(id);
5039 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
5042 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5045 shapes.push_back(sh->getParentShape());
5046 subIds.push_back(sh->getIdent());
5047 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5048 if (iGeomEdge.isValid())
5052 if ( close_cb->isChecked() ){ //closed line
5053 QModelIndex iFirstVertex = patternDataModel->mapToSource( _index[first_vex_le] );
5054 if ( !iFirstVertex.isValid() )
5056 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
5059 bool inv = inverse_cb->isChecked();
5060 assocOk = getDocumentModel()->associateClosedLine( iFirstVertex, iEdges, shapes, subIds, pstart_spb->value(), inv );
5064 assocOk = getDocumentModel()->associateOpenedLine( iEdges, shapes, subIds, pstart_spb->value(), pend_spb->value() );
5068 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) + "\n" + getErrorMsg() );
5072 // highlight associated items in the trees
5073 pdsm->unhighlightTreeItems();
5074 pgsm->unhighlightTreeItems();
5075 pdsm->highlightTreeItems(edges);
5076 pgsm->highlightTreeItems(lines);
5078 // highlight associated items in the views
5079 highlightSelectedAssocs();
5084 // ------------------------- QuadAssocDialog ----------------------------------
5085 // ============================================================== Constructeur
5086 QuadAssocDialog::QuadAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5087 HexaBaseDialog(parent, editmode, f)
5089 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-face-or-a-shell-of-the-geometry";
5091 _initWidget(editmode);
5094 // ============================================================== Destructeur
5095 QuadAssocDialog::~QuadAssocDialog()
5097 disconnect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
5098 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(addFace()) );
5099 delete _delFaceShortcut;
5102 // ============================================================== close
5103 void QuadAssocDialog::close()
5105 HEXABLOCKGUI::assocInProgress = false;
5106 HexaBaseDialog::close();
5109 // ============================================================== _initInputWidget
5110 void QuadAssocDialog::_initInputWidget( Mode editmode )
5113 QValidator *validator = new QRegExpValidator(rx, this);
5115 quad_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5116 quad_le->installEventFilter(this);
5117 quad_le->setValidator( validator );
5119 faces_lw->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
5120 faces_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
5121 faces_lw->installEventFilter(this);
5122 _delFaceShortcut = new QShortcut( QKeySequence(Qt::Key_X/*Qt::Key_Delete*/), faces_lw );
5123 _delFaceShortcut->setContext( Qt::WidgetShortcut );
5125 quad_le->setReadOnly(true);
5127 connect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
5128 connect( faces_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
5131 // ============================================================== getAssocsVTK
5133 * Returns elements currently being associated in vtk side
5135 QModelIndexList QuadAssocDialog::getAssocsVTK()
5137 QModelIndexList assocs;
5141 QVariant v = quad_le->property("QModelIndex");
5144 assocs << v.value<QModelIndex>();
5148 // ============================================================== getAssocsGEOM
5150 * Returns elements currently being associated in geom side
5152 QMultiMap<QString, int> QuadAssocDialog::getAssocsGEOM()
5154 QMultiMap<QString, int> assocs;
5155 QListWidgetItem* item = NULL;
5156 DocumentModel::GeomObj geomObj;
5158 //ListWidget content
5159 unsigned int nbFaces = faces_lw->count();
5160 for ( int r = 0; r < nbFaces; ++r){
5161 item = faces_lw->item(r);
5162 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5163 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
5168 // ============================================================== selectElementOfGeom
5169 /*Highlight in the OCC view selected elements in a listwidget,
5170 * or an element in a line edit.*/
5172 void QuadAssocDialog::selectElementOfGeom()
5174 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5175 if ( !currentListWidget )
5179 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5180 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
5181 pgsm->clearSelection();
5182 if (sel.count() == 0)
5184 QListWidgetItem *item = sel[0];
5185 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
5186 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5187 if ( index.isValid() )
5188 pgsm->select( index, QItemSelectionModel::SelectCurrent );
5191 void QuadAssocDialog::clear()
5194 modelUnregister(quad_le);
5198 modelUnregister(this);
5201 // ============================================================== onWindowActivated
5202 void QuadAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
5204 QString vmType = vm->getType();
5205 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
5206 quad_le->setFocus();
5207 else if ( vmType == OCCViewer_Viewer::Type() ){
5208 faces_lw->setFocus();
5212 // ============================================================== deleteFaceItem
5213 void QuadAssocDialog::deleteFaceItem()
5215 delete faces_lw->currentItem();
5218 // ============================================================== apply
5219 bool QuadAssocDialog::apply(QModelIndex& result)
5221 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5224 PatternDataModel* patternDataModel = getPatternDataModel();
5225 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
5226 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
5229 QModelIndex iQuad, iGeomFace;
5230 HEXA_NS::SubShape* ssh;
5231 HEXA_NS::FaceShape* sh;
5235 iQuad = patternDataModel->mapToSource( _index[quad_le] );
5238 QListWidgetItem* item = NULL;
5239 DocumentModel::GeomObj aFace;
5240 QModelIndexList quads, faces;
5241 int nbFaces = faces_lw->count();
5242 for ( int r = 0; r < nbFaces; ++r ){
5243 item = faces_lw->item(r);
5244 aFace = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
5245 id = aFace.shapeName+","+aFace.subId;
5246 ssh = getDocumentModel()->getGeomPtr(id);
5247 sh = dynamic_cast<HEXA_NS::FaceShape*>(ssh);
5250 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) );
5253 iGeomFace = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
5254 if (!getDocumentModel()->addQuadAssociation(iQuad, iGeomFace))
5256 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) + "\n" + getErrorMsg() );
5259 else if (iGeomFace.isValid())
5264 if (iQuad.isValid())
5265 quads << _index[quad_le];
5267 // highlight associated items in the trees
5268 pdsm->highlightTreeItems(quads);
5269 pgsm->highlightTreeItems(faces);
5271 // highlight associated items in the views
5272 highlightSelectedAssocs();
5277 // ------------------------- GroupDialog ----------------------------------
5278 // ============================================================== Constructeur
5279 GroupDialog::GroupDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5280 HexaBaseDialog(parent, editmode, f),
5283 _helpFileName = "gui_groups.html#add-group";
5285 _initWidget(editmode);
5286 // setFocusProxy( name_le/*eltBase_lw */);
5288 if ( editmode == NEW_MODE ){
5289 setWindowTitle( tr("Group Construction") );
5290 } else if ( editmode == UPDATE_MODE ){
5291 setWindowTitle( tr("Group Modification") );
5292 } else if ( editmode == INFO_MODE ){
5293 setWindowTitle( tr("Group Information") );
5297 // ============================================================== Destructeur
5298 GroupDialog::~GroupDialog()
5302 // ============================================================== getAssocsVTK
5304 * Returns elements currently being associated in vtk side
5306 QModelIndexList GroupDialog::getAssocsVTK()
5308 QModelIndexList assocs;
5310 QListWidgetItem* item = NULL;
5311 if (getPatternDataSelectionModel() == NULL) return assocs;
5312 //ListWidget content
5313 const PatternDataModel* patternDataModel = getPatternDataModel();
5314 if ( !patternDataModel ) return assocs;
5315 int nbElts = eltBase_lw->count();
5316 for ( int r = 0; r < nbElts; ++r){
5317 item = eltBase_lw->item(r);
5318 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5319 if ( iItem.isValid() ) assocs << iItem;
5324 // ============================================================== _initInputWidget
5325 void GroupDialog::_initInputWidget( Mode editmode )
5327 installEventFilter(this);
5328 name_le->installEventFilter(this);
5331 strKind[ HEXA_NS::HexaCell ] = "HexaCell";
5332 strKind[ HEXA_NS::QuadCell ] = "QuadCell";
5333 strKind[ HEXA_NS::EdgeCell ] = "EdgeCell";
5334 strKind[ HEXA_NS::HexaNode ] = "HexaNode";
5335 strKind[ HEXA_NS::QuadNode ] = "QuadNode";
5336 strKind[ HEXA_NS::EdgeNode ] = "EdgeNode";
5337 strKind[ HEXA_NS::VertexNode ] = "VertexNode";
5339 QMap<HEXA_NS::EnumGroup, QString>::ConstIterator iKind;
5340 for( iKind = strKind.constBegin(); iKind != strKind.constEnd(); ++iKind )
5341 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5343 onKindChanged( kind_cb->currentIndex() );
5344 eltBase_lw->installEventFilter(this);
5346 if ( editmode != INFO_MODE ){
5347 QShortcut* delEltShortcut = new QShortcut( QKeySequence(Qt::Key_X), eltBase_lw );
5348 delEltShortcut->setContext( Qt::WidgetShortcut );
5349 connect(delEltShortcut, SIGNAL(activated()), this, SLOT(removeEltBase()));
5350 connect(kind_cb, SIGNAL(activated(int)), this, SLOT(onKindChanged(int)) );
5353 if ( editmode == INFO_MODE)
5355 name_le->setReadOnly(true);
5356 kind_cb->setEnabled(false);
5357 eltBase_lw->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
5360 connect(eltBase_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5363 // ============================================================== clear
5364 void GroupDialog::clear()
5368 eltBase_lw->clear();
5369 modelUnregister(eltBase_lw);
5371 modelUnregister(this);
5374 // ============================================================== onKindChanged
5375 void GroupDialog::onKindChanged(int index)
5378 switch ( kind_cb->itemData(index).toInt() ){
5379 case HEXA_NS::HexaCell:
5380 case HEXA_NS::HexaNode:
5381 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(HEXA_TREE));
5384 case HEXA_NS::QuadCell:
5385 case HEXA_NS::QuadNode:
5386 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5389 case HEXA_NS::EdgeCell:
5390 case HEXA_NS::EdgeNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
5393 case HEXA_NS::VertexNode:
5394 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
5397 default:Q_ASSERT(false);
5399 eltBase_lw->clear();
5400 eltBase_lw->setFocus();
5403 // ============================================================== setValue
5404 void GroupDialog::setValue(HEXA_NS::Group* g)
5407 name_le->setText( g->getName() );
5411 kind_cb->addItem ( strKind[g->getKind()], QVariant( g->getKind() ) );
5414 HEXA_NS::EltBase* eltBase = NULL;
5415 QListWidgetItem* item = NULL;
5416 QModelIndex iEltBase;
5417 QList<QStandardItem *> eltBaseItems;
5420 if ( !getPatternDataSelectionModel() ) return;
5421 if ( !getGroupsSelectionModel() ) return;
5423 QModelIndex iGroup = getGroupsSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(g) );
5424 name_le->setProperty( "QModelIndex", QVariant::fromValue(iGroup) );
5427 int nbElts = g->countElement();
5428 for ( int nr = 0; nr < nbElts; ++nr ){
5429 eltBase = g->getElement( nr );
5430 switch ( g->getKind() ){
5431 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: v = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
5432 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: v = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
5433 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: v = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
5434 case HEXA_NS::VertexNode: v = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
5436 iEltBase = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, v);
5437 if ( iEltBase.isValid() ){
5438 item = new QListWidgetItem( eltBase->getName() );
5439 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iEltBase) );
5440 item->setData(LW_DATA_ROLE, iEltBase.data(HEXA_DATA_ROLE));
5441 eltBase_lw->addItem( item );
5447 // ============================================================== getValue
5448 HEXA_NS::Group* GroupDialog::getValue()
5453 // ============================================================== removeEltBase
5454 void GroupDialog::removeEltBase()
5456 QListWidgetItem *item = eltBase_lw->currentItem();
5459 int r = eltBase_lw->row(item);
5460 eltBase_lw->takeItem(r);
5466 // ============================================================== apply
5467 bool GroupDialog::apply(QModelIndex& result)
5469 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5472 if ( !getDocumentModel() ) return false;
5473 const PatternDataModel* patternDataModel = getPatternDataModel();
5474 const GroupsModel* groupsModel = getGroupsModel();
5475 if (patternDataModel == NULL || groupsModel == NULL) return false;
5477 QString grpName = name_le->text();
5478 DocumentModel::Group grpKind = static_cast<DocumentModel::Group>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5480 if ( _value == NULL ){ // create group
5481 iGrp = getDocumentModel()->addGroup( grpName, grpKind );
5483 QModelIndexList iGrps = getDocumentModel()->match(
5484 getDocumentModel()->index(0, 0),
5486 QVariant::fromValue( _value ),
5488 Qt::MatchRecursive );
5489 if ( !iGrps.isEmpty() )
5494 if ( !iGrp.isValid() ){
5495 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD GROUP" ) + "\n" + getErrorMsg() );
5499 //fill it and select it
5500 QModelIndex iEltBase;
5501 QListWidgetItem* item = NULL;
5502 bool eltAdded = false;
5503 getDocumentModel()->clearGroupElement(iGrp);
5504 int nbElts = eltBase_lw->count();
5505 for ( int r = 0; r < nbElts; ++r){
5506 item = eltBase_lw->item(r);
5507 iEltBase = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5508 if ( iEltBase.isValid() )
5509 eltAdded = getDocumentModel()->addGroupElement( iGrp, iEltBase );
5512 QString newName = name_le->text();
5513 if ( !newName.isEmpty() )
5514 getDocumentModel()->setName( iGrp, newName );
5516 HEXA_NS::Group* hGroup = getDocumentModel()->data(iGrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
5519 QString groupName = QString::fromStdString(hGroup->getNextName());
5520 name_le->setText(groupName);
5523 result = groupsModel->mapFromSource(iGrp);
5528 // ------------------------- LawDialog ----------------------------------
5529 // ============================================================== Constructeur
5531 LawDialog::LawDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5532 : HexaBaseDialog(parent, editmode, f),
5535 _helpFileName = "gui_discret_law.html#add-law";
5537 _initWidget(editmode);
5538 if ( editmode == NEW_MODE ){
5539 setWindowTitle( tr("Law Construction") );
5540 } else if ( editmode == UPDATE_MODE ){
5541 setWindowTitle( tr("Law Modification") );
5543 else if ( editmode == INFO_MODE){
5544 setWindowTitle( tr("Law Information") );
5548 // ============================================================== Destructeur
5549 LawDialog::~LawDialog()
5553 // ============================================================== _initInputWidget
5554 void LawDialog::_initInputWidget( Mode editmode )
5558 // setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5559 installEventFilter(this);
5561 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5562 name_le->installEventFilter(this);
5565 strKind[ HEXA_NS::Uniform ] = "Uniform";
5566 strKind[ HEXA_NS::Arithmetic ] = "Arithmetic";
5567 strKind[ HEXA_NS::Geometric ] = "Geometric";
5570 QMap<HEXA_NS::KindLaw, QString>::ConstIterator iKind, iEnd;
5571 for( iKind = strKind.constBegin(), iEnd = strKind.constEnd(); iKind != iEnd; ++iKind )
5572 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5574 if (editmode == INFO_MODE)
5576 name_le->setReadOnly(true);
5577 nb_nodes_spb->setReadOnly(true);
5578 coeff_spb->setReadOnly(true);
5579 kind_cb->setEnabled(false);
5583 // ============================================================== clear
5584 void LawDialog::clear()
5588 modelUnregister(this);
5591 // ============================================================== setValue
5592 void LawDialog::setValue(HEXA_NS::Law* l)
5595 name_le->setText( l->getName() );
5597 nb_nodes_spb->setValue( l->getNodes() );
5598 coeff_spb->setValue( l->getCoefficient() );
5600 HEXA_NS::KindLaw k = l->getKind();
5601 kind_cb->setCurrentIndex( kind_cb->findData(k) );
5606 // ============================================================== getValue
5607 HEXA_NS::Law* LawDialog::getValue()
5612 // ============================================================== apply
5613 bool LawDialog::apply(QModelIndex& result)
5615 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5618 if ( !getDocumentModel() ) return false;
5620 const MeshModel* meshModel = getMeshModel();
5621 if (meshModel == NULL) return false;
5623 QString lawName = name_le->text();
5624 int nbnodes = nb_nodes_spb->value();
5625 double coeff = coeff_spb->value();
5626 DocumentModel::KindLaw lawKind = static_cast<DocumentModel::KindLaw>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5629 if ( _value == NULL ){ // create Law
5630 iLaw = getDocumentModel()->addLaw( lawName, nbnodes );
5632 QModelIndexList iLaws = getDocumentModel()->match(
5633 getDocumentModel()->index(0, 0),
5635 QVariant::fromValue( _value ),
5637 Qt::MatchRecursive );
5638 if ( !iLaws.isEmpty() )
5642 if ( !iLaw.isValid() ){
5643 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5646 //fill it and select it
5647 bool setOk = getDocumentModel()->setLaw( iLaw, nbnodes, coeff, lawKind );
5649 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5653 QString newName = name_le->text();
5654 if ( !newName.isEmpty() )/*{*/
5655 getDocumentModel()->setName( iLaw, newName );
5657 HEXA_NS::Law* hLaw = getDocumentModel()->data(iLaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
5661 name_le->setText(hLaw->getNextName(buffer));
5665 result = meshModel->mapFromSource(iLaw);
5670 // ------------------------- PropagationDialog ----------------------------------
5671 // ============================================================== Constructeur
5672 PropagationDialog::PropagationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5673 : HexaBaseDialog(parent, editmode, f),
5676 _helpFileName = "gui_propag.html";
5678 _initWidget(editmode);
5680 if ( editmode == INFO_MODE ){
5681 setWindowTitle( tr("Propagation Information") );
5684 } else if ( editmode == UPDATE_MODE ){
5685 setWindowTitle( tr("Propagation Modification") );
5688 } else if ( editmode == NEW_MODE ){
5689 setWindowTitle( tr("Propagation(s) Setting") );
5693 // ============================================================== Destructeur
5694 PropagationDialog::~PropagationDialog()
5698 // ============================================================== _initInputWidget
5699 void PropagationDialog::_initInputWidget( Mode editmode )
5702 QValidator *validator = new QRegExpValidator(rx, this);
5704 installEventFilter(this);
5707 law_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5708 law_le->installEventFilter(this);
5709 law_le->setValidator( validator );
5711 propagations_lw->setProperty( "HexaWidgetType", QVariant::fromValue(PROPAGATION_TREE) );
5712 propagations_lw->installEventFilter(this);
5714 QShortcut* delPropagationShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), propagations_lw);
5715 delPropagationShortcut->setContext( Qt::WidgetShortcut );
5717 law_le->setReadOnly(true);
5719 if ( editmode == INFO_MODE)
5720 way_cb->setEnabled(false);
5722 connect( delPropagationShortcut, SIGNAL(activated()), this, SLOT(deletePropagationItem()) );
5723 connect( propagations_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
5726 // ============================================================== clear
5727 void PropagationDialog::clear()
5729 propagations_lw->clear();
5730 modelUnregister(propagations_lw);
5733 modelUnregister(law_le);
5735 modelUnregister(this);
5738 // ============================================================== deletePropagationItem
5739 void PropagationDialog::deletePropagationItem()
5741 delete propagations_lw->currentItem();
5744 // ============================================================== setValue
5745 void PropagationDialog::setValue(HEXA_NS::Propagation* p)
5747 if (getMeshSelectionModel() == NULL) return;
5748 HEXA_NS::Law* l = p->getLaw();
5749 bool way = p->getWay();
5752 QModelIndex ip = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
5753 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(ip) );
5755 // law on propagation
5757 law_le->setText( l->getName() );
5758 QModelIndex il = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(l) );
5759 law_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(il) );
5762 // way of propagation
5763 way_cb->setChecked(way);
5768 // ============================================================== selectElementOfModel
5770 /*Selects in the model (treeview) elements selected in a listwidget,
5771 * or an element in a line edit.*/
5773 void PropagationDialog::selectElementOfModel()
5775 if (!getMeshSelectionModel()) return;
5777 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5778 if ( !currentListWidget ) return;
5780 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5782 getMeshSelectionModel()->clearSelection();
5783 foreach ( QListWidgetItem *item, sel ){
5784 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
5785 index = getMeshSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5786 if ( index.isValid() )
5787 getMeshSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
5791 // ============================================================== getValue
5792 HEXA_NS::Propagation* PropagationDialog::getValue()
5797 // ============================================================== apply
5798 bool PropagationDialog::apply(QModelIndex& result)
5800 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5804 if ( !getDocumentModel() ) return false;
5805 const MeshModel* meshModel = getMeshModel();
5806 if (meshModel == NULL) return false;
5808 bool way = way_cb->isChecked();
5809 QListWidgetItem* item = NULL;
5811 QModelIndex iPropagation;
5812 QModelIndex iLaw = meshModel->mapToSource( law_le->property("QModelIndex").value<QModelIndex>() );
5813 if (!iLaw.isValid() ){
5814 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5818 int nbPropagations = propagations_lw->count();
5819 for (int r = 0; r < nbPropagations; ++r){
5820 item = propagations_lw->item(r);
5821 iPropagation = meshModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5822 if ( !iPropagation.isValid() ){
5823 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5827 //fill it and select it
5828 isOk = getDocumentModel()->setPropagation( iPropagation, iLaw, way );
5830 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) + "\n" + getErrorMsg() );
5834 result = meshModel->mapFromSource(iPropagation);
5840 // ------------------------- ComputeMeshDialog ----------------------------------
5841 // ============================================================== Constructeur
5842 ComputeMeshDialog::ComputeMeshDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5843 HexaBaseDialog(parent, editmode, f)
5845 _helpFileName = "gui_mesh.html";
5846 setWindowTitle( tr("Compute mesh") );
5848 _initWidget(editmode);
5851 // ============================================================== Destructeur
5852 ComputeMeshDialog::~ComputeMeshDialog()
5856 // ============================================================== _initInputWidget
5857 void ComputeMeshDialog::_initInputWidget( Mode editmode )
5861 // ============================================================== setDocumentModel
5862 void ComputeMeshDialog::setDocumentModel(DocumentModel* m)
5864 if (m == NULL) return;
5865 _name->setText(m->getName());
5868 // ============================================================== clear
5869 void ComputeMeshDialog::clear()
5871 modelUnregister(this);
5874 // ============================================================== apply
5875 bool ComputeMeshDialog::apply(QModelIndex& result)
5877 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5880 if (getDocumentModel() == NULL) return false;
5881 #ifndef DISABLE_PYCONSOLE
5882 QString command = QString("import hexablock ; %1 = hexablock.mesh(\"%2\", \"%1\", %3, \"%4\")")
5883 .arg( _name->text() )
5884 .arg( getDocumentModel()->getName() )
5885 .arg( _dim->value() )
5886 .arg( _fact->text() );
5888 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
5889 PyConsole_Console* pyConsole = app->pythonConsole();
5892 pyConsole->exec( command );
5902 // ------------------------- ReplaceHexaDialog ----------------------------------
5903 // ============================================================== Constructeur
5904 ReplaceHexaDialog::ReplaceHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5905 HexaBaseDialog(parent, editmode, f)
5907 _helpFileName = "gui_replace_hexa.html";
5909 _initWidget(editmode);
5912 // ============================================================== Destructeur
5913 ReplaceHexaDialog::~ReplaceHexaDialog()
5917 // ============================================================== getAssocsVTK
5919 * Returns elements currently associated to vtk
5921 QModelIndexList ReplaceHexaDialog::getAssocsVTK()
5923 QModelIndexList assocs;
5925 QListWidgetItem* item = NULL;
5927 //ListWidget content
5928 int nbQuads = quads_lw->count();
5929 for ( int r = 0; r < nbQuads; ++r ){
5930 item = quads_lw->item(r);
5931 //iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
5932 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5933 if ( iQuad.isValid() )
5937 nbQuads = quads_lw_2->count();
5938 for( int i = 0; i < nbQuads; ++i)
5940 item = quads_lw_2->item(i);
5941 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5942 if (iQuad.isValid())
5949 // ============================================================== _initInputWidget
5950 void ReplaceHexaDialog::_initInputWidget( Mode editmode )
5954 installEventFilter(this);
5956 c1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5957 c2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5959 p1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5960 p2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5962 c1_le->installEventFilter(this);
5963 c2_le->installEventFilter(this);
5965 p1_le->installEventFilter(this);
5966 p2_le->installEventFilter(this);
5968 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5969 quads_lw->installEventFilter(this);
5971 quads_lw_2->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5972 quads_lw_2->installEventFilter(this);
5974 if ( editmode == NEW_MODE ){
5975 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5976 QShortcut* delQuadShortcut2 = new QShortcut( QKeySequence(Qt::Key_X), quads_lw_2 );
5977 delQuadShortcut->setContext( Qt::WidgetShortcut );
5978 delQuadShortcut2->setContext( Qt::WidgetShortcut );
5979 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()) );
5980 connect( quads_lw, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5981 connect( delQuadShortcut2, SIGNAL(activated()), this, SLOT(deleteQuadItem2()));
5982 connect( quads_lw_2, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5985 c1_le->setReadOnly(true);
5986 c2_le->setReadOnly(true);
5988 p1_le->setReadOnly(true);
5989 p2_le->setReadOnly(true);
5991 connect(quads_lw, SIGNAL(itemSelectionChanged()),
5992 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5994 connect(quads_lw_2, SIGNAL(itemSelectionChanged()),
5995 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5998 // ============================================================== clear
5999 void ReplaceHexaDialog::clear()
6002 modelUnregister(quads_lw);
6004 quads_lw_2->clear();
6005 modelUnregister(quads_lw_2);
6008 modelUnregister(p1_le);
6011 modelUnregister(p2_le);
6014 modelUnregister(c1_le);
6017 modelUnregister(c2_le);
6019 modelUnregister(this);
6022 // ============================================================== updateButtonBox
6023 void ReplaceHexaDialog::updateButtonBox()
6025 int nbQuad = quads_lw->count();
6028 _applyButton->setEnabled(true);
6030 _applyButton->setEnabled(false);
6034 // ============================================================== deleteQuadItem
6035 void ReplaceHexaDialog::deleteQuadItem()
6037 delete quads_lw->currentItem();
6041 // ============================================================== deleteQuadItem2
6042 void ReplaceHexaDialog::deleteQuadItem2()
6044 delete quads_lw_2->currentItem();
6048 // ============================================================== apply
6049 bool ReplaceHexaDialog::apply(QModelIndex& result)
6051 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6054 if ( !getDocumentModel() ) return false;
6055 const PatternDataModel* patternDataModel = getPatternDataModel();
6056 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6057 if ( !patternDataModel /*|| !patternBuilderModel*/) return false;
6059 QModelIndex ielts; //result
6061 QListWidgetItem* item = NULL;
6062 QModelIndexList iquads_source;
6064 int nbQuads = quads_lw->count();
6065 for ( int r = 0; r < nbQuads; ++r){
6066 item = quads_lw->item(r);
6067 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6068 if ( iquad.isValid() )
6069 iquads_source << iquad;
6072 QModelIndexList iquads_dest;
6073 nbQuads = quads_lw_2->count();
6074 for (int i = 0; i < nbQuads; ++i)
6076 item = quads_lw_2->item(i);
6077 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6078 if (iquad.isValid())
6079 iquads_dest << iquad;
6082 QModelIndex ip1_source = patternDataModel->mapToSource( _index[p1_le] );
6083 QModelIndex ip2_source = patternDataModel->mapToSource( _index[p2_le] );
6085 QModelIndex ic1_dest = patternDataModel->mapToSource( _index[c1_le] );
6086 QModelIndex ic2_dest = patternDataModel->mapToSource( _index[c2_le] );
6088 bool ipts_ok = ip1_source.isValid() && ip2_source.isValid() &&
6089 ic1_dest.isValid() && ic2_dest.isValid();
6093 ielts = getDocumentModel()->replace( iquads_source, iquads_dest,
6094 ip1_source, ic1_dest,
6095 ip2_source, ic2_dest );
6098 if ( !ielts.isValid() ){
6099 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REPLACE HEXA" ) + "\n" + getErrorMsg() );
6102 _value = ielts.model()->data(ielts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6103 // result = patternBuilderModel->mapFromSource(ielts);
6104 result = patternDataModel->mapFromSource(ielts);
6106 //update the list (indexes)
6107 for ( int r = 0; r < nbQuads; ++r ){
6108 item = quads_lw->item(r);
6109 iquad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
6110 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iquad) );
6111 item->setData(LW_DATA_ROLE, iquad.data(HEXA_DATA_ROLE));
6117 // ------------------------- QuadRevolutionDialog ----------------------------------
6118 // ============================================================== Constructeur
6120 QuadRevolutionDialog::QuadRevolutionDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
6121 HexaBaseDialog(parent, editmode, f)
6124 _helpFileName = "gui_quad_revolution.html#guiquadsrevolution";
6125 connect( revolutionUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6126 connect( revolution_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6127 _initWidget(editmode);
6128 revolutionUni_rb->click();
6131 // ============================================================== getAssocsVTK
6133 * Returns elements currently associated to vtk
6135 QModelIndexList QuadRevolutionDialog::getAssocsVTK()
6137 QModelIndexList assocs;
6139 QListWidgetItem* item = NULL;
6140 if (getPatternDataSelectionModel() == NULL) return assocs;
6142 //ListWidget content
6143 const PatternDataModel* patternDataModel = getPatternDataModel();
6144 if ( !patternDataModel ) return assocs;
6145 int nbQuads = quads_lw->count();
6146 for ( int r = 0; r < nbQuads; ++r ){
6147 item = quads_lw->item(r);
6148 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6149 if ( iQuad.isValid() )
6155 // ============================================================== Destructeur
6156 QuadRevolutionDialog::~QuadRevolutionDialog()
6160 // ============================================================== _initInputWidget
6161 void QuadRevolutionDialog::_initInputWidget( Mode editmode )
6163 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
6164 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6165 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6167 angle_spb->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
6168 angle_spb->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
6169 angle_spb->setProperty("Angle", QVariant::fromValue(true));
6170 angle_spb->installEventFilter(this);
6172 angles_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
6173 angles_lw->setProperty("GeomWidgetType", QVariant::fromValue(TopAbs_EDGE));
6174 angles_lw->setProperty("Angle", QVariant::fromValue(true));
6175 angles_lw->installEventFilter(this);
6177 installEventFilter(this);
6178 revolutionUni_rb->installEventFilter(this);
6179 revolution_rb->installEventFilter(this);
6181 quads_lw->installEventFilter(this);
6182 center_le->installEventFilter(this);
6183 axis_le->installEventFilter(this);
6185 center_le->setReadOnly(true);
6186 axis_le->setReadOnly(true);
6188 angles_lw->setItemDelegate( new HexaAngleDoubleSpinBoxDelegate(angles_lw) );
6189 angles_lw->setEditTriggers( QAbstractItemView::DoubleClicked );
6191 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
6192 delQuadShortcut->setContext( Qt::WidgetShortcut );
6193 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(delQuadItem()) );
6194 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()));
6195 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()));
6197 connect(quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
6200 // ============================================================== updateHelpFileName
6201 void QuadRevolutionDialog::updateHelpFileName()
6203 if ( sender() == revolutionUni_rb ){
6204 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutionuniform";
6205 } else if ( sender() == revolution_rb ){
6206 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutioncustom";
6210 // ============================================================== clear
6211 void QuadRevolutionDialog::clear()
6214 modelUnregister(quads_lw);
6217 modelUnregister(center_le);
6220 modelUnregister(axis_le);
6222 modelUnregister(this);
6225 // ============================================================== addAngleItem
6226 void QuadRevolutionDialog::addAngleItem() //CS_TODO
6228 QListWidgetItem* previousItem = angles_lw->currentItem();
6229 QListWidgetItem* newItem = new QListWidgetItem();
6231 double defaultValue = 180.;
6233 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6235 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6236 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6237 angles_lw->addItem(newItem);
6242 // ============================================================== delAngleItem
6243 void QuadRevolutionDialog::delAngleItem()
6245 delete angles_lw->currentItem();
6249 // ============================================================== delQuadItem
6250 void QuadRevolutionDialog::delQuadItem()
6252 delete quads_lw->currentItem();
6256 // ============================================================== apply
6257 bool QuadRevolutionDialog::apply(QModelIndex& result)
6259 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6262 DocumentModel* docModel = getDocumentModel();
6263 PatternDataModel* patternDataModel = getPatternDataModel();
6264 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6266 QListWidgetItem* item = NULL;
6268 QModelIndexList istartquads;
6270 int nbQuads = quads_lw->count();
6271 for ( int r = 0; r < nbQuads; ++r){
6272 item = quads_lw->item(r);
6273 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
6274 if ( iquad.isValid() )
6275 istartquads << iquad;
6278 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6279 QModelIndex iaxis = patternDataModel->mapToSource(_index[axis_le]);
6280 // QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
6281 int angle = angle_spb->value();
6282 int nbre = nbre_spb->value();
6284 vector<double> angles;
6285 int nbAngles = angles_lw->count();
6286 for ( int r = 0; r < nbAngles; ++r){
6287 item = angles_lw->item(r);
6288 angles.push_back(item->data(Qt::EditRole).toDouble());
6291 QModelIndex iElts; //result
6292 if (nbQuads == 1 && istartquads[0].isValid() && icenter.isValid() && iaxis.isValid())
6294 if (revolutionUni_rb->isChecked())
6295 iElts = docModel->revolutionQuadUni(istartquads[0], icenter, iaxis, angle, nbre);
6296 else if (revolution_rb->isChecked())
6297 iElts = docModel->revolutionQuad(istartquads[0], icenter, iaxis, angles);
6299 else if (nbQuads > 1 && icenter.isValid() && iaxis.isValid())
6301 if (revolutionUni_rb->isChecked())
6302 iElts = docModel->revolutionQuadsUni(istartquads, icenter, iaxis, angle, nbre);
6303 else if (revolution_rb->isChecked())
6304 iElts = docModel->revolutionQuads(istartquads, icenter, iaxis, angles);
6307 if ( !iElts.isValid() ){
6308 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD REVOLUTION" ) + "\n" + getErrorMsg() );
6311 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6312 result = patternDataModel->mapFromSource(iElts);
6313 // result = patternBuilderModel->mapFromSource(iElts);
6318 // ------------------------- MakeHemiSphereDialog ----------------------------------
6319 // ============================================================== Constructeur
6320 MakeHemiSphereDialog::MakeHemiSphereDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
6321 HexaBaseDialog(parent, editmode, f)
6323 _helpFileName = "gui_hemisphere.html";
6325 _initWidget(editmode);
6328 connect( sphereTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6329 connect( sphereUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6330 connect( sphere2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6331 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6332 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6334 connect( sphericalTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6335 connect( sphericalUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6336 connect( spherical2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6337 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6338 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6340 connect( rindTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6341 connect( rindUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6342 connect( rind2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6343 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6344 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6347 // ============================================================== Destructeur
6348 MakeHemiSphereDialog::~MakeHemiSphereDialog()
6352 // ============================================================== _initInputWidget
6353 void MakeHemiSphereDialog::_initInputWidget( Mode editmode )
6355 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6356 hole_axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6357 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6358 vplan_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6360 sphere_radext_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6361 sphere_radext_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6362 sphere_radext_spb->setProperty("Radius", QVariant::fromValue(true));
6364 sphere_radint_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6365 sphere_radint_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6366 sphere_radint_spb->setProperty("Radius", QVariant::fromValue(true));
6368 hole_rad_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6369 hole_rad_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6370 hole_rad_spb->setProperty("Radius", QVariant::fromValue(true));
6372 radial_angle_spb->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6373 radial_angle_spb->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6374 radial_angle_spb->setProperty("Angle", QVariant::fromValue(true));
6376 radius_lw_1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6377 radius_lw_1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6378 radius_lw_1->setProperty("Radius", QVariant::fromValue(true));
6380 radius_lw_2->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6381 radius_lw_2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6382 radius_lw_2->setProperty("Radius", QVariant::fromValue(true));
6384 height_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6385 height_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6386 height_lw->setProperty("Length", QVariant::fromValue(true));
6388 angle_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
6389 angle_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
6390 angle_lw->setProperty("Angle", QVariant::fromValue(true));
6392 installEventFilter(this);
6393 center_le->installEventFilter(this);
6394 hole_axis_le->installEventFilter(this);
6395 base_le->installEventFilter(this);
6396 vplan_le->installEventFilter(this);
6398 sphere_radext_spb->installEventFilter(this);
6399 sphere_radint_spb->installEventFilter(this);
6400 hole_rad_spb->installEventFilter(this);
6401 radial_angle_spb->installEventFilter(this);
6402 radius_lw_1->installEventFilter(this);
6403 radius_lw_2->installEventFilter(this);
6404 height_lw->installEventFilter(this);
6405 angle_lw->installEventFilter(this);
6407 sphere_rb->installEventFilter(this);
6408 sphereTop_rb->installEventFilter(this);
6409 sphereUni_rb->installEventFilter(this);
6410 sphere2_rb->installEventFilter(this);
6411 rind_rb->installEventFilter(this);
6412 rindTop_rb->installEventFilter(this);
6413 rindUni_rb->installEventFilter(this);
6414 rind2_rb->installEventFilter(this);
6415 spherical_rb->installEventFilter(this);
6416 sphericalTop_rb->installEventFilter(this);
6417 sphericalUni_rb->installEventFilter(this);
6418 spherical2_rb->installEventFilter(this);
6420 center_le->setReadOnly(true);
6421 hole_axis_le->setReadOnly(true);
6422 base_le->setReadOnly(true);
6423 vplan_le->setReadOnly(true);
6425 radius_lw_1->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_1));
6426 radius_lw_1->setEditTriggers(QAbstractItemView::DoubleClicked);
6428 radius_lw_2->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_2));
6429 radius_lw_2->setEditTriggers(QAbstractItemView::DoubleClicked);
6431 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
6432 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6434 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
6435 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6437 connect( add_radius_pb_1, SIGNAL(clicked()), this, SLOT(addRadiusItem1()) );
6438 connect( del_radius_pb_1, SIGNAL(clicked()), this, SLOT(delRadiusItem1()) );
6440 connect( add_radius_pb_2, SIGNAL(clicked()), this, SLOT(addRadiusItem2()) );
6441 connect( del_radius_pb_2, SIGNAL(clicked()), this, SLOT(delRadiusItem2()) );
6443 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
6444 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
6446 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
6447 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
6450 // ============================================================== updateHelpFileName
6451 void MakeHemiSphereDialog::updateHelpFileName()
6453 if ( sender() == sphereTop_rb || sender() == rindTop_rb ){
6454 _helpFileName = "gui_hemisphere.html#guisphereandrindsimple";
6455 } else if ( sender() == sphereUni_rb ){
6456 _helpFileName = "gui_hemisphere.html#guisphereuniform";
6457 } else if ( sender() == sphere2_rb ){
6458 _helpFileName = "gui_hemisphere.html#guispherecustom";
6459 } else if ( sender() == rindUni_rb ){
6460 _helpFileName = "gui_hemisphere.html#guirinduniform";
6461 } else if ( sender() == rind2_rb ){
6462 _helpFileName = "gui_hemisphere.html#guirindcustom";
6463 } else if ( sender() == sphericalTop_rb ){
6464 _helpFileName = "gui_hemisphere.html#guiconcentricsimple";
6465 } else if ( sender() == sphericalUni_rb ){
6466 _helpFileName = "gui_hemisphere.html#guiconcentricuniform";
6467 } else if ( sender() == spherical2_rb ){
6468 _helpFileName = "gui_hemisphere.html#guiconcentriccustom";
6472 // ============================================================== addRadiusItem
6473 void MakeHemiSphereDialog::addRadiusItem1()
6475 QListWidgetItem* previousItem = radius_lw_1->currentItem();
6476 QListWidgetItem* newItem = new QListWidgetItem();
6478 double defaultValue = 1.;
6480 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6482 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6483 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6484 radius_lw_1->addItem(newItem);
6487 // ============================================================== delRadiusItem
6488 void MakeHemiSphereDialog::delRadiusItem1()
6490 delete radius_lw_1->currentItem();
6493 // ============================================================== addRadiusItem
6494 void MakeHemiSphereDialog::addRadiusItem2()
6496 QListWidgetItem* previousItem = radius_lw_2->currentItem();
6497 QListWidgetItem* newItem = new QListWidgetItem();
6499 double defaultValue = 1.;
6501 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6503 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6504 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6505 radius_lw_2->addItem(newItem);
6508 // ============================================================== delRadiusItem
6509 void MakeHemiSphereDialog::delRadiusItem2()
6511 delete radius_lw_2->currentItem();
6514 // ============================================================== addAngleItem
6515 void MakeHemiSphereDialog::addAngleItem()
6517 QListWidgetItem* previousItem = angle_lw->currentItem();
6518 QListWidgetItem* newItem = new QListWidgetItem();
6520 double defaultValue = 180.;
6522 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6524 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6525 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6526 angle_lw->addItem(newItem);
6529 // ============================================================== delAngleItem
6530 void MakeHemiSphereDialog::delAngleItem()
6532 delete angle_lw->currentItem();
6535 // ============================================================== addHeightItem
6536 void MakeHemiSphereDialog::addHeightItem()
6538 QListWidgetItem* previousItem = height_lw->currentItem();
6539 QListWidgetItem* newItem = new QListWidgetItem();
6541 double defaultValue = 1.;
6543 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6545 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6546 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6547 height_lw->addItem(newItem);
6550 // ============================================================== delHeightItem
6551 void MakeHemiSphereDialog::delHeightItem()
6553 delete height_lw->currentItem();
6556 // ============================================================== clear
6557 void MakeHemiSphereDialog::clear()
6560 modelUnregister(center_le);
6562 hole_axis_le->clear();
6563 modelUnregister(hole_axis_le);
6566 modelUnregister(base_le);
6569 modelUnregister(vplan_le);
6571 modelUnregister(this);
6574 // ============================================================== apply
6575 bool MakeHemiSphereDialog::apply(QModelIndex& result)
6577 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6580 DocumentModel* docModel = getDocumentModel();
6581 PatternDataModel* patternDataModel = getPatternDataModel();
6582 // PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6585 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6586 QModelIndex ivplan = patternDataModel->mapToSource( _index[vplan_le] );
6587 QModelIndex ivecx = patternDataModel->mapToSource(_index[base_le]);
6588 QModelIndex ivecz = patternDataModel->mapToSource(_index[hole_axis_le]);
6589 // QModelIndex ivecx = patternBuilderModel->mapToSource( _index[base_le] );
6590 // QModelIndex ivecz = patternBuilderModel->mapToSource( _index[hole_axis_le] );
6592 double radhole = hole_rad_spb->value();
6593 double radext = sphere_radext_spb->value();
6594 double radint = sphere_radint_spb->value();
6595 double radang = radial_angle_spb->value();
6597 int crit = crit_spb->value();
6598 int nb = nbre_spb->value();
6599 int nrad = ngrid_rad_spb->value();
6600 int nang = ngrid_ang_spb->value();
6601 int nhaut = ngrid_height_spb->value();
6603 //radius, angles and heights collection
6604 QListWidgetItem* item = NULL;
6606 vector<double> radius1;
6607 vector<double> radius2;
6608 vector<double> angles;
6609 vector<double> heights;
6612 // double somme = 0.;
6613 int nbAngles = angle_lw->count();
6614 for ( int r = 0; r < nbAngles; ++r){
6615 item = angle_lw->item(r);
6616 double itemValue = item->data(Qt::EditRole).toDouble();
6617 angles.push_back(itemValue);
6618 // somme += itemValue;
6621 //radius1 collection
6622 int nbRadius = radius_lw_1->count();
6623 for ( int r = 0; r < nbRadius; ++r){
6624 item = radius_lw_1->item(r);
6625 radius1.push_back(item->data(Qt::EditRole).toDouble());
6628 //radius2 collection
6629 nbRadius = radius_lw_2->count();
6630 for ( int r = 0; r < nbRadius; ++r){
6631 item = radius_lw_2->item(r);
6632 radius2.push_back(item->data(Qt::EditRole).toDouble());
6635 //heights collection
6636 int nbHeight = height_lw->count();
6637 for ( int r = 0; r < nbHeight; ++r){
6638 item = height_lw->item(r);
6639 heights.push_back(item->data(Qt::EditRole).toDouble());
6642 if (sphere_rb->isChecked())
6644 if (sphereTop_rb->isChecked())
6645 iElts = docModel->makeSphereTop( nrad, nang, nhaut );
6646 else if (sphereUni_rb->isChecked())
6648 if (icenter.isValid() && ivplan.isValid() && ivecx.isValid() && ivecz.isValid())
6649 iElts = docModel->makeSphereUni(icenter, ivecx, ivecz, radhole, radext, radang,
6650 ivplan, nrad, nang, nhaut);
6652 else if (sphere2_rb->isChecked())
6654 // if (somme > 360.01)
6656 // SUIT_MessageBox::information( 0,
6658 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6661 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6662 iElts = docModel->makeSphere(icenter, ivecx, ivecz, radius2, angles, heights);
6665 else if (spherical_rb->isChecked())
6667 if (sphericalTop_rb->isChecked())
6668 iElts = docModel->makeSphericalTop(nb, crit);
6669 else if (sphericalUni_rb->isChecked())
6671 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6672 iElts = docModel->makeSphericalUni(icenter, ivecx, ivecz, radhole, nb, crit);
6674 else if (spherical2_rb->isChecked())
6676 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6677 iElts = docModel->makeSpherical(icenter, ivecx, ivecz, radius1, crit);
6680 else if (rind_rb->isChecked())
6682 if (rindTop_rb->isChecked())
6683 iElts = docModel->makeRindTop(nrad, nang, nhaut);
6684 else if (rindUni_rb->isChecked())
6686 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid() && ivplan.isValid())
6687 iElts = docModel->makeRindUni(icenter, ivecx, ivecz,
6688 radhole, radint, radext, radang,
6689 ivplan, nrad, nang, nhaut);
6691 else if (rind2_rb->isChecked())
6693 // if (somme > 360.01)
6695 // SUIT_MessageBox::information( 0,
6697 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6700 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6701 iElts = docModel->makeRind(icenter, ivecx, ivecz, radius2, angles, heights);
6705 if ( !iElts.isValid() ){
6706 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) + "\n" + getErrorMsg() );
6709 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6710 result = patternDataModel->mapFromSource(iElts);
6711 // result = patternBuilderModel->mapFromSource(iElts);
6716 // ------------------------- ModelInfoDialog ----------------------------------
6717 ModelInfoDialog::ModelInfoDialog(QWidget* parent, Qt::WindowFlags wf):
6718 HexaBaseDialog(parent, INFO_MODE, wf)
6721 setWindowTitle(HEXABLOCKGUI::tr("MODEL_INFO"));
6724 void ModelInfoDialog::updateInfo()
6726 DocumentModel* docModel = getDocumentModel();
6727 if (docModel == NULL) return;
6730 model_name_le->setText(docModel->getName());
6732 //Nb of elements in the model
6733 total_vertices_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_VERTEX)));
6734 total_edges_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_EDGE)));
6735 total_quads_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_QUAD)));
6736 total_hexas_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_HEXA)));
6738 ///Nb of used elements in the model
6739 used_vertices_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_VERTEX)));
6740 used_edges_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_EDGE)));
6741 used_quads_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_QUAD)));
6742 used_hexas_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_HEXA)));
6744 //Nb of unused elements in the model
6745 unused_vertices_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_VERTEX)));
6746 unused_edges_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_EDGE)));
6747 unused_quads_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_QUAD)));
6748 unused_hexas_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_HEXA)));
6751 void ModelInfoDialog::showEvent( QShowEvent * event )
6754 QDialog::showEvent ( event );
6757 // ============================================================== hideEvent
6758 void ModelInfoDialog::hideEvent ( QHideEvent * event )
6760 QDialog::hideEvent( event );
6763 // ------------------------- AddShapeDialog ----------------------------------
6764 AddShapeDialog::AddShapeDialog(QWidget* parent, Mode editmode, Qt::WindowFlags wf):
6765 HexaBaseDialog(parent, editmode, wf)
6767 _helpFileName = "gui_add_geometry.html#guiaddgeometry";
6769 _initWidget(editmode);
6770 setWindowTitle(HEXABLOCKGUI::tr("ADD_SHAPE"));
6773 // ============================================================== Destructeur
6774 AddShapeDialog::~AddShapeDialog()
6776 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
6777 this, SLOT(onCurrentSelectionChanged()) );
6780 // ============================================================== close
6781 void AddShapeDialog::close()
6783 HEXABLOCKGUI::assocInProgress = false;
6784 HexaBaseDialog::close();
6787 // ============================================================== _initInputWidget
6788 void AddShapeDialog::_initInputWidget( Mode editmode )
6790 shape_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMSHAPE_TREE) );
6791 shape_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_SHAPE) );
6792 shape_le->installEventFilter(this);
6793 shape_le->setReadOnly(true);
6796 void AddShapeDialog::clear()
6799 shape_le->setProperty("GeomObj", QVariant());
6801 modelUnregister(this);
6804 // ============================================================== onCurrentSelectionChanged
6805 void AddShapeDialog::onCurrentSelectionChanged()
6807 SALOME_ListIO selectedObjects;
6808 HEXABLOCKGUI::currentDocGView->getSelected(selectedObjects);
6809 if (selectedObjects.IsEmpty())
6812 // * extract the TopoDS_Shape of the selected object
6813 TopoDS_Shape selectedTopoShape = GEOMBase::GetTopoFromSelection( selectedObjects );
6814 if (selectedTopoShape.IsNull())
6816 shape_le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(selectedTopoShape));
6818 // * extract the name of the selected shape
6820 GEOMBase::GetNameOfSelectedIObjects( selectedObjects, name, true );
6821 shape_le->setText(name);
6824 // ============================================================== onWindowActivated
6825 void AddShapeDialog::onWindowActivated(SUIT_ViewManager* vm)
6827 QString vmType = vm->getType();
6828 if ( vmType == OCCViewer_Viewer::Type() )
6829 shape_le->setFocus();
6832 // ============================================================== apply
6833 bool AddShapeDialog::apply(QModelIndex& result)
6836 QString shapeName = shape_le->text();
6837 QVariant v = shape_le->property("TopoDS_Shape");
6838 if ( !v.isValid() || shapeName.isEmpty())
6842 TopoDS_Shape shape = v.value<TopoDS_Shape>();
6846 assocOk = getDocumentModel()->addShape(shape, shapeName);
6850 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), HEXABLOCKGUI::tr("ADD_SHAPE_FAILED") + "\n" + getErrorMsg() );