1 // Copyright (C) 2009-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <OCCViewer_ViewWindow.h>
21 #include "HEXABLOCKGUI_DocumentPanel.hxx"
22 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
23 #include "HEXABLOCKGUI_OccGraphicView.hxx"
24 #include "HEXABLOCKGUI_SalomeTools.hxx"
31 #include <SalomeApp_Application.h>
32 #include <SalomeApp_Study.h>
33 #include <PyConsole_Console.h>
34 #include <SalomeApp_Tools.h>
36 #include <Standard_GUID.hxx>
37 #include <TDF_Label.hxx>
39 #include <OCCViewer_ViewManager.h>
42 #include <TopExp_Explorer.hxx>
43 #include <TopoDS_Iterator.hxx>
44 #include <TopTools_MapOfShape.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <TColStd_IndexedMapOfInteger.hxx>
48 #include <SUIT_Session.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_OverrideCursor.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_Session.h>
53 #include "SVTK_Selection.h"
54 #include <SVTK_ViewModel.h>
55 #include <VTKViewer_ViewModel.h>
56 #include <SVTK_View.h>
58 #include <SUIT_ResourceMgr.h>
62 #define BUTTON_BOX_MIN_WIDTH 5
63 #define VERTEX_COORD_MIN -1000000
64 #define VERTEX_COORD_MAX 1000000
65 #define SPINBOX_ANGLE_MAX 360
66 #define SPINBOX_DOUBLE_MAX 1000000000
67 #define SPINBOX_POSITIVE_DOUBLE_MIN 0
72 using namespace HEXABLOCK::GUI;
75 Q_DECLARE_METATYPE(HEXABLOCK::GUI::HexaTreeRole);
76 Q_DECLARE_METATYPE(DocumentModel::GeomObj);
77 Q_DECLARE_METATYPE(TopAbs_ShapeEnum);
78 Q_DECLARE_METATYPE(TopoDS_Shape);
80 //General SpinBox Delegate
81 class HexaDoubleSpinBoxDelegate : public QStyledItemDelegate {
83 HexaDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
85 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
86 const QModelIndex &index) const{
87 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
88 sb->setDecimals(NB_DECIMALS);
93 //Angle SpinBox Delegate
94 class HexaAngleDoubleSpinBoxDelegate : public QStyledItemDelegate {
96 HexaAngleDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
98 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
99 const QModelIndex &index) const{
100 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
101 sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
102 sb->setMaximum(SPINBOX_ANGLE_MAX);
103 sb->setDecimals(NB_DECIMALS);
109 //Positive DoubleSpinBox Delegate (for heigth, radius, ...)
110 class HexaPositiveDoubleSpinBoxDelegate : public QStyledItemDelegate {
112 HexaPositiveDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
114 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
115 const QModelIndex &index) const{
116 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
117 sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
118 /////// sb->setMaximum(1000000000000000); //10e15 Abu : Pb en 32 bits
119 sb->setMaximum(SPINBOX_DOUBLE_MAX); //10e9
120 sb->setDecimals(NB_DECIMALS);
125 // ======================================================== Constructeur
126 HexaBaseDialog::HexaBaseDialog( QWidget * parent, Mode editmode, Qt::WindowFlags f ):
128 _editMode( editmode ),
131 debugEdgeAssoc(false),
132 autoFocusSwitch(true)
134 _strHexaWidgetType[VERTEX_TREE] = tr( "VERTEX" );
135 _strHexaWidgetType[EDGE_TREE] = tr( "EDGE" );
136 _strHexaWidgetType[QUAD_TREE] = tr( "QUAD" );
137 _strHexaWidgetType[HEXA_TREE] = tr( "HEXA" );
139 _strHexaWidgetType[VECTOR_TREE] = tr( "VECTOR" );
140 // _strHexaWidgetType[CYLINDER_TREE] = tr( "CYLINDER" );
141 // _strHexaWidgetType[PIPE_TREE] = tr( "PIPE" );
142 _strHexaWidgetType[ELEMENTS_TREE] = tr( "ELEMENTS" );
143 _strHexaWidgetType[CROSSELEMENTS_TREE]= tr( "CROSSELEMENTS" );
146 _strHexaWidgetType[GEOMSHAPE_TREE] = tr( "GEOMSHAPE" );
147 _strHexaWidgetType[GEOMPOINT_TREE] = tr( "GEOMPOINT" );
148 _strHexaWidgetType[GEOMEDGE_TREE] = tr( "GEOMEDGE" );
149 _strHexaWidgetType[GEOMFACE_TREE] = tr( "GEOMFACE" );
152 _strHexaWidgetType[GROUP_TREE] = tr( "GROUP" );
153 _strHexaWidgetType[LAW_TREE] = tr( "LAW" );
154 _strHexaWidgetType[PROPAGATION_TREE]= tr( "PROPAGATION" );
157 // ============================================================= getIndexList
158 QModelIndexList HexaBaseDialog::getIndexList(QListWidget* itemsList, bool mapToSource)
160 QModelIndexList iItems;
162 QListWidgetItem* item = NULL;
164 const PatternDataModel* patternDataModel = getPatternDataModel();
165 if (patternDataModel == NULL || itemsList == NULL) return iItems;
167 unsigned int nbItems = itemsList->count();
168 for ( int r = 0; r < nbItems; ++r){
169 item = itemsList->item(r);
171 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
173 iItem = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
179 // ============================================================= lockSizeToSizeHint
180 void HexaBaseDialog::lockSizeToSizeHint()
182 setMaximumHeight(sizeHint().height());
183 // setMaximumWidth(sizeHint().width());
184 // setMinimumHeight(sizeHint().height());
185 // setMinimumWidth(sizeHint().width());
188 // ============================================================= unlockSizeModification
189 void HexaBaseDialog::unlockSizeModification()
191 setMaximumHeight(MAX_HEIGHT);
192 // setMaximumWidth(MAX_WIDTH);
193 // setMinimumHeight(MIN_HEIGHT);
194 // setMinimumWidth(MIN_WIDTH);
197 // ============================================================= resetSizeAndShow
198 void HexaBaseDialog::resetSizeAndShow(QDockWidget* parent)
200 //force the dialog to fit its contain
201 lockSizeToSizeHint();
203 //set the dialog in the dockwidget
204 parent->setWidget(this);
205 parent->setWindowTitle(windowTitle());
206 parent->setVisible(true);
209 unlockSizeModification();
212 QString HexaBaseDialog::getErrorMsg()
214 DocumentModel* docModel = getDocumentModel();
215 Hex::Hex* hex = docModel->getHexaRoot();
216 int nbErrorMsg = hex->sizeofMessage();
217 QString msg, newLine = "\n";
218 for (int i = 1; i < nbErrorMsg; ++i)
219 msg += newLine + hex->getMessageLine(i);
224 //unlink the widget from the model
225 void HexaBaseDialog::modelUnregister(QWidget* widget)
227 if (widget == NULL) return;
229 if (widget->property("GeomWidgetType").isValid())
231 widget->setProperty("GeomObj", QVariant());
232 widget->setProperty("TopoDS_Shape", QVariant());
235 widget->setProperty("HexaData", QVariant());
236 widget->setProperty("QModelIndex", QVariant());
237 _index[widget] = QModelIndex();
239 HexaBaseDialog* diag = dynamic_cast<HexaBaseDialog*>(widget);
241 diag->clearWidgetsIndexes();
244 // ============================================================= connectDocumentGraphicView
245 void HexaBaseDialog::connectDocumentGraphicView(VtkDocumentGraphicView* docGView)
247 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
248 if (docGView == NULL) return;
250 disconnectDocumentGraphicView(docGView); //to avoid double connect
252 //Connect the graphic view and its model to the dialog box
253 connect( docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
254 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
255 connect( docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
256 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
257 connect( docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
258 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
259 connect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
260 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
261 connect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
262 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
265 // ============================================================= disconnectDocumentGraphicView
266 void HexaBaseDialog::disconnectDocumentGraphicView(VtkDocumentGraphicView* docGView)
268 if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
269 if (docGView == NULL) return;
272 //Disconnect graphic view signals form the dialog box
273 disconnect(docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
274 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
276 disconnect(docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
277 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
279 disconnect(docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
280 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
282 disconnect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
283 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
285 disconnect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
286 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
289 // ============================================================= onCurrentSelectionChanged
290 void HexaBaseDialog::onCurrentSelectionChanged()
292 highlightSelectedAssocs();
295 void HexaBaseDialog::clearCurrentObjectFocus()
297 QWidget* currentWidget = dynamic_cast<QWidget*>(_currentObj);
298 if (currentWidget != NULL)
300 currentWidget->clearFocus();
305 // ============================================================= setFocusToNextField
306 //Sets focus to the next field of the current object
307 void HexaBaseDialog::setFocusToNextField()
311 if (!HEXABLOCKGUI::assocInProgress && autoFocusSwitch)
313 _highlightWidget(_currentObj, Qt::white);
318 // ============================================================== _initButtonBox
319 QGroupBox* HexaBaseDialog::_initButtonBox( Mode editmode )
321 if ( editmode == INFO_MODE )
324 QGroupBox* buttonBox = new QGroupBox();
325 buttonBox->setMinimumWidth(BUTTON_BOX_MIN_WIDTH);
326 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
327 QHBoxLayout* buttonsHLayout = new QHBoxLayout();
328 _applyButton = new QPushButton(tr("Apply"));
329 QPushButton* closeButton = new QPushButton(tr("Close"));
330 QPushButton* helpButton = new QPushButton(tr("Help"));
332 connect( _applyButton, SIGNAL(clicked()), this, SLOT(apply()), Qt::UniqueConnection );
333 connect( closeButton, SIGNAL(clicked()), this, SLOT(close()), Qt::UniqueConnection );
334 connect( helpButton, SIGNAL(clicked()), this, SLOT(onHelpRequested()), Qt::UniqueConnection );
336 buttonsHLayout->addWidget( _applyButton );
337 buttonsHLayout->addWidget( closeButton );
338 buttonsHLayout->addStretch(1);
339 buttonsHLayout->addWidget( helpButton );
340 buttonBox->setLayout(buttonsHLayout);
341 layout()->addWidget(buttonBox);
342 buttonBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
346 // ============================================================== _initWidget
347 void HexaBaseDialog::_initWidget( Mode editmode )
349 _initInputWidget( editmode );
350 _initButtonBox( editmode );
353 // ============================================================== apply
354 bool HexaBaseDialog::apply()
357 bool applied = apply(iNew);
360 _selectAndHighlight( iNew );
361 if (!HEXABLOCKGUI::assocInProgress)
362 getDocumentModel()->updateGeomTree();
367 void HexaBaseDialog::clearVTKSelection()
369 HEXABLOCKGUI::currentDocGView->clearSelection();
370 _highlightWidget(_currentObj, Qt::white);
373 void HexaBaseDialog::clearOCCSelection()
375 HEXABLOCKGUI::currentOccGView->clearSelection();
378 // ============================================================== close
379 void HexaBaseDialog::close()
381 //reset the data selection pattern (forget all selections of the current context)
382 getPatternDataSelectionModel()->reset();
383 getPatternBuilderSelectionModel()->reset();
384 getPatternGeomSelectionModel()->reset();
386 //Clear vtk selection
389 //Clear occ selection
392 //Close the dialog box
394 parentWidget()->close();
397 // ============================================================== onHelpRequested
398 void HexaBaseDialog::onHelpRequested()
400 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
402 app->onHelpContextModule( "HEXABLOCK", _helpFileName );
406 platform = "winapplication";
408 platform = "application";
411 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
412 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
413 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( _helpFileName ),
414 QObject::tr( "BUT_OK" ) );
418 // ============================================================== highlightSelectedAssocs
419 void HexaBaseDialog::highlightSelectedAssocs()
421 QMultiMap<QString, int> geomAssocs = getAssocsGEOM();
422 QModelIndexList vtkAssocs = getAssocsVTK();
424 // HEXABLOCKGUI::selectionMgr()->clearSelected();
425 //highlight geom selected elts
426 if (geomAssocs.size() > 0)
427 HEXABLOCKGUI::currentOccGView->highlight(geomAssocs, false);
429 //highlight vtk selected elts
430 if (!vtkAssocs.isEmpty())
431 HEXABLOCKGUI::currentDocGView->highlight(vtkAssocs);
434 // ============================================================== refreshHighlight
435 void HexaBaseDialog::refreshHighlight()
437 HEXABLOCKGUI::selectionMgr()->clearSelected();
438 highlightSelectedAssocs();
441 // ============================================================== getObjectViewType
442 HEXABLOCKGUI::ViewType HexaBaseDialog::getObjectViewType(QObject* obj)
445 return HEXABLOCKGUI::UNKNOWN;
447 QVariant v = obj->property("GeomWidgetType");
449 return HEXABLOCKGUI::OCC;
451 v = obj->property("HexaWidgetType");
453 return HEXABLOCKGUI::VTK;
455 return HEXABLOCKGUI::UNKNOWN;
458 // ============================================================== _selectAndHighlight
459 void HexaBaseDialog::_selectAndHighlight( const QModelIndex& i )
461 if ( !i.isValid() ) return;
462 setProperty("QModelIndex", QVariant::fromValue(i));
466 // ============================================================== _allowSelection
467 void HexaBaseDialog::_allowSelection()
469 if ( getDocumentModel() )
470 getDocumentModel()->disallowEdition();
473 // ============================================================== _disallowSelection
474 void HexaBaseDialog::_disallowSelection()
476 if ( getDocumentModel() ){
477 getDocumentModel()->allowEdition();
479 HEXABLOCKGUI::currentDocGView->setAllSelection();
482 // ============================================================== _allowVTKSelection
483 bool HexaBaseDialog::_allowVTKSelection( QObject* obj )
488 QVariant v = obj->property("HexaWidgetType");
489 HexaWidgetType wType = v.value<HexaWidgetType>();
493 HEXABLOCKGUI::currentDocGView->setVertexSelection(); isOk = true;
496 HEXABLOCKGUI::currentDocGView->setEdgeSelection(); isOk = true;
499 HEXABLOCKGUI::currentDocGView->setQuadSelection(); isOk = true;
502 HEXABLOCKGUI::currentDocGView->setHexaSelection(); isOk = true;
504 default: HEXABLOCKGUI::currentDocGView->setAllSelection();
509 // ============================================================== _allowOCCSelection
510 bool HexaBaseDialog::_allowOCCSelection( QObject* obj )
512 QVariant v = obj->property("GeomWidgetType");
513 GeomWidgetType wType = v.value<GeomWidgetType>();
514 HEXABLOCKGUI::currentOccGView->setSelectionMode(wType);
519 // ============================================================== _getSelector
520 QItemSelectionModel* HexaBaseDialog::_getSelector( QObject* obj )
522 QItemSelectionModel* selector = NULL;
524 HexaWidgetType wtype;
525 QVariant v = obj->property("HexaWidgetType");
526 if ( !v.isValid() ) {
530 wtype = v.value<HexaWidgetType>();
536 case HEXA_TREE: selector = getPatternDataSelectionModel(); break;
538 // case CYLINDER_TREE:
541 case CROSSELEMENTS_TREE: selector = getPatternBuilderSelectionModel(); break;
544 case GEOMFACE_TREE: selector = getPatternGeomSelectionModel(); break;
545 case GROUP_TREE: selector = getGroupsSelectionModel(); break;
547 case PROPAGATION_TREE: selector = getMeshSelectionModel(); break;
554 DocumentModel::GeomObj* HexaBaseDialog::getGeomObj(const QModelIndex& index)
556 HEXA_NS::NewShape* aSh = getDocumentModel()->getHexaPtr<HEXA_NS::NewShape*>(index);
557 DocumentModel::GeomObj* geomObj = NULL;
560 geomObj = new DocumentModel::GeomObj;
561 geomObj->shapeName = aSh->getName();
562 geomObj->subId = QString::number(-1);
566 HEXA_NS::EltBase* aSShElt = getDocumentModel()->getHexaPtr(index);
567 HEXA_NS::SubShape* aSSh = dynamic_cast<HEXA_NS::SubShape*>(aSShElt);
570 geomObj = new DocumentModel::GeomObj;
572 if (aSSh->getParentShape() != NULL)
573 shapeName = aSSh->getParentShape()->getName();
574 geomObj->shapeName = shapeName;
575 geomObj->subId = QString::number(aSSh->getIdent());
581 // ============================================================== _onSelectionChanged
583 * Puts elements selected in the model (treeview) in the corresponding
584 * line edit widget (the one that has the focus) of the current dialog box.
586 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QLineEdit* le )
588 QModelIndexList l = sel.indexes();
589 if ( l.count() == 0 ) return false;
591 // mono selection mode: we just get the first selected element
592 QModelIndex selected = l[0];
594 // we just return if the selection is not valid or the selection and the
595 // line content are the same
596 if ( !selected.isValid() || le->property("HexaData") == selected.data(HEXA_DATA_ROLE) )
600 int selType = selected.data(HEXA_TREE_ROLE).toInt();
603 QVariant v = le->property("HexaWidgetType");
604 if ( !v.isValid() ) return false;
605 HexaWidgetType wType = v.value<HexaWidgetType>();
607 // check selection compatibility between selection and widget
608 if ( selType != wType ){
609 SUIT_MessageBox::information( 0, tr("HEXA_INFO"),
610 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg(_strHexaWidgetType[wType]));
613 if (le->property("GeomWidgetType").isValid())
615 DocumentModel::GeomObj* geomObj = getGeomObj(selected);
618 le->setProperty("GeomObj", QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
620 DocumentModel* docModel = getDocumentModel();
621 QString objId = geomObj->shapeName + "," + geomObj->subId;
622 HEXA_NS::SubShape* ssh = docModel->getGeomPtr(objId);
625 TopoDS_Shape shape = ssh->getShape();
627 le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(shape));
629 setCurrentGeomObj(geomObj);
633 //fill the lineEdit if selection is OK
634 le->setText( selected.data().toString() );// name
635 le->setProperty("QModelIndex", QVariant::fromValue(selected));
636 le->setProperty("HexaData", selected.data(HEXA_DATA_ROLE));
637 _index[le] = selected;
639 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(_currentObj);
640 if (selected.isValid() && lineEdit != NULL)
641 setFocusToNextField();
646 // ============================================================== _onSelectionChanged
648 * Puts elements selected in the model (treeview) in the corresponding list widget
649 * of the current dialog box.
651 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QListWidget* lw )
653 QModelIndexList l = sel.indexes();
655 if ( l.count() == 0 ) return false;
658 QVariant v = lw->property("HexaWidgetType");
659 if ( !v.isValid() ) return false;
660 HexaWidgetType wType = v.value<HexaWidgetType>();
662 //fill the listWidget
663 QListWidgetItem* item = NULL;
667 foreach( const QModelIndex& isel, l ){
668 // if ( lw->count() == maxSize) break;
669 selType = isel.data(HEXA_TREE_ROLE).toInt();
670 if ( selType != wType ){ // check selection compatibility between selection and widget
671 SUIT_MessageBox::information( 0,
673 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg( _strHexaWidgetType[wType]) );
676 // add selection to listWidget if selection is OK
677 selName = isel.data().toString();
678 QList<QListWidgetItem *> twice = lw->findItems( selName, Qt::MatchExactly);
679 if ( twice.count() == 0 ){
680 item = new QListWidgetItem( selName );
681 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(isel) );
682 item->setData(LW_DATA_ROLE, isel.data(HEXA_DATA_ROLE));
683 if (lw->property("GeomWidgetType").isValid())
685 DocumentModel::GeomObj* geomObj = getGeomObj(isel);
687 item->setData(LW_ASSOC_ROLE, QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
696 // ============================================================== onSelectionChanged
698 * Puts elements selected in the model in the corresponding widget (list widget or line edit)
699 * of the current dialog box.
701 void HexaBaseDialog::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
703 // * no edition for Info Dialogs
704 if ( _editMode == INFO_MODE )
707 QLineEdit* aLineEdit = NULL;
708 QListWidget* aListWidget = NULL;
710 // * fill the lineedit with selection
711 aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
714 _onSelectionChanged( sel, aLineEdit );
718 // * fill the listWidget with selection
719 aListWidget = dynamic_cast<QListWidget*>(_currentObj);
721 _onSelectionChanged( sel, aListWidget );
724 // ============================================================== showEvent
725 void HexaBaseDialog::showEvent( QShowEvent * event )
727 if ( _editMode == INFO_MODE )
728 getDocumentModel()->allowEdition();
730 getDocumentModel()->disallowEdition();
732 //Connect to salome selection signals
733 if (HEXABLOCKGUI::selectionMgr() != NULL)
735 connect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
736 this, SLOT(onCurrentSelectionChanged()), Qt::UniqueConnection );
739 //connect model selection signals
740 connectDocumentGraphicView();
742 QDialog::showEvent ( event );
746 // ============================================================== hideEvent
747 void HexaBaseDialog::hideEvent ( QHideEvent * event )
749 //Disconnection salome selection signals
750 if (HEXABLOCKGUI::selectionMgr() != NULL)
752 disconnect( HEXABLOCKGUI::selectionMgr() , SIGNAL(currentSelectionChanged()),
753 this, SLOT(onCurrentSelectionChanged()) );
756 //Disconnect vtk window activation signals
757 // if (HEXABLOCKGUI::currentDocGView->getViewWindow() != NULL)
758 // disconnect( HEXABLOCKGUI::currentDocGView->getViewWindow()->getViewManager(),
759 // SIGNAL( activated(SUIT_ViewManager*) ),
760 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
762 //Disconnect occ window activation signals
763 // if (HEXABLOCKGUI::currentOccGView->getViewWindow() != NULL)
764 // disconnect( HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager(),
765 // SIGNAL( activated(SUIT_ViewManager*) ),
766 // this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
768 //Disconnect model selection signals
769 disconnectDocumentGraphicView();
771 getDocumentModel()->allowEdition();
773 QDialog::hideEvent( event );
776 // ============================================================== updateButtonBox
777 void HexaBaseDialog::updateButtonBox()
781 // ============================================================== updateName
782 void HexaBaseDialog::updateName()
784 const PatternDataModel* patternDataModel = getPatternDataModel();
786 QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(sender());
787 if (!lineEdit) return;
788 QString newName = lineEdit->text();
789 if ( newName.isEmpty() ) return;
791 QVariant v = lineEdit->property("QModelIndex");
792 if ( !v.isValid() ) return;
794 QModelIndex index = v.value<QModelIndex>();
795 if ( index.isValid() )
796 getDocumentModel()->setName( patternDataModel->mapToSource(index), newName );
799 // ============================================================== updateDefaultName
800 void HexaBaseDialog::updateDefaultName(QLineEdit* name_field, HEXA_NS::EnumElt type)
802 if (name_field == NULL) return;
804 HEXA_NS::Document* doc = getDocumentModel()->getHexaDocument();
805 if (doc == NULL) return;
807 name_field->setText(doc->getNextName(type).c_str());
810 // ============================================================== selectElementOfModel
811 /*Selects in the model (treeview) elements selected in a listwidget,
812 * or an element in a line edit.*/
813 void HexaBaseDialog::selectElementOfModel()
815 if (getPatternDataSelectionModel() == NULL) return;
817 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
818 if ( !currentListWidget ) return;
820 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
822 getPatternDataSelectionModel()->clearSelection();
823 foreach ( QListWidgetItem *item, sel ){
824 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
825 index = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
826 if ( index.isValid() )
827 getPatternDataSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
831 // ============================================================== _isLineOrListWidget
833 * Return true is the widget is a line or a list
836 bool HexaBaseDialog::_isLineOrListWidget(QObject *widget)
838 if (widget == NULL) return false;
840 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(widget);
841 QListWidget *listWidget = dynamic_cast<QListWidget*>(widget);
842 return (lineEdit != NULL) || (listWidget != NULL);
844 }//_isLineOrListWidget
847 // ============================================================== _highlightWidget
849 * Highlight the given widget with the given color.
851 void HexaBaseDialog::_highlightWidget(QObject *obj, Qt::GlobalColor clr)
853 if (!_isLineOrListWidget(obj)) return;
855 QWidget *widget = dynamic_cast<QWidget*>(obj); //sure it's not NULL (_isLineOrListWidget(obj))
856 QPalette palette1 = widget->palette();
857 palette1.setColor(widget->backgroundRole(), clr);
858 widget->setPalette(palette1);
863 // ============================================================== _updateCurrentObject
864 void HexaBaseDialog::_updateCurrentObject(QObject* obj)
866 _highlightWidget(_currentObj, Qt::white);
868 _highlightWidget(obj, Qt::yellow);
871 // ============================================================== eventFilter
873 * Handles events from the treeview and the dialog boxes.
875 bool HexaBaseDialog::eventFilter(QObject *obj, QEvent *event)
877 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(obj);
878 QListWidget *listWidget = dynamic_cast<QListWidget*>(obj);
880 // * Enter key press ------
881 if ( event->type() == QEvent::KeyPress &&
882 ((QKeyEvent*)event)->key() == Qt::Key_Return)
884 setFocusToNextField();
888 // * Focus out from a list widget ------
889 if ( event->type() == QEvent::FocusOut && listWidget != NULL)
891 QItemSelectionModel * selectionModel = listWidget->selectionModel();
892 selectionModel->clearSelection();
895 if ( event->type() != QEvent::FocusIn )
900 // allow vtk selection
901 if (getObjectViewType(obj) == HEXABLOCKGUI::VTK)
902 _allowVTKSelection( obj );
904 //allow occ selection
905 if (getObjectViewType(obj) == HEXABLOCKGUI::OCC)
906 _allowOCCSelection( obj );
908 //Depending on the focused widget type, get the right selector for it
911 QItemSelectionModel* selector = _getSelector( obj );
912 if ( selector == NULL )
914 _updateCurrentObject(obj);
918 if ( _currentObj != obj && (lineEdit == NULL || listWidget == NULL) )
919 selector->clearSelection();
921 _updateCurrentObject(obj);
923 //If the widget contains an element, select it in model/view
924 if ( lineEdit != NULL ){ //element can be from lineEdit
925 v = lineEdit->property("HexaData");
927 return QObject::eventFilter(obj, event);
928 index = ((SelectionModel*)selector)->indexBy( HEXA_DATA_ROLE, v);
930 selector->select( index, QItemSelectionModel::SelectCurrent );
933 return QObject::eventFilter(obj, event);
936 // ------------------------- VERTEX ----------------------------------
937 // ============================================================== Constructeur
938 VertexDialog::VertexDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
939 HexaBaseDialog(parent, editmode, f),
942 _helpFileName = "gui_vertex.html";
944 _initWidget(editmode);
945 // setFocusProxy( name_le );
947 if ( editmode == NEW_MODE ){
948 setWindowTitle( tr("Vertex Construction") );
949 } else if ( editmode == UPDATE_MODE ){
950 setWindowTitle( tr("Vertex Modification") );
952 else if ( editmode == INFO_MODE){
953 setWindowTitle( tr("Vertex Information") );
957 // ============================================================== Destructeur
958 VertexDialog::~VertexDialog()
962 // ============================================================== _initInputWidget
963 void VertexDialog::_initInputWidget( Mode editmode )
965 // x_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
966 // y_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
967 // z_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
968 QDoubleValidator *doubleValidator = new QDoubleValidator(widget_2);
969 x_spb->setValidator(doubleValidator);
970 y_spb->setValidator(doubleValidator);
971 z_spb->setValidator(doubleValidator);
973 // setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
974 installEventFilter(this);
975 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
976 name_le->installEventFilter(this);
978 if (editmode == INFO_MODE)
980 name_le->setReadOnly(true);
981 x_spb->setReadOnly(true);
982 y_spb->setReadOnly(true);
983 z_spb->setReadOnly(true);
986 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
989 // ============================================================== clear
990 void VertexDialog::clear()
994 modelUnregister(this);
997 // ============================================================== setValue
998 void VertexDialog::setValue(HEXA_NS::Vertex* v)
1001 name_le->setText( v->getName() );
1004 // x_spb->setValue( v->getX() );
1005 // y_spb->setValue( v->getY() );
1006 // z_spb->setValue( v->getZ() );
1007 x_spb->setText( QString::number(v->getX()) );
1008 y_spb->setText( QString::number(v->getY()) );
1009 z_spb->setText( QString::number(v->getZ()) );
1011 if ( getPatternDataSelectionModel() != NULL ){
1012 QModelIndex iv = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1014 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1015 name_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(iv) );
1020 // ============================================================== getValue
1021 HEXA_NS::Vertex* VertexDialog::getValue()
1027 // ============================================================== apply
1028 bool VertexDialog::apply(QModelIndex& result)
1030 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1033 if ( !getDocumentModel() ) return false;
1034 if ( !getPatternDataSelectionModel() ) return false;
1035 const PatternDataModel* patternDataModel = getPatternDataModel();
1036 if ( !patternDataModel ) return false;
1038 QModelIndex iVertex;
1040 QString xStr = x_spb->text();
1041 QString yStr = y_spb->text();
1042 QString zStr = z_spb->text();
1043 bool isOk = false, validArgs = !xStr.isEmpty() && !yStr.isEmpty() && !zStr.isEmpty();
1045 double newX, newY, newZ;
1048 newX = xStr.toDouble();
1049 newY = yStr.toDouble();
1050 newZ = zStr.toDouble();
1053 if ( _editMode == UPDATE_MODE && validArgs){
1054 QVariant v = property("QModelIndex");
1056 iVertex = patternDataModel->mapToSource( v.value<QModelIndex>() );
1057 if ( iVertex.isValid() )
1058 isOk = getDocumentModel()->updateVertex( iVertex, newX, newY, newZ );
1060 } else if ( _editMode == NEW_MODE && validArgs){
1061 iVertex = getDocumentModel()->addVertex( newX, newY, newZ );
1062 if ( iVertex.isValid() )
1066 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "VERTEX UPDATE/CONSTRUCTION" ) + "\n" + getErrorMsg() );
1070 QString newName = name_le->text();
1071 if ( !newName.isEmpty() )/*{*/
1072 getDocumentModel()->setName( iVertex, newName );
1074 //the default name in the dialog box
1075 HEXA_NS::Vertex* v = getDocumentModel()->getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1077 updateDefaultName(name_le, v->getType());
1079 // to select/highlight result
1080 result = patternDataModel->mapFromSource(iVertex);
1082 // updateDialogBoxName(name_le, result);
1083 // const char *defaultName = getDocumentModel()->getHexaPtr(last)->getName();
1087 // ------------------------- EDGE ----------------------------------
1089 // ============================================================== Constructeur
1090 EdgeDialog::EdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1091 HexaBaseDialog(parent, editmode, f),
1094 _helpFileName = "gui_edge.html";
1096 _initWidget(editmode);
1098 // rb0->setFocusProxy( v0_le_rb0 );
1099 // rb1->setFocusProxy( vex_le_rb1 );
1101 if ( editmode == INFO_MODE ){
1102 setWindowTitle( tr("Edge Information") );
1105 else if ( editmode == UPDATE_MODE ){
1106 setWindowTitle( tr("Edge Modification") );
1112 // ============================================================== Destructeur
1113 EdgeDialog::~EdgeDialog()
1118 // ============================================================== _initInputWidget
1119 void EdgeDialog::_initInputWidget( Mode editmode )
1122 QValidator *validator = new QRegExpValidator(rx, this);
1124 // setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1125 installEventFilter(this);
1127 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1128 name_le->installEventFilter(this);
1130 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1131 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1132 v0_le_rb0->setValidator( validator );
1133 v1_le_rb0->setValidator( validator );
1134 v0_le_rb0->installEventFilter(this);
1135 v1_le_rb0->installEventFilter(this);
1137 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1138 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1139 vex_le_rb1->setValidator( validator );
1140 vec_le_rb1->setValidator( validator );
1141 vex_le_rb1->installEventFilter(this);
1142 vec_le_rb1->installEventFilter(this);
1144 v0_le_rb0->setReadOnly(true);
1145 v1_le_rb0->setReadOnly(true);
1146 vex_le_rb1->setReadOnly(true);
1147 vec_le_rb1->setReadOnly(true);
1149 if (editmode == INFO_MODE)
1150 name_le->setReadOnly(true);
1152 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()) );
1156 // ============================================================== Clear
1157 void EdgeDialog::clear()
1162 modelUnregister(v0_le_rb0);
1165 modelUnregister(v1_le_rb0);
1167 vex_le_rb1->clear();
1168 modelUnregister(vex_le_rb1);
1170 vec_le_rb1->clear();
1171 modelUnregister(vec_le_rb1);
1173 modelUnregister(this);
1176 // ============================================================== setValue
1177 void EdgeDialog::setValue(HEXA_NS::Edge* e)
1179 HEXA_NS::Vertex* v0 = e->getVertex(0);
1180 HEXA_NS::Vertex* v1 = e->getVertex(1);
1182 name_le->setText( e->getName() );
1183 v0_le_rb0->setText( v0->getName() );
1184 v1_le_rb0->setText( v1->getName() );
1186 if ( getPatternDataSelectionModel() ){
1187 QModelIndex ie = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e) );
1188 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1189 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1191 name_le->setProperty( "QModelIndex", QVariant::fromValue(ie) );
1192 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1193 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1198 // ============================================================== getValue
1199 HEXA_NS::Edge* EdgeDialog::getValue()
1204 // ============================================================== apply
1205 bool EdgeDialog::apply(QModelIndex& result)
1207 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1210 if ( !getDocumentModel() ) return false;
1211 const PatternDataModel* patternDataModel = getPatternDataModel();
1212 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1213 if ( !patternDataModel || !patternBuilderModel ) return false;
1217 if ( rb0->isChecked() ){
1218 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1219 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1220 if ( iv0.isValid()&& iv1.isValid() ){
1221 iEdge = getDocumentModel()->addEdgeVertices( iv0, iv1 );
1223 } else if ( rb1->isChecked() ){
1224 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
1225 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
1226 if ( ivex.isValid() && ivec.isValid() ){
1227 iEdge = getDocumentModel()->addEdgeVector( ivex, ivec );
1231 if ( !iEdge.isValid() ){
1232 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD EDGE" ) + "\n" + getErrorMsg() );
1235 _value = iEdge.model()->data(iEdge, HEXA_DATA_ROLE).value<HEXA_NS::Edge*>();
1237 QString newName = name_le->text();
1238 if ( !newName.isEmpty() )/*{*/
1239 getDocumentModel()->setName( iEdge, newName );
1241 //update the default name in the dialog box
1243 updateDefaultName(name_le, _value->getType());
1245 result = patternDataModel->mapFromSource(iEdge);
1250 // ------------------------- QUAD ----------------------------------
1252 // ============================================================== Constructeur
1253 QuadDialog::QuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1254 HexaBaseDialog(parent, editmode, f),
1257 _helpFileName = "gui_quadrangle.html";
1259 _initWidget(editmode);
1262 if ( editmode == INFO_MODE ){
1263 setWindowTitle( tr("Quad Information") );
1267 // ============================================================== Destructeur
1268 QuadDialog::~QuadDialog()
1272 // ============================================================== _initInputWidget
1273 void QuadDialog::_initInputWidget( Mode editmode )
1276 QValidator *validator = new QRegExpValidator(rx, this);
1278 installEventFilter(this);
1279 name_le->installEventFilter(this);
1281 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1282 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1283 v2_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1284 v3_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1286 v0_le_rb0->setValidator( validator );
1287 v1_le_rb0->setValidator( validator );
1288 v2_le_rb0->setValidator( validator );
1289 v3_le_rb0->setValidator( validator );
1290 v0_le_rb0->installEventFilter(this);
1291 v1_le_rb0->installEventFilter(this);
1292 v2_le_rb0->installEventFilter(this);
1293 v3_le_rb0->installEventFilter(this);
1295 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1296 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1297 e2_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1298 e3_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
1300 e0_le_rb1->setValidator( validator );
1301 e1_le_rb1->setValidator( validator );
1302 e2_le_rb1->setValidator( validator );
1303 e3_le_rb1->setValidator( validator );
1305 e0_le_rb1->installEventFilter(this);
1306 e1_le_rb1->installEventFilter(this);
1307 e2_le_rb1->installEventFilter(this);
1308 e3_le_rb1->installEventFilter(this);
1310 v0_le_rb0->setReadOnly(true);
1311 v1_le_rb0->setReadOnly(true);
1312 v2_le_rb0->setReadOnly(true);
1313 v3_le_rb0->setReadOnly(true);
1315 e0_le_rb1->setReadOnly(true);
1316 e1_le_rb1->setReadOnly(true);
1317 e2_le_rb1->setReadOnly(true);
1318 e3_le_rb1->setReadOnly(true);
1320 if (editmode == INFO_MODE)
1321 name_le->setReadOnly(true);
1324 // ============================================================== clear
1325 void QuadDialog::clear()
1327 //Clear the dialog and unregister it from the model
1328 QModelIndex invalidIndex;
1333 modelUnregister(v0_le_rb0);
1336 modelUnregister(v1_le_rb0);
1339 modelUnregister(v2_le_rb0);
1342 modelUnregister(v3_le_rb0);
1345 modelUnregister(e0_le_rb1);
1348 modelUnregister(e1_le_rb1);
1351 modelUnregister(e2_le_rb1);
1354 modelUnregister(e3_le_rb1);
1356 modelUnregister(this);
1360 // ============================================================== setValue
1361 void QuadDialog::setValue(HEXA_NS::Quad* q)
1363 Q_ASSERT( q->countEdge() == 4 );
1364 Q_ASSERT( q->countVertex() == 4 );
1367 name_le->setText( q->getName() );
1370 HEXA_NS::Vertex* v0 = q->getVertex(0);
1371 HEXA_NS::Vertex* v1 = q->getVertex(1);
1372 HEXA_NS::Vertex* v2 = q->getVertex(2);
1373 HEXA_NS::Vertex* v3 = q->getVertex(3);
1375 v0_le_rb0->setText( v0->getName() );
1376 v1_le_rb0->setText( v1->getName() );
1377 v2_le_rb0->setText( v2->getName() );
1378 v3_le_rb0->setText( v3->getName() );
1382 HEXA_NS::Edge* e0 = q->getEdge(0);
1383 HEXA_NS::Edge* e1 = q->getEdge(1);
1384 HEXA_NS::Edge* e2 = q->getEdge(2);
1385 HEXA_NS::Edge* e3 = q->getEdge(3);
1387 e0_le_rb1->setText( e0->getName() );
1388 e1_le_rb1->setText( e1->getName() );
1389 e2_le_rb1->setText( e2->getName() );
1390 e3_le_rb1->setText( e3->getName() );
1392 if ( getPatternDataSelectionModel() ){
1393 QModelIndex iq = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(q) );
1395 QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1396 QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1397 QModelIndex iv2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v2) );
1398 QModelIndex iv3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v3) );
1400 QModelIndex ie0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e0) );
1401 QModelIndex ie1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e1) );
1402 QModelIndex ie2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e2) );
1403 QModelIndex ie3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e3) );
1405 name_le->setProperty( "QModelIndex", QVariant::fromValue(iq) );
1407 v0_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv0) );
1408 v1_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv1) );
1409 v2_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv2) );
1410 v3_le_rb0->setProperty( "QModelIndex", QVariant::fromValue(iv3) );
1412 e0_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie0) );
1413 e1_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie1) );
1414 e2_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie2) );
1415 e3_le_rb1->setProperty( "QModelIndex", QVariant::fromValue(ie3) );
1421 // ============================================================== getValue
1422 HEXA_NS::Quad* QuadDialog::getValue()
1428 // ============================================================== apply
1429 bool QuadDialog::apply(QModelIndex& result)
1431 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1434 if ( !getDocumentModel() ) return false;
1435 const PatternDataModel* patternDataModel = getPatternDataModel();
1436 if ( !patternDataModel ) return false;
1440 if ( rb0->isChecked() ){ //vertices
1441 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1442 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1443 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb0] );
1444 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb0] );
1450 iQuad = getDocumentModel()->addQuadVertices( iv0, iv1, iv2, iv3 );
1452 } else if ( rb1->isChecked() ){ //edges
1453 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
1454 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
1455 QModelIndex ie2 = patternDataModel->mapToSource( _index[e2_le_rb1] );
1456 QModelIndex ie3 = patternDataModel->mapToSource( _index[e3_le_rb1] );
1462 iQuad = getDocumentModel()->addQuadEdges( ie0, ie1, ie2, ie3 );
1466 if ( !iQuad.isValid() ){
1467 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD QUAD" ) + "\n" + getErrorMsg());
1470 _value = iQuad.model()->data(iQuad, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1472 QString newName = name_le->text();
1473 if ( !newName.isEmpty() )/*{*/
1474 getDocumentModel()->setName( iQuad, newName );
1476 //the default name in the dialog box
1478 updateDefaultName(name_le, _value->getType());
1480 // to select/highlight result
1481 result = patternDataModel->mapFromSource(iQuad);
1487 // ------------------------- HEXA ----------------------------------
1489 // ============================================================== HexaDialog
1491 HexaDialog::HexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1492 HexaBaseDialog(parent, editmode, f),
1495 _helpFileName = "gui_hexahedron.html";
1497 _initWidget(editmode);
1500 if ( editmode == INFO_MODE ){
1501 setWindowTitle( tr("Hexahedron Information") );
1505 // ============================================================== Destructeur
1506 HexaDialog::~HexaDialog()
1510 // ============================================================== _initInputWidget
1511 void HexaDialog::_initInputWidget( Mode editmode )
1515 installEventFilter(this);
1516 name_le->installEventFilter(this);
1518 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
1519 quads_lw->installEventFilter(this);
1521 vertices_lw->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1522 vertices_lw->installEventFilter(this);
1525 if ( editmode != INFO_MODE ) {
1526 // delete item from listwidget
1527 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
1528 QShortcut* delVertexShortcut = new QShortcut( QKeySequence(Qt::Key_X), vertices_lw );
1529 delQuadShortcut->setContext( Qt::WidgetShortcut );
1530 delVertexShortcut->setContext( Qt::WidgetShortcut );
1531 connect(delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()));
1532 connect(delVertexShortcut, SIGNAL(activated()), this, SLOT(deleteVertexItem()));
1534 // highlight item on model view (VTK) from listwidget
1535 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1536 connect( vertices_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1538 if ( editmode != INFO_MODE)
1540 connect( vertices_rb, SIGNAL(clicked()), vertices_lw, SLOT(setFocus()));
1541 connect( quads_rb, SIGNAL(clicked()), quads_lw, SLOT(setFocus()));
1544 connect( vertices_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1545 connect( quads_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1547 if (editmode == INFO_MODE)
1548 name_le->setReadOnly(true);
1552 // ============================================================== clear
1553 void HexaDialog::clear()
1558 modelUnregister(quads_lw);
1560 vertices_lw->clear();
1561 modelUnregister(vertices_lw);
1563 modelUnregister(this);
1566 // ============================================================== getAssocsVTK
1568 * Returns elements currently associated to vtk
1570 QModelIndexList HexaDialog::getAssocsVTK()
1572 QModelIndexList assocs;
1573 QModelIndex iQuad, iVertex;
1574 QListWidgetItem* item = NULL;
1576 const PatternDataModel* patternDataModel = getPatternDataModel();
1577 if (patternDataModel == NULL) return assocs;
1578 if (quads_rb->isChecked())
1580 //ListWidget content
1581 int nbQuads = quads_lw->count();
1582 for ( int r = 0; r < nbQuads; ++r ){
1583 item = quads_lw->item(r);
1584 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1585 if ( iQuad.isValid() )
1590 else if (vertices_rb->isChecked())
1592 //ListWidget content
1593 int nbVertices = vertices_lw->count();
1594 for ( int r = 0; r < nbVertices; ++r ){
1595 item = vertices_lw->item(r);
1596 iVertex = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1597 if ( iVertex.isValid() )
1606 // ============================================================== updateButtonBox
1607 void HexaDialog::updateButtonBox()
1609 if ( _editMode == INFO_MODE )
1612 if ( quads_rb->isChecked() ){ // build from quads count() must be between [2,6]
1613 int nbQuads = quads_lw->count();
1614 if ( nbQuads >= 2 && nbQuads <= 6 ){
1615 _applyButton->setEnabled(true);
1617 _applyButton->setEnabled(false);
1619 } else if ( vertices_rb->isChecked() ){ // build from vertices count() must be equals to 8
1620 int nbVertices = vertices_lw->count();
1621 if ( nbVertices == 8 ){
1622 _applyButton->setEnabled(true);
1624 _applyButton->setEnabled(false);
1629 // ============================================================== deleteQuadItem
1630 void HexaDialog::deleteQuadItem()
1632 delete quads_lw->currentItem();
1636 // ============================================================== deleteVertexItem
1637 void HexaDialog::deleteVertexItem()
1639 delete vertices_lw->currentItem();
1643 // ============================================================== _setValueQuads
1644 void HexaDialog::_setValueQuads( HEXA_NS::Hexa* h )
1646 QListWidgetItem *qItem = NULL;
1647 HEXA_NS::Quad *q = NULL;
1649 if (getPatternDataSelectionModel() == NULL) return;
1651 for( int i = 0; i <= 5; ++i ){
1653 qIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(q)) );
1654 qItem = new QListWidgetItem( q->getName() );
1655 qItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(qIndex) );
1656 qItem->setData(LW_DATA_ROLE, qIndex.data(HEXA_DATA_ROLE));
1657 quads_lw->addItem( qItem );
1661 // ============================================================== _setValueVertices
1662 void HexaDialog::_setValueVertices( HEXA_NS::Hexa* h )
1664 QListWidgetItem *vItem = NULL;
1665 HEXA_NS::Vertex* v = NULL;
1667 if (getPatternDataSelectionModel() == NULL) return;
1668 vertices_lw->clear();
1669 for( int i = 0; i <= 7; ++i ){
1670 v = h->getVertex(i);
1671 vIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(v)) );
1672 vItem = new QListWidgetItem( v->getName() );
1673 vItem->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(vIndex) );
1674 vItem->setData(LW_DATA_ROLE, vIndex.data(HEXA_DATA_ROLE));
1675 vertices_lw->addItem( vItem );
1679 // ============================================================== setValue
1680 void HexaDialog::setValue(HEXA_NS::Hexa* h)
1683 name_le->setText( h->getName() );
1685 if ( getPatternDataSelectionModel()){
1686 QModelIndex hIndex = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(h) );
1687 _setValueVertices(h);
1689 name_le->setProperty( "QModelIndex", QVariant::fromValue(hIndex) );
1694 // ============================================================== getValue
1695 HEXA_NS::Hexa* HexaDialog::getValue()
1700 // ============================================================== apply
1701 bool HexaDialog::apply(QModelIndex& result)
1703 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1706 if ( !getDocumentModel() ) return false;
1707 const PatternDataModel* patternDataModel = getPatternDataModel();
1708 if ( !patternDataModel ) return false;
1712 QListWidget* currentLw = NULL;
1713 QListWidgetItem* item = NULL;
1715 if ( quads_rb->isChecked() )
1716 currentLw = dynamic_cast<QListWidget*>( quads_lw );
1717 else if ( vertices_rb->isChecked() )
1718 currentLw = dynamic_cast<QListWidget*>( vertices_lw );
1721 QModelIndexList iElts;
1722 int nbItems = currentLw->count();
1723 for ( int r = 0; r < nbItems; ++r){
1724 item = currentLw->item(r);
1725 iElt = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1726 if ( iElt.isValid() )
1730 nbItems = iElts.count();
1731 if ( quads_rb->isChecked() and (nbItems>=2 and nbItems<=6) ){ // build from quads iElts.count() should be between [2,6]
1732 iHexa = getDocumentModel()->addHexaQuads( iElts );
1733 } else if ( vertices_rb->isChecked() and nbItems== 8 ){ // build from vertices
1734 iHexa = getDocumentModel()->addHexaVertices( iElts[0], iElts[1], iElts[2], iElts[3],
1735 iElts[4], iElts[5], iElts[6], iElts[7] );
1738 if ( !iHexa.isValid() ){
1739 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD HEXA" ) + "\n" + getErrorMsg() );
1742 _value = iHexa.model()->data(iHexa, HEXA_DATA_ROLE).value<HEXA_NS::Hexa*>();
1744 QString newName = name_le->text();
1745 if ( !newName.isEmpty() )/*{*/
1746 getDocumentModel()->setName( iHexa, newName );
1748 //update the default name in the dialog box
1750 updateDefaultName(name_le, _value->getType());
1752 // to select/highlight result
1753 result = patternDataModel->mapFromSource(iHexa);
1759 // ------------------------- VECTOR ----------------------------------
1761 // ============================================================== Constructeur
1763 VectorDialog::VectorDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1764 HexaBaseDialog(parent, editmode, f),
1767 _helpFileName = "gui_vector.html";
1769 _initWidget(editmode);
1773 if ( editmode == INFO_MODE ){
1774 setWindowTitle( tr("Vector Information") );
1779 // ============================================================== Destructeur
1780 VectorDialog::~VectorDialog()
1784 // ============================================================== _initInputWidget
1785 void VectorDialog::_initInputWidget( Mode editmode )
1788 QValidator *validator = new QRegExpValidator(rx, this);
1790 installEventFilter(this);
1791 name_le->installEventFilter(this);
1793 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1794 v0_le_rb1->setValidator( validator );
1795 v0_le_rb1->installEventFilter(this);
1797 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1798 v1_le_rb1->setValidator( validator );
1799 v1_le_rb1->installEventFilter(this);
1801 if ( editmode == INFO_MODE ){
1802 name_le->setReadOnly(true);
1803 dx_spb_rb0->setReadOnly(true);
1804 dy_spb_rb0->setReadOnly(true);
1805 dz_spb_rb0->setReadOnly(true);
1808 v0_le_rb1->setReadOnly(true);
1809 v1_le_rb1->setReadOnly(true);
1812 // ============================================================== clear
1813 void VectorDialog::clear()
1817 modelUnregister(v0_le_rb1);
1820 modelUnregister(v1_le_rb1);
1822 modelUnregister(this);
1825 // ============================================================== setValue
1826 void VectorDialog::setValue(HEXA_NS::Vector* v)
1828 name_le->setText( v->getName() );
1829 dx_spb_rb0->setValue( v->getDx() );
1830 dy_spb_rb0->setValue( v->getDy() );
1831 dz_spb_rb0->setValue( v->getDz() );
1833 if ( getPatternDataSelectionModel() ){
1834 QModelIndex ivec = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1835 name_le->setProperty( "QModelIndex", QVariant::fromValue(ivec) );
1840 // ============================================================== getValue
1841 HEXA_NS::Vector* VectorDialog::getValue()
1846 // ============================================================== apply
1847 bool VectorDialog::apply(QModelIndex& result)
1849 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1852 if ( !getDocumentModel() ) return false;
1853 const PatternDataModel* patternDataModel = getPatternDataModel();
1854 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1855 if ( !patternDataModel || !patternBuilderModel) return false;
1857 QModelIndex iVector;
1859 if ( rb0->isChecked() ){ //scalar
1860 double dx = dx_spb_rb0->value();
1861 double dy = dy_spb_rb0->value();
1862 double dz = dz_spb_rb0->value();
1864 iVector = getDocumentModel()->addVector( dx, dy, dz );
1865 } else if ( rb1->isChecked() ){ //vertices
1866 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
1867 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
1871 iVector = getDocumentModel()->addVectorVertices( iv0, iv1 );
1875 if ( !iVector.isValid() ){
1876 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD VECTOR" ) + "\n" + getErrorMsg());
1880 _value = iVector.model()->data(iVector, HEXA_DATA_ROLE).value<HEXA_NS::Vector *>();
1882 QString newName = name_le->text();
1883 if ( !newName.isEmpty() )/*{*/
1884 getDocumentModel()->setName( iVector, newName );
1886 //update the default name in the dialog box
1888 updateDefaultName(name_le, _value->getType());
1890 // to select/highlight result
1891 result = patternBuilderModel->mapFromSource(iVector);
1896 // ------------------------- MakeGridDialog ----------------------------------
1897 // ============================================================== Constructeur
1899 MakeGridDialog::MakeGridDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
1900 : HexaBaseDialog(parent, editmode, f)
1903 _initWidget(editmode);
1906 _helpFileName = "creategrids.html#guicartgridsimple";
1907 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1908 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1909 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1911 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1912 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1913 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1915 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1916 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1917 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1920 // ============================================================== Destructeur
1921 MakeGridDialog::~MakeGridDialog()
1925 // ============================================================== _initInputWidget
1926 void MakeGridDialog::_initInputWidget( Mode editmode )
1928 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
1929 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1930 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1931 vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1933 center_le->setReadOnly(true);
1934 axis_le->setReadOnly(true);
1935 base_le->setReadOnly(true);
1936 vec_le->setReadOnly(true);
1938 installEventFilter(this);
1939 center_le->installEventFilter(this);
1940 axis_le->installEventFilter(this);
1941 base_le->installEventFilter(this);
1942 vec_le->installEventFilter(this);
1944 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
1945 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
1947 angle_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(angle_lw));
1948 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
1950 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
1951 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
1953 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
1954 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
1956 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
1957 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
1959 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
1960 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
1963 // ============================================================== clear
1964 void MakeGridDialog::clear()
1967 modelUnregister(center_le);
1970 modelUnregister(axis_le);
1973 modelUnregister(base_le);
1976 modelUnregister(vec_le);
1978 modelUnregister(this);
1981 // ============================================================== updateHelpFileName
1982 void MakeGridDialog::updateHelpFileName()
1984 if ( sender() == rb0 ){
1985 _helpFileName = "creategrids.html#guicartgridsimple";
1986 } else if ( sender() == rb1 ){
1987 _helpFileName = "creategrids.html#guicartgriduniform";
1988 } else if ( sender() == rb2 ){
1989 _helpFileName = "creategrids.html#guicartgridcustom";
1993 // ============================================================== addRadiusItem
1994 void MakeGridDialog::addRadiusItem()
1996 QListWidgetItem* previousItem = radius_lw->currentItem();
1997 QListWidgetItem* newItem = new QListWidgetItem();
1999 double defaultValue = 1.;
2001 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2003 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2004 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2005 radius_lw->addItem(newItem);
2008 // ============================================================== delRadiusItem
2009 void MakeGridDialog::delRadiusItem()
2011 delete radius_lw->currentItem();
2014 // ============================================================== addAngleItem
2015 void MakeGridDialog::addAngleItem()
2017 QListWidgetItem* previousItem = angle_lw->currentItem();
2018 QListWidgetItem* newItem = new QListWidgetItem();
2020 double defaultValue = 1.;
2022 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2024 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2025 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2026 angle_lw->addItem(newItem);
2029 // ============================================================== delAngleItem
2030 void MakeGridDialog::delAngleItem()
2032 delete angle_lw->currentItem();
2035 // ============================================================== addHeightItem
2036 void MakeGridDialog::addHeightItem()
2038 QListWidgetItem* previousItem = height_lw->currentItem();
2039 QListWidgetItem* newItem = new QListWidgetItem();
2041 double defaultValue = 1.;
2043 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2045 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2046 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2047 height_lw->addItem(newItem);
2050 // ============================================================== delHeightItem
2051 void MakeGridDialog::delHeightItem()
2053 delete height_lw->currentItem();
2056 // ============================================================== apply
2057 bool MakeGridDialog::apply(QModelIndex& result)
2059 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2062 DocumentModel* docModel = getDocumentModel();
2063 PatternDataModel* patternDataModel = getPatternDataModel();
2064 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2066 QModelIndex iNewElts;
2067 if ( rb0->isChecked() )
2069 long nx = nx_spb->value();
2070 long ny = ny_spb->value();
2071 long nz = nz_spb->value();
2072 iNewElts = docModel->makeCartesianTop(nx, ny, nz);
2074 else if ( rb1->isChecked() )
2076 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2077 QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2078 QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2079 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2081 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2083 double lx = lx_spb->value();
2084 double ly = ly_spb->value();
2085 double lz = lz_spb->value();
2086 double nx = nx_spb->value();
2087 double ny = ny_spb->value();
2088 double nz = nz_spb->value();
2090 iNewElts = docModel->makeCartesianUni( icenter, ibase, ivec, iaxis,
2091 lx, ly, lz, nx, ny, nz);
2094 } else if ( rb2->isChecked() )
2096 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2097 QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2098 QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2099 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2101 if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2103 QListWidgetItem* item = NULL;
2105 vector<double> radius;
2106 vector<double> angles;
2107 vector<double> heights;
2109 // double somme = 0.;
2110 int nbAngles = angle_lw->count();
2111 for ( int r = 0; r < nbAngles; ++r){
2112 item = angle_lw->item(r);
2113 double itemValue = item->data(Qt::EditRole).toDouble();
2114 angles.push_back(itemValue);
2115 // somme += itemValue;
2117 // if (somme > 360.01)
2119 // SUIT_MessageBox::information( 0,
2121 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2125 int nbRadius = radius_lw->count();
2126 for ( int r = 0; r < nbRadius; ++r){
2127 item = radius_lw->item(r);
2128 radius.push_back(item->data(Qt::EditRole).toDouble());
2131 int nbHeight = height_lw->count();
2132 for ( int r = 0; r < nbHeight; ++r){
2133 item = height_lw->item(r);
2134 heights.push_back(item->data(Qt::EditRole).toDouble());
2137 iNewElts = docModel->makeCartesian( icenter, ibase, ivec, iaxis,
2138 radius, angles, heights);
2143 if ( !iNewElts.isValid() )
2145 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE GRID" ) + "\n" + getErrorMsg() );
2149 result = patternBuilderModel->mapFromSource( iNewElts );
2154 // ============================================================== Constructeur
2156 MakeCylinderDialog::MakeCylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2157 : HexaBaseDialog(parent, editmode, f)
2160 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinder";
2161 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2162 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2163 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2164 _initWidget(editmode);
2169 // ============================================================== Destructeur
2170 MakeCylinderDialog::~MakeCylinderDialog()
2174 void MakeCylinderDialog::_initInputWidget( Mode editmode )
2176 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
2177 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2178 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE));
2180 installEventFilter(this);
2181 origin_le->installEventFilter(this);
2182 axis_le->installEventFilter(this);
2183 base_le->installEventFilter(this);
2185 origin_le->setReadOnly(true);
2186 axis_le->setReadOnly(true);
2187 base_le->setReadOnly(true);
2189 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2190 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2192 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2193 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2195 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2196 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2198 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2199 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2201 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2202 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2204 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2205 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2208 // ============================================================== updateHelpFileName
2209 void MakeCylinderDialog::updateHelpFileName()
2211 if ( sender() == rb0 ){
2212 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindersimple";
2213 } else if ( sender() == rb1 ){
2214 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinderuniform";
2215 } else if ( sender() == rb2 ){
2216 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylindercustom";
2220 // ============================================================== addRadiusItem
2221 void MakeCylinderDialog::addRadiusItem()
2223 QListWidgetItem* previousItem = radius_lw->currentItem();
2224 QListWidgetItem* newItem = new QListWidgetItem();
2226 double defaultValue = 1.;
2228 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2230 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2231 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2232 radius_lw->addItem(newItem);
2235 // ============================================================== delRadiusItem
2236 void MakeCylinderDialog::delRadiusItem()
2238 delete radius_lw->currentItem();
2241 // ============================================================== addAngleItem
2242 void MakeCylinderDialog::addAngleItem()
2244 QListWidgetItem* previousItem = angle_lw->currentItem();
2245 QListWidgetItem* newItem = new QListWidgetItem();
2247 double defaultValue = 180.;
2249 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2251 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2252 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2253 angle_lw->addItem(newItem);
2256 // ============================================================== delAngleItem
2257 void MakeCylinderDialog::delAngleItem()
2259 delete angle_lw->currentItem();
2262 // ============================================================== addHeightItem
2263 void MakeCylinderDialog::addHeightItem()
2265 QListWidgetItem* previousItem = height_lw->currentItem();
2266 QListWidgetItem* newItem = new QListWidgetItem();
2268 double defaultValue = 1.;
2270 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2272 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2273 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2274 height_lw->addItem(newItem);
2277 // ============================================================== delHeightItem
2278 void MakeCylinderDialog::delHeightItem()
2280 delete height_lw->currentItem();
2283 // ============================================================== clear
2284 void MakeCylinderDialog::clear()
2287 modelUnregister(origin_le);
2290 modelUnregister(axis_le);
2293 modelUnregister(base_le);
2295 modelUnregister(this);
2298 // ============================================================== apply
2299 bool MakeCylinderDialog::apply(QModelIndex& result)
2301 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2304 DocumentModel* docModel = getDocumentModel();
2305 PatternDataModel* patternDataModel = getPatternDataModel();
2306 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2308 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2309 QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2310 QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2311 double rext = ext_radius_spb->value();
2312 double rint = int_radius_spb->value();
2313 double angle = angle_spb->value();
2314 double height = height_spb->value();
2315 double nr = nr_spb->value();
2316 double na = na_spb->value();
2317 double nh = nh_spb->value();
2320 if (rb0->isChecked())
2321 iElts = docModel->makeCylinderTop(nr, na, nh);
2322 else if (rb1->isChecked())
2324 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2325 iElts = docModel->makeCylinderUni(iorigin, ibase, iaxis, rint,
2326 rext, angle, height, nr, na, nh);
2328 else if (rb2->isChecked())
2330 QListWidgetItem* item = NULL;
2332 vector<double> radius;
2333 vector<double> angles;
2334 vector<double> heights;
2336 // double somme = 0.;
2337 int nbAngles = angle_lw->count();
2338 for ( int r = 0; r < nbAngles; ++r){
2339 item = angle_lw->item(r);
2340 double itemValue = item->data(Qt::EditRole).toDouble();
2341 angles.push_back(itemValue);
2342 // somme += itemValue;
2344 // if (somme > 360.01)
2346 // SUIT_MessageBox::information( 0,
2348 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2352 int nbRadius = radius_lw->count();
2353 for ( int r = 0; r < nbRadius; ++r){
2354 item = radius_lw->item(r);
2355 radius.push_back(item->data(Qt::EditRole).toDouble());
2358 int nbHeight = height_lw->count();
2359 for ( int r = 0; r < nbHeight; ++r){
2360 item = height_lw->item(r);
2361 heights.push_back(item->data(Qt::EditRole).toDouble());
2364 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2365 iElts = docModel->makeCylinder( iorigin, ibase, iaxis, radius, angles, heights);
2369 if ( !iElts.isValid() ){
2370 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDER" ) + "\n" + getErrorMsg() );
2374 result = patternBuilderModel->mapFromSource(iElts);
2379 //---------------------------------- MakePipeDialog -----------------------------
2380 // ============================================================== Constructeur
2382 MakePipeDialog::MakePipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2383 : HexaBaseDialog(parent, editmode, f)
2386 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipe";
2387 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2388 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2389 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2390 _initWidget(editmode);
2394 // ============================================================== Destructeur
2395 MakePipeDialog::~MakePipeDialog()
2399 // ============================================================== _initInputWidget
2400 void MakePipeDialog::_initInputWidget( Mode editmode )
2402 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2403 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2404 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2406 installEventFilter(this);
2407 origin_le->installEventFilter(this);
2408 axis_le->installEventFilter(this);
2409 base_le->installEventFilter(this);
2411 origin_le->setReadOnly(true);
2412 axis_le->setReadOnly(true);
2413 base_le->setReadOnly(true);
2415 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2416 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2418 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2419 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2421 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2422 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2424 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2425 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2427 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2428 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2430 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2431 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2435 // ============================================================== updateHelpFileName
2436 void MakePipeDialog::updateHelpFileName()
2438 if ( sender() == rb0 ){
2439 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipesimple";
2440 } else if ( sender() == rb1 ){
2441 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipeuniform";
2442 } else if ( sender() == rb2 ){
2443 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipecustom";
2447 // ============================================================== addRadiusItem
2448 void MakePipeDialog::addRadiusItem()
2450 QListWidgetItem* previousItem = radius_lw->currentItem();
2451 QListWidgetItem* newItem = new QListWidgetItem();
2453 double defaultValue = 1.;
2455 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2457 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2458 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2459 radius_lw->addItem(newItem);
2462 // ============================================================== delRadiusItem
2463 void MakePipeDialog::delRadiusItem()
2465 delete radius_lw->currentItem();
2468 // ============================================================== addAngleItem
2469 void MakePipeDialog::addAngleItem()
2471 QListWidgetItem* previousItem = angle_lw->currentItem();
2472 QListWidgetItem* newItem = new QListWidgetItem();
2474 double defaultValue = 180.;
2476 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2478 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2479 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2480 angle_lw->addItem(newItem);
2483 // ============================================================== delAngleItem
2484 void MakePipeDialog::delAngleItem()
2486 delete angle_lw->currentItem();
2489 // ============================================================== addHeightItem
2490 void MakePipeDialog::addHeightItem()
2492 QListWidgetItem* previousItem = height_lw->currentItem();
2493 QListWidgetItem* newItem = new QListWidgetItem();
2495 double defaultValue = 1.;
2497 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2499 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2500 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2501 height_lw->addItem(newItem);
2504 // ============================================================== delHeightItem
2505 void MakePipeDialog::delHeightItem()
2507 delete height_lw->currentItem();
2510 // ============================================================== clear
2511 void MakePipeDialog::clear()
2514 modelUnregister(origin_le);
2517 modelUnregister(axis_le);
2520 modelUnregister(base_le);
2522 modelUnregister(this);
2525 // ============================================================== apply
2526 bool MakePipeDialog::apply(QModelIndex& result)
2528 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2531 DocumentModel* docModel = getDocumentModel();
2532 PatternDataModel* patternDataModel = getPatternDataModel();
2533 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2535 QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2536 QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2537 QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2538 double rext = ext_radius_spb->value();
2539 double rint = int_radius_spb->value();
2540 double angle = angle_spb->value();
2541 double height = height_spb->value();
2542 int nr = nr_spb->value();
2543 int na = na_spb->value();
2544 int nh = nh_spb->value();
2548 if (rb0->isChecked())
2549 iElts = docModel->makePipeTop(nr, na, nh);
2550 else if (rb1->isChecked())
2552 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2553 iElts = docModel->makePipeUni(iorigin, ibase, iaxis, rint, rext, angle, height,
2556 else if (rb2->isChecked())
2558 QListWidgetItem* item = NULL;
2560 vector<double> radius;
2561 vector<double> angles;
2562 vector<double> heights;
2564 // double somme = 0.;
2565 int nbAngles = angle_lw->count();
2566 for ( int r = 0; r < nbAngles; ++r){
2567 item = angle_lw->item(r);
2568 double itemValue = item->data(Qt::EditRole).toDouble();
2569 angles.push_back(itemValue);
2570 // somme += itemValue;
2572 // if (somme > 360.01)
2574 // SUIT_MessageBox::information( 0,
2576 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2580 int nbRadius = radius_lw->count();
2581 for ( int r = 0; r < nbRadius; ++r){
2582 item = radius_lw->item(r);
2583 radius.push_back(item->data(Qt::EditRole).toDouble());
2586 int nbHeight = height_lw->count();
2587 for ( int r = 0; r < nbHeight; ++r){
2588 item = height_lw->item(r);
2589 heights.push_back(item->data(Qt::EditRole).toDouble());
2591 if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2592 iElts = docModel->makePipe( iorigin, ibase, iaxis, radius, angles, heights );
2595 if ( !iElts.isValid() ){
2596 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPE" ) + "\n" + getErrorMsg() );
2600 // to select/highlight result
2601 result = patternBuilderModel->mapFromSource(iElts);
2606 //---------------------------------- MakeCylindersDialog -----------------------------
2607 // ============================================================== Constructeur
2609 MakeCylindersDialog::MakeCylindersDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2610 : HexaBaseDialog(parent, editmode, f)
2612 _helpFileName = "gui_blocks_for_cyl_pipe.html#guicylinders";
2614 _initWidget(editmode);
2617 // ============================================================== Destructeur
2618 MakeCylindersDialog::~MakeCylindersDialog()
2622 void MakeCylindersDialog::_initInputWidget( Mode editmode )
2624 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2625 center2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2626 direction_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2627 direction2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2629 installEventFilter(this);
2630 center_le->installEventFilter(this);
2631 center2_le->installEventFilter(this);
2632 direction_le->installEventFilter(this);
2633 direction2_le->installEventFilter(this);
2635 center_le->setReadOnly(true);
2636 center2_le->setReadOnly(true);
2637 direction_le->setReadOnly(true);
2638 direction2_le->setReadOnly(true);
2641 // ============================================================== clear
2642 void MakeCylindersDialog::clear()
2645 modelUnregister(center_le);
2647 center2_le->clear();
2648 modelUnregister(center2_le);
2650 direction_le->clear();
2651 modelUnregister(direction_le);
2653 direction2_le->clear();
2654 modelUnregister(direction2_le);
2656 modelUnregister(this);
2659 // ============================================================== apply
2660 bool MakeCylindersDialog::apply(QModelIndex& result)
2662 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2665 DocumentModel* docModel = getDocumentModel();
2666 PatternDataModel* patternDataModel = getPatternDataModel();
2667 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2670 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2671 QModelIndex icenter2 = patternDataModel->mapToSource( _index[center2_le] );
2672 QModelIndex idir = patternBuilderModel->mapToSource( _index[direction_le] );
2673 QModelIndex idir2 = patternBuilderModel->mapToSource( _index[direction2_le] );
2675 if ( icenter.isValid() && icenter2.isValid() && idir.isValid() && idir2.isValid()){
2676 double r1 = radius_spb->value();
2677 double h1 = height_spb->value();
2678 double r2 = radius2_spb->value();
2679 double h2 = height2_spb->value();
2680 iElts = docModel->makeCylinders( icenter, idir, r1, h1, icenter2, idir2, r2, h2 );
2683 if ( !iElts.isValid() ){
2684 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDERS" ) + "\n" + getErrorMsg() );
2688 result = patternBuilderModel->mapFromSource(iElts);
2693 //---------------------------------- MakePipesDialog -----------------------------
2694 // ============================================================== Constructeur
2696 MakePipesDialog::MakePipesDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2697 : HexaBaseDialog(parent, editmode, f)
2699 _helpFileName = "gui_blocks_for_cyl_pipe.html#guipipes";
2701 _initWidget(editmode);
2704 // ============================================================== Destructeur
2705 MakePipesDialog::~MakePipesDialog()
2709 // ============================================================== _initInputWidget
2710 void MakePipesDialog::_initInputWidget( Mode editmode )
2712 origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2713 origin2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2714 dir_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2715 dir2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2717 installEventFilter(this);
2718 origin_le->installEventFilter(this);
2719 origin2_le->installEventFilter(this);
2720 dir_le->installEventFilter(this);
2721 dir2_le->installEventFilter(this);
2723 origin_le->setReadOnly(true);
2724 origin2_le->setReadOnly(true);
2725 dir_le->setReadOnly(true);
2726 dir2_le->setReadOnly(true);
2729 // ============================================================== clear
2730 void MakePipesDialog::clear()
2733 modelUnregister(origin_le);
2735 origin2_le->clear();
2736 modelUnregister(origin2_le);
2739 modelUnregister(dir_le);
2742 modelUnregister(dir2_le);
2744 modelUnregister(this);
2747 // ============================================================== apply
2748 bool MakePipesDialog::apply(QModelIndex& result)
2750 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2753 DocumentModel* docModel = getDocumentModel();
2754 PatternDataModel* patternDataModel = getPatternDataModel();
2755 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2757 QModelIndex iorigin1 = patternDataModel->mapToSource( _index[origin_le] );
2758 QModelIndex iorigin2 = patternDataModel->mapToSource( _index[origin2_le] );
2759 QModelIndex idir1 = patternBuilderModel->mapToSource( _index[dir_le] );
2760 QModelIndex idir2 = patternBuilderModel->mapToSource( _index[dir2_le] );
2761 double rint1 = int_radius_spb->value();
2762 double rext1 = ext_radius_spb->value();
2763 double height1 = height_spb->value();
2764 double rint2 = int_radius2_spb->value();
2765 double rext2 = ext_radius2_spb->value();
2766 double height2 = height_spb->value();
2770 if ( iorigin1.isValid() && iorigin2.isValid() && idir1.isValid() && idir2.isValid())
2771 iElts = docModel->makePipes( iorigin1, idir1, rint1, rext1, height1,
2772 iorigin2, idir2, rint2, rext2, height2);
2774 if ( !iElts.isValid() ){
2775 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPES" ) + "\n" + getErrorMsg() );
2779 result = patternBuilderModel->mapFromSource(iElts);
2784 //---------------------------------- RemoveHexaDialog -----------------------------
2785 // ============================================================== Constructeur
2787 RemoveHexaDialog::RemoveHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2788 : HexaBaseDialog(parent, editmode, f)
2790 _helpFileName = "gui_remove.html";
2792 _initWidget(editmode);
2795 // ============================================================== Destructeur
2796 RemoveHexaDialog::~RemoveHexaDialog()
2800 // ============================================================== _initInputWidget
2801 void RemoveHexaDialog::_initInputWidget( Mode editmode )
2804 QValidator *validator = new QRegExpValidator(rx, this);
2806 hexa_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
2807 hexa_le->setValidator( validator );
2808 hexa_le->installEventFilter(this);
2809 hexa_le->setReadOnly(true);
2810 autoFocusSwitch = false;
2813 // ============================================================== clear
2814 void RemoveHexaDialog::clear()
2817 modelUnregister(hexa_le);
2819 modelUnregister(this);
2822 // ============================================================== apply
2823 bool RemoveHexaDialog::apply(QModelIndex& result)
2825 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2828 if ( !getDocumentModel() ) return false;
2829 const PatternDataModel* patternDataModel = getPatternDataModel();
2830 if ( !patternDataModel ) return false;
2832 QModelIndex ihexa = patternDataModel->mapToSource( _index[hexa_le] );
2834 bool removed = false;
2835 if ( ihexa.isValid() ){
2836 if ( connected_cb->isChecked() ){
2837 removed = getDocumentModel()->removeConnectedHexa( ihexa );
2839 removed = getDocumentModel()->removeHexa( ihexa );
2843 if ( removed == false ){
2844 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE HEXA" ) + "\n" + getErrorMsg() );
2853 //---------------------------------- PrismQuadDialog -----------------------------
2854 // ============================================================== Constructeur
2856 PrismQuadDialog::PrismQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2857 : HexaBaseDialog(parent, editmode, f)
2860 _helpFileName = "gui_prism_join_quad.html#guiextrudequads";
2861 connect( extrudeTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2862 connect( extrudeUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2863 connect( extrude_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2864 _initWidget(editmode);
2865 extrudeTop_rb->click();
2868 // ============================================================== Destructeur
2869 PrismQuadDialog::~PrismQuadDialog()
2873 // ============================================================== getAssocsVTK
2875 * Returns elements currently associated to vtk
2877 QModelIndexList PrismQuadDialog::getAssocsVTK()
2879 QModelIndexList assocs;
2881 QListWidgetItem* item = NULL;
2883 //ListWidget content
2884 const PatternDataModel* patternDataModel = getPatternDataModel();
2885 if ( !patternDataModel ) return assocs;
2886 int nbQuads = quads_lw->count();
2887 for ( int r = 0; r < nbQuads; ++r ){
2888 item = quads_lw->item(r);
2889 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
2890 if ( iQuad.isValid() )
2896 // ============================================================== _initInputWidget
2897 void PrismQuadDialog::_initInputWidget( Mode editmode )
2899 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
2900 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2902 installEventFilter(this);
2903 quads_lw->installEventFilter(this);
2904 axis_le->installEventFilter(this);
2906 axis_le->setReadOnly(true);
2908 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
2909 delQuadShortcut->setContext( Qt::WidgetShortcut );
2910 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2911 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2913 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
2914 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
2915 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2916 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2919 // ============================================================== updateHelpFileName
2920 void PrismQuadDialog::updateHelpFileName()
2922 if ( sender() == extrudeTop_rb ){
2923 _helpFileName = "gui_prism_join_quad.html#guiextrudequadssimple";
2924 } else if ( sender() == extrudeUni_rb ){
2925 _helpFileName = "gui_prism_join_quad.html#guiextrudequadsuniform";
2926 } else if ( sender() == extrude_rb ){
2927 _helpFileName = "gui_prism_join_quad.html#guiextrudequadscustom";
2931 // ============================================================== clear
2932 void PrismQuadDialog::clear()
2935 modelUnregister(quads_lw);
2938 modelUnregister(axis_le);
2940 modelUnregister(this);
2943 // ============================================================== removeQuad
2944 void PrismQuadDialog::removeQuad()
2946 QListWidgetItem *item = quads_lw->currentItem();
2949 int r = quads_lw->row(item);
2950 quads_lw->takeItem(r);
2955 // ============================================================== addHeightItem
2956 void PrismQuadDialog::addHeightItem()
2958 QListWidgetItem* previousItem = height_lw->currentItem();
2959 QListWidgetItem* newItem = new QListWidgetItem();
2961 double defaultValue = 1.;
2963 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2965 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
2966 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2967 height_lw->addItem(newItem);
2970 // ============================================================== delHeightItem
2971 void PrismQuadDialog::delHeightItem()
2973 delete height_lw->currentItem();
2976 // ============================================================== apply
2977 bool PrismQuadDialog::apply(QModelIndex& result)
2979 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2982 DocumentModel* docModel = getDocumentModel();
2983 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2985 QModelIndexList iquads = getIndexList(quads_lw);
2986 QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2987 double length = length_spb->value();
2988 int nb = nb_spb->value();
2990 vector<double> heights;
2991 QListWidgetItem* item = NULL;
2992 int nbItems = height_lw->count();
2994 for ( int r = 0; r < nbItems; ++r){
2995 item = height_lw->item(r);
2996 heights.push_back( item->data(Qt::EditRole).toDouble() );
3000 int nbQuads = iquads.count();
3002 if (nbQuads == 1 && iquads[0].isValid())
3004 if (extrudeTop_rb->isChecked())
3005 iElts = docModel->extrudeQuadTop(iquads[0], nb);
3006 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3007 iElts = docModel->extrudeQuadUni(iquads[0], iaxis, length, nb);
3008 else if (extrude_rb->isChecked() && iaxis.isValid())
3009 iElts = docModel->extrudeQuad(iquads[0], iaxis, heights);
3011 else if (nbQuads > 1)
3013 if (extrudeTop_rb->isChecked())
3014 iElts = docModel->extrudeQuadsTop(iquads, nb);
3015 else if (extrudeUni_rb->isChecked() && iaxis.isValid())
3016 iElts = docModel->extrudeQuadsUni(iquads, iaxis, length, nb);
3017 else if (extrude_rb->isChecked() && iaxis.isValid())
3018 iElts = docModel->extrudeQuads(iquads, iaxis, heights);
3021 if ( !iElts.isValid() ){
3022 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PRISM QUAD(S)" ) + "\n" + getErrorMsg() );
3026 result = patternBuilderModel->mapFromSource(iElts);
3031 //---------------------------------- JoinQuadDialog -----------------------------
3032 // ============================================================== Constructeur
3034 JoinQuadDialog::JoinQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3035 : HexaBaseDialog(parent, editmode, f)
3038 _helpFileName = "gui_prism_join_quad.html#guijoinquads";
3039 connect( joinUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3040 connect( join_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3041 _initWidget(editmode);
3042 joinUni_rb->click();
3045 // ============================================================== Destructeur
3046 JoinQuadDialog::~JoinQuadDialog()
3050 // ============================================================== getAssocsVTK
3052 * Returns elements currently associated to vtk
3054 QModelIndexList JoinQuadDialog::getAssocsVTK()
3056 QModelIndexList assocs;
3058 QListWidgetItem* item = NULL;
3060 if (getPatternDataSelectionModel() == NULL) return assocs;
3062 //ListWidget content
3063 const PatternDataModel* patternDataModel = getPatternDataModel();
3064 if ( !patternDataModel ) return assocs;
3065 int nbQuads = quads_lw->count();
3066 for ( int r = 0; r < nbQuads; ++r ){
3067 item = quads_lw->item(r);
3068 // iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
3069 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
3070 if ( iQuad.isValid() ) assocs << iQuad;
3075 // ============================================================== _initInputWidget
3076 void JoinQuadDialog::_initInputWidget( Mode editmode )
3078 quad_dest_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3079 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3080 vex0_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3081 vex1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3082 vex2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3083 vex3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3085 installEventFilter(this);
3086 quad_dest_le->installEventFilter(this);
3087 quads_lw->installEventFilter(this);
3088 vex0_le->installEventFilter(this);
3089 vex1_le->installEventFilter(this);
3090 vex2_le->installEventFilter(this);
3091 vex3_le->installEventFilter(this);
3093 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3094 delQuadShortcut->setContext( Qt::WidgetShortcut );
3095 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
3097 quad_dest_le->setReadOnly(true);
3098 vex0_le->setReadOnly(true);
3099 vex1_le->setReadOnly(true);
3100 vex2_le->setReadOnly(true);
3101 vex3_le->setReadOnly(true);
3103 _currentObj = quads_lw;
3104 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3105 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3107 connect( quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3109 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3110 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3113 // ============================================================== updateHelpFileName
3114 void JoinQuadDialog::updateHelpFileName()
3116 if ( sender() == joinUni_rb ){
3117 _helpFileName = "gui_prism_join_quad.html#guijoinquadsuniform";
3118 } else if ( sender() == join_rb ){
3119 _helpFileName = "gui_prism_join_quad.html#guijoinquadscustom";
3123 // ============================================================== addHeightItem
3124 void JoinQuadDialog::addHeightItem()
3126 QListWidgetItem* previousItem = height_lw->currentItem();
3127 QListWidgetItem* newItem = new QListWidgetItem();
3129 double defaultValue = 1.;
3131 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3133 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3134 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3135 height_lw->addItem(newItem);
3138 // ============================================================== delHeightItem
3139 void JoinQuadDialog::delHeightItem()
3141 delete height_lw->currentItem();
3144 // ============================================================== clear
3145 void JoinQuadDialog::clear()
3147 quad_dest_le->clear();
3148 modelUnregister(quad_dest_le);
3151 modelUnregister(quads_lw);
3154 modelUnregister(vex0_le);
3157 modelUnregister(vex1_le);
3160 modelUnregister(vex2_le);
3163 modelUnregister(vex3_le);
3165 modelUnregister(this);
3168 // ============================================================== removeQuad
3169 void JoinQuadDialog::removeQuad()
3171 QListWidgetItem *item = quads_lw->currentItem();
3174 int r = quads_lw->row(item);
3175 quads_lw->takeItem(r);
3180 // ============================================================== apply
3181 bool JoinQuadDialog::apply(QModelIndex& result)
3183 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3186 DocumentModel* docModel = getDocumentModel();
3187 PatternDataModel* patternDataModel = getPatternDataModel();
3188 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3190 QModelIndexList iquads;
3192 QListWidgetItem* item = NULL;
3193 int nbQuads = quads_lw->count();
3194 for ( int r = 0; r < nbQuads; ++r){
3195 item = quads_lw->item(r);
3196 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3197 if ( iquad.isValid() )
3200 QModelIndex iquaddest = patternDataModel->mapToSource( _index[quad_dest_le] );
3201 QModelIndex ivex0 = patternDataModel->mapToSource( _index[vex0_le] );
3202 QModelIndex ivex1 = patternDataModel->mapToSource( _index[vex1_le] );
3203 QModelIndex ivex2 = patternDataModel->mapToSource( _index[vex2_le] );
3204 QModelIndex ivex3 = patternDataModel->mapToSource( _index[vex3_le] );
3205 double nb = nb_spb->value();
3207 vector<double> heights;
3208 int nbHeight = height_lw->count();
3209 for ( int r = 0; r < nbHeight; ++r){
3210 item = height_lw->item(r);
3211 heights.push_back(item->data(Qt::EditRole).toDouble());
3215 if (nbQuads == 1 && iquads[0].isValid() && iquaddest.isValid() && ivex0.isValid() &&
3216 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3218 if (joinUni_rb->isChecked())
3219 iElts = docModel->joinQuadUni(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3220 else if (join_rb->isChecked())
3221 iElts = docModel->joinQuad(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3223 else if (nbQuads > 1 && iquaddest.isValid() && ivex0.isValid() &&
3224 ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3226 if (joinUni_rb->isChecked())
3227 iElts = docModel->joinQuadsUni(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3228 else if (join_rb->isChecked())
3229 iElts = docModel->joinQuads(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3232 if ( !iElts.isValid() ){
3233 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT JOIN QUAD(S)" ) + "\n" + getErrorMsg() );
3236 result = patternBuilderModel->mapFromSource(iElts);
3241 // ------------------------- MergeDialog ----------------------------------
3242 // ============================================================== Constructeur
3244 MergeDialog::MergeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3245 : HexaBaseDialog(parent, editmode, f)
3248 _initWidget(editmode);
3251 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3252 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3253 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3254 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3256 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3257 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3258 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3260 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3261 connect( rb2, SIGNAL(cliked()), this, SLOT(clearVTKSelection()) );
3262 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3265 // ============================================================== Destructeur
3266 MergeDialog::~MergeDialog()
3270 // ============================================================== _initInputWidget
3271 void MergeDialog::_initInputWidget( Mode editmode )
3274 QValidator *validator = new QRegExpValidator(rx, this);
3276 v0_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3277 v1_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3278 v0_le_rb0->setValidator( validator );
3279 v1_le_rb0->setValidator( validator );
3280 v0_le_rb0->installEventFilter(this);
3281 v1_le_rb0->installEventFilter(this);
3283 v0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3284 v1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3285 e0_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3286 e1_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3288 v0_le_rb1->setValidator( validator );
3289 v1_le_rb1->setValidator( validator );
3290 e0_le_rb1->setValidator( validator );
3291 e1_le_rb1->setValidator( validator );
3293 v0_le_rb1->installEventFilter(this);
3294 v1_le_rb1->installEventFilter(this);
3295 e0_le_rb1->installEventFilter(this);
3296 e1_le_rb1->installEventFilter(this);
3298 v0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3299 v1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3300 v2_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3301 v3_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3302 q0_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3303 q1_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3305 v0_le_rb2->setValidator( validator );
3306 v1_le_rb2->setValidator( validator );
3307 v2_le_rb2->setValidator( validator );
3308 v3_le_rb2->setValidator( validator );
3309 q0_le_rb2->setValidator( validator );
3310 q1_le_rb2->setValidator( validator );
3312 v0_le_rb2->installEventFilter(this);
3313 v1_le_rb2->installEventFilter(this);
3314 v2_le_rb2->installEventFilter(this);
3315 v3_le_rb2->installEventFilter(this);
3316 q0_le_rb2->installEventFilter(this);
3317 q1_le_rb2->installEventFilter(this);
3319 v0_le_rb0->setReadOnly(true);
3320 v1_le_rb0->setReadOnly(true);
3322 v0_le_rb1->setReadOnly(true);
3323 v1_le_rb1->setReadOnly(true);
3324 e0_le_rb1->setReadOnly(true);
3325 e1_le_rb1->setReadOnly(true);
3327 v0_le_rb2->setReadOnly(true);
3328 v1_le_rb2->setReadOnly(true);
3329 v2_le_rb2->setReadOnly(true);
3330 v3_le_rb2->setReadOnly(true);
3331 q0_le_rb2->setReadOnly(true);
3332 q1_le_rb2->setReadOnly(true);
3335 // ============================================================== clear
3336 void MergeDialog::clear()
3339 modelUnregister(v0_le_rb0);
3342 modelUnregister(v1_le_rb0);
3345 modelUnregister(e0_le_rb1);
3348 modelUnregister(e1_le_rb1);
3351 modelUnregister(v0_le_rb1);
3354 modelUnregister(v1_le_rb1);
3357 modelUnregister(q0_le_rb2);
3360 modelUnregister(q1_le_rb2);
3363 modelUnregister(v0_le_rb2);
3366 modelUnregister(v1_le_rb2);
3369 modelUnregister(v2_le_rb2);
3372 modelUnregister(v3_le_rb2);
3374 modelUnregister(this);
3377 // ============================================================== updateHelpFileName
3378 void MergeDialog::updateHelpFileName()
3380 if ( sender() == rb0 ){
3381 _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3382 } else if ( sender() == rb1 ){
3383 _helpFileName = "gui_merge_elmts.html#merge-two-edges";
3384 } else if ( sender() == rb2 ){
3385 _helpFileName = "gui_merge_elmts.html#merge-two-quadrangles";
3389 // ============================================================== apply
3390 bool MergeDialog::apply(QModelIndex& result)
3392 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3395 if (getDocumentModel() == NULL) return false;
3396 const PatternDataModel* patternDataModel = getPatternDataModel();
3397 if ( !patternDataModel ) return false;
3399 bool merged = false;
3401 if ( rb0->isChecked() ){
3402 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
3403 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
3407 merged = getDocumentModel()->mergeVertices( iv0, iv1 );
3409 } else if ( rb1->isChecked() ){
3410 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
3411 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
3412 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
3413 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
3419 merged = getDocumentModel()->mergeEdges( ie0, ie1, iv0, iv1);
3421 } else if ( rb2->isChecked() ){
3423 QModelIndex iq0 = patternDataModel->mapToSource( _index[q0_le_rb2] );
3424 QModelIndex iq1 = patternDataModel->mapToSource( _index[q1_le_rb2] );
3425 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb2] );
3426 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb2] );
3427 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb2] );
3428 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb2] );
3436 merged = getDocumentModel()->mergeQuads( iq0, iq1,
3437 iv0, iv1, iv2, iv3 );
3441 if ( merged == false ){
3442 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MERGE" ) + "\n" + getErrorMsg() );
3449 // ------------------------- DisconnectDialog ----------------------------------
3450 // ============================================================== Constructeur
3452 DisconnectDialog::DisconnectDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3453 : HexaBaseDialog(parent, editmode, f)
3456 _initWidget(editmode);
3459 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3461 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3462 connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3463 connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3465 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3466 connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3467 connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3469 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3470 connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3471 connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3473 connect( rb3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3474 connect( rb3, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3475 connect( rb3, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3479 // ============================================================== Destructeur
3480 DisconnectDialog::~DisconnectDialog()
3484 // ============================================================== _initInputWidget
3485 void DisconnectDialog::_initInputWidget( Mode editmode )
3488 QValidator *validator = new QRegExpValidator(rx, this);
3490 installEventFilter(this);
3493 v_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3494 h_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3495 v_le_rb0->setValidator( validator );
3496 h_le_rb0->setValidator( validator );
3497 v_le_rb0->installEventFilter(this);
3498 h_le_rb0->installEventFilter(this);
3501 e_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3502 h_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3503 e_le_rb1->setValidator( validator );
3504 h_le_rb1->setValidator( validator );
3505 e_le_rb1->installEventFilter(this);
3506 h_le_rb1->installEventFilter(this);
3509 q_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
3510 h_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3511 q_le_rb2->setValidator( validator );
3512 h_le_rb2->setValidator( validator );
3513 q_le_rb2->installEventFilter(this);
3514 h_le_rb2->installEventFilter(this);
3517 d_edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3518 hexas_lw->setProperty( "HexaWidgetType", QVariant::fromValue(HEXA_TREE) );
3519 d_edges_lw->installEventFilter(this);
3520 hexas_lw->installEventFilter(this);
3522 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), d_edges_lw);
3523 QShortcut* delHexaShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), hexas_lw);
3524 delEdgeShortcut->setContext( Qt::WidgetShortcut );
3525 delHexaShortcut->setContext( Qt::WidgetShortcut );
3527 v_le_rb0->setReadOnly(true);
3528 h_le_rb0->setReadOnly(true);
3530 e_le_rb1->setReadOnly(true);
3531 h_le_rb1->setReadOnly(true);
3533 q_le_rb2->setReadOnly(true);
3534 h_le_rb2->setReadOnly(true);
3536 connect( d_edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3537 connect( hexas_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3538 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
3539 connect( delHexaShortcut, SIGNAL(activated()), this, SLOT(deleteHexaItem()) );
3540 autoFocusSwitch = false;
3544 // =============================================== getAssocsVTK
3546 * Returns elements in the list
3548 QModelIndexList DisconnectDialog::getAssocsVTK()
3550 QModelIndexList iElts;
3552 QListWidgetItem* item = NULL;
3554 const PatternDataModel* patternDataModel = getPatternDataModel();
3555 if (patternDataModel == NULL || !rb3->isChecked())
3557 //ListWidget content
3558 if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == EDGE_TREE)
3560 int nbEdges = d_edges_lw->count();
3561 for ( int r = 0; r < nbEdges; ++r )
3563 item = d_edges_lw->item(r);
3564 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3565 if ( index.isValid() )
3569 else if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == HEXA_TREE)
3571 int nbHexas = hexas_lw->count();
3572 for ( int r = 0; r < nbHexas; ++r )
3574 item = hexas_lw->item(r);
3575 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3576 if ( index.isValid() )
3583 // ============================================================== clear
3584 void DisconnectDialog::clear()
3587 modelUnregister(v_le_rb0);
3590 modelUnregister(h_le_rb0);
3593 modelUnregister(e_le_rb1);
3596 modelUnregister(h_le_rb1);
3598 d_edges_lw->clear();
3599 modelUnregister(d_edges_lw);
3602 modelUnregister(hexas_lw);
3605 modelUnregister(q_le_rb2);
3608 modelUnregister(h_le_rb2);
3610 modelUnregister(this);
3613 // ============================================================== deleteEdgeItem
3614 void DisconnectDialog::deleteEdgeItem()
3616 delete d_edges_lw->currentItem();
3619 // ============================================================== deleteHexaItem
3620 void DisconnectDialog::deleteHexaItem()
3622 delete hexas_lw->currentItem();
3625 // ============================================================== updateHelpFileName
3626 void DisconnectDialog::updateHelpFileName()
3628 if ( sender() == rb0 ){
3629 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3630 } else if ( sender() == rb1 ){
3631 _helpFileName = "gui_disc_elmts.html#disconnect-an-edge";
3632 } else if ( sender() == rb2 ){
3633 _helpFileName = "gui_disc_elmts.html#disconnect-a-quadrangle";
3634 } else if (sender() == rb3 ){
3635 _helpFileName = "gui_disc_elmts.html#disconnect-edges";
3639 // ============================================================== apply
3640 bool DisconnectDialog::apply(QModelIndex& result)
3642 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3644 if (getDocumentModel() == NULL) return false;
3645 const PatternDataModel* patternDataModel = getPatternDataModel();
3646 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3647 if ( !patternDataModel || !patternBuilderModel) return false;
3651 if ( rb0->isChecked() ){
3652 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb0] );
3653 QModelIndex ivex = patternDataModel->mapToSource( _index[v_le_rb0] );
3655 if ( ihexa.isValid()
3656 && ivex.isValid() ){
3657 iElts = getDocumentModel()->disconnectVertex( ihexa, ivex );
3659 } else if ( rb1->isChecked() ){
3660 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb1] );
3661 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le_rb1] );
3663 if ( ihexa.isValid()
3664 && iedge.isValid() ){
3665 iElts = getDocumentModel()->disconnectEdge( ihexa, iedge );
3667 } else if ( rb2->isChecked() ){
3668 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb2] );
3669 QModelIndex iquad = patternDataModel->mapToSource( _index[q_le_rb2] );
3671 if ( ihexa.isValid()
3672 && iquad.isValid() ){
3673 iElts = getDocumentModel()->disconnectQuad( ihexa, iquad );
3675 } else if ( rb3->isChecked() ){ //
3677 QModelIndex iedge, ihexa;
3678 QModelIndexList iedges, ihexas;
3679 QListWidgetItem* item = NULL;
3682 int nbEdges = d_edges_lw->count();
3683 for (int r = 0; r < nbEdges; ++r){
3684 item = d_edges_lw->item(r);
3685 iedge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3686 if ( iedge.isValid() )
3691 int nbHexas = hexas_lw->count();
3692 for (int r = 0; r < nbHexas; ++r){
3693 item = hexas_lw->item(r);
3694 ihexa = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3695 if ( ihexa.isValid() )
3699 iElts = getDocumentModel()->disconnectEdges( ihexas, iedges );
3702 if ( !iElts.isValid() ){
3703 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT DISCONNECT" ) + "\n" + getErrorMsg() );
3707 result = patternBuilderModel->mapFromSource(iElts);
3713 // ------------------------- CutEdgeDialog ----------------------------------
3714 // ============================================================== Constructeur
3716 CutEdgeDialog::CutEdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3717 HexaBaseDialog(parent, editmode, f)
3720 _helpFileName = "gui_cut_hexa.html";
3721 connect( cutUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3722 connect( cut_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3723 _initWidget(editmode);
3728 // ============================================================== Destructeur
3729 CutEdgeDialog::~CutEdgeDialog()
3733 // ============================================================== _initInputWidget
3734 void CutEdgeDialog::_initInputWidget( Mode editmode )
3736 installEventFilter(this);
3738 e_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
3739 e_le->installEventFilter(this);
3741 e_le->setReadOnly(true);
3743 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3744 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3746 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3747 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3750 // ============================================================== updateHelpFileName
3751 void CutEdgeDialog::updateHelpFileName()
3753 if ( sender() == cutUni_rb ){
3754 _helpFileName = "gui_cut_hexa.html#guicuthexauniform";
3755 } else if ( sender() == cut_rb ){
3756 _helpFileName = "gui_cut_hexa.html#guicuthexacustom";
3760 // ============================================================== clear
3761 void CutEdgeDialog::clear()
3764 modelUnregister(e_le);
3766 modelUnregister(this);
3769 // ============================================================== addHeightItem
3770 void CutEdgeDialog::addHeightItem()
3772 QListWidgetItem* previousItem = height_lw->currentItem();
3773 QListWidgetItem* newItem = new QListWidgetItem();
3775 double defaultValue = 1.;
3777 defaultValue = previousItem->data(Qt::EditRole).toDouble();
3779 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
3780 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3781 height_lw->addItem(newItem);
3784 // ============================================================== delHeightItem
3785 void CutEdgeDialog::delHeightItem()
3787 delete height_lw->currentItem();
3790 // ============================================================== apply
3791 bool CutEdgeDialog::apply(QModelIndex& result)
3793 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3796 DocumentModel* docModel = getDocumentModel();
3797 PatternDataModel* patternDataModel = getPatternDataModel();
3798 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3801 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le] );
3803 if (cutUni_rb->isChecked() && iedge.isValid())
3805 int nbCut = nb_cut_spb->value();
3806 iElts = docModel->cutUni(iedge, nbCut);
3808 else if (cut_rb->isChecked() && iedge.isValid())
3810 vector<double> heights;
3811 QListWidgetItem* item = NULL;
3812 int nbItems = height_lw->count();
3814 for ( int r = 0; r < nbItems; ++r){
3815 item = height_lw->item(r);
3816 heights.push_back( item->data(Qt::EditRole).toDouble() );
3819 iElts = docModel->cut(iedge, heights);
3822 if ( !iElts.isValid() ){
3823 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT CUT EDGE" ) + "\n" + getErrorMsg() );
3827 result = patternBuilderModel->mapFromSource(iElts);
3829 //Update the line edit
3831 e_le->setProperty("QModelIndex", invalid );
3833 QModelIndex invalidIndex;
3834 _index[e_le] = invalidIndex;
3841 // // ------------------------- MakeTransformationDialog ----------------------------------
3842 // ============================================================== Constructeur
3844 MakeTransformationDialog::MakeTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3845 : HexaBaseDialog(parent, editmode, f)
3848 _initWidget(editmode);
3851 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
3852 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3853 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3854 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3857 // ============================================================== Destructeur
3858 MakeTransformationDialog::~MakeTransformationDialog()
3862 // ============================================================== _initInputWidget
3863 void MakeTransformationDialog::_initInputWidget( Mode editmode )
3866 QValidator *validator = new QRegExpValidator(rx, this);
3868 installEventFilter(this);
3870 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3871 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3873 vec_le_rb0->setValidator( validator );
3874 elts_le_rb0->setValidator( validator );
3875 vec_le_rb0->installEventFilter(this);
3876 elts_le_rb0->installEventFilter(this);
3878 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3879 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3880 vex_le_rb1->setValidator( validator );
3881 elts_le_rb1->setValidator( validator );
3882 vex_le_rb1->installEventFilter(this);
3883 elts_le_rb1->installEventFilter(this);
3885 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3886 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3887 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3888 vex_le_rb2->setValidator( validator );
3889 vec_le_rb2->setValidator( validator );
3890 elts_le_rb2->setValidator( validator );
3891 vex_le_rb2->installEventFilter(this);
3892 vec_le_rb2->installEventFilter(this);
3893 elts_le_rb2->installEventFilter(this);
3895 vec_le_rb0->setReadOnly(true);
3896 elts_le_rb0->setReadOnly(true);
3898 vex_le_rb1->setReadOnly(true);
3899 elts_le_rb1->setReadOnly(true);
3901 vex_le_rb2->setReadOnly(true);
3902 vec_le_rb2->setReadOnly(true);
3903 elts_le_rb2->setReadOnly(true);
3907 // ============================================================== clear
3908 void MakeTransformationDialog::clear()
3910 elts_le_rb0->clear();
3911 modelUnregister(elts_le_rb0);
3913 vec_le_rb0->clear();
3914 modelUnregister(vec_le_rb0);
3916 elts_le_rb1->clear();
3917 modelUnregister(elts_le_rb1);
3919 vex_le_rb1->clear();
3920 modelUnregister(vex_le_rb1);
3922 elts_le_rb2->clear();
3923 modelUnregister(elts_le_rb2);
3925 vex_le_rb2->clear();
3926 modelUnregister(vex_le_rb2);
3928 vec_le_rb2->clear();
3929 modelUnregister(vec_le_rb2);
3931 modelUnregister(this);
3934 // ============================================================== updateHelpFileName
3935 void MakeTransformationDialog::updateHelpFileName()
3937 if ( sender() == rb0 ){
3938 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
3939 } else if ( sender() == rb1 ){
3940 _helpFileName = "gui_make_elmts.html#make-elements-by-scaling";
3941 } else if ( sender() == rb2 ){
3942 _helpFileName = "gui_make_elmts.html#make-elements-by-rotation";
3946 // ============================================================== apply
3947 bool MakeTransformationDialog::apply(QModelIndex& result)
3949 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3952 if (getDocumentModel() == NULL) return false;
3953 const PatternDataModel* patternDataModel = getPatternDataModel();
3954 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3955 if ( !patternDataModel || !patternBuilderModel) return false;
3957 QModelIndex iNewElts;
3959 if ( rb0->isChecked() ){
3960 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
3961 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
3963 if ( ielts.isValid()
3965 iNewElts = getDocumentModel()->makeTranslation( ielts, ivec );
3967 } else if ( rb1->isChecked() ){
3968 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
3969 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
3970 double k = k_spb->value();
3972 if ( ielts.isValid()
3974 iNewElts = getDocumentModel()->makeScale( ielts, ivex, k );
3976 } else if ( rb2->isChecked() ){
3977 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
3978 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
3979 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
3980 double angle = angle_spb->value();
3982 if ( ielts.isValid()
3985 iNewElts = getDocumentModel()->makeRotation( ielts, ivex, ivec, angle );
3988 if ( !iNewElts.isValid() ){
3989 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
3993 result = patternBuilderModel->mapFromSource(iNewElts);
3998 // // ------------------------- MakeSymmetryDialog ----------------------------------
3999 // ============================================================== Constructeur
4001 MakeSymmetryDialog::MakeSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4002 HexaBaseDialog(parent, editmode, f)
4005 _initWidget(editmode);
4008 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4009 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4010 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4011 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4014 // ============================================================== Destructeur
4015 MakeSymmetryDialog::~MakeSymmetryDialog()
4019 // ============================================================== _initInputWidget
4020 void MakeSymmetryDialog::_initInputWidget( Mode editmode )
4023 QValidator *validator = new QRegExpValidator(rx, this);
4025 installEventFilter(this);
4027 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4028 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4029 vex_le_rb0->setValidator( validator );
4030 elts_le_rb0->setValidator( validator );
4031 vex_le_rb0->installEventFilter(this);
4032 elts_le_rb0->installEventFilter(this);
4034 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4035 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4036 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4037 vex_le_rb1->setValidator( validator );
4038 vec_le_rb1->setValidator( validator );
4039 elts_le_rb1->setValidator( validator );
4040 vex_le_rb1->installEventFilter(this);
4041 vec_le_rb1->installEventFilter(this);
4042 elts_le_rb1->installEventFilter(this);
4044 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4045 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4046 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4047 vex_le_rb2->setValidator( validator );
4048 vec_le_rb2->setValidator( validator );
4049 elts_le_rb2->setValidator( validator );
4050 vex_le_rb2->installEventFilter(this);
4051 vec_le_rb2->installEventFilter(this);
4052 elts_le_rb2->installEventFilter(this);
4054 vex_le_rb0->setReadOnly(true);
4055 elts_le_rb0->setReadOnly(true);
4056 vex_le_rb1->setReadOnly(true);
4057 vec_le_rb1->setReadOnly(true);
4058 elts_le_rb1->setReadOnly(true);
4059 vex_le_rb2->setReadOnly(true);
4060 vec_le_rb2->setReadOnly(true);
4061 elts_le_rb2->setReadOnly(true);
4064 // ============================================================== clear
4065 void MakeSymmetryDialog::clear()
4067 elts_le_rb0->clear();
4068 modelUnregister(elts_le_rb0);
4070 vex_le_rb0->clear();
4071 modelUnregister(vex_le_rb0);
4073 elts_le_rb1->clear();
4074 modelUnregister(elts_le_rb1);
4076 vex_le_rb1->clear();
4077 modelUnregister(vex_le_rb1);
4079 vec_le_rb1->clear();
4080 modelUnregister(vec_le_rb1);
4082 elts_le_rb2->clear();
4083 modelUnregister(elts_le_rb2);
4085 vex_le_rb2->clear();
4086 modelUnregister(vex_le_rb2);
4088 vec_le_rb2->clear();
4089 modelUnregister(vec_le_rb2);
4091 modelUnregister(this);
4094 // ============================================================== updateHelpFileName
4095 void MakeSymmetryDialog::updateHelpFileName()
4097 if ( sender() == rb0 ){
4098 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4099 } else if ( sender() == rb1 ){
4100 _helpFileName = "gui_make_symmetry.html#make-elements-by-line-symmetry";
4101 } else if ( sender() == rb2 ){
4102 _helpFileName = "gui_make_symmetry.html#make-elements-by-plane-symmetry";
4106 // ============================================================== apply
4107 bool MakeSymmetryDialog::apply(QModelIndex& result)
4109 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4111 if (getDocumentModel() == NULL) return false;
4112 const PatternDataModel* patternDataModel = getPatternDataModel();
4113 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4114 if ( !patternDataModel || !patternBuilderModel) return false;
4116 QModelIndex iNewElts;
4118 if ( rb0->isChecked() ){
4119 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4120 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4122 if ( ielts.isValid()
4124 iNewElts = getDocumentModel()->makeSymmetryPoint( ielts, ivex );
4127 } else if ( rb1->isChecked() ){
4128 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4129 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4130 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4132 if ( ielts.isValid()
4135 iNewElts = getDocumentModel()->makeSymmetryLine( ielts, ivex, ivec );
4137 } else if ( rb2->isChecked() ){
4138 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4139 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4140 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4142 if ( ielts.isValid()
4145 iNewElts = getDocumentModel()->makeSymmetryPlane( ielts, ivex, ivec );
4148 if ( !iNewElts.isValid() ){
4149 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4153 result = patternBuilderModel->mapFromSource(iNewElts);
4158 // // ------------------------- PerformTransformationDialog ----------------------------------
4159 // ============================================================== Constructeur
4160 PerformTransformationDialog::PerformTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4161 HexaBaseDialog(parent, editmode, f)
4164 _initWidget(editmode);
4167 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4168 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4169 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4170 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4173 // ============================================================== Destructeur
4174 PerformTransformationDialog::~PerformTransformationDialog()
4178 // ============================================================== _initInputWidget
4179 void PerformTransformationDialog::_initInputWidget( Mode editmode )
4182 QValidator *validator = new QRegExpValidator(rx, this);
4184 vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4185 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4186 vec_le_rb0->setValidator( validator );
4187 elts_le_rb0->setValidator( validator );
4188 vec_le_rb0->installEventFilter(this);
4189 elts_le_rb0->installEventFilter(this);
4191 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4192 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4193 vex_le_rb1->setValidator( validator );
4194 elts_le_rb1->setValidator( validator );
4195 vex_le_rb1->installEventFilter(this);
4196 elts_le_rb1->installEventFilter(this);
4199 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4200 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4201 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4202 vex_le_rb2->setValidator( validator );
4203 vec_le_rb2->setValidator( validator );
4204 elts_le_rb2->setValidator( validator );
4205 vex_le_rb2->installEventFilter(this);
4206 vec_le_rb2->installEventFilter(this);
4207 elts_le_rb2->installEventFilter(this);
4209 vec_le_rb0->setReadOnly(true);
4210 elts_le_rb0->setReadOnly(true);
4211 vex_le_rb1->setReadOnly(true);
4212 elts_le_rb1->setReadOnly(true);
4213 vex_le_rb2->setReadOnly(true);
4214 vec_le_rb2->setReadOnly(true);
4215 elts_le_rb2->setReadOnly(true);
4219 // ============================================================== clear
4220 void PerformTransformationDialog::clear()
4222 vec_le_rb0->clear();
4223 modelUnregister(vec_le_rb0);
4225 elts_le_rb0->clear();
4226 modelUnregister(elts_le_rb0);
4228 vex_le_rb1->clear();
4229 modelUnregister(vex_le_rb1);
4231 elts_le_rb1->clear();
4232 modelUnregister(elts_le_rb1);
4234 vex_le_rb2->clear();
4235 modelUnregister(vex_le_rb2);
4237 vec_le_rb2->clear();
4238 modelUnregister(vec_le_rb2);
4240 elts_le_rb2->clear();
4241 modelUnregister(elts_le_rb2);
4243 modelUnregister(this);
4246 // ============================================================== updateHelpFileName
4247 void PerformTransformationDialog::updateHelpFileName()
4249 if ( sender() == rb0 ){
4250 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4251 } else if ( sender() == rb1 ){
4252 _helpFileName = "gui_modify_elmts.html#modify-elements-by-scaling";
4253 } else if ( sender() == rb2 ){
4254 _helpFileName = "gui_modify_elmts.html#modify-elements-by-rotation";
4258 // ============================================================== apply
4259 bool PerformTransformationDialog::apply(QModelIndex& result)
4261 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4264 if (getDocumentModel() == NULL) return false;
4265 const PatternDataModel* patternDataModel = getPatternDataModel();
4266 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4267 if ( !patternDataModel || !patternBuilderModel) return false;
4269 bool performed = false;
4271 if ( rb0->isChecked() ){
4272 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4273 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4275 if ( ielts.isValid()
4277 performed = getDocumentModel()->performTranslation( ielts, ivec );
4279 } else if ( rb1->isChecked() ){
4280 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4281 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4282 double k = k_spb->value();
4284 if ( ielts.isValid()
4286 performed = getDocumentModel()->performScale( ielts, ivex, k );
4288 } else if ( rb2->isChecked() ){
4289 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4290 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4291 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4292 double angle = angle_spb->value();
4294 if ( ielts.isValid()
4297 performed = getDocumentModel()->performRotation( ielts, ivex, ivec, angle );
4300 if ( performed == false){
4301 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM TRANSFORMATION" ) + "\n" + getErrorMsg() );
4308 // // ------------------------- PerformSymmetryDialog ----------------------------------
4309 // ============================================================== Constructeur
4310 PerformSymmetryDialog::PerformSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4311 : HexaBaseDialog(parent, editmode, f)
4314 _initWidget( editmode );
4317 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4318 connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4319 connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4320 connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4323 // ============================================================== Destructeur
4324 PerformSymmetryDialog::~PerformSymmetryDialog()
4328 // ============================================================== _initInputWidget
4329 void PerformSymmetryDialog::_initInputWidget( Mode editmode )
4332 QValidator *validator = new QRegExpValidator(rx, this);
4334 vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4335 elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4336 vex_le_rb0->setValidator( validator );
4337 elts_le_rb0->setValidator( validator );
4338 vex_le_rb0->installEventFilter(this);
4339 elts_le_rb0->installEventFilter(this);
4341 vex_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4342 vec_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4343 elts_le_rb1->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4344 vex_le_rb1->setValidator( validator );
4345 vec_le_rb1->setValidator( validator );
4346 elts_le_rb1->setValidator( validator );
4347 vex_le_rb1->installEventFilter(this);
4348 vec_le_rb1->installEventFilter(this);
4349 elts_le_rb1->installEventFilter(this);
4351 vex_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4352 vec_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
4353 elts_le_rb2->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4354 vex_le_rb2->setValidator( validator );
4355 vec_le_rb2->setValidator( validator );
4356 elts_le_rb2->setValidator( validator );
4357 vex_le_rb2->installEventFilter(this);
4358 vec_le_rb2->installEventFilter(this);
4359 elts_le_rb2->installEventFilter(this);
4361 vex_le_rb0->setReadOnly(true);
4362 elts_le_rb0->setReadOnly(true);
4363 vex_le_rb1->setReadOnly(true);
4364 vec_le_rb1->setReadOnly(true);
4365 elts_le_rb1->setReadOnly(true);
4366 vex_le_rb2->setReadOnly(true);
4367 vec_le_rb2->setReadOnly(true);
4368 elts_le_rb2->setReadOnly(true);
4372 // ============================================================== clear
4373 void PerformSymmetryDialog::clear()
4375 vex_le_rb0->clear();
4376 modelUnregister(vex_le_rb0);
4378 elts_le_rb0->clear();
4379 modelUnregister(elts_le_rb0);
4381 elts_le_rb1->clear();
4382 modelUnregister(elts_le_rb1);
4384 vex_le_rb1->clear();
4385 modelUnregister(vex_le_rb1);
4387 vec_le_rb1->clear();
4388 modelUnregister(vec_le_rb1);
4390 elts_le_rb2->clear();
4391 modelUnregister(elts_le_rb2);
4393 vex_le_rb2->clear();
4394 modelUnregister(vex_le_rb2);
4396 vec_le_rb2->clear();
4397 modelUnregister(vec_le_rb2);
4399 modelUnregister(this);
4402 // ============================================================== updateHelpFileName
4403 void PerformSymmetryDialog::updateHelpFileName()
4405 if ( sender() == rb0 ){
4406 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4407 } else if ( sender() == rb1 ){
4408 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-line-symmetry";
4409 } else if ( sender() == rb2 ){
4410 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-plane-symmetry";
4414 // ============================================================== apply
4415 bool PerformSymmetryDialog::apply(QModelIndex& result)
4417 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4420 if (getDocumentModel() == NULL) return false;
4421 const PatternDataModel* patternDataModel = getPatternDataModel();
4422 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4423 if ( !patternDataModel || !patternBuilderModel) return false;
4425 bool performed = false;
4427 if ( rb0->isChecked() ){
4428 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4429 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4431 if ( ielts.isValid()
4433 performed = getDocumentModel()->performSymmetryPoint( ielts, ivex );
4435 } else if ( rb1->isChecked() ){
4436 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4437 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4438 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4440 if ( ielts.isValid()
4443 performed = getDocumentModel()->performSymmetryLine( ielts, ivex, ivec );
4445 } else if ( rb2->isChecked() ){
4446 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4447 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4448 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4450 if ( ielts.isValid()
4453 performed = getDocumentModel()->performSymmetryPlane( ielts, ivex, ivec );
4456 if ( performed == false ){
4457 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM SYMMETRY" ) + "\n" + getErrorMsg() );
4464 // // ------------------------- EdgeAssocDialog ----------------------------------
4465 // ============================================================== Constructeur
4466 EdgeAssocDialog::EdgeAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4467 HexaBaseDialog( parent, editmode, f )
4469 _helpFileName ="gui_asso_quad_to_geom.html#one-edge";
4471 _initWidget(editmode);
4476 // ============================================================== Destructeur
4477 EdgeAssocDialog::~EdgeAssocDialog()
4481 // ============================================================== close
4482 void EdgeAssocDialog::close()
4484 HEXABLOCKGUI::assocInProgress = false;
4485 HexaBaseDialog::close();
4488 // ============================================================== _initInputWidget
4489 void EdgeAssocDialog::_initInputWidget( Mode editmode )
4492 QValidator *validator = new QRegExpValidator(rx, this);
4495 first_vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4496 first_vex_le->installEventFilter(this);
4497 first_vex_le->setValidator( validator );
4499 single_edge_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4500 single_edge_le->installEventFilter(this);
4502 edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4503 edges_lw->installEventFilter(this);
4507 lines_lw->setProperty("HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4508 lines_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4509 lines_lw->installEventFilter(this);
4511 single_line_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4512 single_line_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4513 single_line_le->installEventFilter(this);
4516 QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), edges_lw);
4517 QShortcut* delLineShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), lines_lw);
4518 delLineShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4519 delEdgeShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4521 pend_spb->setValue(1.);
4523 first_vex_le->setReadOnly(true);
4524 single_edge_le->setReadOnly(true);
4525 single_line_le->setReadOnly(true);
4527 connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
4528 connect( delLineShortcut, SIGNAL(activated()), this, SLOT(deleteLineItem()) );
4529 connect( edges_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
4530 connect( lines_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4531 connect( single_rb, SIGNAL(clicked()), this, SLOT( refreshHighlight()), Qt::UniqueConnection );
4532 connect( multiple_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection );
4533 connect( single_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4534 connect( multiple_rb, SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4537 // ============================================================== updateHelpFileName
4538 void EdgeAssocDialog::updateHelpFileName()
4540 if ( sender() == single_rb ){
4541 _helpFileName = "gui_asso_quad_to_geom.html#one-edge";
4542 } else if ( sender() == multiple_rb ){
4543 _helpFileName = "gui_asso_quad_to_geom.html#line";
4547 // ============================================================== getAssocsVTK
4549 * Returns elements currently being associated in vtk side
4551 QModelIndexList EdgeAssocDialog::getAssocsVTK()
4553 QModelIndexList assocs;
4555 QListWidgetItem* item = NULL;
4557 if (getPatternDataSelectionModel() == NULL) return assocs;
4558 if (single_rb->isChecked())
4561 QVariant v = single_edge_le->property("QModelIndex");
4562 if ( !v.isValid() ) return assocs;
4563 assocs << v.value<QModelIndex>();
4566 else if (multiple_rb->isChecked())
4568 //ListWidget content
4569 const PatternDataModel* patternDataModel = getPatternDataModel();
4570 if ( !patternDataModel ) return assocs;
4571 int nbEdges = edges_lw->count();
4572 for ( int r = 0; r < nbEdges; ++r){
4573 item = edges_lw->item(r);
4574 iEdge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4575 if ( iEdge.isValid() ) assocs << iEdge;
4582 // ============================================================== getAssocsGEOM
4584 * Returns elements currently being associated in geom side
4586 QMultiMap<QString, int> EdgeAssocDialog::getAssocsGEOM()
4588 QMultiMap<QString, int> assocs;
4589 QListWidgetItem* item = NULL;
4590 DocumentModel::GeomObj geomObj;
4592 if (single_rb->isChecked())
4595 QVariant v = single_line_le->property("GeomObj");
4596 if ( !v.isValid() ) return assocs;
4597 geomObj = v.value<DocumentModel::GeomObj>();
4598 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4601 else if (multiple_rb->isChecked())
4603 //ListWidget content
4604 unsigned int nbEdges = lines_lw->count();
4605 for ( int r = 0; r < nbEdges; ++r){
4606 item = lines_lw->item(r);
4607 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4608 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4615 // ============================================================== selectElementOfGeom
4616 /*Highlight in the OCC view selected elements in a listwidget,
4617 * or an element in a line edit.*/
4618 void EdgeAssocDialog::selectElementOfGeom()
4620 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4621 if ( !currentListWidget )
4625 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4626 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4627 pgsm->clearSelection();
4628 if (sel.count() == 0)
4631 QListWidgetItem *item = sel[0];
4632 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
4633 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4634 if ( index.isValid() )
4635 pgsm->select( index, QItemSelectionModel::SelectCurrent );
4638 // ============================================================== clear
4639 void EdgeAssocDialog::clear()
4641 first_vex_le->clear();
4642 modelUnregister(first_vex_le);
4645 modelUnregister(edges_lw);
4649 single_edge_le->clear();
4650 modelUnregister(single_edge_le);
4652 single_line_le->clear();
4653 modelUnregister(single_line_le);
4655 modelUnregister(this);
4658 // ============================================================== onWindowActivated
4659 void EdgeAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4661 QString vmType = vm->getType();
4662 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4664 if (single_rb->isChecked())
4665 single_edge_le->setFocus();
4666 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le )
4667 edges_lw->setFocus();
4669 else if ( vmType == OCCViewer_Viewer::Type() ){
4670 if (single_rb->isChecked())
4671 single_line_le->setFocus();
4672 else if (multiple_rb->isChecked() && focusWidget() != first_vex_le)
4673 lines_lw->setFocus();
4677 // ============================================================== apply
4678 bool EdgeAssocDialog::apply(QModelIndex& result)
4680 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4683 bool assocOk = false;
4685 PatternDataModel* patternDataModel = getPatternDataModel();
4686 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4687 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4689 QModelIndex iEdge, iGeomEdge;
4690 QModelIndexList iEdges;
4691 QListWidgetItem* item = NULL;
4692 QList<DocumentModel::GeomObj> assocs;
4693 DocumentModel::GeomObj aLine;
4694 HEXA_NS::SubShape* ssh;
4695 HEXA_NS::EdgeShape* sh;
4696 HEXA_NS::NewShapes shapes;
4697 HEXA_NS::IntVector subIds;
4699 QModelIndexList edges, lines;
4701 if (single_rb->isChecked()){ //Single edge and/or line association
4703 iEdge = patternDataModel->mapToSource( _index[single_edge_le] );
4704 if ( !iEdge.isValid() || myLine == NULL)
4706 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4709 id = myLine->shapeName+","+myLine->subId;
4710 ssh = getDocumentModel()->getGeomPtr(id);
4711 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
4712 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
4713 if (!iGeomEdge.isValid())
4715 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4718 assocOk = getDocumentModel()->addEdgeAssociation(iEdge, iGeomEdge, pstart_spb->value(), pend_spb->value());
4719 edges << _index[single_edge_le];
4722 else { //Multiple edge and/or line association
4725 iEdges = getIndexList(edges_lw, true);
4726 int nbLines = lines_lw->count();
4727 if (iEdges.count() == 0 || nbLines == 0)
4729 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4732 edges = getIndexList(edges_lw, false);
4734 for (int r = 0; r < nbLines; ++r){
4735 item = lines_lw->item(r);
4736 aLine = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4737 id = aLine.shapeName+","+aLine.subId;
4738 ssh = getDocumentModel()->getGeomPtr(id);
4739 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
4742 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4745 shapes.push_back(sh->getParentShape());
4746 subIds.push_back(sh->getIdent());
4747 iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
4748 if (iGeomEdge.isValid())
4752 if ( close_cb->isChecked() ){ //closed line
4753 QModelIndex iFirstVertex = patternDataModel->mapToSource( _index[first_vex_le] );
4754 if ( !iFirstVertex.isValid() )
4756 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4759 bool inv = inverse_cb->isChecked();
4760 assocOk = getDocumentModel()->associateClosedLine( iFirstVertex, iEdges, shapes, subIds, pstart_spb->value(), inv );
4764 assocOk = getDocumentModel()->associateOpenedLine( iEdges, shapes, subIds, pstart_spb->value(), pend_spb->value() );
4768 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) + "\n" + getErrorMsg() );
4772 // highlight associated items in the trees
4773 pdsm->unhighlightTreeItems();
4774 pgsm->unhighlightTreeItems();
4775 pdsm->highlightTreeItems(edges);
4776 pgsm->highlightTreeItems(lines);
4778 // highlight associated items in the views
4779 highlightSelectedAssocs();
4784 // ------------------------- QuadAssocDialog ----------------------------------
4785 // ============================================================== Constructeur
4786 QuadAssocDialog::QuadAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4787 HexaBaseDialog(parent, editmode, f)
4789 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-face-or-a-shell-of-the-geometry";
4791 _initWidget(editmode);
4794 // ============================================================== Destructeur
4795 QuadAssocDialog::~QuadAssocDialog()
4797 disconnect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
4798 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(addFace()) );
4799 delete _delFaceShortcut;
4802 // ============================================================== close
4803 void QuadAssocDialog::close()
4805 HEXABLOCKGUI::assocInProgress = false;
4806 HexaBaseDialog::close();
4809 // ============================================================== _initInputWidget
4810 void QuadAssocDialog::_initInputWidget( Mode editmode )
4813 QValidator *validator = new QRegExpValidator(rx, this);
4815 quad_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
4816 quad_le->installEventFilter(this);
4817 quad_le->setValidator( validator );
4820 faces_lw->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
4821 faces_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
4822 faces_lw->installEventFilter(this);
4823 _delFaceShortcut = new QShortcut( QKeySequence(Qt::Key_X/*Qt::Key_Delete*/), faces_lw );
4824 _delFaceShortcut->setContext( Qt::WidgetShortcut );
4826 quad_le->setReadOnly(true);
4828 connect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
4829 connect( faces_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4832 // ============================================================== getAssocsVTK
4834 * Returns elements currently being associated in vtk side
4836 QModelIndexList QuadAssocDialog::getAssocsVTK()
4838 QModelIndexList assocs;
4842 QVariant v = quad_le->property("QModelIndex");
4845 assocs << v.value<QModelIndex>();
4849 // ============================================================== getAssocsGEOM
4851 * Returns elements currently being associated in geom side
4853 QMultiMap<QString, int> QuadAssocDialog::getAssocsGEOM()
4855 QMultiMap<QString, int> assocs;
4856 QListWidgetItem* item = NULL;
4857 DocumentModel::GeomObj geomObj;
4859 //ListWidget content
4860 unsigned int nbFaces = faces_lw->count();
4861 for ( int r = 0; r < nbFaces; ++r){
4862 item = faces_lw->item(r);
4863 geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4864 assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4869 // ============================================================== selectElementOfGeom
4870 /*Highlight in the OCC view selected elements in a listwidget,
4871 * or an element in a line edit.*/
4873 void QuadAssocDialog::selectElementOfGeom()
4875 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4876 if ( !currentListWidget )
4880 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4881 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4882 pgsm->clearSelection();
4883 if (sel.count() == 0)
4885 QListWidgetItem *item = sel[0];
4886 // index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
4887 index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4888 if ( index.isValid() )
4889 pgsm->select( index, QItemSelectionModel::SelectCurrent );
4892 void QuadAssocDialog::clear()
4895 modelUnregister(quad_le);
4899 modelUnregister(this);
4902 // ============================================================== onWindowActivated
4903 void QuadAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4905 QString vmType = vm->getType();
4906 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4907 quad_le->setFocus();
4908 else if ( vmType == OCCViewer_Viewer::Type() ){
4909 faces_lw->setFocus();
4913 // ============================================================== deleteFaceItem
4914 void QuadAssocDialog::deleteFaceItem()
4916 delete faces_lw->currentItem();
4919 // ============================================================== apply
4920 bool QuadAssocDialog::apply(QModelIndex& result)
4922 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4925 PatternDataModel* patternDataModel = getPatternDataModel();
4926 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4927 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4930 QModelIndex iQuad, iGeomFace;
4931 HEXA_NS::SubShape* ssh;
4932 HEXA_NS::FaceShape* sh;
4936 iQuad = patternDataModel->mapToSource( _index[quad_le] );
4939 QListWidgetItem* item = NULL;
4940 DocumentModel::GeomObj aFace;
4941 QModelIndexList quads, faces;
4942 int nbFaces = faces_lw->count();
4943 for ( int r = 0; r < nbFaces; ++r ){
4944 item = faces_lw->item(r);
4945 aFace = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4946 id = aFace.shapeName+","+aFace.subId;
4947 ssh = getDocumentModel()->getGeomPtr(id);
4948 sh = dynamic_cast<HEXA_NS::FaceShape*>(ssh);
4951 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) );
4954 iGeomFace = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
4955 if (!getDocumentModel()->addQuadAssociation(iQuad, iGeomFace))
4957 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) + "\n" + getErrorMsg() );
4960 else if (iGeomFace.isValid())
4965 if (iQuad.isValid())
4966 quads << _index[quad_le];
4968 // highlight associated items in the trees
4969 pdsm->highlightTreeItems(quads);
4970 pgsm->highlightTreeItems(faces);
4972 // highlight associated items in the views
4973 highlightSelectedAssocs();
4978 // ------------------------- GroupDialog ----------------------------------
4979 // ============================================================== Constructeur
4980 GroupDialog::GroupDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4981 HexaBaseDialog(parent, editmode, f),
4984 _helpFileName = "gui_groups.html#add-group";
4986 _initWidget(editmode);
4987 // setFocusProxy( name_le/*eltBase_lw */);
4989 if ( editmode == NEW_MODE ){
4990 setWindowTitle( tr("Group Construction") );
4991 } else if ( editmode == UPDATE_MODE ){
4992 setWindowTitle( tr("Group Modification") );
4993 } else if ( editmode == INFO_MODE ){
4994 setWindowTitle( tr("Group Information") );
4998 // ============================================================== Destructeur
4999 GroupDialog::~GroupDialog()
5003 // ============================================================== getAssocsVTK
5005 * Returns elements currently being associated in vtk side
5007 QModelIndexList GroupDialog::getAssocsVTK()
5009 QModelIndexList assocs;
5011 QListWidgetItem* item = NULL;
5012 if (getPatternDataSelectionModel() == NULL) return assocs;
5013 //ListWidget content
5014 const PatternDataModel* patternDataModel = getPatternDataModel();
5015 if ( !patternDataModel ) return assocs;
5016 int nbElts = eltBase_lw->count();
5017 for ( int r = 0; r < nbElts; ++r){
5018 item = eltBase_lw->item(r);
5019 iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5020 if ( iItem.isValid() ) assocs << iItem;
5025 // ============================================================== _initInputWidget
5026 void GroupDialog::_initInputWidget( Mode editmode )
5028 installEventFilter(this);
5029 name_le->installEventFilter(this);
5032 strKind[ HEXA_NS::HexaCell ] = "HexaCell";
5033 strKind[ HEXA_NS::QuadCell ] = "QuadCell";
5034 strKind[ HEXA_NS::EdgeCell ] = "EdgeCell";
5035 strKind[ HEXA_NS::HexaNode ] = "HexaNode";
5036 strKind[ HEXA_NS::QuadNode ] = "QuadNode";
5037 strKind[ HEXA_NS::EdgeNode ] = "EdgeNode";
5038 strKind[ HEXA_NS::VertexNode ] = "VertexNode";
5040 QMap<HEXA_NS::EnumGroup, QString>::ConstIterator iKind;
5041 for( iKind = strKind.constBegin(); iKind != strKind.constEnd(); ++iKind )
5042 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5044 onKindChanged( kind_cb->currentIndex() );
5045 eltBase_lw->installEventFilter(this);
5047 if ( editmode != INFO_MODE ){
5048 QShortcut* delEltShortcut = new QShortcut( QKeySequence(Qt::Key_X), eltBase_lw );
5049 delEltShortcut->setContext( Qt::WidgetShortcut );
5050 connect(delEltShortcut, SIGNAL(activated()), this, SLOT(removeEltBase()));
5051 connect(kind_cb, SIGNAL(activated(int)), this, SLOT(onKindChanged(int)) );
5054 if ( editmode == INFO_MODE)
5056 name_le->setReadOnly(true);
5057 kind_cb->setEnabled(false);
5060 connect(eltBase_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5063 // ============================================================== clear
5064 void GroupDialog::clear()
5068 eltBase_lw->clear();
5069 modelUnregister(eltBase_lw);
5071 modelUnregister(this);
5074 // ============================================================== onKindChanged
5075 void GroupDialog::onKindChanged(int index)
5078 switch ( kind_cb->itemData(index).toInt() ){
5079 case HEXA_NS::HexaCell:
5080 case HEXA_NS::HexaNode:
5081 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(HEXA_TREE));
5084 case HEXA_NS::QuadCell:
5085 case HEXA_NS::QuadNode:
5086 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5089 case HEXA_NS::EdgeCell:
5090 case HEXA_NS::EdgeNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
5093 case HEXA_NS::VertexNode:
5094 eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
5097 default:Q_ASSERT(false);
5099 eltBase_lw->clear();
5100 eltBase_lw->setFocus();
5103 // ============================================================== setValue
5104 void GroupDialog::setValue(HEXA_NS::Group* g)
5107 name_le->setText( g->getName() );
5111 kind_cb->addItem ( strKind[g->getKind()], QVariant( g->getKind() ) );
5114 HEXA_NS::EltBase* eltBase = NULL;
5115 QListWidgetItem* item = NULL;
5116 QModelIndex iEltBase;
5117 QList<QStandardItem *> eltBaseItems;
5120 if ( !getPatternDataSelectionModel() ) return;
5121 if ( !getGroupsSelectionModel() ) return;
5123 QModelIndex iGroup = getGroupsSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(g) );
5124 name_le->setProperty( "QModelIndex", QVariant::fromValue(iGroup) );
5127 int nbElts = g->countElement();
5128 for ( int nr = 0; nr < nbElts; ++nr ){
5129 eltBase = g->getElement( nr );
5130 switch ( g->getKind() ){
5131 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: v = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
5132 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: v = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
5133 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: v = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
5134 case HEXA_NS::VertexNode: v = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
5136 iEltBase = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, v);
5137 if ( iEltBase.isValid() ){
5138 item = new QListWidgetItem( eltBase->getName() );
5139 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iEltBase) );
5140 item->setData(LW_DATA_ROLE, iEltBase.data(HEXA_DATA_ROLE));
5141 eltBase_lw->addItem( item );
5147 // ============================================================== getValue
5148 HEXA_NS::Group* GroupDialog::getValue()
5153 // ============================================================== removeEltBase
5154 void GroupDialog::removeEltBase()
5156 QListWidgetItem *item = eltBase_lw->currentItem();
5159 int r = eltBase_lw->row(item);
5160 eltBase_lw->takeItem(r);
5166 // ============================================================== apply
5167 bool GroupDialog::apply(QModelIndex& result)
5169 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5172 if ( !getDocumentModel() ) return false;
5173 const PatternDataModel* patternDataModel = getPatternDataModel();
5174 const GroupsModel* groupsModel = getGroupsModel();
5175 if (patternDataModel == NULL || groupsModel == NULL) return false;
5177 QString grpName = name_le->text();
5178 DocumentModel::Group grpKind = static_cast<DocumentModel::Group>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5180 if ( _value == NULL ){ // create group
5181 iGrp = getDocumentModel()->addGroup( grpName, grpKind );
5183 QModelIndexList iGrps = getDocumentModel()->match(
5184 getDocumentModel()->index(0, 0),
5186 QVariant::fromValue( _value ),
5188 Qt::MatchRecursive );
5189 if ( !iGrps.isEmpty() )
5194 if ( !iGrp.isValid() ){
5195 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD GROUP" ) + "\n" + getErrorMsg() );
5199 //fill it and select it
5200 QModelIndex iEltBase;
5201 QListWidgetItem* item = NULL;
5202 bool eltAdded = false;
5203 getDocumentModel()->clearGroupElement(iGrp);
5204 int nbElts = eltBase_lw->count();
5205 for ( int r = 0; r < nbElts; ++r){
5206 item = eltBase_lw->item(r);
5207 iEltBase = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5208 if ( iEltBase.isValid() )
5209 eltAdded = getDocumentModel()->addGroupElement( iGrp, iEltBase );
5212 QString newName = name_le->text();
5213 if ( !newName.isEmpty() )
5214 getDocumentModel()->setName( iGrp, newName );
5216 HEXA_NS::Group* hGroup = getDocumentModel()->data(iGrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
5219 QString groupName = QString::fromStdString(hGroup->getNextName());
5220 name_le->setText(groupName);
5223 result = groupsModel->mapFromSource(iGrp);
5228 // ------------------------- LawDialog ----------------------------------
5229 // ============================================================== Constructeur
5231 LawDialog::LawDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5232 : HexaBaseDialog(parent, editmode, f),
5235 _helpFileName = "gui_discret_law.html#add-law";
5237 _initWidget(editmode);
5238 if ( editmode == NEW_MODE ){
5239 setWindowTitle( tr("Law Construction") );
5240 } else if ( editmode == UPDATE_MODE ){
5241 setWindowTitle( tr("Law Modification") );
5243 else if ( editmode == INFO_MODE){
5244 setWindowTitle( tr("Law Information") );
5248 // ============================================================== Destructeur
5249 LawDialog::~LawDialog()
5253 // ============================================================== _initInputWidget
5254 void LawDialog::_initInputWidget( Mode editmode )
5258 // setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5259 installEventFilter(this);
5261 // name_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5262 name_le->installEventFilter(this);
5265 strKind[ HEXA_NS::Uniform ] = "Uniform";
5266 strKind[ HEXA_NS::Arithmetic ] = "Arithmetic";
5267 strKind[ HEXA_NS::Geometric ] = "Geometric";
5270 QMap<HEXA_NS::KindLaw, QString>::ConstIterator iKind, iEnd;
5271 for( iKind = strKind.constBegin(), iEnd = strKind.constEnd(); iKind != iEnd; ++iKind )
5272 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5274 if (editmode == INFO_MODE)
5276 name_le->setReadOnly(true);
5277 nb_nodes_spb->setReadOnly(true);
5278 coeff_spb->setReadOnly(true);
5279 kind_cb->setEnabled(false);
5283 // ============================================================== clear
5284 void LawDialog::clear()
5288 modelUnregister(this);
5291 // ============================================================== setValue
5292 void LawDialog::setValue(HEXA_NS::Law* l)
5295 name_le->setText( l->getName() );
5297 nb_nodes_spb->setValue( l->getNodes() );
5298 coeff_spb->setValue( l->getCoefficient() );
5300 HEXA_NS::KindLaw k = l->getKind();
5301 kind_cb->setCurrentIndex( kind_cb->findData(k) );
5306 // ============================================================== getValue
5307 HEXA_NS::Law* LawDialog::getValue()
5312 // ============================================================== apply
5313 bool LawDialog::apply(QModelIndex& result)
5315 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5318 if ( !getDocumentModel() ) return false;
5320 const MeshModel* meshModel = getMeshModel();
5321 if (meshModel == NULL) return false;
5323 QString lawName = name_le->text();
5324 int nbnodes = nb_nodes_spb->value();
5325 double coeff = coeff_spb->value();
5326 DocumentModel::KindLaw lawKind = static_cast<DocumentModel::KindLaw>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5329 if ( _value == NULL ){ // create Law
5330 iLaw = getDocumentModel()->addLaw( lawName, nbnodes );
5332 QModelIndexList iLaws = getDocumentModel()->match(
5333 getDocumentModel()->index(0, 0),
5335 QVariant::fromValue( _value ),
5337 Qt::MatchRecursive );
5338 if ( !iLaws.isEmpty() )
5342 if ( !iLaw.isValid() ){
5343 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5346 //fill it and select it
5347 bool setOk = getDocumentModel()->setLaw( iLaw, nbnodes, coeff, lawKind );
5349 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5353 QString newName = name_le->text();
5354 if ( !newName.isEmpty() )/*{*/
5355 getDocumentModel()->setName( iLaw, newName );
5357 HEXA_NS::Law* hLaw = getDocumentModel()->data(iLaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
5361 name_le->setText(hLaw->getNextName(buffer));
5365 result = meshModel->mapFromSource(iLaw);
5370 // ------------------------- PropagationDialog ----------------------------------
5371 // ============================================================== Constructeur
5372 PropagationDialog::PropagationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5373 : HexaBaseDialog(parent, editmode, f),
5376 _helpFileName = "gui_propag.html";
5378 _initWidget(editmode);
5380 if ( editmode == INFO_MODE ){
5381 setWindowTitle( tr("Propagation Information") );
5384 } else if ( editmode == UPDATE_MODE ){
5385 setWindowTitle( tr("Propagation Modification") );
5388 } else if ( editmode == NEW_MODE ){
5389 setWindowTitle( tr("Propagation(s) Setting") );
5393 // ============================================================== Destructeur
5394 PropagationDialog::~PropagationDialog()
5398 // ============================================================== _initInputWidget
5399 void PropagationDialog::_initInputWidget( Mode editmode )
5402 QValidator *validator = new QRegExpValidator(rx, this);
5404 installEventFilter(this);
5407 law_le->setProperty( "HexaWidgetType", QVariant::fromValue(LAW_TREE) );
5408 law_le->installEventFilter(this);
5409 law_le->setValidator( validator );
5411 propagations_lw->setProperty( "HexaWidgetType", QVariant::fromValue(PROPAGATION_TREE) );
5412 propagations_lw->installEventFilter(this);
5414 QShortcut* delPropagationShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), propagations_lw);
5415 delPropagationShortcut->setContext( Qt::WidgetShortcut );
5417 law_le->setReadOnly(true);
5419 if ( editmode == INFO_MODE)
5420 way_cb->setEnabled(false);
5422 connect( delPropagationShortcut, SIGNAL(activated()), this, SLOT(deletePropagationItem()) );
5423 connect( propagations_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
5426 // ============================================================== clear
5427 void PropagationDialog::clear()
5429 propagations_lw->clear();
5430 modelUnregister(propagations_lw);
5433 modelUnregister(law_le);
5435 modelUnregister(this);
5438 // ============================================================== deletePropagationItem
5439 void PropagationDialog::deletePropagationItem()
5441 delete propagations_lw->currentItem();
5444 // ============================================================== setValue
5445 void PropagationDialog::setValue(HEXA_NS::Propagation* p)
5447 if (getMeshSelectionModel() == NULL) return;
5448 HEXA_NS::Law* l = p->getLaw();
5449 bool way = p->getWay();
5452 QModelIndex ip = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
5453 setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(ip) );
5455 // law on propagation
5457 law_le->setText( l->getName() );
5458 QModelIndex il = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(l) );
5459 law_le->setProperty( "QModelIndex", QVariant::fromValue<QModelIndex>(il) );
5462 // way of propagation
5463 way_cb->setChecked(way);
5468 // ============================================================== selectElementOfModel
5470 /*Selects in the model (treeview) elements selected in a listwidget,
5471 * or an element in a line edit.*/
5473 void PropagationDialog::selectElementOfModel()
5475 if (!getMeshSelectionModel()) return;
5477 QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5478 if ( !currentListWidget ) return;
5480 QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5482 getMeshSelectionModel()->clearSelection();
5483 foreach ( QListWidgetItem *item, sel ){
5484 //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
5485 index = getMeshSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5486 if ( index.isValid() )
5487 getMeshSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
5491 // ============================================================== getValue
5492 HEXA_NS::Propagation* PropagationDialog::getValue()
5497 // ============================================================== apply
5498 bool PropagationDialog::apply(QModelIndex& result)
5500 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5504 if ( !getDocumentModel() ) return false;
5505 const MeshModel* meshModel = getMeshModel();
5506 if (meshModel == NULL) return false;
5508 bool way = way_cb->isChecked();
5509 QListWidgetItem* item = NULL;
5511 QModelIndex iPropagation;
5512 QModelIndex iLaw = meshModel->mapToSource( law_le->property("QModelIndex").value<QModelIndex>() );
5513 if (!iLaw.isValid() ){
5514 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5518 int nbPropagations = propagations_lw->count();
5519 for (int r = 0; r < nbPropagations; ++r){
5520 item = propagations_lw->item(r);
5521 iPropagation = meshModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5522 if ( !iPropagation.isValid() ){
5523 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5527 //fill it and select it
5528 isOk = getDocumentModel()->setPropagation( iPropagation, iLaw, way );
5530 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) + "\n" + getErrorMsg() );
5534 result = meshModel->mapFromSource(iPropagation);
5540 // ------------------------- ComputeMeshDialog ----------------------------------
5541 // ============================================================== Constructeur
5542 ComputeMeshDialog::ComputeMeshDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5543 HexaBaseDialog(parent, editmode, f)
5545 _helpFileName = "gui_mesh.html";
5546 setWindowTitle( tr("Compute mesh") );
5547 QVBoxLayout* layout = new QVBoxLayout;
5550 QHBoxLayout* up = new QHBoxLayout;
5551 QHBoxLayout* down = new QHBoxLayout;
5553 layout->addLayout(up);
5554 layout->addLayout(down);
5556 QVBoxLayout* vlg = new QVBoxLayout;
5557 QVBoxLayout* vld = new QVBoxLayout;
5562 vlg->addWidget(new QLabel("Name"));
5563 vlg->addWidget(new QLabel("Dimension"));
5564 vlg->addWidget(new QLabel("Container"));
5566 _name = new QLineEdit("Mesh");
5567 _dim = new QSpinBox();
5568 _fact = new QLineEdit("FactoryServer");
5570 vld->addWidget(_name);
5571 vld->addWidget(_dim);
5572 vld->addWidget(_fact);
5574 _dim->setRange(1, 3);
5577 _initWidget(editmode);
5580 // ============================================================== Destructeur
5581 ComputeMeshDialog::~ComputeMeshDialog()
5585 // ============================================================== _initInputWidget
5586 void ComputeMeshDialog::_initInputWidget( Mode editmode )
5590 // ============================================================== setDocumentModel
5591 void ComputeMeshDialog::setDocumentModel(DocumentModel* m)
5593 if (m == NULL) return;
5594 _name->setText(m->getName());
5597 // ============================================================== clear
5598 void ComputeMeshDialog::clear()
5600 modelUnregister(this);
5603 // ============================================================== apply
5604 bool ComputeMeshDialog::apply(QModelIndex& result)
5606 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5609 if (getDocumentModel() == NULL) return false;
5610 QString command = QString("import hexablock ; %1 = hexablock.mesh(\"%2\", \"%1\", %3, \"%4\")")
5611 .arg( _name->text() )
5612 .arg( getDocumentModel()->getName() )
5613 .arg( _dim->value() )
5614 .arg( _fact->text() );
5616 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
5617 PyConsole_Console* pyConsole = app->pythonConsole();
5620 pyConsole->exec( command );
5627 // ------------------------- ReplaceHexaDialog ----------------------------------
5628 // ============================================================== Constructeur
5629 ReplaceHexaDialog::ReplaceHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5630 HexaBaseDialog(parent, editmode, f)
5632 _helpFileName = "gui_replace_hexa.html";
5634 _initWidget(editmode);
5637 // ============================================================== Destructeur
5638 ReplaceHexaDialog::~ReplaceHexaDialog()
5642 // ============================================================== getAssocsVTK
5644 * Returns elements currently associated to vtk
5646 QModelIndexList ReplaceHexaDialog::getAssocsVTK()
5648 QModelIndexList assocs;
5650 QListWidgetItem* item = NULL;
5652 //ListWidget content
5653 const PatternDataModel* patternDataModel = getPatternDataModel();
5654 if ( !patternDataModel ) return assocs;
5655 int nbQuads = quads_lw->count();
5656 for ( int r = 0; r < nbQuads; ++r ){
5657 item = quads_lw->item(r);
5658 // iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
5659 iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5660 if ( iQuad.isValid() ) assocs << iQuad;
5665 // ============================================================== _initInputWidget
5666 void ReplaceHexaDialog::_initInputWidget( Mode editmode )
5670 installEventFilter(this);
5672 c1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5673 c2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5674 c3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5676 p1_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5677 p2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5678 p3_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5680 c1_le->installEventFilter(this);
5681 c2_le->installEventFilter(this);
5682 c3_le->installEventFilter(this);
5684 p1_le->installEventFilter(this);
5685 p2_le->installEventFilter(this);
5686 p3_le->installEventFilter(this);
5688 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5689 quads_lw->installEventFilter(this);
5691 if ( editmode == NEW_MODE ){
5692 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5693 delQuadShortcut->setContext( Qt::WidgetShortcut );
5695 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()) );
5696 connect( quads_lw, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5699 c1_le->setReadOnly(true);
5700 c2_le->setReadOnly(true);
5701 c3_le->setReadOnly(true);
5703 p1_le->setReadOnly(true);
5704 p2_le->setReadOnly(true);
5705 p3_le->setReadOnly(true);
5707 connect(quads_lw, SIGNAL(itemSelectionChanged()),
5708 this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5711 // ============================================================== clear
5712 void ReplaceHexaDialog::clear()
5715 modelUnregister(quads_lw);
5718 modelUnregister(p1_le);
5721 modelUnregister(p2_le);
5724 modelUnregister(p3_le);
5727 modelUnregister(c1_le);
5730 modelUnregister(c2_le);
5733 modelUnregister(c3_le);
5735 modelUnregister(this);
5738 // ============================================================== updateButtonBox
5739 void ReplaceHexaDialog::updateButtonBox()
5741 int nbQuad = quads_lw->count();
5744 _applyButton->setEnabled(true);
5746 _applyButton->setEnabled(false);
5750 // ============================================================== deleteQuadItem
5751 void ReplaceHexaDialog::deleteQuadItem()
5753 delete quads_lw->currentItem();
5757 // ============================================================== apply
5758 bool ReplaceHexaDialog::apply(QModelIndex& result)
5760 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5763 if ( !getDocumentModel() ) return false;
5764 const PatternDataModel* patternDataModel = getPatternDataModel();
5765 const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
5766 if ( !patternDataModel || !patternBuilderModel) return false;
5768 QModelIndex ielts; //result
5770 QListWidgetItem* item = NULL;
5771 QModelIndexList iquads;
5773 int nbQuads = quads_lw->count();
5774 for ( int r = 0; r < nbQuads; ++r){
5775 item = quads_lw->item(r);
5776 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5777 if ( iquad.isValid() )
5781 QModelIndex ic1 = patternDataModel->mapToSource( _index[c1_le] );
5782 QModelIndex ic2 = patternDataModel->mapToSource( _index[c2_le] );
5783 QModelIndex ic3 = patternDataModel->mapToSource( _index[c3_le] );
5785 QModelIndex ip1 = patternDataModel->mapToSource( _index[p1_le] );
5786 QModelIndex ip2 = patternDataModel->mapToSource( _index[p2_le] );
5787 QModelIndex ip3 = patternDataModel->mapToSource( _index[p3_le] );
5789 if ( ic1.isValid() && ic2.isValid() && ic3.isValid()
5790 && ip1.isValid() && ip2.isValid() && ip3.isValid() ){
5791 ielts = getDocumentModel()->replace( iquads,
5797 if ( !ielts.isValid() ){
5798 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REPLACE HEXA" ) + "\n" + getErrorMsg() );
5801 _value = ielts.model()->data(ielts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
5802 result = patternBuilderModel->mapFromSource(ielts);
5804 //update the list (indexes)
5805 for ( int r = 0; r < nbQuads; ++r ){
5806 item = quads_lw->item(r);
5807 iquad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5808 item->setData( LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iquad) );
5809 item->setData(LW_DATA_ROLE, iquad.data(HEXA_DATA_ROLE));
5815 // ------------------------- QuadRevolutionDialog ----------------------------------
5816 // ============================================================== Constructeur
5818 QuadRevolutionDialog::QuadRevolutionDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5819 HexaBaseDialog(parent, editmode, f)
5822 _helpFileName = "gui_quad_revolution.html#guiquadsrevolution";
5823 connect( revolutionUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5824 connect( revolution_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5825 _initWidget(editmode);
5826 revolutionUni_rb->click();
5829 // ============================================================== getAssocsVTK
5831 * Returns elements currently associated to vtk
5833 QModelIndexList QuadRevolutionDialog::getAssocsVTK()
5835 QModelIndexList assocs;
5837 QListWidgetItem* item = NULL;
5838 if (getPatternDataSelectionModel() == NULL) return assocs;
5840 //ListWidget content
5841 const PatternDataModel* patternDataModel = getPatternDataModel();
5842 if ( !patternDataModel ) return assocs;
5843 int nbQuads = quads_lw->count();
5844 for ( int r = 0; r < nbQuads; ++r ){
5845 item = quads_lw->item(r);
5846 iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5847 if ( iQuad.isValid() )
5853 // ============================================================== Destructeur
5854 QuadRevolutionDialog::~QuadRevolutionDialog()
5858 // ============================================================== _initInputWidget
5859 void QuadRevolutionDialog::_initInputWidget( Mode editmode )
5861 quads_lw->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
5862 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
5863 axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
5865 installEventFilter(this);
5866 quads_lw->installEventFilter(this);
5867 center_le->installEventFilter(this);
5868 axis_le->installEventFilter(this);
5870 center_le->setReadOnly(true);
5871 axis_le->setReadOnly(true);
5873 angles_lw->setItemDelegate( new HexaAngleDoubleSpinBoxDelegate(angles_lw) );
5874 angles_lw->setEditTriggers( QAbstractItemView::DoubleClicked );
5876 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5877 delQuadShortcut->setContext( Qt::WidgetShortcut );
5878 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(delQuadItem()) );
5879 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()));
5880 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()));
5882 connect(quads_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5885 // ============================================================== updateHelpFileName
5886 void QuadRevolutionDialog::updateHelpFileName()
5888 if ( sender() == revolutionUni_rb ){
5889 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutionuniform";
5890 } else if ( sender() == revolution_rb ){
5891 _helpFileName = "gui_quad_revolution.html#guiquadsrevolutioncustom";
5895 // ============================================================== clear
5896 void QuadRevolutionDialog::clear()
5899 modelUnregister(quads_lw);
5902 modelUnregister(center_le);
5905 modelUnregister(axis_le);
5907 modelUnregister(this);
5910 // ============================================================== addAngleItem
5911 void QuadRevolutionDialog::addAngleItem() //CS_TODO
5913 QListWidgetItem* previousItem = angles_lw->currentItem();
5914 QListWidgetItem* newItem = new QListWidgetItem();
5916 double defaultValue = 180.;
5918 defaultValue = previousItem->data(Qt::EditRole).toDouble();
5920 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
5921 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
5922 angles_lw->addItem(newItem);
5927 // ============================================================== delAngleItem
5928 void QuadRevolutionDialog::delAngleItem()
5930 delete angles_lw->currentItem();
5934 // ============================================================== delQuadItem
5935 void QuadRevolutionDialog::delQuadItem()
5937 delete quads_lw->currentItem();
5941 // ============================================================== apply
5942 bool QuadRevolutionDialog::apply(QModelIndex& result)
5944 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5947 DocumentModel* docModel = getDocumentModel();
5948 PatternDataModel* patternDataModel = getPatternDataModel();
5949 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
5951 QListWidgetItem* item = NULL;
5953 QModelIndexList istartquads;
5955 int nbQuads = quads_lw->count();
5956 for ( int r = 0; r < nbQuads; ++r){
5957 item = quads_lw->item(r);
5958 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5959 if ( iquad.isValid() )
5960 istartquads << iquad;
5963 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
5964 QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
5965 int angle = angle_spb->value();
5966 int nbre = nbre_spb->value();
5968 vector<double> angles;
5969 int nbAngles = angles_lw->count();
5970 for ( int r = 0; r < nbAngles; ++r){
5971 item = angles_lw->item(r);
5972 angles.push_back(item->data(Qt::EditRole).toDouble());
5975 QModelIndex iElts; //result
5976 if (nbQuads == 1 && istartquads[0].isValid() && icenter.isValid() && iaxis.isValid())
5978 if (revolutionUni_rb->isChecked())
5979 iElts = docModel->revolutionQuadUni(istartquads[0], icenter, iaxis, angle, nbre);
5980 else if (revolution_rb->isChecked())
5981 iElts = docModel->revolutionQuad(istartquads[0], icenter, iaxis, angles);
5983 else if (nbQuads > 1 && icenter.isValid() && iaxis.isValid())
5985 if (revolutionUni_rb->isChecked())
5986 iElts = docModel->revolutionQuadsUni(istartquads, icenter, iaxis, angle, nbre);
5987 else if (revolution_rb->isChecked())
5988 iElts = docModel->revolutionQuads(istartquads, icenter, iaxis, angles);
5991 if ( !iElts.isValid() ){
5992 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD REVOLUTION" ) + "\n" + getErrorMsg() );
5995 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
5996 result = patternBuilderModel->mapFromSource(iElts);
6001 // ------------------------- MakeHemiSphereDialog ----------------------------------
6002 // ============================================================== Constructeur
6003 MakeHemiSphereDialog::MakeHemiSphereDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
6004 HexaBaseDialog(parent, editmode, f)
6006 _helpFileName = "gui_hemisphere.html";
6008 _initWidget(editmode);
6011 connect( sphereTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6012 connect( sphereUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6013 connect( sphere2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6014 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6015 connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6017 connect( sphericalTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6018 connect( sphericalUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6019 connect( spherical2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6020 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6021 connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6023 connect( rindTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6024 connect( rindUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6025 connect( rind2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
6026 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
6027 connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
6030 // ============================================================== Destructeur
6031 MakeHemiSphereDialog::~MakeHemiSphereDialog()
6035 // ============================================================== _initInputWidget
6036 void MakeHemiSphereDialog::_initInputWidget( Mode editmode )
6038 center_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6039 hole_axis_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6040 base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6041 vplan_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6043 installEventFilter(this);
6044 center_le->installEventFilter(this);
6045 hole_axis_le->installEventFilter(this);
6046 base_le->installEventFilter(this);
6047 vplan_le->installEventFilter(this);
6049 center_le->setReadOnly(true);
6050 hole_axis_le->setReadOnly(true);
6051 base_le->setReadOnly(true);
6052 vplan_le->setReadOnly(true);
6054 radius_lw_1->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_1));
6055 radius_lw_1->setEditTriggers(QAbstractItemView::DoubleClicked);
6057 radius_lw_2->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_2));
6058 radius_lw_2->setEditTriggers(QAbstractItemView::DoubleClicked);
6060 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
6061 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6063 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
6064 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
6066 connect( add_radius_pb_1, SIGNAL(clicked()), this, SLOT(addRadiusItem1()) );
6067 connect( del_radius_pb_1, SIGNAL(clicked()), this, SLOT(delRadiusItem1()) );
6069 connect( add_radius_pb_2, SIGNAL(clicked()), this, SLOT(addRadiusItem2()) );
6070 connect( del_radius_pb_2, SIGNAL(clicked()), this, SLOT(delRadiusItem2()) );
6072 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
6073 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
6075 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
6076 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
6079 // ============================================================== updateHelpFileName
6080 void MakeHemiSphereDialog::updateHelpFileName()
6082 if ( sender() == sphereTop_rb || sender() == rindTop_rb ){
6083 _helpFileName = "gui_hemisphere.html#guisphereandrindsimple";
6084 } else if ( sender() == sphereUni_rb ){
6085 _helpFileName = "gui_hemisphere.html#guisphereuniform";
6086 } else if ( sender() == sphere2_rb ){
6087 _helpFileName = "gui_hemisphere.html#guispherecustom";
6088 } else if ( sender() == rindUni_rb ){
6089 _helpFileName = "gui_hemisphere.html#guirinduniform";
6090 } else if ( sender() == rind2_rb ){
6091 _helpFileName = "gui_hemisphere.html#guirindcustom";
6092 } else if ( sender() == sphericalTop_rb ){
6093 _helpFileName = "gui_hemisphere.html#guiconcentricsimple";
6094 } else if ( sender() == sphericalUni_rb ){
6095 _helpFileName = "gui_hemisphere.html#guiconcentricuniform";
6096 } else if ( sender() == spherical2_rb ){
6097 _helpFileName = "gui_hemisphere.html#guiconcentriccustom";
6101 // ============================================================== addRadiusItem
6102 void MakeHemiSphereDialog::addRadiusItem1()
6104 QListWidgetItem* previousItem = radius_lw_1->currentItem();
6105 QListWidgetItem* newItem = new QListWidgetItem();
6107 double defaultValue = 1.;
6109 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6111 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6112 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6113 radius_lw_1->addItem(newItem);
6116 // ============================================================== delRadiusItem
6117 void MakeHemiSphereDialog::delRadiusItem1()
6119 delete radius_lw_1->currentItem();
6122 // ============================================================== addRadiusItem
6123 void MakeHemiSphereDialog::addRadiusItem2()
6125 QListWidgetItem* previousItem = radius_lw_2->currentItem();
6126 QListWidgetItem* newItem = new QListWidgetItem();
6128 double defaultValue = 1.;
6130 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6132 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6133 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6134 radius_lw_2->addItem(newItem);
6137 // ============================================================== delRadiusItem
6138 void MakeHemiSphereDialog::delRadiusItem2()
6140 delete radius_lw_2->currentItem();
6143 // ============================================================== addAngleItem
6144 void MakeHemiSphereDialog::addAngleItem()
6146 QListWidgetItem* previousItem = angle_lw->currentItem();
6147 QListWidgetItem* newItem = new QListWidgetItem();
6149 double defaultValue = 180.;
6151 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6153 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6154 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6155 angle_lw->addItem(newItem);
6158 // ============================================================== delAngleItem
6159 void MakeHemiSphereDialog::delAngleItem()
6161 delete angle_lw->currentItem();
6164 // ============================================================== addHeightItem
6165 void MakeHemiSphereDialog::addHeightItem()
6167 QListWidgetItem* previousItem = height_lw->currentItem();
6168 QListWidgetItem* newItem = new QListWidgetItem();
6170 double defaultValue = 1.;
6172 defaultValue = previousItem->data(Qt::EditRole).toDouble();
6174 newItem->setData( Qt::EditRole, QVariant(defaultValue) );
6175 newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6176 height_lw->addItem(newItem);
6179 // ============================================================== delHeightItem
6180 void MakeHemiSphereDialog::delHeightItem()
6182 delete height_lw->currentItem();
6185 // ============================================================== clear
6186 void MakeHemiSphereDialog::clear()
6189 modelUnregister(center_le);
6191 hole_axis_le->clear();
6192 modelUnregister(hole_axis_le);
6195 modelUnregister(base_le);
6198 modelUnregister(vplan_le);
6200 modelUnregister(this);
6203 // ============================================================== apply
6204 bool MakeHemiSphereDialog::apply(QModelIndex& result)
6206 if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6209 DocumentModel* docModel = getDocumentModel();
6210 PatternDataModel* patternDataModel = getPatternDataModel();
6211 PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6214 QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6215 QModelIndex ivplan = patternDataModel->mapToSource( _index[vplan_le] );
6216 QModelIndex ivecx = patternBuilderModel->mapToSource( _index[base_le] );
6217 QModelIndex ivecz = patternBuilderModel->mapToSource( _index[hole_axis_le] );
6219 double radhole = hole_rad_spb->value();
6220 double radext = sphere_radext_spb->value();
6221 double radint = sphere_radint_spb->value();
6222 double radang = radial_angle_spb->value();
6224 int crit = crit_spb->value();
6225 int nb = nbre_spb->value();
6226 int nrad = ngrid_rad_spb->value();
6227 int nang = ngrid_ang_spb->value();
6228 int nhaut = ngrid_height_spb->value();
6230 //radius, angles and heights collection
6231 QListWidgetItem* item = NULL;
6233 vector<double> radius1;
6234 vector<double> radius2;
6235 vector<double> angles;
6236 vector<double> heights;
6239 // double somme = 0.;
6240 int nbAngles = angle_lw->count();
6241 for ( int r = 0; r < nbAngles; ++r){
6242 item = angle_lw->item(r);
6243 double itemValue = item->data(Qt::EditRole).toDouble();
6244 angles.push_back(itemValue);
6245 // somme += itemValue;
6248 //radius1 collection
6249 int nbRadius = radius_lw_1->count();
6250 for ( int r = 0; r < nbRadius; ++r){
6251 item = radius_lw_1->item(r);
6252 radius1.push_back(item->data(Qt::EditRole).toDouble());
6255 //radius2 collection
6256 nbRadius = radius_lw_2->count();
6257 for ( int r = 0; r < nbRadius; ++r){
6258 item = radius_lw_2->item(r);
6259 radius2.push_back(item->data(Qt::EditRole).toDouble());
6262 //heights collection
6263 int nbHeight = height_lw->count();
6264 for ( int r = 0; r < nbHeight; ++r){
6265 item = height_lw->item(r);
6266 heights.push_back(item->data(Qt::EditRole).toDouble());
6269 if (sphere_rb->isChecked())
6271 if (sphereTop_rb->isChecked())
6272 iElts = docModel->makeSphereTop( nrad, nang, nhaut );
6273 else if (sphereUni_rb->isChecked())
6275 if (icenter.isValid() && ivplan.isValid() && ivecx.isValid() && ivecz.isValid())
6276 iElts = docModel->makeSphereUni(icenter, ivecx, ivecz, radhole, radext, radang,
6277 ivplan, nrad, nang, nhaut);
6279 else if (sphere2_rb->isChecked())
6281 // if (somme > 360.01)
6283 // SUIT_MessageBox::information( 0,
6285 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6288 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6289 iElts = docModel->makeSphere(icenter, ivecx, ivecz, radius2, angles, heights);
6292 else if (spherical_rb->isChecked())
6294 if (sphericalTop_rb->isChecked())
6295 iElts = docModel->makeSphericalTop(nb, crit);
6296 else if (sphericalUni_rb->isChecked())
6298 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6299 iElts = docModel->makeSphericalUni(icenter, ivecx, ivecz, radhole, nb, crit);
6301 else if (spherical2_rb->isChecked())
6303 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6304 iElts = docModel->makeSpherical(icenter, ivecx, ivecz, radius1, crit);
6307 else if (rind_rb->isChecked())
6309 if (rindTop_rb->isChecked())
6310 iElts = docModel->makeRindTop(nrad, nang, nhaut);
6311 else if (rindUni_rb->isChecked())
6313 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid() && ivplan.isValid())
6314 iElts = docModel->makeRindUni(icenter, ivecx, ivecz,
6315 radhole, radint, radext, radang,
6316 ivplan, nrad, nang, nhaut);
6318 else if (rind2_rb->isChecked())
6320 // if (somme > 360.01)
6322 // SUIT_MessageBox::information( 0,
6324 // tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6327 if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6328 iElts = docModel->makeRind(icenter, ivecx, ivecz, radius2, angles, heights);
6332 if ( !iElts.isValid() ){
6333 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) + "\n" + getErrorMsg() );
6336 _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6337 result = patternBuilderModel->mapFromSource(iElts);
6342 // ------------------------- ModelInfoDialog ----------------------------------
6343 ModelInfoDialog::ModelInfoDialog(QWidget* parent, Qt::WindowFlags wf):
6344 HexaBaseDialog(parent, INFO_MODE, wf)
6347 setWindowTitle(HEXABLOCKGUI::tr("MODEL_INFO"));
6350 void ModelInfoDialog::updateInfo()
6352 DocumentModel* docModel = getDocumentModel();
6353 if (docModel == NULL) return;
6356 model_name_le->setText(docModel->getName());
6358 //Nb of elements in the model
6359 total_vertices_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_VERTEX)));
6360 total_edges_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_EDGE)));
6361 total_quads_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_QUAD)));
6362 total_hexas_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_HEXA)));
6364 ///Nb of used elements in the model
6365 used_vertices_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_VERTEX)));
6366 used_edges_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_EDGE)));
6367 used_quads_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_QUAD)));
6368 used_hexas_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_HEXA)));
6370 //Nb of unused elements in the model
6371 unused_vertices_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_VERTEX)));
6372 unused_edges_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_EDGE)));
6373 unused_quads_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_QUAD)));
6374 unused_hexas_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_HEXA)));
6377 void ModelInfoDialog::showEvent( QShowEvent * event )
6380 QDialog::showEvent ( event );
6383 // ============================================================== hideEvent
6384 void ModelInfoDialog::hideEvent ( QHideEvent * event )
6386 QDialog::hideEvent( event );
6389 // ------------------------- AddShapeDialog ----------------------------------
6390 AddShapeDialog::AddShapeDialog(QWidget* parent, Mode editmode, Qt::WindowFlags wf):
6391 HexaBaseDialog(parent, editmode, wf)
6395 _initWidget(editmode);
6396 setWindowTitle(HEXABLOCKGUI::tr("ADD_SHAPE"));
6399 // ============================================================== Destructeur
6400 AddShapeDialog::~AddShapeDialog()
6402 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
6403 this, SLOT(onCurrentSelectionChanged()) );
6406 // ============================================================== close
6407 void AddShapeDialog::close()
6409 HEXABLOCKGUI::assocInProgress = false;
6410 HexaBaseDialog::close();
6413 // ============================================================== _initInputWidget
6414 void AddShapeDialog::_initInputWidget( Mode editmode )
6416 shape_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMSHAPE_TREE) );
6417 shape_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_SHAPE) );
6418 shape_le->installEventFilter(this);
6419 shape_le->setReadOnly(true);
6422 void AddShapeDialog::clear()
6425 shape_le->setProperty("GeomObj", QVariant());
6427 modelUnregister(this);
6430 // ============================================================== onCurrentSelectionChanged
6431 void AddShapeDialog::onCurrentSelectionChanged()
6433 SALOME_ListIO selectedObjects;
6434 HEXABLOCKGUI::currentDocGView->getSelected(selectedObjects);
6435 if (selectedObjects.IsEmpty())
6438 // * extract the TopoDS_Shape of the selected object
6439 TopoDS_Shape selectedTopoShape = GEOMBase::GetTopoFromSelection( selectedObjects );
6440 if (selectedTopoShape.IsNull())
6442 shape_le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(selectedTopoShape));
6444 // * extract the name of the selected shape
6446 GEOMBase::GetNameOfSelectedIObjects( selectedObjects, name, true );
6447 shape_le->setText(name);
6450 // ============================================================== onWindowActivated
6451 void AddShapeDialog::onWindowActivated(SUIT_ViewManager* vm)
6453 QString vmType = vm->getType();
6454 if ( vmType == OCCViewer_Viewer::Type() )
6455 shape_le->setFocus();
6458 // ============================================================== apply
6459 bool AddShapeDialog::apply(QModelIndex& result)
6462 QString shapeName = shape_le->text();
6463 QVariant v = shape_le->property("TopoDS_Shape");
6464 if ( !v.isValid() || shapeName.isEmpty())
6468 TopoDS_Shape shape = v.value<TopoDS_Shape>();
6472 assocOk = getDocumentModel()->addShape(shape, shapeName);
6476 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), HEXABLOCKGUI::tr("ADD_SHAPE_FAILED") + "\n" + getErrorMsg() );
6488 //***************************** OBSOLETE: A SUPPRIMER !!!! ************************************//
6490 // ============================================================== Constructeur
6491 CylinderDialog::CylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
6492 : HexaBaseDialog(parent, editmode, f),
6495 _helpFileName = "gui_cyl.html";
6497 _initWidget(editmode);
6499 if ( editmode == INFO_MODE ){
6500 setWindowTitle( tr("Cylinder Information") );
6504 // ============================================================== Destructeur
6505 CylinderDialog::~CylinderDialog()
6509 // ============================================================== _initInputWidget
6510 void CylinderDialog::_initInputWidget( Mode editmode )
6513 QValidator *validator = new QRegExpValidator(rx, this);
6515 installEventFilter(this);
6516 name_le->installEventFilter(this);
6518 vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6519 vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6521 vex_le->setValidator( validator );
6522 vec_le->setValidator( validator );
6524 vex_le->installEventFilter(this);
6525 vec_le->installEventFilter(this);
6527 vex_le->setReadOnly(true);
6528 vec_le->setReadOnly(true);
6530 if (editmode == INFO_MODE)
6532 name_le->setReadOnly(true);
6533 r_spb->setReadOnly(true);
6534 h_spb->setReadOnly(true);
6539 // ============================================================== clear
6540 void CylinderDialog::clear()
6545 modelUnregister(vex_le);
6548 modelUnregister(vec_le);
6553 modelUnregister(this);
6557 // ============================================================== setValue
6558 void CylinderDialog::setValue(HEXA_NS::Cylinder* c)
6560 HEXA_NS::Vertex* base = c->getBase();
6561 HEXA_NS::Vector* direction = c->getDirection();
6562 double r = c->getRadius();
6563 double h = c->getHeight();
6565 name_le->setText( c->getName() );
6566 vex_le->setText( base->getName() );
6567 vec_le->setText( direction->getName() );
6571 if ( getPatternDataSelectionModel() ){
6572 QModelIndex iCyl = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(c) );
6573 QModelIndex iBase = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(base) );
6574 QModelIndex iDirection = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(direction) );
6576 name_le->setProperty( "QModelIndex", QVariant::fromValue(iCyl) );
6577 vex_le->setProperty( "QModelIndex", QVariant::fromValue(iBase) );
6578 vec_le->setProperty( "QModelIndex", QVariant::fromValue(iDirection) );
6583 // ============================================================== getValue
6584 HEXA_NS::Cylinder* CylinderDialog::getValue()
6589 // ============================================================== apply
6590 bool CylinderDialog::apply(QModelIndex& result)
6592 // if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6593 // _currentObj = NULL;
6595 // if ( !getDocumentModel() ) return false;
6596 // const PatternDataModel* patternDataModel = getPatternDataModel();
6597 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6598 // if ( !patternDataModel || !patternBuilderModel) return false;
6600 // QModelIndex iCyl;
6601 // QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le] );
6602 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
6603 // double r = r_spb->value();
6604 // double h = h_spb->value();
6606 // if ( ivex.isValid()
6607 // && ivec.isValid() ){
6608 // iCyl = getDocumentModel()->addCylinder( ivex, ivec, r, h );
6611 // if ( !iCyl.isValid() ){
6612 // SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD CYLINDER" ) );
6616 // _value = iCyl.model()->data(iCyl, HEXA_DATA_ROLE).value<HEXA_NS::Cylinder *>();
6618 // QString newName = name_le->text();
6619 // if (!newName.isEmpty()) /*{*/
6620 // getDocumentModel()->setName( iCyl, newName );
6622 // //update the default name in the dialog box
6623 // if (_value != NULL)
6624 // updateDefaultName(name_le, _value->getType());
6626 // // to select/highlight result
6627 // result = patternBuilderModel->mapFromSource(iCyl);
6632 //------------------------------- PipeDialog -----------------------------------
6634 // ============================================================== Constructeur
6636 PipeDialog::PipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
6637 : HexaBaseDialog(parent, editmode, f),
6640 _helpFileName = "gui_pipe.html";
6642 _initWidget(editmode);
6643 // setFocusProxy( vex_le );
6645 if ( editmode == INFO_MODE ){
6646 setWindowTitle( tr("Pipe Information") );
6651 // ============================================================== Destructeur
6652 PipeDialog::~PipeDialog()
6656 // ============================================================== _initInputWidget
6657 void PipeDialog::_initInputWidget( Mode editmode )
6660 QValidator *validator = new QRegExpValidator(rx, this);
6662 installEventFilter(this);
6663 name_le->installEventFilter(this);
6665 //Vertex Field config
6666 vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
6667 vex_le->installEventFilter(this);
6668 vex_le->setValidator( validator );
6670 //Vector Field config
6671 vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
6672 vec_le->installEventFilter(this);
6673 vec_le->setValidator( validator );
6676 if ( editmode == INFO_MODE ){
6677 name_le->setReadOnly(true);
6678 ir_spb->setReadOnly(true);
6679 er_spb->setReadOnly(true);
6680 h_spb->setReadOnly(true);
6683 vex_le->setReadOnly(true);
6684 vec_le->setReadOnly(true);
6686 //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
6689 // ============================================================== clear
6690 void PipeDialog::clear()
6695 modelUnregister(vex_le);
6698 modelUnregister(vec_le);
6700 modelUnregister(this);
6703 // ============================================================== setValue
6704 void PipeDialog::setValue(HEXA_NS::Pipe* p)
6706 HEXA_NS::Vertex* base = p->getBase();
6707 HEXA_NS::Vector* direction = p->getDirection();
6708 double ir = p->getInternalRadius();
6709 double er = p->getRadius();
6710 double h = p->getHeight();
6712 name_le->setText( p->getName() );
6713 vex_le->setText( base->getName() );
6714 vec_le->setText( direction->getName() );
6715 ir_spb->setValue(ir);
6716 er_spb->setValue(er);
6719 if ( getPatternDataSelectionModel() ){
6720 QModelIndex iPipe = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
6721 QModelIndex iBase = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(base) );
6722 QModelIndex iDirection = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(direction) );
6724 name_le->setProperty( "QModelIndex", QVariant::fromValue(iPipe) );
6725 vex_le->setProperty( "QModelIndex", QVariant::fromValue(iBase) );
6726 vec_le->setProperty( "QModelIndex", QVariant::fromValue(iDirection) );
6731 // ============================================================== getValue
6732 HEXA_NS::Pipe* PipeDialog::getValue()
6737 // ============================================================== apply
6738 bool PipeDialog::apply(QModelIndex& result)
6740 // if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6741 // _currentObj = NULL;
6743 // if ( !getDocumentModel() ) return false;
6744 // const PatternDataModel* patternDataModel = getPatternDataModel();
6745 // const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6746 // if ( !patternDataModel || !patternBuilderModel) return false;
6748 // QModelIndex iPipe;
6749 // QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le] );
6750 // QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
6751 // double ir = ir_spb->value();
6752 // double er = er_spb->value();
6753 // double h = h_spb->value();
6756 // SUIT_MessageBox::information( this, tr( "CANNOT ADD PIPE" ), tr( "External radius must be greather than Internal radius!" ) );
6761 // if ( ivex.isValid()
6762 // && ivec.isValid() ){
6763 // iPipe = getDocumentModel()->addPipe( ivex, ivec, ir, er, h );
6766 // if ( !iPipe.isValid() ){
6767 // SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD PIPE" ) );
6770 // _value = iPipe.model()->data(iPipe, HEXA_DATA_ROLE).value<HEXA_NS::Pipe *>();
6772 // QString newName = name_le->text();
6773 // if ( !newName.isEmpty() )/*{*/
6774 // getDocumentModel()->setName( iPipe, newName );
6776 // //update the default name in the dialog box
6777 // if (_value != NULL)
6778 // updateDefaultName(name_le, _value->getType());
6780 // // to select/highlight result
6781 // result = patternBuilderModel->mapFromSource(iPipe);
6785 // ************************************** FIN A SUPPRIMER ******************************************//