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_Module.h"
22 #include "HYDROGUI_Tool.h"
23 #include "HYDROGUI_AISTrihedron.h"
24 #include "HYDROGUI_Tool2.h"
26 #include <CurveCreator_Widget.h>
27 #include <CurveCreator_ICurve.hxx>
28 #include <CurveCreator_Utils.hxx>
29 #include <HYDROGUI_CurveCreatorProfile.h>
30 #include <CurveCreator_Displayer.hxx>
32 #include <OCCViewer_ViewPort3d.h>
33 #include <OCCViewer_Utilities.h>
34 #include <OCCViewer_ViewManager.h>
35 #include <OCCViewer_ViewFrame.h>
36 #include <LightApp_Application.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_ResourceMgr.h>
42 #include <QHBoxLayout>
45 #include <QMouseEvent>
48 #include <QListWidget>
49 #include <QPushButton>
52 const QString splitter_key = "HYDROGUI_ProfileDlg::splitter";
54 HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle,
55 bool theSingleProfileMode )
56 : HYDROGUI_ViewerDlg( theModule, theTitle, true ),
57 myName( NULL ), myProfileNames (NULL), myProfilesPointer (NULL),
58 mySingleProfileMode (theSingleProfileMode)
60 QFrame* name_frame = new QFrame( mainFrame() );
61 QHBoxLayout* name_layout = new QHBoxLayout( name_frame );
62 name_layout->setMargin( 0 );
63 QLabel* aNameLabel = new QLabel(tr("PROFILE_NAME_TLT"), this);
64 name_layout->addWidget(aNameLabel);
65 if (theSingleProfileMode)
67 myName = new QLineEdit(this);
68 name_layout->addWidget(myName);
72 myProfileNames = new QListWidget(this);
73 myProfileNames->setSelectionMode(QAbstractItemView::SingleSelection);
74 //myProfileNames->setEditable(true);
75 //myProfileNames->setInsertPolicy(QComboBox::InsertPolicy::NoInsert);
76 name_layout->addWidget(myProfileNames);
78 myAddProfBtn = new QPushButton("Add Profile(s)", this);
79 myRemProfBtn = new QPushButton("Remove Profile(s)", this);
80 name_layout->addWidget(myAddProfBtn);
81 name_layout->addWidget(myRemProfBtn);
84 insertWidget( name_frame, 0, 0 );
87 CurveCreator_Widget::DisableNewSection | CurveCreator_Widget::DisableDetectionMode |
88 CurveCreator_Widget::DisableClosedSection;
89 QStringList aCoordTitles;
90 aCoordTitles << tr( "U_TITLE" ) << tr( "Z_TITLE" );
91 myEditorWidget = new CurveCreator_Widget( this, NULL, anActionFlags, aCoordTitles );
92 insertWidget( myEditorWidget, 1, 1 );
94 myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this );
95 insertWidget( myAddElementBox, 2, 1 );
97 QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox );
98 anAddElementLayout->setMargin( 0 );
99 anAddElementLayout->setSpacing( 5 );
101 myEditorWidget->setOCCViewer( viewer() );
103 connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
104 connect( myEditorWidget, SIGNAL( subOperationStarted(QWidget*, bool) ), this, SLOT( processStartedSubOperation(QWidget*, bool) ) );
105 connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) );
106 if (!mySingleProfileMode)
108 //connect( myProfileNames, SIGNAL( currentTextChanged(QString)), SLOT(ProfileNameChanged(QString)) );
109 connect( myProfileNames, SIGNAL( itemSelectionChanged()), this, SLOT( onProfileIndexChanged()));
110 connect( myProfileNames, SIGNAL( itemChanged(QListWidgetItem*)), this, SLOT( onProfileNameChanged(QListWidgetItem*)));
111 connect( myAddProfBtn, SIGNAL( clicked(bool)), this, SLOT( onAddBtnPressed(bool)));
112 connect( myRemProfBtn, SIGNAL( clicked(bool)), this, SLOT( onRemoveBtnPressed(bool)));
114 myAddElementBox->hide();
122 splitter()->setSizes( sizes );
126 splitter()->restoreState( settings.value( splitter_key ).toByteArray() );
130 HYDROGUI_ProfileDlg::~HYDROGUI_ProfileDlg()
134 settings.setValue( splitter_key, splitter()->saveState() );
138 void HYDROGUI_ProfileDlg::reset()
140 myEditorWidget->reset();
141 myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
142 viewer()->setTrihedronShown( false ); // Issue #548
143 myProfileNames->clear();
146 void HYDROGUI_ProfileDlg::setProfileName( const QString& theName )
148 if (!mySingleProfileMode)
150 myName->setText(theName);
151 //myProfileNames->setItemText(theInd, theName); //should used TODO check this
152 //myName->setText(theName);
155 void HYDROGUI_ProfileDlg::eraseProfile( int index )
157 myProfileNames->takeItem(index);
160 void HYDROGUI_ProfileDlg::addProfileName( const QString& theName, const QColor& theColor )
162 if (mySingleProfileMode)
164 myProfileNames->blockSignals(true);
165 myProfileNames->addItem(theName);
166 int count = myProfileNames->count();
167 QListWidgetItem* anItem = myProfileNames->item(count - 1);
168 anItem->setFlags (anItem->flags () | Qt::ItemIsEditable);
169 QPixmap SPixmap(16, 16);
170 SPixmap.fill(theColor);
171 QIcon SIcon(SPixmap);
172 anItem->setIcon( SIcon );
173 //anItem->setBackground(QBrush(theColor));
175 anItem->setSelected(true);
176 myProfileNames->blockSignals(false);
179 QStringList HYDROGUI_ProfileDlg::getProfileNames() const
181 QStringList aProfNames;
182 if (mySingleProfileMode)
183 aProfNames << myName->text();
185 for (int i = 0; i < myProfileNames->count(); i++)
186 aProfNames << myProfileNames->item(i)->text();
190 void HYDROGUI_ProfileDlg::setProfile( CurveCreator_ICurve* theProfile )
192 myEditorWidget->setCurve( theProfile );
194 // select the single section by default
195 QList<int> aSections;
197 myEditorWidget->setSelectedSections( aSections );
200 void HYDROGUI_ProfileDlg::setProfilesPointer(std::vector<HYDROGUI_CurveCreatorProfile*>* theProfilesPointer)
202 myProfilesPointer = theProfilesPointer;
205 QList<int> HYDROGUI_ProfileDlg::getSelectedSections()
207 return myEditorWidget->getSelectedSections();
210 void HYDROGUI_ProfileDlg::switchToFirstProfile()
212 emit onProfileIndexChanged();
216 * Redirect the delete action to editor widget
218 void HYDROGUI_ProfileDlg::deleteSelected()
220 myEditorWidget->removeSelected();
224 * Checks whether there are some to delete
226 bool HYDROGUI_ProfileDlg::deleteEnabled()
228 return myEditorWidget->removeEnabled();
231 void HYDROGUI_ProfileDlg::processStartedSubOperation( QWidget* theWidget, bool theIsEdit )
233 myEditorWidget->setEnabled( false );
235 myAddElementBox->setTitle( theIsEdit ? tr( "EDIT_ELEMENT" ) : tr( "ADD_ELEMENT" ) );
236 QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
237 anAddElementLayout->addWidget( theWidget );
240 myAddElementBox->show();
243 void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
245 myEditorWidget->setEnabled( true );
247 QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
248 anAddElementLayout->removeWidget( theWidget );
251 myAddElementBox->hide();
254 //void HYDROGUI_ProfileDlg::ProfileNameChanged(QString theNewText)
256 // myProfileNames->setItemText( myProfileNames->currentIndex(), theNewText ); //TODO???
259 void HYDROGUI_ProfileDlg::onProfileIndexChanged()
261 int theIndex = GetProfileSelectionIndex();
263 SwitchToProfile(theIndex);
266 int HYDROGUI_ProfileDlg::GetProfileSelectionIndex()
268 if (!myProfilesPointer)
270 QModelIndexList MI = myProfileNames->selectionModel()->selectedIndexes();
273 return MI.first().row();
276 void HYDROGUI_ProfileDlg::BlockProfileNameSignals(bool state)
278 myProfileNames->blockSignals(state);
281 void HYDROGUI_ProfileDlg::SwitchToProfile(int theIndex)
283 myEditorWidget->setCurve(NULL);
284 myEditorWidget->reset();
285 myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
286 myEditorWidget->setSelectedSections(QList<int>());
287 setProfile( (*myProfilesPointer)[theIndex] );
288 for (int i = 0; i < myProfilesPointer->size(); i++)
290 HYDROGUI_CurveCreatorProfile* aCurve = (*myProfilesPointer)[i];
293 aCurve->myLineWidth = 3;
294 Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
296 anAISObject->SetWidth(3);
300 aCurve->myLineWidth = 1;
301 Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
303 anAISObject->SetWidth(1);
306 (*myProfilesPointer)[0]->getDisplayer()->Update();
309 void HYDROGUI_ProfileDlg::onAddBtnPressed(bool)
314 void HYDROGUI_ProfileDlg::onRemoveBtnPressed(bool)
316 int theIndex = GetProfileSelectionIndex();
318 emit RemoveProfile(theIndex);
321 void HYDROGUI_ProfileDlg::onProfileNameChanged(QListWidgetItem* item)
323 int ind = GetProfileSelectionIndex();
326 QString text = item->text();
329 void HYDROGUI_ProfileDlg::SetSingleProfileMode(bool SingleMode)
331 mySingleProfileMode = SingleMode;
334 bool HYDROGUI_ProfileDlg::GetSingleProfileMode() const
336 return mySingleProfileMode;
339 Handle(AIS_Trihedron) HYDROGUI_ProfileDlg::trihedron()
341 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
342 Handle(AIS_Trihedron) aTrihedron =
343 HYDROGUI_AISTrihedron::createTrihedron( aResMgr->doubleValue( "3DViewer", "trihedron_size", viewer()->trihedronSize() ) );