1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ProfileDlg.h"
21 #include "HYDROGUI_Tool.h"
22 #include "HYDROGUI_AISTrihedron.h"
24 #include <HYDROGUI_Module.h>
25 #include "HYDROGUI_Tool2.h"
28 #include <CurveCreator_Widget.h>
29 #include <CurveCreator_ICurve.hxx>
30 #include <CurveCreator_Utils.hxx>
31 #include <HYDROGUI_CurveCreatorProfile.h>
32 #include <CurveCreator_Displayer.hxx>
34 #include <OCCViewer_ViewPort3d.h>
35 #include <OCCViewer_Utilities.h>
36 #include <OCCViewer_ViewManager.h>
37 #include <OCCViewer_ViewFrame.h>
40 #include <LightApp_Application.h>
42 #include <SUIT_Desktop.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_ResourceMgr.h>
47 #include <QHBoxLayout>
50 #include <QMouseEvent>
53 #include <QListWidget>
54 #include <QPushButton>
55 #include <SUIT_MessageBox.h>
57 const QString splitter_key = "HYDROGUI_ProfileDlg::splitter";
59 HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle,
61 : HYDROGUI_ViewerDlg( theModule, theTitle, true, false ),
62 myName( NULL ), myProfileNames (NULL), myProfilesPointer (NULL),
65 QFrame* name_frame = new QFrame( mainFrame() );
66 QHBoxLayout* name_layout = new QHBoxLayout( name_frame );
67 name_layout->setMargin( 0 );
68 QLabel* aNameLabel = new QLabel(tr("PROFILE_NAME_TLT"), this);
69 name_layout->addWidget(aNameLabel);
72 myName = new QLineEdit(this);
73 name_layout->addWidget(myName);
77 myProfileNames = new QListWidget(this);
78 myProfileNames->setSelectionMode(QAbstractItemView::SingleSelection);
79 name_layout->addWidget(myProfileNames);
80 myAddProfBtn = new QPushButton(tr("ADD_PROFILES"), this);
81 myRemProfBtn = new QPushButton(tr("REMOVE_PROFILE"), this);
82 name_layout->addWidget(myAddProfBtn);
83 name_layout->addWidget(myRemProfBtn);
86 insertWidget( name_frame, 0, 0 );
89 CurveCreator_Widget::DisableNewSection | CurveCreator_Widget::DisableDetectionMode |
90 CurveCreator_Widget::DisableClosedSection;
91 QStringList aCoordTitles;
92 aCoordTitles << tr( "U_TITLE" ) << tr( "Z_TITLE" );
93 myEditorWidget = new CurveCreator_Widget( this, NULL, anActionFlags, aCoordTitles );
94 insertWidget( myEditorWidget, 1, 1 );
96 myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this );
97 insertWidget( myAddElementBox, 2, 1 );
99 QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox );
100 anAddElementLayout->setMargin( 0 );
101 anAddElementLayout->setSpacing( 5 );
103 myEditorWidget->setOCCViewer( viewer() );
105 connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
106 connect( myEditorWidget, SIGNAL( subOperationStarted(QWidget*, bool) ), this, SLOT( processStartedSubOperation(QWidget*, bool) ) );
107 connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) );
110 connect( myProfileNames, SIGNAL( currentTextChanged(QString)), SLOT(ProfileNameChanged(QString)) );
111 connect( myProfileNames, SIGNAL( itemSelectionChanged()), this, SLOT( onProfileIndexChanged()));
112 connect( myProfileNames, SIGNAL( itemChanged(QListWidgetItem*)), this, SLOT( onProfileNameChanged(QListWidgetItem*)));
113 connect( myAddProfBtn, SIGNAL( clicked(bool)), this, SLOT( onAddBtnPressed(bool)));
114 connect( myRemProfBtn, SIGNAL( clicked(bool)), this, SLOT( onRemoveBtnPressed(bool)));
116 myAddElementBox->hide();
124 splitter()->setSizes( sizes );
128 splitter()->restoreState( settings.value( splitter_key ).toByteArray() );
132 HYDROGUI_ProfileDlg::~HYDROGUI_ProfileDlg()
136 settings.setValue( splitter_key, splitter()->saveState() );
140 void HYDROGUI_ProfileDlg::reset()
142 myEditorWidget->reset();
143 myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
144 viewer()->setTrihedronShown( false ); // Issue #548
145 viewer()->setStaticTrihedronDisplayed(false);
147 myProfileNames->clear();
150 void HYDROGUI_ProfileDlg::setProfileName( const QString& theName )
154 myName->setText(theName);
157 void HYDROGUI_ProfileDlg::eraseProfile( int index )
159 myProfileNames->takeItem(index);
160 if (myProfileNames->count() == 1)
161 myRemProfBtn->setEnabled(false);
164 void HYDROGUI_ProfileDlg::addProfileName( const QString& theName, const QColor& theColor )
168 myProfileNames->blockSignals(true);
169 myProfileNames->addItem(theName);
170 int count = myProfileNames->count();
171 QListWidgetItem* anItem = myProfileNames->item(count - 1);
172 anItem->setFlags (anItem->flags () | Qt::ItemIsEditable);
173 QPixmap SPixmap(16, 16);
174 SPixmap.fill(theColor);
175 QIcon SIcon(SPixmap);
176 anItem->setIcon( SIcon );
178 anItem->setSelected(true);
179 if (count == 1 && myIsEdit)
180 myRemProfBtn->setEnabled(false);
182 myRemProfBtn->setEnabled(true);
184 myProfileNames->blockSignals(false);
187 QStringList HYDROGUI_ProfileDlg::getProfileNames() const
189 QStringList aProfNames;
191 aProfNames << myName->text();
193 for (int i = 0; i < myProfileNames->count(); i++)
194 aProfNames << myProfileNames->item(i)->text();
198 void HYDROGUI_ProfileDlg::setProfile( CurveCreator_ICurve* theProfile )
200 myEditorWidget->setCurve( theProfile );
202 // select the single section by default
203 QList<int> aSections;
205 myEditorWidget->setSelectedSections( aSections );
208 void HYDROGUI_ProfileDlg::setProfilesPointer(std::vector<HYDROGUI_CurveCreatorProfile*>* theProfilesPointer)
210 myProfilesPointer = theProfilesPointer;
213 QList<int> HYDROGUI_ProfileDlg::getSelectedSections()
215 return myEditorWidget->getSelectedSections();
218 void HYDROGUI_ProfileDlg::switchToFirstProfile()
220 emit onProfileIndexChanged();
224 * Redirect the delete action to editor widget
226 void HYDROGUI_ProfileDlg::deleteSelected()
228 myEditorWidget->removeSelected();
232 * Checks whether there are some to delete
234 bool HYDROGUI_ProfileDlg::deleteEnabled()
236 return myEditorWidget->removeEnabled();
239 void HYDROGUI_ProfileDlg::processStartedSubOperation( QWidget* theWidget, bool theIsEdit )
241 myEditorWidget->setEnabled( false );
243 myAddElementBox->setTitle( theIsEdit ? tr( "EDIT_ELEMENT" ) : tr( "ADD_ELEMENT" ) );
244 QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
245 anAddElementLayout->addWidget( theWidget );
248 myAddElementBox->show();
251 void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
253 myEditorWidget->setEnabled( true );
255 QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
256 anAddElementLayout->removeWidget( theWidget );
259 myAddElementBox->hide();
262 void HYDROGUI_ProfileDlg::ProfileNameChanged(QString text)
264 myCurrentName = text;
267 void HYDROGUI_ProfileDlg::onProfileIndexChanged()
269 int theIndex = GetProfileSelectionIndex();
271 SwitchToProfile(theIndex);
274 int HYDROGUI_ProfileDlg::GetProfileSelectionIndex()
276 if (!myProfilesPointer)
278 QModelIndexList MI = myProfileNames->selectionModel()->selectedIndexes();
281 return MI.first().row();
284 void HYDROGUI_ProfileDlg::BlockProfileNameSignals(bool state)
286 myProfileNames->blockSignals(state);
289 void HYDROGUI_ProfileDlg::SwitchToProfile(int theIndex)
291 myEditorWidget->setCurve(NULL);
292 myEditorWidget->reset();
293 myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
294 myEditorWidget->setSelectedSections(QList<int>());
295 setProfile( (*myProfilesPointer)[theIndex] );
296 for (int i = 0; i < myProfilesPointer->size(); i++)
298 HYDROGUI_CurveCreatorProfile* aCurve = (*myProfilesPointer)[i];
301 aCurve->myLineWidth = 3;
302 Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
304 anAISObject->SetWidth(3);
308 aCurve->myLineWidth = 1;
309 Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
311 anAISObject->SetWidth(1);
315 if( myProfilesPointer &&
316 myProfilesPointer->size()>0 &&
317 myProfilesPointer->at(0) &&
318 myProfilesPointer->at(0)->getDisplayer() )
319 myProfilesPointer->at(0)->getDisplayer()->Update();
322 void HYDROGUI_ProfileDlg::onAddBtnPressed(bool)
327 void HYDROGUI_ProfileDlg::onRemoveBtnPressed(bool)
329 int theIndex = GetProfileSelectionIndex();
331 emit RemoveProfile(theIndex);
334 void HYDROGUI_ProfileDlg::onProfileNameChanged(QListWidgetItem* item)
336 int ind = GetProfileSelectionIndex();
339 int count = myProfileNames->count();
341 for (int i = 0; i < count; i++)
343 QListWidgetItem* citem = myProfileNames->item(i);
345 names << citem->text();
347 QString curText = item->text();
348 myProfileNames->blockSignals(true);
349 if (names.contains(curText))
351 QString mes = tr( "PROFILE_ALREADY_EXISTS" );
352 QString title = tr( "PROFILEDLG_WARNING" );
354 SUIT_MessageBox::warning( module()->getApp()->desktop(), title, mes );
356 item->setText(myCurrentName);
358 myProfileNames->blockSignals(false);
362 void HYDROGUI_ProfileDlg::SetSingleProfileMode(bool SingleMode)
364 mySingleProfileMode = SingleMode;
367 bool HYDROGUI_ProfileDlg::GetSingleProfileMode() const
369 return mySingleProfileMode;
372 Handle(AIS_Trihedron) HYDROGUI_ProfileDlg::trihedron()
374 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
375 Handle(AIS_Trihedron) aTrihedron =
376 HYDROGUI_AISTrihedron::createTrihedron( aResMgr->doubleValue( "3DViewer", "trihedron_size", viewer()->trihedronSize() ) );