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
148 myProfileNames->clear();
151 void HYDROGUI_ProfileDlg::setProfileName( const QString& theName )
153 if (!mySingleProfileMode)
155 myName->setText(theName);
156 //myProfileNames->setItemText(theInd, theName); //should used TODO check this
157 //myName->setText(theName);
160 void HYDROGUI_ProfileDlg::eraseProfile( int index )
162 myProfileNames->takeItem(index);
165 void HYDROGUI_ProfileDlg::addProfileName( const QString& theName, const QColor& theColor )
167 if (mySingleProfileMode)
169 myProfileNames->blockSignals(true);
170 myProfileNames->addItem(theName);
171 int count = myProfileNames->count();
172 QListWidgetItem* anItem = myProfileNames->item(count - 1);
173 anItem->setFlags (anItem->flags () | Qt::ItemIsEditable);
174 QPixmap SPixmap(16, 16);
175 SPixmap.fill(theColor);
176 QIcon SIcon(SPixmap);
177 anItem->setIcon( SIcon );
178 //anItem->setBackground(QBrush(theColor));
180 anItem->setSelected(true);
181 myProfileNames->blockSignals(false);
184 QStringList HYDROGUI_ProfileDlg::getProfileNames() const
186 QStringList aProfNames;
187 if (mySingleProfileMode)
188 aProfNames << myName->text();
190 for (int i = 0; i < myProfileNames->count(); i++)
191 aProfNames << myProfileNames->item(i)->text();
195 void HYDROGUI_ProfileDlg::setProfile( CurveCreator_ICurve* theProfile )
197 myEditorWidget->setCurve( theProfile );
199 // select the single section by default
200 QList<int> aSections;
202 myEditorWidget->setSelectedSections( aSections );
205 void HYDROGUI_ProfileDlg::setProfilesPointer(std::vector<HYDROGUI_CurveCreatorProfile*>* theProfilesPointer)
207 myProfilesPointer = theProfilesPointer;
210 QList<int> HYDROGUI_ProfileDlg::getSelectedSections()
212 return myEditorWidget->getSelectedSections();
215 void HYDROGUI_ProfileDlg::switchToFirstProfile()
217 emit onProfileIndexChanged();
221 * Redirect the delete action to editor widget
223 void HYDROGUI_ProfileDlg::deleteSelected()
225 myEditorWidget->removeSelected();
229 * Checks whether there are some to delete
231 bool HYDROGUI_ProfileDlg::deleteEnabled()
233 return myEditorWidget->removeEnabled();
236 void HYDROGUI_ProfileDlg::processStartedSubOperation( QWidget* theWidget, bool theIsEdit )
238 myEditorWidget->setEnabled( false );
240 myAddElementBox->setTitle( theIsEdit ? tr( "EDIT_ELEMENT" ) : tr( "ADD_ELEMENT" ) );
241 QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
242 anAddElementLayout->addWidget( theWidget );
245 myAddElementBox->show();
248 void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
250 myEditorWidget->setEnabled( true );
252 QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
253 anAddElementLayout->removeWidget( theWidget );
256 myAddElementBox->hide();
259 //void HYDROGUI_ProfileDlg::ProfileNameChanged(QString theNewText)
261 // myProfileNames->setItemText( myProfileNames->currentIndex(), theNewText ); //TODO???
264 void HYDROGUI_ProfileDlg::onProfileIndexChanged()
266 int theIndex = GetProfileSelectionIndex();
268 SwitchToProfile(theIndex);
271 int HYDROGUI_ProfileDlg::GetProfileSelectionIndex()
273 if (!myProfilesPointer)
275 QModelIndexList MI = myProfileNames->selectionModel()->selectedIndexes();
278 return MI.first().row();
281 void HYDROGUI_ProfileDlg::BlockProfileNameSignals(bool state)
283 myProfileNames->blockSignals(state);
286 void HYDROGUI_ProfileDlg::SwitchToProfile(int theIndex)
288 myEditorWidget->setCurve(NULL);
289 myEditorWidget->reset();
290 myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
291 myEditorWidget->setSelectedSections(QList<int>());
292 setProfile( (*myProfilesPointer)[theIndex] );
293 for (int i = 0; i < myProfilesPointer->size(); i++)
295 HYDROGUI_CurveCreatorProfile* aCurve = (*myProfilesPointer)[i];
298 aCurve->myLineWidth = 3;
299 Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
301 anAISObject->SetWidth(3);
305 aCurve->myLineWidth = 1;
306 Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
308 anAISObject->SetWidth(1);
311 (*myProfilesPointer)[0]->getDisplayer()->Update();
314 void HYDROGUI_ProfileDlg::onAddBtnPressed(bool)
319 void HYDROGUI_ProfileDlg::onRemoveBtnPressed(bool)
321 int theIndex = GetProfileSelectionIndex();
323 emit RemoveProfile(theIndex);
326 void HYDROGUI_ProfileDlg::onProfileNameChanged(QListWidgetItem* item)
328 int ind = GetProfileSelectionIndex();
331 QString text = item->text();
334 void HYDROGUI_ProfileDlg::SetSingleProfileMode(bool SingleMode)
336 mySingleProfileMode = SingleMode;
339 bool HYDROGUI_ProfileDlg::GetSingleProfileMode() const
341 return mySingleProfileMode;
344 Handle(AIS_Trihedron) HYDROGUI_ProfileDlg::trihedron()
346 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
347 Handle(AIS_Trihedron) aTrihedron =
348 HYDROGUI_AISTrihedron::createTrihedron( aResMgr->doubleValue( "3DViewer", "trihedron_size", viewer()->trihedronSize() ) );