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 ),
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
146 myProfileNames->clear();
149 void HYDROGUI_ProfileDlg::setProfileName( const QString& theName )
153 myName->setText(theName);
156 void HYDROGUI_ProfileDlg::eraseProfile( int index )
158 myProfileNames->takeItem(index);
159 if (myProfileNames->count() == 1)
160 myRemProfBtn->setEnabled(false);
163 void HYDROGUI_ProfileDlg::addProfileName( const QString& theName, const QColor& theColor )
167 myProfileNames->blockSignals(true);
168 myProfileNames->addItem(theName);
169 int count = myProfileNames->count();
170 QListWidgetItem* anItem = myProfileNames->item(count - 1);
171 anItem->setFlags (anItem->flags () | Qt::ItemIsEditable);
172 QPixmap SPixmap(16, 16);
173 SPixmap.fill(theColor);
174 QIcon SIcon(SPixmap);
175 anItem->setIcon( SIcon );
177 anItem->setSelected(true);
178 if (count == 1 && myIsEdit)
179 myRemProfBtn->setEnabled(false);
181 myRemProfBtn->setEnabled(true);
183 myProfileNames->blockSignals(false);
186 QStringList HYDROGUI_ProfileDlg::getProfileNames() const
188 QStringList aProfNames;
190 aProfNames << myName->text();
192 for (int i = 0; i < myProfileNames->count(); i++)
193 aProfNames << myProfileNames->item(i)->text();
197 void HYDROGUI_ProfileDlg::setProfile( CurveCreator_ICurve* theProfile )
199 myEditorWidget->setCurve( theProfile );
201 // select the single section by default
202 QList<int> aSections;
204 myEditorWidget->setSelectedSections( aSections );
207 void HYDROGUI_ProfileDlg::setProfilesPointer(std::vector<HYDROGUI_CurveCreatorProfile*>* theProfilesPointer)
209 myProfilesPointer = theProfilesPointer;
212 QList<int> HYDROGUI_ProfileDlg::getSelectedSections()
214 return myEditorWidget->getSelectedSections();
217 void HYDROGUI_ProfileDlg::switchToFirstProfile()
219 emit onProfileIndexChanged();
223 * Redirect the delete action to editor widget
225 void HYDROGUI_ProfileDlg::deleteSelected()
227 myEditorWidget->removeSelected();
231 * Checks whether there are some to delete
233 bool HYDROGUI_ProfileDlg::deleteEnabled()
235 return myEditorWidget->removeEnabled();
238 void HYDROGUI_ProfileDlg::processStartedSubOperation( QWidget* theWidget, bool theIsEdit )
240 myEditorWidget->setEnabled( false );
242 myAddElementBox->setTitle( theIsEdit ? tr( "EDIT_ELEMENT" ) : tr( "ADD_ELEMENT" ) );
243 QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
244 anAddElementLayout->addWidget( theWidget );
247 myAddElementBox->show();
250 void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
252 myEditorWidget->setEnabled( true );
254 QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
255 anAddElementLayout->removeWidget( theWidget );
258 myAddElementBox->hide();
261 void HYDROGUI_ProfileDlg::ProfileNameChanged(QString text)
263 myCurrentName = text;
266 void HYDROGUI_ProfileDlg::onProfileIndexChanged()
268 int theIndex = GetProfileSelectionIndex();
270 SwitchToProfile(theIndex);
273 int HYDROGUI_ProfileDlg::GetProfileSelectionIndex()
275 if (!myProfilesPointer)
277 QModelIndexList MI = myProfileNames->selectionModel()->selectedIndexes();
280 return MI.first().row();
283 void HYDROGUI_ProfileDlg::BlockProfileNameSignals(bool state)
285 myProfileNames->blockSignals(state);
288 void HYDROGUI_ProfileDlg::SwitchToProfile(int theIndex)
290 myEditorWidget->setCurve(NULL);
291 myEditorWidget->reset();
292 myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
293 myEditorWidget->setSelectedSections(QList<int>());
294 setProfile( (*myProfilesPointer)[theIndex] );
295 for (int i = 0; i < myProfilesPointer->size(); i++)
297 HYDROGUI_CurveCreatorProfile* aCurve = (*myProfilesPointer)[i];
300 aCurve->myLineWidth = 3;
301 Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
303 anAISObject->SetWidth(3);
307 aCurve->myLineWidth = 1;
308 Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
310 anAISObject->SetWidth(1);
314 if( myProfilesPointer &&
315 myProfilesPointer->size()>0 &&
316 myProfilesPointer->at(0) &&
317 myProfilesPointer->at(0)->getDisplayer() )
318 myProfilesPointer->at(0)->getDisplayer()->Update();
321 void HYDROGUI_ProfileDlg::onAddBtnPressed(bool)
326 void HYDROGUI_ProfileDlg::onRemoveBtnPressed(bool)
328 int theIndex = GetProfileSelectionIndex();
330 emit RemoveProfile(theIndex);
333 void HYDROGUI_ProfileDlg::onProfileNameChanged(QListWidgetItem* item)
335 int ind = GetProfileSelectionIndex();
338 int count = myProfileNames->count();
340 for (int i = 0; i < count; i++)
342 QListWidgetItem* citem = myProfileNames->item(i);
344 names << citem->text();
346 QString curText = item->text();
347 myProfileNames->blockSignals(true);
348 if (names.contains(curText))
350 QString mes = tr( "PROFILE_ALREADY_EXISTS" );
351 QString title = tr( "PROFILEDLG_WARNING" );
353 SUIT_MessageBox::warning( module()->getApp()->desktop(), title, mes );
355 item->setText(myCurrentName);
357 myProfileNames->blockSignals(false);
361 void HYDROGUI_ProfileDlg::SetSingleProfileMode(bool SingleMode)
363 mySingleProfileMode = SingleMode;
366 bool HYDROGUI_ProfileDlg::GetSingleProfileMode() const
368 return mySingleProfileMode;
371 Handle(AIS_Trihedron) HYDROGUI_ProfileDlg::trihedron()
373 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
374 Handle(AIS_Trihedron) aTrihedron =
375 HYDROGUI_AISTrihedron::createTrihedron( aResMgr->doubleValue( "3DViewer", "trihedron_size", viewer()->trihedronSize() ) );