- SUIT_OverrideCursor wc;
- if ( !_documentModel ) return false;
- if ( !_patternBuilderSelectionModel ) return false;
- if ( !_patternDataSelectionModel ) return false;
- const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
- const PatternDataModel* patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
- if ( !patternBuilderModel ) return false;
- if ( !patternDataModel ) return false;
- _currentObj = NULL;
-
- QModelIndex iElts;
- QModelIndex icenter = patternDataModel->mapToSource( _index[sphere_center_le] );
- QModelIndex iplorig = patternDataModel->mapToSource( _index[cross_pt_le] );
- QModelIndex ivecx = patternBuilderModel->mapToSource( _index[radial_vec_le] );
- QModelIndex ivecz = patternBuilderModel->mapToSource( _index[hole_axis_le] );
-
- double radext = sphere_radext_spb->value();
- double radhole = hole_rad_spb->value();
-
- int nrad = ngrid_rad_spb->value();
- int nang = ngrid_ang_spb->value();
- int nhaut = ngrid_height_spb->value();
-
-
- if ( icenter.isValid() && ivecx.isValid() && ivecz.isValid() && iplorig.isValid() ){
- if ( sphere_rind_cb->isChecked() ){ // rind
- double radint = sphere_radint_spb->value();
- if ( radial_partial_cb->isChecked() ){
- double angle = radial_angle_spb->value();
- iElts = _documentModel->makePartRind( icenter, ivecx, ivecz,
- radext, radint, radhole,
- iplorig, angle,
- nrad, nang, nhaut );
- } else {
- iElts = _documentModel->makeRind( icenter,
- ivecx, ivecz,
- radext, radint, radhole,
- iplorig,
- nrad, nang, nhaut );
- }
- } else { // sphere
- if ( radial_partial_cb->isChecked() ){
- double angle = radial_angle_spb->value();
- iElts = _documentModel->makePartSphere( icenter, ivecx, ivecz,
- radext, radhole,
- iplorig, angle,
- nrad, nang, nhaut );
- } else {
- iElts = _documentModel->makeSphere( icenter,
- ivecx, ivecz,
- radext, radhole,
- iplorig,
- nrad, nang, nhaut );
- }
- }
- }
-
-
- if ( !iElts.isValid() ){
- SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) );
- return false;
- }
- _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
-
- QString newName = name_le->text();
- if ( !newName.isEmpty() )/*{*/
- _documentModel->setName( iElts, newName );
-
- result = patternBuilderModel->mapFromSource(iElts);
-
- return true;
-}
-// ==============================================================
-
-
-// MakeRindDialog::MakeRindDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
-// HexaBaseDialog(parent, editmode, f)
-// {
-// // _helpFileName()
-// setupUi( this );
-// setWindowTitle( tr("MAKE RIND") );
-//
-// if ( editmode == NEW_MODE ){
-// _initButtonBox( editmode );
-//
-// //selection management
-// _vertexLineEdits << center_le << plorig_le;
-// _vectorLineEdits << vx_le << vz_le;
-//
-// center_le->installEventFilter(this);
-// plorig_le->installEventFilter(this);
-// vx_le->installEventFilter(this);
-// vz_le->installEventFilter(this);
-// }
-// }
-//
-//
-// MakeRindDialog::~MakeRindDialog()
-// {
-// }
-//
-//
-//
-// bool MakeRindDialog::apply(QModelIndex& result)
-// {
-// SUIT_OverrideCursor wc;
-// if ( !_documentModel ) return false;
-// if ( !_patternBuilderSelectionModel ) return false;
-// if ( !_patternDataSelectionModel ) return false;
-// const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
-// const PatternDataModel* patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
-// if ( !patternBuilderModel ) return false;
-// if ( !patternDataModel ) return false;
-//
-// QModelIndex iElts;
-// QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
-// QModelIndex iplorig = patternDataModel->mapToSource( _index[plorig_le] );
-// QModelIndex ivecx = patternBuilderModel->mapToSource( _index[vx_le] );
-// QModelIndex ivecz = patternBuilderModel->mapToSource( _index[vz_le] );
-//
-// double radext = radext_spb->value();
-// double radint = radint_spb->value();
-// double radhole = radhole_spb->value();
-//
-// int nrad = nrad_spb->value();
-// int nang = nang_spb->value();
-// int nhaut = nhaut_spb->value();
-//
-// if ( icenter.isValid() && ivecx.isValid() && ivecz.isValid() && iplorig.isValid() ){
-// if ( partial_cb->isChecked() ){
-// double angle = angle_spb->value(); // Part Rind only
-// iElts = _documentModel->makePartRind( icenter, ivecx, ivecz,
-// radext, radint, radhole,
-// iplorig, angle,
-// nrad, nang, nhaut );
-// } else {
-// iElts = _documentModel->makeRind( icenter,
-// ivecx, ivecz,
-// radext, radint, radhole,
-// iplorig,
-// nrad, nang, nhaut );
-// }
-// }
-//
-// if ( !iElts.isValid() ){
-// SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) );
-// return false;
-// }
-//
-// QString newName = name_le->text();
-// if (!newName.isEmpty()) _documentModel->setName( iElts, newName );
-//
-// return true;
-// }
-
-// QVariant v = lineEdit->property("index");
-// if ( v.isValid() ){
-// MESSAGE("* get index ... " );
-// QModelIndex i = v.value<QModelIndex>();
-// _selectionMutex = true;
-// _patternDataSelectionModel->select( i, QItemSelectionModel::Clear );
-// _patternDataSelectionModel->select( i, QItemSelectionModel::Select );
-// _selectionMutex = false;
-// }
+ if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
+ _currentObj = NULL;
+
+ DocumentModel* docModel = getDocumentModel();
+ PatternDataModel* patternDataModel = getPatternDataModel();
+// PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
+
+ QModelIndex iElts;
+ QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
+ QModelIndex ivplan = patternDataModel->mapToSource( _index[vplan_le] );
+ QModelIndex ivecx = patternDataModel->mapToSource(_index[base_le]);
+ QModelIndex ivecz = patternDataModel->mapToSource(_index[hole_axis_le]);
+// QModelIndex ivecx = patternBuilderModel->mapToSource( _index[base_le] );
+// QModelIndex ivecz = patternBuilderModel->mapToSource( _index[hole_axis_le] );
+
+ double radhole = hole_rad_spb->value();
+ double radext = sphere_radext_spb->value();
+ double radint = sphere_radint_spb->value();
+ double radang = radial_angle_spb->value();
+
+ int crit = crit_spb->value();
+ int nb = nbre_spb->value();
+ int nrad = ngrid_rad_spb->value();
+ int nang = ngrid_ang_spb->value();
+ int nhaut = ngrid_height_spb->value();
+
+ //radius, angles and heights collection
+ QListWidgetItem* item = NULL;
+
+ vector<double> radius1;
+ vector<double> radius2;
+ vector<double> angles;
+ vector<double> heights;
+
+ //angles collection
+// double somme = 0.;
+ int nbAngles = angle_lw->count();
+ for ( int r = 0; r < nbAngles; ++r){
+ item = angle_lw->item(r);
+ double itemValue = item->data(Qt::EditRole).toDouble();
+ angles.push_back(itemValue);
+// somme += itemValue;
+ }
+
+ //radius1 collection
+ int nbRadius = radius_lw_1->count();
+ for ( int r = 0; r < nbRadius; ++r){
+ item = radius_lw_1->item(r);
+ radius1.push_back(item->data(Qt::EditRole).toDouble());
+ }
+
+ //radius2 collection
+ nbRadius = radius_lw_2->count();
+ for ( int r = 0; r < nbRadius; ++r){
+ item = radius_lw_2->item(r);
+ radius2.push_back(item->data(Qt::EditRole).toDouble());
+ }
+
+ //heights collection
+ int nbHeight = height_lw->count();
+ for ( int r = 0; r < nbHeight; ++r){
+ item = height_lw->item(r);
+ heights.push_back(item->data(Qt::EditRole).toDouble());
+ }
+
+ if (sphere_rb->isChecked())
+ {
+ if (sphereTop_rb->isChecked())
+ iElts = docModel->makeSphereTop( nrad, nang, nhaut );
+ else if (sphereUni_rb->isChecked())
+ {
+ if (icenter.isValid() && ivplan.isValid() && ivecx.isValid() && ivecz.isValid())
+ iElts = docModel->makeSphereUni(icenter, ivecx, ivecz, radhole, radext, radang,
+ ivplan, nrad, nang, nhaut);
+ }
+ else if (sphere2_rb->isChecked())
+ {
+// if (somme > 360.01)
+// {
+// SUIT_MessageBox::information( 0,
+// tr("HEXA_INFO"),
+// tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
+// return false;
+// }
+ if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
+ iElts = docModel->makeSphere(icenter, ivecx, ivecz, radius2, angles, heights);
+ }
+ }
+ else if (spherical_rb->isChecked())
+ {
+ if (sphericalTop_rb->isChecked())
+ iElts = docModel->makeSphericalTop(nb, crit);
+ else if (sphericalUni_rb->isChecked())
+ {
+ if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
+ iElts = docModel->makeSphericalUni(icenter, ivecx, ivecz, radhole, nb, crit);
+ }
+ else if (spherical2_rb->isChecked())
+ {
+ if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
+ iElts = docModel->makeSpherical(icenter, ivecx, ivecz, radius1, crit);
+ }
+ }
+ else if (rind_rb->isChecked())
+ {
+ if (rindTop_rb->isChecked())
+ iElts = docModel->makeRindTop(nrad, nang, nhaut);
+ else if (rindUni_rb->isChecked())
+ {
+ if (icenter.isValid() && ivecx.isValid() && ivecz.isValid() && ivplan.isValid())
+ iElts = docModel->makeRindUni(icenter, ivecx, ivecz,
+ radhole, radint, radext, radang,
+ ivplan, nrad, nang, nhaut);
+ }
+ else if (rind2_rb->isChecked())
+ {
+// if (somme > 360.01)
+// {
+// SUIT_MessageBox::information( 0,
+// tr("HEXA_INFO"),
+// tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
+// return false;
+// }
+ if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
+ iElts = docModel->makeRind(icenter, ivecx, ivecz, radius2, angles, heights);
+ }
+ }
+
+ if ( !iElts.isValid() ){
+ SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) + "\n" + getErrorMsg() );
+ return false;
+ }
+ _value = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
+ result = patternDataModel->mapFromSource(iElts);
+// result = patternBuilderModel->mapFromSource(iElts);
+
+ return true;
+}
+
+// ------------------------- ModelInfoDialog ----------------------------------
+ModelInfoDialog::ModelInfoDialog(QWidget* parent, Qt::WindowFlags wf):
+ HexaBaseDialog(parent, INFO_MODE, wf)
+{
+ setupUi( this );
+ setWindowTitle(HEXABLOCKGUI::tr("MODEL_INFO"));
+}
+
+void ModelInfoDialog::updateInfo()
+{
+ DocumentModel* docModel = getDocumentModel();
+ if (docModel == NULL) return;
+
+ //Model name
+ model_name_le->setText(docModel->getName());
+
+ //Nb of elements in the model
+ total_vertices_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_VERTEX)));
+ total_edges_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_EDGE)));
+ total_quads_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_QUAD)));
+ total_hexas_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_HEXA)));
+
+ ///Nb of used elements in the model
+ used_vertices_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_VERTEX)));
+ used_edges_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_EDGE)));
+ used_quads_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_QUAD)));
+ used_hexas_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_HEXA)));
+
+ //Nb of unused elements in the model
+ unused_vertices_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_VERTEX)));
+ unused_edges_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_EDGE)));
+ unused_quads_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_QUAD)));
+ unused_hexas_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_HEXA)));
+}
+
+void ModelInfoDialog::showEvent( QShowEvent * event )
+{
+ updateInfo();
+ QDialog::showEvent ( event );
+}
+
+// ============================================================== hideEvent
+void ModelInfoDialog::hideEvent ( QHideEvent * event )
+{
+ QDialog::hideEvent( event );
+}
+
+// ------------------------- AddShapeDialog ----------------------------------
+AddShapeDialog::AddShapeDialog(QWidget* parent, Mode editmode, Qt::WindowFlags wf):
+ HexaBaseDialog(parent, editmode, wf)
+{
+ _helpFileName = "gui_add_geometry.html#guiaddgeometry";
+ setupUi( this );
+ _initWidget(editmode);
+ setWindowTitle(HEXABLOCKGUI::tr("ADD_SHAPE"));
+}
+
+// ============================================================== Destructeur
+AddShapeDialog::~AddShapeDialog()
+{
+ disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
+ this, SLOT(onCurrentSelectionChanged()) );
+}
+
+// ============================================================== close
+void AddShapeDialog::close()
+{
+ HEXABLOCKGUI::assocInProgress = false;
+ HexaBaseDialog::close();
+}
+
+// ============================================================== _initInputWidget
+void AddShapeDialog::_initInputWidget( Mode editmode )
+{
+ shape_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMSHAPE_TREE) );
+ shape_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_SHAPE) );
+ shape_le->installEventFilter(this);
+ shape_le->setReadOnly(true);
+}
+
+void AddShapeDialog::clear()
+{
+ shape_le->clear();
+ shape_le->setProperty("GeomObj", QVariant());
+
+ modelUnregister(this);
+}
+
+// ============================================================== onCurrentSelectionChanged
+void AddShapeDialog::onCurrentSelectionChanged()
+{
+ SALOME_ListIO selectedObjects;
+ HEXABLOCKGUI::currentDocGView->getSelected(selectedObjects);
+ if (selectedObjects.IsEmpty())
+ return;
+
+ // * extract the TopoDS_Shape of the selected object
+ TopoDS_Shape selectedTopoShape = GEOMBase::GetTopoFromSelection( selectedObjects );
+ if (selectedTopoShape.IsNull())
+ return;
+ shape_le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(selectedTopoShape));
+
+ // * extract the name of the selected shape
+ QString name;
+ GEOMBase::GetNameOfSelectedIObjects( selectedObjects, name, true );
+ shape_le->setText(name);
+}
+
+// ============================================================== onWindowActivated
+void AddShapeDialog::onWindowActivated(SUIT_ViewManager* vm)
+{
+ QString vmType = vm->getType();
+ if ( vmType == OCCViewer_Viewer::Type() )
+ shape_le->setFocus();
+}
+
+// ============================================================== apply
+bool AddShapeDialog::apply(QModelIndex& result)
+{
+ bool assocOk;
+ QString shapeName = shape_le->text();
+ QVariant v = shape_le->property("TopoDS_Shape");
+ if ( !v.isValid() || shapeName.isEmpty())
+ assocOk = false;
+ else
+ {
+ TopoDS_Shape shape = v.value<TopoDS_Shape>();
+ if (shape.IsNull())
+ assocOk = false;
+ else
+ assocOk = getDocumentModel()->addShape(shape, shapeName);
+ }
+
+ if ( !assocOk ){
+ SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), HEXABLOCKGUI::tr("ADD_SHAPE_FAILED") + "\n" + getErrorMsg() );
+ return false;
+ }
+
+ return true;
+}