1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : OperationGUI_GetSharedShapesDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25 #include "OperationGUI_GetSharedShapesDlg.h"
28 #include <GeometryGUI.h>
31 #include <GEOMImpl_Types.hxx>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_MessageBox.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
40 #include <TopoDS_Iterator.hxx>
41 #include <TopoDS_Shape.hxx>
45 GEOM::shape_type maxShapeType(const GEOM::ListOfGO& objs)
47 GEOM::shape_type r = GEOM::SHAPE;
48 for ( int i = 0; i < objs.length(); i++ ) {
49 GEOM::shape_type t = objs[i]->GetShapeType();
50 if ( t == GEOM::COMPOUND || t == GEOM::COMPSOLID )
51 t = objs[i]->GetMaxShapeType();
52 else if ( t < GEOM::VERTEX )
53 t = GEOM::shape_type( (int)t+1 );
55 if ( r <= GEOM::SOLID ) break;
61 //=================================================================================
62 // class : OperationGUI_GetSharedShapesDlg()
63 // purpose : Constructs a OperationGUI_GetSharedShapesDlg which is a child of 'parent', with the
64 // name 'name' and widget flags set to 'f'.
65 // The dialog will by default be modeless, unless you set 'modal' to
66 // TRUE to construct a modal dialog.
67 //=================================================================================
68 OperationGUI_GetSharedShapesDlg::OperationGUI_GetSharedShapesDlg
69 (GeometryGUI* theGeometryGUI, QWidget* parent)
70 : GEOMBase_Skeleton(theGeometryGUI, parent, false)
72 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
73 QPixmap image0(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_SHARED_SHAPES")));
74 QPixmap image2(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
76 setWindowTitle(tr("GEOM_SHARED_SHAPES_TITLE"));
78 /***************************************************************/
79 mainFrame()->GroupConstructors->setTitle(tr("GEOM_GET_SHARED_SHAPES"));
80 mainFrame()->RadioButton1->setIcon(image0);
81 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
82 mainFrame()->RadioButton2->close();
83 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
84 mainFrame()->RadioButton3->close();
86 GroupPoints = new DlgRef_2Sel1List1Check(centralWidget());
87 GroupPoints->GroupBox1->setTitle(tr("GEOM_SHARED_SHAPES_INPUT"));
88 GroupPoints->TextLabel1->setText(tr("GEOM_SHAPES"));
89 GroupPoints->TextLabel2->hide();
90 GroupPoints->TextLabel3->setText(tr("GEOM_SUBSHAPE_TYPE"));
91 GroupPoints->PushButton1->setIcon(image2);
92 GroupPoints->PushButton2->hide();
93 GroupPoints->LineEdit1->setReadOnly(true);
94 GroupPoints->LineEdit2->hide();
95 GroupPoints->LineEdit1->setEnabled(true);
96 GroupPoints->CheckButton1->setText(tr("GEOM_SHARED_SHAPES_MULTISHARE"));
98 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
99 layout->setMargin(0); layout->setSpacing(6);
100 layout->addWidget(GroupPoints);
102 /***************************************************************/
104 setHelpFileName("shared_shapes_page.html");
109 //=================================================================================
110 // function : ~OperationGUI_GetSharedShapesDlg()
111 // purpose : Destroys the object and frees any allocated resources
112 //=================================================================================
113 OperationGUI_GetSharedShapesDlg::~OperationGUI_GetSharedShapesDlg()
115 // no need to delete child widgets, Qt does it all for us
118 //=================================================================================
121 //=================================================================================
122 void OperationGUI_GetSharedShapesDlg::Init()
126 showOnlyPreviewControl();
128 /* signals and slots connections */
129 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
130 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
132 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
134 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
140 connect(GroupPoints->CheckButton1, SIGNAL(clicked()), this, SLOT(processPreview()));
142 connect(myGeomGUI->getApp()->selectionMgr(),
143 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
145 //initName(getNewObjectName());
146 initName(getPrefixByType());
148 ConstructorsClicked(0);
149 GroupPoints->PushButton1->click();
152 void OperationGUI_GetSharedShapesDlg::initTypes()
154 GEOM::shape_type t = maxShapeType( myListShapes );
156 int idx = GroupPoints->ComboBox1->count() > 0 ?
157 GroupPoints->ComboBox1->itemData( GroupPoints->ComboBox1->currentIndex() ).toInt() : -1;
159 GroupPoints->ComboBox1->clear();
161 if ( t == GEOM::SHAPE || t <= GEOM::SOLID )
162 GroupPoints->ComboBox1->addItem( tr( "GEOM_SOLID" ), int( GEOM::SOLID ) );
163 if ( t == GEOM::SHAPE || t <= GEOM::SHELL )
164 GroupPoints->ComboBox1->addItem( tr( "GEOM_SHELL" ), int( GEOM::SHELL ) );
165 if ( t == GEOM::SHAPE || t <= GEOM::FACE )
166 GroupPoints->ComboBox1->addItem( tr( "GEOM_FACE" ), int( GEOM::FACE ) );
167 if ( t == GEOM::SHAPE || t <= GEOM::WIRE )
168 GroupPoints->ComboBox1->addItem( tr( "GEOM_WIRE" ), int( GEOM::WIRE ) );
169 if ( t == GEOM::SHAPE || t <= GEOM::EDGE )
170 GroupPoints->ComboBox1->addItem( tr( "GEOM_EDGE" ), int( GEOM::EDGE ) );
171 if ( t == GEOM::SHAPE || t <= GEOM::VERTEX )
172 GroupPoints->ComboBox1->addItem( tr( "GEOM_VERTEX" ), int( GEOM::VERTEX ) );
174 idx = GroupPoints->ComboBox1->findData( idx );
175 GroupPoints->ComboBox1->setCurrentIndex( idx >= 0 ? idx : 0 );
181 //=================================================================================
182 // function : ConstructorsClicked()
183 // purpose : Radio button management
184 //=================================================================================
185 void OperationGUI_GetSharedShapesDlg::ConstructorsClicked (int constructorId)
187 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
190 myListShapes.length(0);
192 GroupPoints->PushButton1->setDown(true);
194 myEditCurrentArgument = GroupPoints->LineEdit1;
195 GroupPoints->LineEdit1->clear();
197 qApp->processEvents();
199 resize(minimumSizeHint());
201 myEditCurrentArgument->setFocus();
202 connect(myGeomGUI->getApp()->selectionMgr(),
203 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
204 SelectionIntoArgument();
207 //=================================================================================
208 // function : ClickOnOk()
210 //=================================================================================
211 void OperationGUI_GetSharedShapesDlg::ClickOnOk()
213 setIsApplyAndClose( true );
218 //=================================================================================
219 // function : ClickOnApply()
221 //=================================================================================
222 bool OperationGUI_GetSharedShapesDlg::ClickOnApply()
227 //initName(getNewObjectName());
228 initName(getPrefixByType());
233 //=================================================================================
234 // function : SelectionIntoArgument()
235 // purpose : Called when selection as changed or other case
236 //=================================================================================
237 void OperationGUI_GetSharedShapesDlg::SelectionIntoArgument()
239 myEditCurrentArgument->setText("");
240 QString aString = "";
242 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
243 SALOME_ListIO aSelList;
244 aSelMgr->selectedObjects(aSelList);
246 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
249 myListShapes.length(0);
252 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
256 if (!myListShapes.length())
259 myEditCurrentArgument->setText(aString);
263 //=================================================================================
264 // function : SetEditCurrentArgument()
266 //=================================================================================
267 void OperationGUI_GetSharedShapesDlg::SetEditCurrentArgument()
269 QPushButton* send = (QPushButton*)sender();
271 if (send == GroupPoints->PushButton1) {
272 myEditCurrentArgument = GroupPoints->LineEdit1;
273 GroupPoints->LineEdit1->setEnabled(true);
276 globalSelection(GEOM_ALLSHAPES);
278 myEditCurrentArgument->setFocus();
279 SelectionIntoArgument();
283 //=================================================================================
284 // function : ActivateThisDialog()
286 //=================================================================================
287 void OperationGUI_GetSharedShapesDlg::ActivateThisDialog()
289 GEOMBase_Skeleton::ActivateThisDialog();
290 connect(myGeomGUI->getApp()->selectionMgr(),
291 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
293 ConstructorsClicked(getConstructorId());
297 //=================================================================================
298 // function : enterEvent()
300 //=================================================================================
301 void OperationGUI_GetSharedShapesDlg::enterEvent(QEvent*)
303 if (!mainFrame()->GroupConstructors->isEnabled())
304 this->ActivateThisDialog();
307 //=======================================================================
308 //function : ComboTextChanged
310 //=======================================================================
311 void OperationGUI_GetSharedShapesDlg::ComboTextChanged()
313 //initName(getNewObjectName());
314 initName(getPrefixByType());
318 //=================================================================================
319 // function : GetType()
321 //=================================================================================
322 int OperationGUI_GetSharedShapesDlg::GetType() const
324 return GroupPoints->ComboBox1->count() > 0 ?
325 GroupPoints->ComboBox1->itemData( GroupPoints->ComboBox1->currentIndex() ).toInt() : (int)GEOM::SHAPE;
328 //=================================================================================
329 // function : createOperation
331 //=================================================================================
332 GEOM::GEOM_IOperations_ptr OperationGUI_GetSharedShapesDlg::createOperation()
334 return getGeomEngine()->GetIShapesOperations(getStudyId());
337 //=================================================================================
338 // function : isValid
340 //=================================================================================
341 bool OperationGUI_GetSharedShapesDlg::isValid (QString& msg)
343 bool isOK = myListShapes.length() > 1 ||
344 ( myListShapes.length() > 0 && myListShapes[0]->GetShapeType() == GEOM::COMPOUND );
347 msg = tr("MSG_SHARED_SHAPES_TOO_FEW_SHAPES");
352 //=================================================================================
353 // function : execute
355 //=================================================================================
356 bool OperationGUI_GetSharedShapesDlg::execute (ObjectList& objects)
358 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
359 GEOM::ListOfGO_var aList = anOper->GetSharedShapesMulti(myListShapes, GetType(), GroupPoints->CheckButton1->isChecked());
361 if (!aList->length())
364 if (aList->length() > 1)
365 myMainFrame->ResultName->setText(getPrefixByType());
367 for (int i = 0, n = aList->length(); i < n; i++)
368 objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
370 return objects.size();
373 //================================================================
374 // Function : getFather
375 // Purpose : Get father object for object to be added in study
376 // ( called with addInStudy method )
377 //================================================================
378 GEOM::GEOM_Object_ptr OperationGUI_GetSharedShapesDlg::getFather (GEOM::GEOM_Object_ptr)
380 if (myListShapes.length() > 0)
381 //return myListShapes[0]._retn();
382 return myListShapes[0];
386 //================================================================
387 // Function : getPrefixByType
389 //================================================================
390 QString OperationGUI_GetSharedShapesDlg::getPrefixByType () const
394 switch ( GetType() ) {
395 case GEOM::SOLID: aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_SOLID")) ; break;
396 case GEOM::SHELL: aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_SHELL")) ; break;
397 case GEOM::FACE: aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_FACE")) ; break;
398 case GEOM::WIRE: aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_WIRE")) ; break;
399 case GEOM::EDGE: aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_EDGE")) ; break;
400 case GEOM::VERTEX: aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_VERTEX")); break;
401 default: aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_SHAPE")) ; break;
407 //=================================================================================
408 // function : getSourceObjects
409 // purpose : virtual method to get source objects
410 //=================================================================================
411 QList<GEOM::GeomObjPtr> OperationGUI_GetSharedShapesDlg::getSourceObjects()
413 QList<GEOM::GeomObjPtr> res;
414 GEOM::ListOfGO aListPtr(myListShapes);
415 for (int i = 0; i < aListPtr.length(); i++) {
416 GEOM::GeomObjPtr aGeomObjPtr(aListPtr[i]);