1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : StdMeshersGUI_QuadrangleParamWdg.cxx
20 // Author : Open CASCADE S.A.S. (jfa)
23 #include "StdMeshersGUI_QuadrangleParamWdg.h"
26 #include "SMESHGUI_SpinBox.h"
27 #include "SMESHGUI_Utils.h"
28 #include "StdMeshersGUI_SubShapeSelectorWdg.h"
31 #include <LightApp_SelectionMgr.h>
32 #include <SALOME_ListIO.hxx>
33 #include <SUIT_ResourceMgr.h>
36 #include <QButtonGroup>
38 #include <QGridLayout>
42 #include <QListWidget>
43 #include <QListWidgetItem>
44 #include <QPushButton>
45 #include <QRadioButton>
46 #include <QTreeWidget>
47 #include <QVBoxLayout>
50 #include <SALOMEconfig.h>
51 #include CORBA_CLIENT_HEADER(SMESH_BasicHypothesis)
52 #include CORBA_CLIENT_HEADER(GEOM_Gen)
58 enum { TAB_TRANSITION, TAB_VERTEX, TAB_CORNERS, TAB_ENF_POINTS };
60 //================================================================================
61 // function : Constructor
63 //================================================================================
65 StdMeshersGUI_QuadrangleParamCreator::StdMeshersGUI_QuadrangleParamCreator(const QString& aHypType)
66 : StdMeshersGUI_StdHypothesisCreator( aHypType )
70 //=======================================================================
73 //=======================================================================
75 QString StdMeshersGUI_QuadrangleParamCreator::helpPage() const
77 return "2d_meshing_hypo.html#hypo-quad-params-anchor";
80 //=======================================================================
81 //function : buildFrame
83 //=======================================================================
85 QFrame* StdMeshersGUI_QuadrangleParamCreator::buildFrame()
87 QFrame* fr = new QFrame();
89 QGridLayout* lay = new QGridLayout( fr );
90 lay->setMargin( MARGIN );
91 lay->setSpacing( SPACING );
97 myName = new QLineEdit( fr );
98 QLabel* nameLab = new QLabel( tr("SMESH_NAME"));
99 lay->addWidget( nameLab, row, 0 );
100 lay->addWidget( myName, row, 1 );
106 myTypeWdg = new StdMeshersGUI_QuadrangleParamWdg( fr );
110 myVertexSelWdg = new StdMeshersGUI_SubShapeSelectorWdg( fr, TopAbs_VERTEX );
111 myVertexSelWdg->layout()->setMargin( MARGIN );
115 QWidget* pointsFrame = new QWidget( fr );
116 QVBoxLayout* pointsLay = new QVBoxLayout( pointsFrame );
117 pointsLay->setMargin(MARGIN);
118 pointsLay->setSpacing(SPACING);
121 QGroupBox* shapesGroup = new QGroupBox( tr("SHAPES"), pointsFrame );
122 myShapesList = new QListWidget( shapesGroup );
123 myAddShapeBut = new QPushButton( tr("SMESH_BUT_ADD"), shapesGroup );
124 QPushButton* remShapeBut = new QPushButton( tr("SMESH_BUT_REMOVE"), shapesGroup );
126 QGridLayout* shapesLay = new QGridLayout( shapesGroup );
127 shapesLay->setMargin(MARGIN);
128 shapesLay->setSpacing(SPACING);
129 shapesLay->addWidget( myShapesList, 0, 0, 3, 2 );
130 shapesLay->addWidget( myAddShapeBut, 0, 2 );
131 shapesLay->addWidget( remShapeBut, 1, 2 );
132 shapesLay->setColumnStretch( 0, 1 );
133 shapesLay->setRowStretch ( 2, 1 );
136 QGroupBox* coordsGroup = new QGroupBox( tr("POINTS"), pointsFrame );
137 myCoordsTreeWdg = new QTreeWidget( coordsGroup );
138 myCoordsTreeWdg->setColumnCount ( 3 );
139 myCoordsTreeWdg->setHeaderLabels( QStringList() << "X" << "Y" << "Z" );
140 myCoordsTreeWdg->setItemDelegate( new ItemDelegate( myCoordsTreeWdg ));
141 QPushButton* addCoordBut = new QPushButton( tr("SMESH_BUT_ADD"), coordsGroup );
142 QPushButton* remCoordBut = new QPushButton( tr("SMESH_BUT_REMOVE"), coordsGroup );
144 QGridLayout* coordsLay = new QGridLayout( coordsGroup );
145 coordsLay->setMargin(MARGIN);
146 coordsLay->setSpacing(SPACING);
147 coordsLay->addWidget( myCoordsTreeWdg, 0, 0, 3, 2 );
148 coordsLay->addWidget( addCoordBut, 0, 2 );
149 coordsLay->addWidget( remCoordBut, 1, 2 );
150 coordsLay->setColumnStretch( 0, 1 );
151 coordsLay->setRowStretch ( 2, 1 );
153 pointsLay->addWidget( shapesGroup );
154 pointsLay->addWidget( coordsGroup );
158 myCornersSelWdg = new StdMeshersGUI_SubShapeSelectorWdg( fr, TopAbs_VERTEX );
159 myCornersSelWdg->layout()->setMargin( MARGIN );
162 myTabs = new QTabWidget( fr );
163 myTabs->addTab( myTypeWdg, tr("TRANSITION"));
164 myTabs->addTab( myVertexSelWdg, tr("SMESH_BASE_VERTEX"));
165 myTabs->addTab( myCornersSelWdg, tr("CORNERS"));
166 myTabs->addTab( pointsFrame, tr("ENF_NODES"));
168 lay->addWidget( myTabs, row, 0, 2, 3 );
171 connect( myTypeWdg, SIGNAL( typeChanged(int)), SLOT( onTypeChanged(int)));
172 connect( myAddShapeBut, SIGNAL( clicked()), SLOT( onAddShape() ));
173 connect( remShapeBut, SIGNAL( clicked()), SLOT( onRemoveShape() ));
174 connect( addCoordBut, SIGNAL( clicked()), SLOT( onAddPoint() ));
175 connect( remCoordBut, SIGNAL( clicked()), SLOT( onRemovePoint() ));
176 connect( myTabs, SIGNAL( currentChanged(int)),SLOT( onTabChanged(int)));
178 LightApp_SelectionMgr* selMgr = SMESHGUI::GetSMESHGUI()->selectionMgr();
179 connect( selMgr, SIGNAL(currentSelectionChanged()), SLOT( onSelectionChanged()));
184 //=======================================================================
185 //function : retrieveParams
187 //=======================================================================
189 void StdMeshersGUI_QuadrangleParamCreator::retrieveParams() const
191 StdMeshers::StdMeshers_QuadrangleParams_var h =
192 StdMeshers::StdMeshers_QuadrangleParams::_narrow( initParamsHypothesis() );
196 myName->setText( hypName() );
199 myVertexSelWdg->SetMaxSize(1);
200 QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
201 QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
202 if ( anEntry.isEmpty() )
203 anEntry = h->GetObjectEntry();
204 myVertexSelWdg->SetGeomShapeEntry(anEntry,aMainEntry);
205 myCornersSelWdg->SetGeomShapeEntry(anEntry,aMainEntry);
210 myTypeWdg->SetType(int(h->GetQuadType()));
213 int vertID = h->GetTriaVertex();
215 SMESH::long_array_var aVec = new SMESH::long_array;
218 myVertexSelWdg->SetListOfIDs(aVec);
222 SMESH::long_array_var aVec = h->GetCorners();
223 myCornersSelWdg->SetListOfIDs( aVec );
226 GEOM::ListOfGO_var shapes;
227 SMESH::nodes_array_var points;
228 h->GetEnforcedNodes( shapes, points );
229 for ( CORBA::ULong i = 0; i < shapes->length(); ++i )
231 CORBA::String_var name = shapes[i]->GetName();
232 CORBA::String_var entry = shapes[i]->GetStudyEntry();
233 QListWidgetItem* item = new QListWidgetItem( name.in() );
234 item->setData( Qt::UserRole, entry.in() );
235 myShapesList->addItem( item );
237 for ( CORBA::ULong i = 0; i < points->length(); ++i )
239 QTreeWidgetItem* item = new QTreeWidgetItem
241 << QString::number( points[i].x )
242 << QString::number( points[i].y )
243 << QString::number( points[i].z ));
244 item->setFlags( item->flags() | Qt::ItemIsEditable );
245 myCoordsTreeWdg->addTopLevelItem( item );
248 ((StdMeshersGUI_QuadrangleParamCreator*) this)->onSelectionChanged();
251 //=======================================================================
252 //function : storeParams
254 //=======================================================================
256 QString StdMeshersGUI_QuadrangleParamCreator::storeParams() const
258 StdMeshers::StdMeshers_QuadrangleParams_var h =
259 StdMeshers::StdMeshers_QuadrangleParams::_narrow( hypothesis() );
263 SMESH::SetName( SMESH::FindSObject( h ), myName->text().toUtf8().constData() );
266 h->SetQuadType( StdMeshers::QuadType( myTypeWdg->GetType()) );
269 if ( myVertexSelWdg->GetListSize() > 0 )
271 h->SetTriaVertex( myVertexSelWdg->GetListOfIDs()[0] ); // getlist must be called once
272 h->SetObjectEntry( myVertexSelWdg->GetMainShapeEntry() );
276 h->SetTriaVertex( -1 );
280 h->SetCorners( myCornersSelWdg->GetListOfIDs() );
284 GEOM::ListOfGO_var goList = new GEOM::ListOfGO;
286 goList->length( myShapesList->count() );
287 for ( int i = 0; i < myShapesList->count(); ++i )
289 QListWidgetItem* item = myShapesList->item(i);
290 QString entry = item->data( Qt::UserRole ).toString();
291 GEOM::GEOM_Object_var go = SMESH::EntryToInterface<GEOM::GEOM_Object>( entry );
292 if ( !go->_is_nil() )
293 goList[ nbShapes++ ] = go;
295 goList->length( nbShapes );
297 SMESH::nodes_array_var points = new SMESH::nodes_array;
298 points->length( myCoordsTreeWdg->topLevelItemCount() );
299 for ( int i = 0; i < myCoordsTreeWdg->topLevelItemCount(); ++i )
301 QTreeWidgetItem* item = myCoordsTreeWdg->topLevelItem( i );
302 points[i].x = item->text(0).toInt();
303 points[i].y = item->text(1).toInt();
304 points[i].z = item->text(2).toInt();
306 h->SetEnforcedNodes( goList, points );
311 //=======================================================================
312 //function : onTypeChanged
314 //=======================================================================
316 void StdMeshersGUI_QuadrangleParamCreator::onTypeChanged(int type)
318 myTabs->setTabEnabled( TAB_ENF_POINTS, ( type != StdMeshers::QUAD_REDUCED ));
321 //=======================================================================
322 //function : onAddShape
324 //=======================================================================
326 void StdMeshersGUI_QuadrangleParamCreator::onAddShape()
328 if ( !mySelectedShapeIO.IsNull() )
330 QListWidgetItem* item = new QListWidgetItem( mySelectedShapeIO->getName() );
331 item->setData( Qt::UserRole, mySelectedShapeIO->getEntry() );
332 myShapesList->addItem( item );
333 mySelectedShapeIO.Nullify();
334 myAddShapeBut->setEnabled( false );
338 //=======================================================================
339 //function : onRemoveShape
341 //=======================================================================
343 void StdMeshersGUI_QuadrangleParamCreator::onRemoveShape()
345 if ( QListWidgetItem * item = myShapesList->currentItem() )
347 onSelectionChanged();
350 //=======================================================================
351 //function : onAddPoint
353 //=======================================================================
355 void StdMeshersGUI_QuadrangleParamCreator::onAddPoint()
357 QTreeWidgetItem* item = new QTreeWidgetItem( QStringList() << "0" << "0" << "0" );
358 item->setFlags( item->flags() | Qt::ItemIsEditable );
359 myCoordsTreeWdg->addTopLevelItem( item );
362 //=======================================================================
363 //function : onRemovePoint
365 //=======================================================================
367 void StdMeshersGUI_QuadrangleParamCreator::onRemovePoint()
369 if ( myCoordsTreeWdg->topLevelItemCount() )
370 delete myCoordsTreeWdg->currentItem();
373 //=======================================================================
374 //function : onSelectionChanged
376 //=======================================================================
378 void StdMeshersGUI_QuadrangleParamCreator::onSelectionChanged()
380 mySelectedShapeIO.Nullify();
382 // find a sole selected geometry
383 LightApp_SelectionMgr* selMgr = SMESHGUI::GetSMESHGUI()->selectionMgr();
384 SALOME_ListIO selList;
385 selMgr->selectedObjects( selList );
386 SALOME_ListIteratorOfListIO selIt( selList );
387 for ( ; selIt.More(); selIt.Next() )
389 GEOM::GEOM_Object_var go = GEOMBase::ConvertIOinGEOMObject( selIt.Value() );
390 if ( !go->_is_nil() )
392 if ( !mySelectedShapeIO.IsNull() )
394 mySelectedShapeIO.Nullify();
397 mySelectedShapeIO = selIt.Value();
398 if ( !mySelectedShapeIO->getName() || !mySelectedShapeIO->getName()[0] )
399 mySelectedShapeIO.Nullify();
402 // check if a selected geometry is not already in myShapesList
403 if ( !mySelectedShapeIO.IsNull() )
405 for ( int i = 0; i < myShapesList->count(); ++i )
406 if ( myShapesList->item(i)->data( Qt::UserRole ) == mySelectedShapeIO->getEntry() )
408 mySelectedShapeIO.Nullify();
412 myAddShapeBut->setEnabled( !mySelectedShapeIO.IsNull() );
415 //=======================================================================
416 //function : onTabChanged
418 //=======================================================================
420 void StdMeshersGUI_QuadrangleParamCreator::onTabChanged(int i)
422 myVertexSelWdg->ShowPreview( i == TAB_VERTEX );
423 myCornersSelWdg->ShowPreview( i == TAB_CORNERS );
426 //================================================================================
427 // function : Constructor
429 //================================================================================
431 StdMeshersGUI_QuadrangleParamWdg::StdMeshersGUI_QuadrangleParamWdg (QWidget * parent)
432 : QWidget(parent), myType(0)
434 myType = new QButtonGroup (this);
436 QGridLayout* typeLay = new QGridLayout( this );
438 typeLay->setMargin(MARGIN);
439 typeLay->setSpacing(SPACING);
441 QString aTypeKey ("SMESH_QUAD_TYPE_%1");
442 QString aPictKey ("ICON_StdMeshers_Quadrangle_Params_%1");
445 for (; itype < int(StdMeshers::QUAD_NB_TYPES); itype++) {
446 QRadioButton* rbi = new QRadioButton (tr(aTypeKey.arg(itype).toLatin1()), this);
447 QPixmap pmi (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr(aPictKey.arg(itype).toLatin1())));
448 QLabel* pli = new QLabel (this);
450 typeLay->addWidget(rbi, itype, 0, 1, 1);
451 typeLay->addWidget(pli, itype, 1, 1, 1);
452 myType->addButton(rbi, itype);
454 myType->button(0)->setChecked(true);
457 setMinimumWidth(300);
459 connect( myType, SIGNAL( buttonClicked(int)), this, SIGNAL( typeChanged(int)));
462 //================================================================================
463 // function : Destructor
465 //================================================================================
466 StdMeshersGUI_QuadrangleParamWdg::~StdMeshersGUI_QuadrangleParamWdg()
470 //=================================================================================
471 // function : SetType
473 //=================================================================================
474 void StdMeshersGUI_QuadrangleParamWdg::SetType (int theType)
476 myType->button(theType)->setChecked(true);
479 //=================================================================================
480 // function : GetType
482 //=================================================================================
483 int StdMeshersGUI_QuadrangleParamWdg::GetType()
485 return myType->checkedId();
488 //================================================================================
492 StdMeshersGUI_QuadrangleParamCreator::
493 ItemDelegate::ItemDelegate( QObject* parent ) : QItemDelegate( parent )
496 //================================================================================
498 \brief Create item editor widget
500 QWidget* StdMeshersGUI_QuadrangleParamCreator::
501 ItemDelegate::createEditor( QWidget* parent,
502 const QStyleOptionViewItem& /*option*/,
503 const QModelIndex& /*index*/ ) const
505 SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox( parent );
506 sb->RangeStepAndValidator( COORD_MIN, COORD_MAX, 10 );