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_Tool2.h"
27 #include <CurveCreator_Widget.h>
28 #include <CurveCreator_ICurve.hxx>
29 #include <CurveCreator_Utils.hxx>
30 #include <HYDROGUI_CurveCreatorProfile.h>
31 #include <CurveCreator_Displayer.hxx>
33 #include <OCCViewer_ViewPort3d.h>
34 #include <OCCViewer_Utilities.h>
35 #include <OCCViewer_ViewManager.h>
36 #include <OCCViewer_ViewFrame.h>
39 #include <LightApp_Application.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_ResourceMgr.h>
46 #include <QHBoxLayout>
49 #include <QMouseEvent>
52 #include <QListWidget>
53 #include <QPushButton>
56 const QString splitter_key = "HYDROGUI_ProfileDlg::splitter";
58 HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle,
59 bool theSingleProfileMode )
60 : HYDROGUI_ViewerDlg( theModule, theTitle, true ),
61 myName( NULL ), myProfileNames (NULL), myProfilesPointer (NULL),
62 mySingleProfileMode (theSingleProfileMode)
64 QFrame* name_frame = new QFrame( mainFrame() );
65 QHBoxLayout* name_layout = new QHBoxLayout( name_frame );
66 name_layout->setMargin( 0 );
67 QLabel* aNameLabel = new QLabel(tr("PROFILE_NAME_TLT"), this);
68 name_layout->addWidget(aNameLabel);
69 if (theSingleProfileMode)
71 myName = new QLineEdit(this);
72 name_layout->addWidget(myName);
76 myProfileNames = new QListWidget(this);
77 myProfileNames->setSelectionMode(QAbstractItemView::SingleSelection);
78 //myProfileNames->setEditable(true);
79 //myProfileNames->setInsertPolicy(QComboBox::InsertPolicy::NoInsert);
80 name_layout->addWidget(myProfileNames);
82 myAddProfBtn = new QPushButton("Add Profile(s)", this);
83 myRemProfBtn = new QPushButton("Remove Profile(s)", this);
84 name_layout->addWidget(myAddProfBtn);
85 name_layout->addWidget(myRemProfBtn);
88 insertWidget( name_frame, 0, 0 );
91 CurveCreator_Widget::DisableNewSection | CurveCreator_Widget::DisableDetectionMode |
92 CurveCreator_Widget::DisableClosedSection;
93 QStringList aCoordTitles;
94 aCoordTitles << tr( "U_TITLE" ) << tr( "Z_TITLE" );
95 myEditorWidget = new CurveCreator_Widget( this, NULL, anActionFlags, aCoordTitles );
96 insertWidget( myEditorWidget, 1, 1 );
98 myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this );
99 insertWidget( myAddElementBox, 2, 1 );
101 QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox );
102 anAddElementLayout->setMargin( 0 );
103 anAddElementLayout->setSpacing( 5 );
105 myEditorWidget->setOCCViewer( viewer() );
107 connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
108 connect( myEditorWidget, SIGNAL( subOperationStarted(QWidget*, bool) ), this, SLOT( processStartedSubOperation(QWidget*, bool) ) );
109 connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) );
110 if (!mySingleProfileMode)
112 //connect( myProfileNames, SIGNAL( currentTextChanged(QString)), SLOT(ProfileNameChanged(QString)) );
113 connect( myProfileNames, SIGNAL( itemSelectionChanged()), this, SLOT( onProfileIndexChanged()));
114 connect( myProfileNames, SIGNAL( itemChanged(QListWidgetItem*)), this, SLOT( onProfileNameChanged(QListWidgetItem*)));
115 connect( myAddProfBtn, SIGNAL( clicked(bool)), this, SLOT( onAddBtnPressed(bool)));
116 connect( myRemProfBtn, SIGNAL( clicked(bool)), this, SLOT( onRemoveBtnPressed(bool)));
118 myAddElementBox->hide();
126 splitter()->setSizes( sizes );
130 splitter()->restoreState( settings.value( splitter_key ).toByteArray() );
134 HYDROGUI_ProfileDlg::~HYDROGUI_ProfileDlg()
138 settings.setValue( splitter_key, splitter()->saveState() );
142 void HYDROGUI_ProfileDlg::reset()
144 myEditorWidget->reset();
145 myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
146 viewer()->setTrihedronShown( false ); // Issue #548
147 myProfileNames->clear();
150 void HYDROGUI_ProfileDlg::setProfileName( const QString& theName )
152 if (!mySingleProfileMode)
154 myName->setText(theName);
155 //myProfileNames->setItemText(theInd, theName); //should used TODO check this
156 //myName->setText(theName);
159 void HYDROGUI_ProfileDlg::eraseProfile( int index )
161 myProfileNames->takeItem(index);
164 void HYDROGUI_ProfileDlg::addProfileName( const QString& theName, const QColor& theColor )
166 if (mySingleProfileMode)
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 );
177 //anItem->setBackground(QBrush(theColor));
179 anItem->setSelected(true);
180 myProfileNames->blockSignals(false);
183 QStringList HYDROGUI_ProfileDlg::getProfileNames() const
185 QStringList aProfNames;
186 if (mySingleProfileMode)
187 aProfNames << myName->text();
189 for (int i = 0; i < myProfileNames->count(); i++)
190 aProfNames << myProfileNames->item(i)->text();
194 void HYDROGUI_ProfileDlg::setProfile( CurveCreator_ICurve* theProfile )
196 myEditorWidget->setCurve( theProfile );
198 // select the single section by default
199 QList<int> aSections;
201 myEditorWidget->setSelectedSections( aSections );
204 void HYDROGUI_ProfileDlg::setProfilesPointer(std::vector<HYDROGUI_CurveCreatorProfile*>* theProfilesPointer)
206 myProfilesPointer = theProfilesPointer;
209 QList<int> HYDROGUI_ProfileDlg::getSelectedSections()
211 return myEditorWidget->getSelectedSections();
214 void HYDROGUI_ProfileDlg::switchToFirstProfile()
216 emit onProfileIndexChanged();
220 * Redirect the delete action to editor widget
222 void HYDROGUI_ProfileDlg::deleteSelected()
224 myEditorWidget->removeSelected();
228 * Checks whether there are some to delete
230 bool HYDROGUI_ProfileDlg::deleteEnabled()
232 return myEditorWidget->removeEnabled();
235 void HYDROGUI_ProfileDlg::processStartedSubOperation( QWidget* theWidget, bool theIsEdit )
237 myEditorWidget->setEnabled( false );
239 myAddElementBox->setTitle( theIsEdit ? tr( "EDIT_ELEMENT" ) : tr( "ADD_ELEMENT" ) );
240 QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
241 anAddElementLayout->addWidget( theWidget );
244 myAddElementBox->show();
247 void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
249 myEditorWidget->setEnabled( true );
251 QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
252 anAddElementLayout->removeWidget( theWidget );
255 myAddElementBox->hide();
258 //void HYDROGUI_ProfileDlg::ProfileNameChanged(QString theNewText)
260 // myProfileNames->setItemText( myProfileNames->currentIndex(), theNewText ); //TODO???
263 void HYDROGUI_ProfileDlg::onProfileIndexChanged()
265 int theIndex = GetProfileSelectionIndex();
267 SwitchToProfile(theIndex);
270 int HYDROGUI_ProfileDlg::GetProfileSelectionIndex()
272 if (!myProfilesPointer)
274 QModelIndexList MI = myProfileNames->selectionModel()->selectedIndexes();
277 return MI.first().row();
280 void HYDROGUI_ProfileDlg::BlockProfileNameSignals(bool state)
282 myProfileNames->blockSignals(state);
285 void HYDROGUI_ProfileDlg::SwitchToProfile(int theIndex)
287 myEditorWidget->setCurve(NULL);
288 myEditorWidget->reset();
289 myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
290 myEditorWidget->setSelectedSections(QList<int>());
291 setProfile( (*myProfilesPointer)[theIndex] );
292 for (int i = 0; i < myProfilesPointer->size(); i++)
294 HYDROGUI_CurveCreatorProfile* aCurve = (*myProfilesPointer)[i];
297 aCurve->myLineWidth = 3;
298 Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
300 anAISObject->SetWidth(3);
304 aCurve->myLineWidth = 1;
305 Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
307 anAISObject->SetWidth(1);
310 (*myProfilesPointer)[0]->getDisplayer()->Update();
313 void HYDROGUI_ProfileDlg::onAddBtnPressed(bool)
318 void HYDROGUI_ProfileDlg::onRemoveBtnPressed(bool)
320 int theIndex = GetProfileSelectionIndex();
322 emit RemoveProfile(theIndex);
325 void HYDROGUI_ProfileDlg::onProfileNameChanged(QListWidgetItem* item)
327 int ind = GetProfileSelectionIndex();
330 QString text = item->text();
333 void HYDROGUI_ProfileDlg::SetSingleProfileMode(bool SingleMode)
335 mySingleProfileMode = SingleMode;
338 bool HYDROGUI_ProfileDlg::GetSingleProfileMode() const
340 return mySingleProfileMode;
343 Handle(AIS_Trihedron) HYDROGUI_ProfileDlg::trihedron()
345 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
346 Handle(AIS_Trihedron) aTrihedron =
347 HYDROGUI_AISTrihedron::createTrihedron( aResMgr->doubleValue( "3DViewer", "trihedron_size", viewer()->trihedronSize() ) );